From 312a19c781da1c31ff1e3dc71c319663a8be9148 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Thu, 22 Oct 2026 13:56:44 +0000 Subject: feat(codegen): accept pointer types to any C type in EXTERN A pseudocode pointer type now counts as a C type, in EXTERN signatures and as a C-struct field, when it finally points to a non-void C type or a C struct, as in TYPE PInt = ^C_INT. A pointer cycle such as TYPE P = ^P and a pointer to a pseudocode type stay rejected. Co-Authored-By: Claude Opus 5.5 --- tests/i/extern-c-struct/program.cps | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'tests/i/extern-c-struct/program.cps') diff --git a/tests/i/extern-c-struct/program.cps b/tests/i/extern-c-struct/program.cps index bcb7af4..62370d3 100644 --- a/tests/i/extern-c-struct/program.cps +++ b/tests/i/extern-c-struct/program.cps @@ -1,4 +1,4 @@ -// Records whose fields are C types pass to C functions through pointer types. +// Records whose fields are C types, and pointer types to C types, pass to C functions. INCLUDE_OBJ "lib.o" TYPE Sample DECLARE Tag : C_CHAR @@ -6,13 +6,25 @@ TYPE Sample DECLARE Count : C_INT ENDTYPE TYPE PSample = ^Sample +TYPE PPSample = ^PSample +TYPE PInt = ^C_INT +TYPE Counter + DECLARE Target : PInt +ENDTYPE +TYPE PCounter = ^Counter EXTERN "C" EXTERN_PROCEDURE scale_sample(PSample, C_INT) EXTERN "C" EXTERN_FUNCTION shared_sample() RETURNS PSample EXTERN "C" EXTERN_FUNCTION shared_count() RETURNS C_INT EXTERN "C" EXTERN_FUNCTION sum_counts(C_INT, ...) RETURNS C_INT +EXTERN "C" EXTERN_PROCEDURE bump(PInt) +EXTERN "C" EXTERN_PROCEDURE bump_counter(PCounter) +EXTERN "C" EXTERN_PROCEDURE get_shared(PPSample) DECLARE S : Sample DECLARE P : PSample DECLARE Q : PSample +DECLARE R : PSample +DECLARE N : C_INT +DECLARE C : Counter S.Tag <- (C_CHAR)'S' S.Value <- (C_DOUBLE)1.5 S.Count <- (C_INT)5 @@ -24,3 +36,10 @@ P^.Count <- (C_INT)9 OUTPUT shared_count() Q <- ^S OUTPUT sum_counts((C_INT)2, P, Q) +N <- (C_INT)1 +CALL bump(^N) +C.Target <- ^N +CALL bump_counter(^C) +OUTPUT N +CALL get_shared(^R) +OUTPUT R^.Tag, " ", R^.Count -- cgit v1.3.1-4-g156e