experimentally loading core/std by default
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 31 Oct 2022 12:50:46 +0000 (07:50 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 31 Oct 2022 12:50:46 +0000 (07:50 -0500)
compiler/include/astnodes.h
compiler/src/onyx.c

index 0b3365936879dc3f2ef360b3f404db82e4263569..6258625a94bff6d533e93257f42c0f20615189d7 100644 (file)
@@ -1579,6 +1579,7 @@ struct CompileOptions {
     b32 use_post_mvp_features : 1;
     b32 use_multi_threading   : 1;
     b32 generate_foreign_info : 1;
+    b32 no_std                : 1;
 
     Runtime runtime;
 
index 6f908e66aa4416d48355aff62e39f698b9df4e2a..a629fa9ecc0a7ed5907ada39dc60d094416e5f1c 100644 (file)
@@ -74,6 +74,7 @@ static CompileOptions compile_opts_parse(bh_allocator alloc, int argc, char *arg
 
         .use_post_mvp_features   = 1,
         .use_multi_threading     = 0,
+        .no_std                  = 0,
 
         .runtime = Runtime_Onyx,
 
@@ -162,6 +163,9 @@ static CompileOptions compile_opts_parse(bh_allocator alloc, int argc, char *arg
             else if (!strcmp(argv[i], "--generate-foreign-info")) {
                 options.generate_foreign_info = 1;
             }
+            else if (!strcmp(argv[i], "--no-std")) {
+                options.no_std = 1;
+            }
             else if (!strcmp(argv[i], "-I")) {
                 bh_arr_push(options.included_folders, argv[++i]);
             }
@@ -317,6 +321,15 @@ static void context_init(CompileOptions* opts) {
         AstInclude* load_node = create_load(context.ast_alloc, (char *) *filename);
         add_entities_for_node(NULL, (AstNode *) load_node, context.global_scope, NULL);
     }
+
+    if (!context.options->no_std) {
+        entity_heap_insert(&context.entities, ((Entity) {
+            .state = Entity_State_Parse,
+            .type = Entity_Type_Load_File,
+            .package = NULL,
+            .include = create_load(context.ast_alloc, "core/std"),
+        }));
+    }
 }
 
 static void context_free() {