typedef struct WasmFuncType {
// NOTE: For now, WASM only allows for 1 return value.
// This may be lifted in the future.
- WasmType return_type;
i32 param_count;
+ WasmType return_type;
WasmType param_types[];
} WasmFuncType;
typedef struct WasmFunc {
- WasmFuncType* type;
i32 idx;
+ i32 type_idx;
} WasmFunc;
typedef struct OnyxWasmModule {
// 0x7f 0x7f : 0x7f ( (i32, i32) -> i32 )
// to the function type index if it has been created.
bh_hash(i32) type_map;
- i32 curr_type_idx;
+ i32 next_type_idx;
+ // NOTE: This have to be pointers because the type is variadic in size
bh_arr(WasmFuncType*) functypes;
bh_arr(WasmFunc) funcs;
} OnyxWasmModule;
}
export mul :: proc (a i32, b i32) -> i64 {
- /* Typechecked */
+ // Typechecked
c: const i64 = ((a as i64) - (b as i64));
- /* Don't love this syntax, but it's easy to parse so whatever
- Inferred type, but constant */
- /* a and b are both i32, so i32 + i32 is i32 so d is i32 */
+ // Don't love this syntax, but it's easy to parse so whatever
+ // Inferred type, but constant
+ // a and b are both i32, so i32 + i32 is i32 so d is i32
d: const = a + b;
e: i32 = 10 as i32;
}
// Comments
- if (*tokenizer->curr == '/' && *(tokenizer->curr + 1) == '*') {
+ if (*tokenizer->curr == '/' && *(tokenizer->curr + 1) == '/') {
tokenizer->curr += 2;
tk.type = TOKEN_TYPE_COMMENT;
tk.token = tokenizer->curr;
- u16 layers = 1;
- while (layers >= 1) {
+ while (*tokenizer->curr != '\n') {
INCREMENT_CURR_TOKEN(tokenizer);
-
- if (tokenizer->curr == tokenizer->end) {
- tk.type = TOKEN_TYPE_END_STREAM;
- break;
- }
-
- if (*tokenizer->curr == '/' && *(tokenizer->curr + 1) == '*') {
- layers++;
- INCREMENT_CURR_TOKEN(tokenizer);
- }
-
- if (*tokenizer->curr == '*' && *(tokenizer->curr + 1) == '/') {
- layers--;
- INCREMENT_CURR_TOKEN(tokenizer);
- }
}
- INCREMENT_CURR_TOKEN(tokenizer);
-
tk.length = tokenizer->curr - tk.token - 2;
goto token_parsed;
}
OnyxAstNodeParam* param = fd->params;
i32 param_count = 0;
while (param) {
+ // HACK: Using these directly as part of a string feels weird but they are
+ // valid characters so I don't think it is going to be much of an issue
*(t++) = (char) onyx_type_to_wasm_type(param->type);
param_count++;
param = param->next;
type_idx = bh_hash_get(i32, mod->type_map, type_repr_buf);
} else {
// NOTE: Make a new type
+ // TODO: Ensure that this isn't going to break things because of alignment
WasmFuncType* type = (WasmFuncType*) bh_alloc(mod->allocator, sizeof(WasmFuncType) + sizeof(WasmType) * param_count);
type->return_type = return_type;
type->param_count = param_count;
bh_arr_push(mod->functypes, type);
- bh_hash_put(i32, mod->type_map, type_repr_buf, mod->curr_type_idx);
- type_idx = mod->curr_type_idx;
- mod->curr_type_idx++;
+ bh_hash_put(i32, mod->type_map, type_repr_buf, mod->next_type_idx);
+ type_idx = mod->next_type_idx;
+ mod->next_type_idx++;
}
}
.allocator = alloc,
.type_map = NULL,
- .curr_type_idx = 0,
+ .next_type_idx = 0,
.functypes = NULL,
.funcs = NULL,