casting from void is not allowed
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 30 Jul 2020 03:45:55 +0000 (22:45 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 30 Jul 2020 03:45:55 +0000 (22:45 -0500)
onyx
progs/alloc.onyx
progs/alloc_test.onyx
src/onyxwasm.c

diff --git a/onyx b/onyx
index b7b0cae59a832202f5d6df92aa18a7b5d34c4fd5..4f3f842f402ce6c92edd5f40a2962ef8bb9f6737 100755 (executable)
Binary files a/onyx and b/onyx differ
index 7ca0b8504236d0c3771a3befe750998052f09e65..11ff27c89473f4bd4eee70d61457fe2e263f8b24 100644 (file)
@@ -125,3 +125,11 @@ heap_alloc_proc :: proc (data: rawptr, aa: AllocAction, size: u32, align: u32, o
 
     return null;
 }
+
+malloc :: proc (size: u32) -> rawptr {
+    return alloc(^heap_allocator, size);
+}
+
+mfree :: proc (ptr: rawptr) {
+    free(^heap_allocator, ptr);
+}
\ No newline at end of file
index 212e1fa1104ca25623fc1c577e927ba14e6a19dc..4b9371e6af5ab767ace3974a8b4761ecd2755a72 100644 (file)
@@ -8,10 +8,10 @@ proc #export "main" {
        asdf :: "staring asdfkjasd asdflkjasdflkajsdflk";
        heap_init();
 
-       first := cast([] i32) alloc(^heap_allocator, sizeof [4] i32);
+       first := cast([] i32) malloc(sizeof [4] i32);
        for i: 0, 4 first[i] = i * 2;
 
-       second := cast([] f32) alloc(^heap_allocator, sizeof [24] f32);
+       second := cast([] f32) malloc(sizeof [24] f32);
        for i: 0, 24 second[i] = cast(f32) i;
 
        print(cast(u32) first);
@@ -20,19 +20,19 @@ proc #export "main" {
        for i: 0, 4 print(first[i]);
        for i: 0, 24 print(second[i]);
 
-       free(^heap_allocator, first);
+       mfree(first);
 
-       third := cast(^i32) alloc(^heap_allocator, sizeof i32);
+       third := cast(^i32) malloc(sizeof i32);
 
        print(cast(u32) third);
        *third = 1234;
        print(*third);
 
-       free(^heap_allocator, second);
+       mfree(second);
 
-       fourth := cast([] i32) alloc(^heap_allocator, sizeof [128]i32);
+       fourth := cast([] i32) malloc(sizeof [128]i32);
        print(cast(u32) fourth);
 
-       fifth := cast(^i32) alloc(^heap_allocator, sizeof i32);
+       fifth := cast(^i32) malloc(sizeof i32);
        print(cast(u32) fifth);
 }
\ No newline at end of file
index 17c8b8d2872e22c1530b8c9eb2c85ea28d4c693a..c6ac1b4606281cab548c75027cebfe93e1540f8d 100644 (file)
@@ -1071,6 +1071,7 @@ COMPILE_FUNC(cast, AstUnaryOp* cast) {
                 cast->token->pos,
                 "cannot cast to or from a struct");
         WI(WI_DROP);
+        *pcode = code;
         return;
     }
 
@@ -1079,11 +1080,22 @@ COMPILE_FUNC(cast, AstUnaryOp* cast) {
                 cast->token->pos,
                 "cannot cast to a function");
         WI(WI_DROP);
+        *pcode = code;
+        return;
+    }
+
+    if (from->kind == Type_Kind_Basic && from->Basic.kind == Basic_Kind_Void) {
+        onyx_message_add(Msg_Type_Literal,
+                cast->token->pos,
+                "cannot cast from void");
+        WI(WI_DROP);
+        *pcode = code;
         return;
     }
 
     if (to->kind == Type_Kind_Basic && to->Basic.kind == Basic_Kind_Void) {
         WI(WI_DROP);
+        *pcode = code;
         return;
     }