fixed clock.sleep for wasmtime
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 30 May 2021 04:42:24 +0000 (23:42 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 30 May 2021 04:42:24 +0000 (23:42 -0500)
bin/onyx
core/wasi/clock.onyx
src/onyxparser.c

index 103360201a8ba16651c2920ade432d57f725fd12..6213c3448ea4a21a441cf240e193183d160314bd 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index bd04ad03be6042c920a9285c41f26072bd3a181a..18b19b59e18cac105ede36c94e47f39b5469e88e 100644 (file)
@@ -18,23 +18,28 @@ time_ns :: () -> u64 {
     return ~~output_time;
 }
 
-sleep :: (milliseconds: u32) {
-    tagged: SubscriptionTagged;
-    tagged.tag = .Clock;
-    tagged.clock = .{
-        id = .Realtime,
-        timeout = cast(u64) milliseconds * 1000000,
-        precision = 1000,
-        flags = .ClockAbsTime,
-    };
-
-    subscription := Subscription.{
-        userdata = 0,
-        u = tagged,
-    };
-
-    event: Event;
-    number_of_events: u32;
-
-    error_code := poll_oneoff(^subscription, ^event, 1, ^number_of_events);
+sleep :: proc {
+    (seconds: u64)      { sleep(nanoseconds=seconds * 1000000000); },
+    (milliseconds: u64) { sleep(nanoseconds=milliseconds * 1000000); },
+
+    (nanoseconds: u64) {
+        tagged: SubscriptionTagged;
+        tagged.tag = .Clock;
+        tagged.clock = .{
+            id = .Realtime,
+            timeout = cast(u64) nanoseconds,
+            precision = 1,
+            flags = ~~0,
+        };
+
+        subscription := Subscription.{
+            userdata = 0,
+            u = tagged,
+        };
+
+        event: Event;
+        number_of_events: u32;
+
+        error_code := poll_oneoff(^subscription, ^event, 1, ^number_of_events);
+    }
 }
\ No newline at end of file
index 3b94e85c81a58151a7351ed3b5d8e2724b48b45e..007d3ac431e8d2c683cff2f9ecc7d9bfbe0ae719 100644 (file)
@@ -64,6 +64,7 @@ static b32            parse_possible_function_definition(OnyxParser* parser, Ast
 static AstFunction*   parse_function_definition(OnyxParser* parser, OnyxToken* token);
 static AstTyped*      parse_global_declaration(OnyxParser* parser);
 static AstEnumType*   parse_enum_declaration(OnyxParser* parser);
+static AstStaticIf*   parse_static_if_stmt(OnyxParser* parser);
 static AstTyped*      parse_top_level_expression(OnyxParser* parser);
 static AstBinding*    parse_top_level_binding(OnyxParser* parser, OnyxToken* symbol);
 static void           parse_top_level_statement(OnyxParser* parser);
@@ -1314,6 +1315,21 @@ static AstNode* parse_statement(OnyxParser* parser) {
                 retval = (AstNode *) context_tmp;
                 break;
             }
+
+            /*
+            This is in theory where the static if in procedures will be parsed. However,
+            this breaks many things because static if statements currently only parse top
+            level expressions in them, not general statements.
+
+            if (next_tokens_are(parser, 2, '#', Token_Type_Keyword_If)) {
+                AstStaticIf* static_if = parse_static_if_stmt(parser);
+                ENTITY_SUBMIT(static_if);
+
+                needs_semicolon = 0;
+                retval = (AstNode *) static_if;
+                break;
+            }
+            */
         }
 
         default: