From: Brendan Hansen Date: Wed, 20 Apr 2022 23:55:14 +0000 (-0500) Subject: for loops over a range iterate backwards if step is negative X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=81e0d1651174ca1f69cae5158999b16c6183adef;p=onyx.git for loops over a range iterate backwards if step is negative --- diff --git a/core/hash.onyx b/core/hash.onyx index f0269537..c915f2cd 100644 --- a/core/hash.onyx +++ b/core/hash.onyx @@ -3,6 +3,7 @@ package core.hash to_u32 :: #match { (key: rawptr) -> u32 { return 0xcbf29ce7 ^ cast(u32) key; }, (key: i8) -> u32 { return ~~ key; }, + (key: i16) -> u32 { return 0x9ce7 ^ ~~ key; }, (key: i32) -> u32 { return 0xcbf29ce7 ^ cast(u32) key; }, (key: i64) -> u32 { return cast(u32) (cast(u64) 0xcbf29ce7 ^ cast(u64) key); }, (key: str) -> u32 { diff --git a/core/type_info/helper.onyx b/core/type_info/helper.onyx index 6864278e..8c9c9ac8 100644 --- a/core/type_info/helper.onyx +++ b/core/type_info/helper.onyx @@ -310,3 +310,12 @@ populate_struct_vtable :: (table: ^$Table_Type, struct_type: type_expr, safe := *dest = *cast(^()->void) struct_method.data; } } + +for_all_types :: macro (body: Code) { + for (package builtin.type_info).type_table.count { + type_info := (package builtin.type_info).type_table[it]; + type_idx : type_expr = ~~ it; + + #unquote body; + } +} \ No newline at end of file diff --git a/docs/logos/logo.svg b/docs/logos/logo.svg index d64d2adf..93c70a6c 100644 --- a/docs/logos/logo.svg +++ b/docs/logos/logo.svg @@ -10,8 +10,8 @@ inkscape:version="1.1.1 (3bf5ae0d25, 2021-09-20)" sodipodi:docname="logo.svg" inkscape:export-filename="C:\dev\onyx\docs\logos\logo.png" - inkscape:export-xdpi="256" - inkscape:export-ydpi="256" + inkscape:export-xdpi="512" + inkscape:export-ydpi="512" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns="http://www.w3.org/2000/svg" @@ -27,12 +27,12 @@ inkscape:document-units="mm" showgrid="false" inkscape:zoom="8.7988366" - inkscape:cx="48.585969" - inkscape:cy="60.519365" - inkscape:window-width="2498" - inkscape:window-height="1417" - inkscape:window-x="54" - inkscape:window-y="-8" + inkscape:cx="23.866792" + inkscape:cy="33.243031" + inkscape:window-width="1920" + inkscape:window-height="1057" + inkscape:window-x="1920" + inkscape:window-y="0" inkscape:window-maximized="1" inkscape:current-layer="layer1" units="px" /> diff --git a/docs/logos/logo_256.png b/docs/logos/logo_256.png new file mode 100644 index 00000000..e0d94be3 Binary files /dev/null and b/docs/logos/logo_256.png differ diff --git a/docs/logos/logo_512.png b/docs/logos/logo_512.png new file mode 100644 index 00000000..71698c6e Binary files /dev/null and b/docs/logos/logo_512.png differ diff --git a/src/wasm_emit.c b/src/wasm_emit.c index 237507d9..07884a2c 100644 --- a/src/wasm_emit.c +++ b/src/wasm_emit.c @@ -840,7 +840,8 @@ EMIT_FUNC(for_range, AstFor* for_node, u64 iter_local) { // but it is important to change the code here. // -brendanfh 2020/09/04 - AstLocal* var = for_node->var; + // NOTE: This might not be a range literal + AstStructLiteral *range = (AstStructLiteral *) for_node->iter; u64 offset = 0; StructMember low_mem, high_mem, step_mem; @@ -860,10 +861,39 @@ EMIT_FUNC(for_range, AstFor* for_node, u64 iter_local) { emit_enter_structured_block(mod, &code, SBT_Basic_Loop); emit_enter_structured_block(mod, &code, SBT_Continue_Block); - WIL(WI_LOCAL_GET, iter_local); - WIL(WI_LOCAL_GET, high_local); - WI(WI_I32_GE_S); - WID(WI_COND_JUMP, 0x02); + if (range->kind == Ast_Kind_Struct_Literal && (range->args.values[2]->flags & Ast_Flag_Comptime) != 0) { + AstNumLit *step_value = (AstNumLit *) range->args.values[2]; + assert(step_value->kind == Ast_Kind_NumLit); + + if (step_value->value.l >= 0) { + WIL(WI_LOCAL_GET, iter_local); + WIL(WI_LOCAL_GET, high_local); + WI(WI_I32_GE_S); + WID(WI_COND_JUMP, 0x02); + } else { + WIL(WI_LOCAL_GET, iter_local); + WIL(WI_LOCAL_GET, high_local); + WI(WI_I32_LT_S); + WID(WI_COND_JUMP, 0x02); + } + + } else { + WIL(WI_LOCAL_GET, step_local); + WID(WI_I32_CONST, 0); + WI(WI_I32_GE_S); + WID(WI_IF_START, 0x40); + WIL(WI_LOCAL_GET, iter_local); + WIL(WI_LOCAL_GET, high_local); + WI(WI_I32_GE_S); + WID(WI_COND_JUMP, 0x03); + WI(WI_ELSE); + WIL(WI_LOCAL_GET, iter_local); + WIL(WI_LOCAL_GET, high_local); + WI(WI_I32_LT_S); + WID(WI_COND_JUMP, 0x03); + WI(WI_IF_END); + } + emit_block(mod, &code, for_node->stmt, 0);