From bbbdc580d45032b6c6d0987a45112198b1f28ed9 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Sat, 29 May 2021 23:42:24 -0500 Subject: [PATCH] fixed clock.sleep for wasmtime --- bin/onyx | Bin 366072 -> 366072 bytes core/wasi/clock.onyx | 43 ++++++++++++++++++++++++------------------- src/onyxparser.c | 16 ++++++++++++++++ 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/bin/onyx b/bin/onyx index 103360201a8ba16651c2920ade432d57f725fd12..6213c3448ea4a21a441cf240e193183d160314bd 100755 GIT binary patch delta 60 zcmeydTI|Pau?-!}B8)+ns!vK^6_|LxTc@wF;=uGfZcWW|n77YiW<36yiGjU6^*tjH PGXXL4_SE+*la~PiLb)4G delta 60 zcmeydTI|Pau?-!}BK()1rcb!~Yfj%kl>>rIh1L_69 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: -- 2.25.1