static inline b32 is_lval(AstNode* node) {
return (node->kind == Ast_Kind_Local)
|| (node->kind == Ast_Kind_Global)
+ || (node->kind == Ast_Kind_Dereference)
|| (node->kind == Ast_Kind_Array_Access);
}
}
// Don't need to bind this function to a symbol
-proc #export "main" {
+proc #export "main2" {
print(__heap_start as i32);
- global_arr = __heap_start as ^i32;
len :: 10;
+ global_arr = alloc((len * 4) as u32) as ^i32;
+ other_arr := alloc((len * 4) as u32) as ^i32;
+
+ print(global_arr as i32);
+ print(other_arr as i32);
for i: 0, len global_arr[i] = (len - i) * 10;
print(1234567);
print(global_arr, len);
}
+
+
+
+
+
+
+
+
+
+
+
+
+alloc :: proc (size: u32) -> rawptr {
+ heap_u32 :: __heap_start as ^u32;
+
+ curr_offset := *heap_u32;
+ if curr_offset == 0 as u32 curr_offset = 8 as u32;
+
+ *heap_u32 = curr_offset + size;
+
+ return ((__heap_start as u32) + curr_offset) as rawptr;
+}
+
+
+
+
+
+multi_arr_test :: proc #export "main" {
+ arrs := alloc((10 * 4) as u32) as ^^i32;
+
+ for i: 0, 10 {
+ arrs[i] = alloc((10 * 4) as u32) as ^i32;
+ }
+
+ for y: 0, 10 for x: 0, 10 arrs[y][x] = x + y * 10;
+ for y: 0, 10 for x: 0, 10 print(arrs[x][y]);
+}
case '+':
case '-':
case '!':
+ case '*':
case Token_Type_Literal_Numeric:
case Token_Type_Literal_String:
retval = (AstNode *) parse_expression(parser);
AstBasicType basic_type_f64 = { { Ast_Kind_Basic_Type, 0, "f64" }, &basic_types[Basic_Kind_F64] };
AstBasicType basic_type_rawptr = { { Ast_Kind_Basic_Type, 0, "rawptr" }, &basic_types[Basic_Kind_Rawptr] };
-AstNumLit builtin_heap_start = { Ast_Kind_NumLit, 0, NULL, NULL, (AstType *) &basic_type_rawptr, NULL, 0 };
+AstNumLit builtin_heap_start = { Ast_Kind_NumLit, Ast_Flag_Const, NULL, NULL, (AstType *) &basic_type_rawptr, NULL, 0 };
const BuiltinSymbol builtin_symbols[] = {
{ "void", (AstNode *) &basic_type_void },
compile_expression(mod, &code, assign->right);
WID(WI_GLOBAL_SET, globalidx);
+ } else if (lval->kind == Ast_Kind_Dereference) {
+ AstDereference* deref = (AstDereference *) lval;
+ compile_expression(mod, &code, deref->expr);
+ compile_expression(mod, &code, assign->right);
+
+ i32 store_size = deref->type->Basic.size;
+ i32 is_integer = (deref->type->Basic.flags & Basic_Flag_Integer)
+ || (deref->type->Basic.flags & Basic_Flag_Pointer);
+
+ if (is_integer) {
+ if (store_size == 1) WID(WI_I32_STORE_8, ((WasmInstructionData) { 0, 0 }));
+ else if (store_size == 2) WID(WI_I32_STORE_16, ((WasmInstructionData) { 1, 0 }));
+ else if (store_size == 4) WID(WI_I32_STORE, ((WasmInstructionData) { 2, 0 }));
+ else if (store_size == 8) WID(WI_I64_STORE, ((WasmInstructionData) { 3, 0 }));
+ } else {
+ if (store_size == 4) WID(WI_F32_STORE, ((WasmInstructionData) { 2, 0 }));
+ else if (store_size == 8) WID(WI_F64_STORE, ((WasmInstructionData) { 3, 0 }));
+ }
+
} else if (lval->kind == Ast_Kind_Array_Access) {
AstArrayAccess* aa = (AstArrayAccess *) lval;
compile_expression(mod, &code, aa->expr);
else if (load_size == 4) instr = WI_I32_LOAD;
else if (load_size == 8) instr = WI_I64_LOAD;
- if (alignment < 4 && is_unsigned) instr += 1;
+ if (load_size < 4 && is_unsigned) instr += 1;
} else {
if (load_size == 4) instr = WI_F32_LOAD;
else if (load_size == 8) instr = WI_F64_LOAD;
else if (load_size == 4) instr = WI_I32_LOAD;
else if (load_size == 8) instr = WI_I64_LOAD;
- if (alignment < 4 && is_unsigned) instr += 1;
+ if (load_size < 4 && is_unsigned) instr += 1;
} else {
if (load_size == 4) instr = WI_F32_LOAD;
else if (load_size == 8) instr = WI_F64_LOAD;