summaryrefslogtreecommitdiff
path: root/chapter-modules/src/main/c/simple_crt.c
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-10-24 15:25:58 -0700
committerCliff Click <cliffc@acm.org>2026-10-24 15:25:58 -0700
commit4ae6a06d94b228a5eb67c8473131a791e310c233 (patch)
tree839dfa84f1bfb982122ce62183b6ae4145a4c615 /chapter-modules/src/main/c/simple_crt.c
parentc4364363dbd969c9aa27aa7c43fbe6d40544501a (diff)
downloadSimple-4ae6a06d94b228a5eb67c8473131a791e310c233.tar.gz
Simple-4ae6a06d94b228a5eb67c8473131a791e310c233.zip
Rename modules chapter to 28a
Diffstat (limited to 'chapter-modules/src/main/c/simple_crt.c')
-rw-r--r--chapter-modules/src/main/c/simple_crt.c61
1 files changed, 0 insertions, 61 deletions
diff --git a/chapter-modules/src/main/c/simple_crt.c b/chapter-modules/src/main/c/simple_crt.c
deleted file mode 100644
index 8656a3cc..00000000
--- a/chapter-modules/src/main/c/simple_crt.c
+++ /dev/null
@@ -1,61 +0,0 @@
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-// errno may be thread-local or a macro calling a platform accessor.
-int32_t simple_errno(void) { return errno; }
-
-// Native process arguments converted to ordinary Simple array layouts.
-// The outer array is mutable; every contained byte array is published as
-// immutable and non-null to Simple code.
-typedef struct SimpleBytes {
- uint32_t len;
- unsigned char bytes[];
-} SimpleBytes;
-
-typedef struct SimpleArgs {
- uint32_t len;
- uint32_t pad;
- SimpleBytes *args[];
-} SimpleArgs;
-
-__attribute__((CALL_CONV))
-extern int64_t simple_main(SimpleArgs *args);
-
-static SimpleArgs *simple_args(int argc, char **argv) {
- if (argc < 0 || (uint64_t)argc > UINT32_MAX)
- return NULL;
-
- SimpleArgs *args = calloc(1, sizeof(*args) + (size_t)argc * sizeof(args->args[0]));
- if (args == NULL)
- return NULL;
- args->len = (uint32_t)argc;
-
- for (int i = 0; i < argc; i++) {
- size_t len = strlen(argv[i]);
- if (len > UINT32_MAX) {
- free(args);
- return NULL;
- }
- SimpleBytes *str = malloc(sizeof(*str) + len);
- if (str == NULL) {
- for (int j = 0; j < i; j++) free(args->args[j]);
- free(args);
- return NULL;
- }
- str->len = (uint32_t)len;
- memcpy(str->bytes, argv[i], len);
- args->args[i] = str;
- }
- return args;
-}
-
-int main(int argc, char **argv) {
- SimpleArgs *args = simple_args(argc, argv);
- if (args == NULL)
- return 1;
- // The language-level hidden receiver is not part of the emitted ABI for
- // free functions; source argument zero occupies native argument zero.
- return (int)simple_main(args);
-}