From d4f28b089b2818d23df8543db3130ac760f37ad8 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sat, 17 Oct 2026 15:12:01 +0000 Subject: test(extern): cover C library calls and EXTERN diagnostics Co-Authored-By: Claude Opus 5.5 --- tests/i/extern-libc/case.json | 3 +++ tests/i/extern-libc/expected.txt | 5 +++++ tests/i/extern-libc/notes.md | 7 +++++++ tests/i/extern-libc/program.cps | 18 ++++++++++++++++++ 4 files changed, 33 insertions(+) create mode 100644 tests/i/extern-libc/case.json create mode 100644 tests/i/extern-libc/expected.txt create mode 100644 tests/i/extern-libc/notes.md create mode 100644 tests/i/extern-libc/program.cps (limited to 'tests/i') diff --git a/tests/i/extern-libc/case.json b/tests/i/extern-libc/case.json new file mode 100644 index 0000000..1f18635 --- /dev/null +++ b/tests/i/extern-libc/case.json @@ -0,0 +1,3 @@ +{ + "exit_code": 0 +} diff --git a/tests/i/extern-libc/expected.txt b/tests/i/extern-libc/expected.txt new file mode 100644 index 0000000..6c94a8c --- /dev/null +++ b/tests/i/extern-libc/expected.txt @@ -0,0 +1,5 @@ +hello +5 +4.000000 +42 x 1.5 -7| +12 diff --git a/tests/i/extern-libc/notes.md b/tests/i/extern-libc/notes.md new file mode 100644 index 0000000..99fa615 --- /dev/null +++ b/tests/i/extern-libc/notes.md @@ -0,0 +1,7 @@ +# extern-libc + +Human review: pending. Expected output was independently traced by AI, not captured from cpsc. + +Basis: compiler extension (EXTERN "C", INCLUDE_OBJ "__libc"); C library semantics. + +Trace: srand(1) has no output. puts prints "hello" and a newline. abs(-5)=5. sqrt(16)=4.0 printed as REAL-style C double "%f". printf receives int 42, "x", float 1.5 promoted to double, short -7 promoted to int, prints "42 x 1.5 -7|" (12 characters) with no newline; OUTPUT "" ends that line, then 12 is printed. diff --git a/tests/i/extern-libc/program.cps b/tests/i/extern-libc/program.cps new file mode 100644 index 0000000..2204969 --- /dev/null +++ b/tests/i/extern-libc/program.cps @@ -0,0 +1,18 @@ +// C library calls through EXTERN, including variadic promotions. +INCLUDE_OBJ "__libc" +TYPE CFloat = C_TYPE("float") +TYPE CShort = C_TYPE("short") +EXTERN "C" EXTERN_FUNCTION printf(C_STRING, ...) RETURNS C_INT +EXTERN "C" EXTERN_FUNCTION puts(C_STRING) RETURNS C_INT +EXTERN "C" EXTERN_FUNCTION abs(C_INT) RETURNS C_INT +EXTERN "C" EXTERN_FUNCTION sqrt(C_DOUBLE) RETURNS C_DOUBLE +TYPE CUnsigned = C_TYPE("unsigned int") +EXTERN "C" EXTERN_PROCEDURE srand(CUnsigned) +CALL srand((CUnsigned)1) +DECLARE Count : C_INT +CALL puts((C_STRING)"hello") +OUTPUT abs((C_INT)-5) +OUTPUT sqrt((C_DOUBLE)16) +Count <- printf((C_STRING)"%d %s %.1f %d|", (C_INT)42, (C_STRING)"x", (CFloat)1.5, (CShort)-7) +OUTPUT "" +OUTPUT Count -- cgit v1.3.1-4-g156e