summaryrefslogtreecommitdiff
path: root/chapter31/src/main/smp
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-11-15 16:11:39 -0800
committerCliff Click <cliffc@acm.org>2026-11-15 16:11:39 -0800
commit9fe7c6f9697b5bbf3041261fdc60040e75cc674f (patch)
treed92a8ff20ed984938d90ad8917b4d67fba9fb745 /chapter31/src/main/smp
parentf0a6c6757a795b8e186de0076836a87acef59fa7 (diff)
downloadSimple-ch32.tar.gz
Simple-ch32.zip
Split off chapter 31ch32
Ch 32 will be focused on compiler performance issues.
Diffstat (limited to 'chapter31/src/main/smp')
-rw-r--r--chapter31/src/main/smp/sys/rt/simple_args.smp18
1 files changed, 9 insertions, 9 deletions
diff --git a/chapter31/src/main/smp/sys/rt/simple_args.smp b/chapter31/src/main/smp/sys/rt/simple_args.smp
index 8bfcc1a7..6f857d91 100644
--- a/chapter31/src/main/smp/sys/rt/simple_args.smp
+++ b/chapter31/src/main/smp/sys/rt/simple_args.smp
@@ -6,19 +6,19 @@ u32 _MAX_U32 = (1<<32)-1;
{ 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 > _MAX_U32 ) 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 < argc; i++ ) {
+ // Build an initialized
+ return new u8[][argc] { int i ->
i64 src = simple_argv(argv,i);
i64 len = strlen(src);
- if( len < 0 || len > _MAX_U32 ) 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;
+ };
};