summaryrefslogtreecommitdiff
path: root/chapter31/src/main/smp/sys/rt
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-11-08 14:20:21 -0800
committerCliff Click <cliffc@acm.org>2026-11-12 13:48:30 -0800
commit6fb3aac50c642ed73ec78e9ceb6e04b127796abb (patch)
treeb0f3df12b85add20a34cfe839bdfdba272237d9a /chapter31/src/main/smp/sys/rt
parent394f0aba21eb7a73a00014b3ffcf2ad21eeb8e21 (diff)
downloadSimple-6fb3aac50c642ed73ec78e9ceb6e04b127796abb.tar.gz
Simple-6fb3aac50c642ed73ec78e9ceb6e04b127796abb.zip
Start Chapter 31 from the completed Chapter 30 compiler
Diffstat (limited to 'chapter31/src/main/smp/sys/rt')
-rw-r--r--chapter31/src/main/smp/sys/rt/simple_args.smp22
1 files changed, 22 insertions, 0 deletions
diff --git a/chapter31/src/main/smp/sys/rt/simple_args.smp b/chapter31/src/main/smp/sys/rt/simple_args.smp
new file mode 100644
index 00000000..3f630e54
--- /dev/null
+++ b/chapter31/src/main/smp/sys/rt/simple_args.smp
@@ -0,0 +1,22 @@
+// Native startup support, compiled independently and linked with the CRT.
+// Raw native addresses stay i64; only the arrays allocated here are Simple objects.
+{ i64 i64 -> i64 } simple_argv = "C";
+{ i64 -> i64 } strlen = "C";
+{ i64 i64 i64 -> i64 } memcpy = "C";
+
+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<argc; i++ ) {
+ i64 src = simple_argv(argv,i);
+ i64 len = strlen(src);
+ if( len < 0 || len > 4294967295 ) return null;
+ val bytes = new u8[len];
+ i64 dst = bytes;
+ memcpy(dst,src,len);
+ args[i] = bytes;
+ }
+ return args;
+};