cleaned up more of builtin.onyx
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 12 Feb 2023 22:27:21 +0000 (16:27 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 12 Feb 2023 22:27:21 +0000 (16:27 -0600)
core/builtin.onyx

index 04fc8533c8a618005ab7a7ff5a0d445ead1b6ef7..e79260330c02228ef133c90321044e6a0a9867b3 100644 (file)
@@ -260,61 +260,73 @@ cfree   :: (ptr: rawptr)            => raw_free(context.allocator, ptr);
 // This cannot be used in a custom runtime, as the other core
 // packages are not included.
 #if runtime.runtime != .Custom {
-    new :: #match {
-        ($T: type_expr, allocator := context.allocator) -> ^T {
-            use package core.intrinsics.onyx { __initialize }
-            memory :: package core.memory
+    new :: #match #local {}
 
-            res := cast(^T) raw_alloc(allocator, sizeof T);
-            memory.set(res, 0, sizeof T);
-            __initialize(res);
+    #overload
+    new :: ($T: type_expr, allocator := context.allocator) -> ^T {
+        use package core.intrinsics.onyx { __initialize }
+        memory :: package core.memory
 
-            return res;
-        },
+        res := cast(^T) raw_alloc(allocator, sizeof T);
+        memory.set(res, 0, sizeof T);
+        __initialize(res);
 
-        (T: type_expr, allocator := context.allocator) -> rawptr {
-            memory :: package core.memory
-            type_info :: package runtime.info
-
-            info := type_info.get_type_info(T);
-            size := type_info.size_of(T);
-            if size == 0 do return null;
-
-            res := raw_alloc(allocator, size);
-            memory.set(res, 0, size);
-
-            if info.kind == .Struct {
-                s_info := cast(^type_info.Type_Info_Struct) info;
-                for s_info.members {
-                    if it.default != null {
-                        member_size := type_info.size_of(it.type);
-                        memory.copy(cast(^u8) res + it.offset, it.default, member_size);
-                    }
+        return res;
+    }
+
+    #overload
+    new :: (T: type_expr, allocator := context.allocator) -> rawptr {
+        memory :: package core.memory
+        type_info :: package runtime.info
+
+        info := type_info.get_type_info(T);
+        size := type_info.size_of(T);
+        if size == 0 do return null;
+
+        res := raw_alloc(allocator, size);
+        memory.set(res, 0, size);
+
+        if info.kind == .Struct {
+            s_info := cast(^type_info.Type_Info_Struct) info;
+            for s_info.members {
+                if it.default != null {
+                    member_size := type_info.size_of(it.type);
+                    memory.copy(cast(^u8) res + it.offset, it.default, member_size);
                 }
             }
-
-            return res;
         }
+
+        return res;
     }
 
     new_temp :: macro (T: type_expr) => {
         return new(T, allocator=context.temp_allocator);
     }
 
-    make :: #match {
-        macro ($T: type_expr, allocator := context.allocator) => {
-            return __make_overload(cast(^T) null, allocator=allocator);
-        },
+    make :: #match #local {}
 
-        macro ($T: type_expr, n: u32, allocator := context.allocator) => {
-            return __make_overload(cast(^T) null, n, allocator=allocator);
-        },
+    #overload
+    make :: macro ($T: type_expr, allocator := context.allocator) => {
+        return __make_overload(cast(^T) null, allocator=allocator);
     }
 
+    #overload
+    make :: macro ($T: type_expr, n: u32, allocator := context.allocator) => {
+        return __make_overload(cast(^T) null, n, allocator=allocator);
+    }
+
+    make_temp :: #match #local {}
+
+    #overload
     make_temp :: macro (T: type_expr) => {
         return make(T, allocator=context.temp_allocator);
     }
 
+    #overload
+    make_temp :: macro (T: type_expr, n: u32) => {
+        return make(T, n, allocator=context.temp_allocator);
+    }
+
     //
     // This is a rather unique way of using the type matching system
     // to select an overload. What is desired here is that when you say: