added `iter.comp`; vscode syntax bugfix
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 7 Oct 2022 18:19:08 +0000 (13:19 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 7 Oct 2022 18:19:08 +0000 (13:19 -0500)
compiler/src/onyx.c
core/container/iter.onyx
misc/vscode/onyx-0.0.4.vsix
misc/vscode/syntaxes/onyx.tmLanguage

index 4e7540c536ecced3baa20cfad482de129198d9c3..6f908e66aa4416d48355aff62e39f698b9df4e2a 100644 (file)
@@ -609,6 +609,21 @@ static i32 onyx_compile() {
         }
 #endif
 
+        /*
+        struct timespec spec;
+        clock_gettime(CLOCK_REALTIME, &spec);
+        u64 nano_time = spec.tv_nsec + 1000000000 * (spec.tv_sec % 100);
+        printf("%lu %d %d %d %d %d %d %d\n",
+                nano_time,
+                bh_arr_length(context.entities.entities),
+                context.entities.state_count[Entity_State_Introduce_Symbols],
+                context.entities.state_count[Entity_State_Parse],
+                context.entities.state_count[Entity_State_Resolve_Symbols],
+                context.entities.state_count[Entity_State_Check_Types],
+                context.entities.state_count[Entity_State_Code_Gen],
+                context.entities.state_count[Entity_State_Finalized]);
+        */
+
         // Mostly a preventative thing to ensure that even if somehow
         // errors were left disabled, they are re-enabled in this cycle.
         onyx_errors_enable();
index 87988f21b48c914b75c5328fa9d83c734b92101b..b3516fdcc6e622f7c03d57fcfd29dbe15925bd68 100644 (file)
@@ -634,6 +634,44 @@ to_array :: (it: Iterator($T), allocator := context.allocator) -> [..] T {
     return arr;
 }
 
+//
+// Simple iterator comprehensions, in the same vein
+// as Pythons comprehension syntax.
+// 
+// Python:
+//     results = [it * 2 for it in [1, 2, 3, 4, 5]]
+// Onyx:
+//     results := iter.comp(u32.[1, 2, 3, 4, 5], #(it * 2));
+comp :: #match #local {}
+
+#overload
+comp :: macro (i: Iterator(^$V), value: Code) => {
+    it: V;
+    a := make([..] typeof #unquote value);
+
+    for __it: i {
+        it := *__it;
+        a << (#unquote value);
+    }
+    return a;
+}
+
+#overload
+comp :: macro (i: Iterator($V), value: Code) => {
+    it: V;
+    a := make([..] typeof #unquote value);
+
+    for i do a << (#unquote value);
+    return a;
+}
+
+#overload
+comp :: macro (i: $I/Iterable, value: Code) => {
+    as_iterator :: as_iterator
+    comp        :: comp
+    return comp(as_iterator(i), value);
+}
+
 
 #if runtime.Multi_Threading_Enabled {
     #local sync :: core.sync
index 6f7437f6e466196e11cd967a5eeaa3dbdcb7a684..2c47d8835c0bc49bc165a2c734220f0178904992 100644 (file)
Binary files a/misc/vscode/onyx-0.0.4.vsix and b/misc/vscode/onyx-0.0.4.vsix differ
index b35555aa9ca61588e7be725b9997d6b6a80edcf9..236b2be9f8bc7c42c5e2cda397620b8e43a37f0f 100644 (file)
                                </dict>
                                <dict>
                                        <key>match</key>
-                                       <string>@[^\s;]+</string>
+                                       <string>@[^\n]+</string>
                                        <key>name</key>
                                        <string>keyword.tag.onyx</string>
                                </dict>