'package builtin' is now just the global scope; cleanup
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 28 Aug 2022 17:59:41 +0000 (12:59 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 28 Aug 2022 17:59:41 +0000 (12:59 -0500)
core/builtin.onyx
core/container/array.onyx
core/container/map.onyx
core/container/set.onyx
misc/onyx.sublime-syntax
misc/onyx.vim
misc/vscode/onyx-0.0.3.vsix
misc/vscode/out/ovmDebug.js
misc/vscode/ovmDebug.ts
src/parser.c
src/utils.c

index 0b6fe9c20c6e03359334be6230f7176c6385c238..1e5238161cdf933181e374f3d0ff51e37dd6fc29 100644 (file)
@@ -3,7 +3,6 @@ package builtin
 // CLEANUP: Should builtin.onyx really be including other files in the compilation?
 // Does that complicate things too much?
 #load "core/runtime/build_opts"
-#local runtime :: package runtime
 
 str  :: #type []u8;
 cstr :: #type ^u8;
index ca36054c251570e6725593ddf70e6a19ae6b0db7..e747fb5d12707895324dca43a87a9367a907ce0e 100644 (file)
@@ -70,7 +70,7 @@ copy :: #match #locked {
     },
 
     (arr: [] $T, allocator := context.allocator) -> [] T {
-        new_arr := make([] T, arr.count);
+        new_arr := builtin.make([] T, arr.count);
         for i: 0 .. arr.count do new_arr.data[i] = arr.data[i];
         return new_arr;
     }
index e12ebaceeedc5e2701c1db7b8d9d2facb2180f66..7ef7bb732dfe5e5ed84b8930193214e010268d88 100644 (file)
@@ -61,7 +61,7 @@ make :: ($Key: type_expr, $Value: type_expr, default := Value.{}) -> Map(Key, Va
     return map;
 }
 
-#match (package builtin).__make_overload macro (x: ^Map($K, $V), allocator := context.allocator) => (package core.map).make(K, V);
+#match __make_overload macro (x: ^Map($K, $V), allocator := context.allocator) => core.map.make(K, V);
 
 init :: (use map: ^Map($K, $V), default := V.{}) {
     __initialize(map);
@@ -69,7 +69,7 @@ init :: (use map: ^Map($K, $V), default := V.{}) {
     allocator = context.allocator;
     default_value = default;
 
-    hashes = make([] u32, 8, allocator=allocator);
+    hashes = builtin.make([] u32, 8, allocator=allocator);
     array.fill(hashes, -1);
 
     array.init(^entries, allocator=allocator);
@@ -208,7 +208,7 @@ format_map :: (output: ^conv.Format_Output, format: ^conv.Format, x: ^Map($K, $V
 
     rehash :: (use map: ^Map, new_size: i32) {
         memory.free_slice(^hashes, allocator);
-        hashes = make([] u32, new_size, allocator=allocator);
+        hashes = builtin.make([] u32, new_size, allocator=allocator);
         array.fill(hashes, -1);
 
         for ^entry: entries do entry.next = -1;
index c758f0adab19460c933026c171d76574d4dbb717..6ec63f4d41de3b8bcf46a8cf2a9f78851f409d91 100644 (file)
@@ -189,7 +189,7 @@ iterator :: (set: ^Set($T)) -> Iterator(T) {
 
     rehash :: (use set: ^Set, new_size: i32) {
         memory.free_slice(^hashes, allocator);
-        hashes = make([] u32, new_size, allocator=allocator);
+        hashes = builtin.make([] u32, new_size, allocator=allocator);
         array.fill(hashes, -1);
 
         for ^entry: entries do entry.next = -1;
index 54a08a3e46ff2c6ddfdab3cf0ff78604e879d66e..a2365ed76f39542b2c130dc3ef34b4a0cda53f8e 100644 (file)
@@ -29,7 +29,7 @@ contexts:
     # strings in YAML. When using single quoted strings, only single quotes
     # need to be escaped: this is done by using two single quotes next to each
     # other.
-    - match: '\b(package|struct|interface|use|where|global|enum|if|elseif|else|for|while|do|break|continue|fallthrough|return|as|cast|sizeof|alignof|typeof|defer|switch|case|macro)\b'
+    - match: '\b(package|struct|interface|use|where|global|enum|if|elseif|else|for|while|do|break|continue|fallthrough|return|cast|sizeof|alignof|typeof|defer|switch|case|macro)\b'
       scope: keyword.control.onyx
 
     - match: '\b(bool|void|i8|u8|i16|u16|i32|u32|i64|u64|f32|f64|rawptr|str|cstr|range|type_expr|any)\b'
index 67e93fbfc3735ef3641007fc87fc15f9dd811899..631208eed51526eedae8c735a335f572cdeb14d3 100644 (file)
@@ -15,7 +15,7 @@ syn keyword onyxKeyword if elseif else where interface
 syn keyword onyxKeyword for while do
 syn keyword onyxKeyword switch case
 syn keyword onyxKeyword break continue return defer fallthrough
-syn keyword onyxKeyword as cast sizeof alignof typeof
+syn keyword onyxKeyword cast sizeof alignof typeof
 syn keyword onyxType bool void
 syn keyword onyxType i8 u8
 syn keyword onyxType i16 u16
index bb16dd8f166e31aac7f5146906ba632e79d7e98f..ba5d515741443ee98170ced23e95ad19a20ca45e 100644 (file)
Binary files a/misc/vscode/onyx-0.0.3.vsix and b/misc/vscode/onyx-0.0.3.vsix differ
index 38de655aa3afa2b9597fe6d4935b80696338f58d..5c66268d0534c21c0d18db884a645f3254c9fc89 100644 (file)
@@ -195,7 +195,7 @@ class OVMDebugSession extends debugadapter_1.LoggingDebugSession {
         this.running_process.stdout.on("data", (chunk) => {
             this.sendEvent(new debugadapter_1.OutputEvent(chunk, "console"));
         });
-        this.attachRequest(response, { "socketPath": "/tmp/ovm-debug.0000", "stopOnEntry": true });
+        this.attachRequest(response, { "socketPath": "/tmp/ovm-debug.0000", "stopOnEntry": args.stopOnEntry });
     }
     attachRequest(response, args, request) {
         return __awaiter(this, void 0, void 0, function* () {
index c24237c3f094e68db4227e4366d53ebd70edd617..08d85494d69481689c1ff32c3bc4b7c9ee3ae639 100644 (file)
@@ -267,7 +267,7 @@ export class OVMDebugSession extends LoggingDebugSession {
                        this.sendEvent(new OutputEvent(chunk, "console"));
                });
 
-               this.attachRequest(response, {"socketPath": "/tmp/ovm-debug.0000", "stopOnEntry": true});
+               this.attachRequest(response, {"socketPath": "/tmp/ovm-debug.0000", "stopOnEntry": args.stopOnEntry});
     }
 
     protected async attachRequest(response: DebugProtocol.AttachResponse, args: IOVMAttachRequestArguments, request?: DebugProtocol.Request): Promise<void> {
index e98ffd16cfe55f6b439ff41187e9149a2ca4ce0a..82ca91b90cb5b48daba112f83b7c33ddc841c988 100644 (file)
@@ -3464,12 +3464,6 @@ void onyx_parse(OnyxParser *parser) {
     parser->file_scope = scope_create(parser->allocator, parser->package->private_scope, parser->tokenizer->tokens[0].pos);
     parser->current_scope = parser->file_scope;
 
-    AstUse* implicit_use_builtin = make_node(AstUse, Ast_Kind_Use);
-    AstPackage* implicit_builtin_package = make_node(AstPackage, Ast_Kind_Package);
-    implicit_builtin_package->package_name = "builtin";
-    implicit_use_builtin->expr = (AstTyped *) implicit_builtin_package;
-    ENTITY_SUBMIT(implicit_use_builtin);
-
     parse_top_level_statements_until(parser, Token_Type_End_Stream);
 
     parser->current_scope = parser->current_scope->parent;
index 3036aab91a28d4b06bf4a1ddeab4bbd14ab9044c..8c6c259badf20d5658b79068022aff7b9f60d1fa 100644 (file)
@@ -39,10 +39,16 @@ Package* package_lookup_or_create(char* package_name, Scope* parent_scope, bh_al
         pac_name[strlen(package_name)] = '\0';
 
         package->name = pac_name;
-        package->scope = scope_create(alloc, parent_scope, (OnyxFilePos) { 0 });
-        package->private_scope = scope_create(alloc, package->scope, (OnyxFilePos) { 0 });
         package->use_package_entities = NULL;
 
+        if (!strcmp(pac_name, "builtin")) {
+            package->private_scope = scope_create(alloc, context.global_scope, pos);
+            package->scope = context.global_scope;
+        } else {
+            package->scope = scope_create(alloc, parent_scope, pos);
+            package->private_scope = scope_create(alloc, package->scope, pos);
+        }
+
         shput(context.packages, pac_name, package);
 
         if (!charset_contains(pac_name, '.')) {