about summary refs log tree commit diff
path: root/boot/catboot.c
diff options
context:
space:
mode:
Diffstat (limited to 'boot/catboot.c')
-rw-r--r--boot/catboot.c56
1 files changed, 33 insertions, 23 deletions
diff --git a/boot/catboot.c b/boot/catboot.c
index ae0fc6c..b36bb97 100644
--- a/boot/catboot.c
+++ b/boot/catboot.c
@@ -1,43 +1,53 @@
+/*
+ * # catboot
+ *
+ * the bootstrap compiler for catskill,
+ * implemented as simply as possible,
+ * depending only on the C standard library,
+ * in this case musl, and built statically
+ * in a single union build.
+ *
+ * should only be used to compile `catskill` itself,
+ * as it is not a full-featured compiler, and never will be.
+ * once `catskill` can compile itself using a C backend,
+ * this compiler version will be permanently retired.
+ * (although that's still very far away!! have fun! :3)
+ */
+
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
 
-void
-error(const char* msg) {
-    fprintf(stderr, ":( error: %s\n", msg);
-    exit(EXIT_FAILURE);
-}
+#include "common.c"
 
-const char*
-read_file(const char* path) {
+const ascii*
+read_file(const ascii* path)
+{
     struct stat stat_info;
-    if (stat(path, &stat_info) == -1)
-        error("i couldn't open that file, sorry :(");
+    if (stat(path, &stat_info) == -1) failure("i couldn't open that file, sorry :(");
 
-    const int file = open(path, O_RDONLY);
-    if (file == -1)
-        error("i couldn't open that file, sorry :(");
+    const int32 file_descriptor = open(path, O_RDONLY);
+    check(file_descriptor != -1, "i couldn't open that file, sorry :(");
 
-    const int mmap_prot = PROT_READ;
-    const int mmap_flags = MAP_PRIVATE;
-    const void* file_data = mmap(
-        NULL, stat_info.st_size, mmap_prot, mmap_flags, file, 0
-    );
+    const flags mmap_prot = PROT_READ;
+    const flags mmap_flags = MAP_PRIVATE;
+    const unknown* file_data =
+        mmap(nil, stat_info.st_size, mmap_prot, mmap_flags, file_descriptor, 0);
 
-    return (const char*)file_data;
+    return file_data;
 }
 
-int
-main(const int argc, const char* argv[]) {
+integer
+main(const integer argc, const ascii* argv[])
+{
     if (argc != 2) {
         printf("usage: catboot <filename>\n");
         return EXIT_FAILURE;
     }
-    const char* file_path = argv[1];
-    const char* source = read_file(file_path);
+    const ascii* file_path = argv[1];
+    const ascii* source = read_file(file_path);
 
     printf("%s", source);