From: Brendan Hansen Date: Sun, 30 May 2021 04:42:24 +0000 (-0500) Subject: fixed clock.sleep for wasmtime X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=bbbdc580d45032b6c6d0987a45112198b1f28ed9;p=onyx.git fixed clock.sleep for wasmtime --- diff --git a/bin/onyx b/bin/onyx index 10336020..6213c344 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/core/wasi/clock.onyx b/core/wasi/clock.onyx index bd04ad03..18b19b59 100644 --- a/core/wasi/clock.onyx +++ b/core/wasi/clock.onyx @@ -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 diff --git a/src/onyxparser.c b/src/onyxparser.c index 3b94e85c..007d3ac4 100644 --- a/src/onyxparser.c +++ b/src/onyxparser.c @@ -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: