Added initial vim syntax highlighting; bug fixes
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 20 Jun 2020 23:14:05 +0000 (18:14 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 20 Jun 2020 23:14:05 +0000 (18:14 -0500)
misc/onyx.vim [new file with mode: 0644]
onyx
progs/minimal.onyx
src/onyx.c
src/onyxwasm.c

diff --git a/misc/onyx.vim b/misc/onyx.vim
new file mode 100644 (file)
index 0000000..89d22c4
--- /dev/null
@@ -0,0 +1,43 @@
+" Vim syntax file
+" Language: Onyx
+" Maintainer: Brendan Hansen <brendan.f.hansen@gmail.com>
+" Last Change: 2020 June 20
+
+if exists("b:current_syntax")
+       finish
+endif
+
+let s:cpo_save = &cpo
+set cpo&vim
+
+syn keyword onyxKeyword struct
+syn keyword onyxKeyword use
+syn keyword onyxKeyword if
+syn keyword onyxKeyword elseif
+syn keyword onyxKeyword else
+syn keyword onyxKeyword export
+syn keyword onyxKeyword proc
+syn keyword onyxKeyword foreign
+syn keyword onyxKeyword for
+syn keyword onyxKeyword return
+syn keyword onyxKeyword do
+syn keyword onyxKeyword global
+syn keyword onyxKeyword as
+
+syn keyword onyxType i32
+syn keyword onyxType i64
+syn keyword onyxType f32
+syn keyword onyxType f64
+
+syn keyword onyxCommentStart   contained TODO NOTE BUG HACK
+
+syn region onyxComment start="//" end="$" keepend contains=onyxCommentStart
+
+hi def link onyxKeyword                Statement
+hi def link onyxType           Type
+hi def link onyxComment                Comment
+hi def link onyxCommentStart   Todo
+
+let b:current_syntax = "onyx"
+let &cpo = s:cpo_save
+unlet s:cpo_save
diff --git a/onyx b/onyx
index 1c15f82624dea9d2e6bdb843f4bea638577c6a7a..7b7f254aa9559225a1e62fc185bd033150fc1f3a 100755 (executable)
Binary files a/onyx and b/onyx differ
index 03ebfcb2d5cf601470960b94f1b0efa0d7df40b3..7114a4cc42f03dbff5862618cfbd850a1afe437d 100644 (file)
@@ -11,12 +11,14 @@ add :: proc (a i32, b i32) -> i32 {
        return a + b;
 }
 
+// NOTE: There is a weird bug here if the else is used instead
+// This is because the WASM embedder does not think that it
+// is possible that all code paths are covered with returning
+// an i32. This will need to be fixed.
 abs :: proc (val i32) -> i32 {
-    if val <= 0 {
-        return -val;
-    } else {
-        return val;
-    };
+    if val <= 0 { return -val; };
+    // else { return val; };
+    return val;
 }
 
 diff_square :: proc (a i32, b i32) -> i32 {
@@ -41,12 +43,13 @@ float_test :: proc -> f32 {
 export main :: proc {
     output := do_stuff();
 
-    if output 66 {
-        new_output :: -output * 2;
+    if output == -66 {
+        new_output :: abs(output) * 2;
         print(new_output);
 
     } else {
         print(-1);
+
     };
 
     print(output);
index 2a57a80e3c912279ffaa6625137049f7e58b6346..816a38a778008652879f76baf8d275e49038b713 100644 (file)
@@ -55,7 +55,7 @@ int main(int argc, char *argv[]) {
                onyx_message_print(&msgs);
                goto main_exit;
        } else {
-               onyx_ast_print(program, 0);
+               // onyx_ast_print(program, 0);
            bh_printf("\nNo errors.\n");
     }
 
index d5016649f68b87fba662c96143e3224bd7543833..771f913d98ce846c289a1b562bf8b787b8e22f7b 100644 (file)
@@ -244,7 +244,8 @@ static void process_statement(OnyxWasmModule* mod, WasmFunc* func, OnyxAstNode*
                case ONYX_AST_NODE_KIND_RETURN: process_return(mod, func, stmt); break;
                case ONYX_AST_NODE_KIND_ASSIGNMENT: process_assignment(mod, func, stmt); break;
         case ONYX_AST_NODE_KIND_IF: process_if(mod, func, (OnyxAstNodeIf *) stmt); break;
-               default: process_expression(mod, func, stmt);
+        case ONYX_AST_NODE_KIND_CALL: process_expression(mod, func, stmt); break;
+               default: break;
        }
 }