From 790268f4a1f6122376c34059f1633c1017436363 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Mon, 10 Aug 2026 11:11:18 -0700 Subject: Chapter 31: Software Drawing, Time, and Graphical Games Co-authored-by: Hsiang-Ying Fu <66062782+fuhsnn@users.noreply.github.com> Co-authored-by: fuhsnn <66062782+fuhsnn@users.noreply.github.com> Co-authored-by: Symious <14933944+symious@users.noreply.github.com> Co-authored-by: Jun Kawasaki Co-authored-by: Claude Opus 5 --- src/main/smp/sys/rt/simple_args.smp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src/main/smp/sys/rt') diff --git a/src/main/smp/sys/rt/simple_args.smp b/src/main/smp/sys/rt/simple_args.smp index 3f630e54..6f857d91 100644 --- a/src/main/smp/sys/rt/simple_args.smp +++ b/src/main/smp/sys/rt/simple_args.smp @@ -1,22 +1,24 @@ // Native startup support, compiled independently and linked with the CRT. // Raw native addresses stay i64; only the arrays allocated here are Simple objects. +// This startup object is built without sys imports. +u32 _MAX_U32 = (1<<32)-1; { i64 i64 -> i64 } simple_argv = "C"; { i64 -> i64 } strlen = "C"; { i64 i64 i64 -> i64 } memcpy = "C"; +// Returns a constant argc-length array, filled with not-null constant u8 +// arrays. val simple_args = { i64 argc, i64 argv -> - if( argc < 0 || argc > 4294967295 ) return null; - // Zero-filled reference arrays require nullable elements. Every slot is - // filled before returning; the native entry bridge publishes u8[~][]. - val args = new u8[~]?[argc]; - for( i64 i=0; i _MAX_U32 ) return null; + // Build an initialized + return new u8[][argc] { int i -> i64 src = simple_argv(argv,i); i64 len = strlen(src); - if( len < 0 || len > 4294967295 ) return null; + if( !(0 < len <= _MAX_U32) ) // If not the u32 range, just use zero-length + len = 0; val bytes = new u8[len]; i64 dst = bytes; - memcpy(dst,src,len); - args[i] = bytes; - } - return args; + memcpy(dst,src,len); // Copy from C memory to Simple memory + return bytes; + }; }; -- cgit v1.2.3