From bed8e60da8d8ebc3d367872bacd64137414e7ae9 Mon Sep 17 00:00:00 2001 From: Mel Date: Tue, 11 Mar 2025 22:34:40 +0100 Subject: Add common library for basic types, functions and macros Signed-off-by: Mel --- boot/catboot.c | 56 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 23 deletions(-) (limited to 'boot/catboot.c') 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 #include #include -#include #include #include -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 \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); -- cgit 1.4.1