From: Brendan Hansen Date: Fri, 7 Oct 2022 18:19:08 +0000 (-0500) Subject: added `iter.comp`; vscode syntax bugfix X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=23fca6ac0e97542f1cd5070a7b953879b32f51e3;p=onyx.git added `iter.comp`; vscode syntax bugfix --- diff --git a/compiler/src/onyx.c b/compiler/src/onyx.c index 4e7540c5..6f908e66 100644 --- a/compiler/src/onyx.c +++ b/compiler/src/onyx.c @@ -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(); diff --git a/core/container/iter.onyx b/core/container/iter.onyx index 87988f21..b3516fdc 100644 --- a/core/container/iter.onyx +++ b/core/container/iter.onyx @@ -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 diff --git a/misc/vscode/onyx-0.0.4.vsix b/misc/vscode/onyx-0.0.4.vsix index 6f7437f6..2c47d883 100644 Binary files a/misc/vscode/onyx-0.0.4.vsix and b/misc/vscode/onyx-0.0.4.vsix differ diff --git a/misc/vscode/syntaxes/onyx.tmLanguage b/misc/vscode/syntaxes/onyx.tmLanguage index b35555aa..236b2be9 100644 --- a/misc/vscode/syntaxes/onyx.tmLanguage +++ b/misc/vscode/syntaxes/onyx.tmLanguage @@ -220,7 +220,7 @@ match - @[^\s;]+ + @[^\n]+ name keyword.tag.onyx