Changed comment syntax
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 5 Jun 2020 02:11:25 +0000 (21:11 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 5 Jun 2020 02:11:25 +0000 (21:11 -0500)
include/onyxwasm.h
onyx
progs/minimal.onyx
src/onyxlex.c
src/onyxwasm.c

index 8c05fe522e257d53da8ccab43d3191a19fbf0e18..030dfa6711a4fc85d9607cae1d39bbc4f353f4a7 100644 (file)
@@ -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 00d2cd3c93fcdf532de7d98d1471af68940c5e44..9aa7cdd2befeeb8ce1182c390ca6a2105ad0ae42 100755 (executable)
Binary files a/onyx and b/onyx differ
index 433a220ad5c5184993f9db041b0e415f36df0c0c..b228c2309463e6a426cf97fcd47f30b757439dbb 100644 (file)
@@ -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;
index d76c93f32b3bace691d751c92ca51e3a5582075e..7fdc43707c7c7442a316a3b11c351f3082833577 100644 (file)
@@ -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;
        }
index a210a605056ceade705afe0d45c726bcb22002f8..3c1f5fa752323a5a13d9d818c907775020c1ca33 100644 (file)
@@ -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,