@@ -210,6 +210,32 @@ __poll :: (fds: [] PollDescription, timeout: i32) -> void {
210
210
}
211
211
}
212
212
213
+ __args :: (allocator: Allocator) -> [] cstr {
214
+ args : [] cstr;
215
+ argv_buf_size : i32;
216
+ args_sizes_get(&args.count, &argv_buf_size);
217
+
218
+ args = make(cstr, args.count, allocator);
219
+ argv_buf := cast([&] u8) allocator->alloc(argv_buf_size);
220
+ args_get(args.data, argv_buf);
221
+
222
+ // This post processing of the argv array needs to happen if the target is using
223
+ // 32-bit pointers, instead of 64-bits. Right now, Onyx pointers take up 64-bits,
224
+ // but in most circumstances, only the lower 32-bits are used. When webassembly
225
+ // standardizes the 64-bit address space, it will be an easy conversion over.
226
+ // But for right now, WASI will give the argv array 32-bit pointers, instead of
227
+ // 64-bit pointers. This loops expands the 32-bit pointers into 64-bit pointers
228
+ // while not clobbering any of them.
229
+ // while i := cast(i32) (args.count - 1); i >= 0 {
230
+ // defer i -= 1;
231
+
232
+ // args[i] = cast(cstr) (cast([&] u32) args.data)[i];
233
+ // }
234
+
235
+ return args;
236
+ }
237
+
238
+
213
239
214
240
// Sets up everything needed for execution.
215
241
__start :: () {
@@ -220,28 +246,7 @@ __start :: () {
220
246
MAIN_PKG.main();
221
247
222
248
} else {
223
- args : [] cstr;
224
- argv_buf_size : Size;
225
- args_sizes_get(&args.count, &argv_buf_size);
226
-
227
- args = core.memory.make_slice(cstr, args.count);
228
- argv_buf := cast(cstr) calloc(argv_buf_size);
229
- args_get(args.data, argv_buf);
230
-
231
-
232
- // This post processing of the argv array needs to happen if the target is using
233
- // 32-bit pointers, instead of 64-bits. Right now, Onyx pointers take up 64-bits,
234
- // but in most circumstances, only the lower 32-bits are used. When webassembly
235
- // standardizes the 64-bit address space, it will be an easy conversion over.
236
- // But for right now, WASI will give the argv array 32-bit pointers, instead of
237
- // 64-bit pointers. This loops expands the 32-bit pointers into 64-bit pointers
238
- // while not clobbering any of them.
239
- while i := cast(i32) (args.count - 1); i >= 0 {
240
- defer i -= 1;
241
-
242
- args[i] = cast(cstr) (cast([&] u32) args.data)[i];
243
- }
244
-
249
+ args := __args(context.allocator);
245
250
MAIN_PKG.main(args);
246
251
}
247
252
0 commit comments