From: Brendan Hansen Date: Fri, 5 Jun 2020 02:11:25 +0000 (-0500) Subject: Changed comment syntax X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=d38eb782db6cf9a79146493f53f8ee49733cfda2;p=onyx.git Changed comment syntax --- diff --git a/include/onyxwasm.h b/include/onyxwasm.h index 8c05fe52..030dfa67 100644 --- a/include/onyxwasm.h +++ b/include/onyxwasm.h @@ -16,14 +16,14 @@ typedef enum WasmType : char { 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 { @@ -33,8 +33,9 @@ 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; diff --git a/onyx b/onyx index 00d2cd3c..9aa7cdd2 100755 Binary files a/onyx and b/onyx differ diff --git a/progs/minimal.onyx b/progs/minimal.onyx index 433a220a..b228c230 100644 --- a/progs/minimal.onyx +++ b/progs/minimal.onyx @@ -4,12 +4,12 @@ export add :: proc (a i32, b i32) -> i32 { } 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; diff --git a/src/onyxlex.c b/src/onyxlex.c index d76c93f3..7fdc4370 100644 --- a/src/onyxlex.c +++ b/src/onyxlex.c @@ -118,33 +118,15 @@ OnyxToken* onyx_get_token(OnyxTokenizer* tokenizer) { } // 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; } diff --git a/src/onyxwasm.c b/src/onyxwasm.c index a210a605..3c1f5fa7 100644 --- a/src/onyxwasm.c +++ b/src/onyxwasm.c @@ -23,6 +23,8 @@ static void process_function_definition(OnyxWasmModule* mod, OnyxAstNodeFuncDef* 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; @@ -38,6 +40,7 @@ static void process_function_definition(OnyxWasmModule* mod, OnyxAstNodeFuncDef* 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; @@ -47,9 +50,9 @@ static void process_function_definition(OnyxWasmModule* mod, OnyxAstNodeFuncDef* 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++; } } @@ -58,7 +61,7 @@ OnyxWasmModule onyx_wasm_generate_module(bh_allocator alloc, OnyxAstNode* progra .allocator = alloc, .type_map = NULL, - .curr_type_idx = 0, + .next_type_idx = 0, .functypes = NULL, .funcs = NULL,