diff options
| author | Cliff Click <cliffc@acm.org> | 2026-11-08 14:10:02 -0800 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-11-08 14:10:02 -0800 |
| commit | 06fb5aceeb65a75b1cd643debd667c52fdcafcb9 (patch) | |
| tree | c99813eaf27d98f840245302c4d6e923c964307e /chapter30/src/main/smp/sys/rt/simple_args.smp | |
| parent | 6560a92433a38825fd1d44d9c66ffba9f26990ff (diff) | |
| download | Simple-ch30.tar.gz Simple-ch30.zip | |
Better error messagesch30
Better error messages.
Buffs to the std lib; getch() to fetch a single character; streaming I/O handles retries, and large sizes, with better error reporting.
Formatted strings.
Default int moved to i32.
TicTacToe, the game.
Diffstat (limited to 'chapter30/src/main/smp/sys/rt/simple_args.smp')
| -rw-r--r-- | chapter30/src/main/smp/sys/rt/simple_args.smp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/chapter30/src/main/smp/sys/rt/simple_args.smp b/chapter30/src/main/smp/sys/rt/simple_args.smp new file mode 100644 index 00000000..3f630e54 --- /dev/null +++ b/chapter30/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; +}; |
