From: Brendan Hansen Date: Thu, 30 Jul 2020 03:45:55 +0000 (-0500) Subject: casting from void is not allowed X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=cb1942ad1c701731c201197841da37f50bb25821;p=onyx.git casting from void is not allowed --- diff --git a/onyx b/onyx index b7b0cae5..4f3f842f 100755 Binary files a/onyx and b/onyx differ diff --git a/progs/alloc.onyx b/progs/alloc.onyx index 7ca0b850..11ff27c8 100644 --- a/progs/alloc.onyx +++ b/progs/alloc.onyx @@ -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 diff --git a/progs/alloc_test.onyx b/progs/alloc_test.onyx index 212e1fa1..4b9371e6 100644 --- a/progs/alloc_test.onyx +++ b/progs/alloc_test.onyx @@ -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 diff --git a/src/onyxwasm.c b/src/onyxwasm.c index 17c8b8d2..c6ac1b46 100644 --- a/src/onyxwasm.c +++ b/src/onyxwasm.c @@ -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; }