# HG changeset patch # User Leonard Ritter # Date 1736951118 -3600 # Wed Jan 15 15:25:18 2025 +0100 # Node ID 2331b49805b9e905d50ce9bd4b243c2376d2f7f1 # Parent 6b2e7f79a878a2091628a088e0b7a07ea04e0874 * compiler.C: generate struct declarations before procs diff --git a/include/noir.h b/include/noir.h --- a/include/noir.h +++ b/include/noir.h @@ -198,7 +198,9 @@ NOIR_DEFINED_FROM(X, P) \ NOIR_ID_V(X) = NOIR_CAST(P, NOIR_ID_T(X)); -#define NOIR_instance(X, PID, ...) +#define NOIR_instance(X, PID, ...) \ + NOIR_DEFINED(X) \ + NOIR_RCAST(X, NOIR_ptr) = malloc(sizeof(NOIR_STRUCT_T(PID))); #define NOIR_msizeof(X, P) \ NOIR_DEFINED(X) \ NOIR_RCAST(X, size_t) = arcsize(NOIR_CAST(P, NOIR_ptr)); diff --git a/lib/scopes/compiler/noir/target/C.sc b/lib/scopes/compiler/noir/target/C.sc --- a/lib/scopes/compiler/noir/target/C.sc +++ b/lib/scopes/compiler/noir/target/C.sc @@ -326,6 +326,11 @@ print /pn /C:call "NOIR_STRUCT_END" + + for proc in self.proc + procid := proc.id + /procid := /id procid + PT := 'schemaof module-index procid proc-order := 'scheduleof module-index procid inline sizeofvalue (id) diff --git a/testing/noir/hello.sc b/testing/noir/hello.sc --- a/testing/noir/hello.sc +++ b/testing/noir/hello.sc @@ -17,11 +17,14 @@ TRACE COUNTOF y +macro testf : + pcall printf_s32_s32_s32 printf "hell(o) world! %i %i %i\n" x + fn main : s32 argc : s32 argv : ptr do - pcall printf_s32_s32_s32 printf "hell(o) world! %i %i %i\n" x + testf; if (ieq argc 2) pcall printf_ printf "two arguments passed\n" else