for loops over a range iterate backwards if step is negative
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 20 Apr 2022 23:55:14 +0000 (18:55 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 20 Apr 2022 23:55:14 +0000 (18:55 -0500)
core/hash.onyx
core/type_info/helper.onyx
docs/logos/logo.svg
docs/logos/logo_256.png [new file with mode: 0644]
docs/logos/logo_512.png [new file with mode: 0644]
src/wasm_emit.c

index f02695374cec60c34f832be85fc107f83885e6c3..c915f2cdf3288691916cbb87021a6731a42e4b2b 100644 (file)
@@ -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 {
index 6864278e7d9b70e68d3ec009a256f1076b6a49e5..8c9c9ac818d85142aa6d22286ad43ade3e689a93 100644 (file)
@@ -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
index d64d2adf8d62cb622f8c32dac50f0b32125f4a9b..93c70a6ca3a5fe19781beda029d150020895ed90 100644 (file)
@@ -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"
      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 (file)
index 0000000..e0d94be
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 (file)
index 0000000..71698c6
Binary files /dev/null and b/docs/logos/logo_512.png differ
index 237507d9f078c77f583b64513bf452aa2a2995a9..07884a2c19ea8804df628c34b85df32e105646d6 100644 (file)
@@ -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);