breaking syntax change
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 3 Feb 2024 21:59:01 +0000 (15:59 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 3 Feb 2024 21:59:01 +0000 (15:59 -0600)
`for` loop syntax
`case` capture syntax
added `.*`

131 files changed:
compiler/include/lex.h
compiler/src/checker.c
compiler/src/lex.c
compiler/src/parser.c
core/alloc/alloc.onyx
core/alloc/memdebug.onyx
core/alloc/pool.onyx
core/builtin.onyx
core/container/array.onyx
core/container/bucket_array.onyx
core/container/iter.onyx
core/container/map.onyx
core/container/optional.onyx
core/container/result.onyx
core/container/set.onyx
core/container/slice.onyx
core/conv/conv.onyx
core/conv/format.onyx
core/encoding/base64.onyx
core/encoding/csv.onyx
core/encoding/hex.onyx
core/encoding/ini.onyx
core/encoding/json/encoder.onyx
core/encoding/json/parser.onyx
core/encoding/json/tokenizer.onyx
core/encoding/json/types.onyx
core/encoding/kdl/encoder.onyx
core/encoding/kdl/kdl.onyx
core/encoding/kdl/kql.onyx
core/encoding/kdl/parser.onyx
core/encoding/osad.onyx
core/hash/hash.onyx
core/hash/md5.onyx
core/hash/sha256.onyx
core/io/stdio.onyx
core/io/stream.onyx
core/io/writer.onyx
core/math/math.onyx
core/misc/arg_parse.onyx
core/net/net.onyx
core/net/tcp.onyx
core/onyx/cbindgen.onyx
core/onyx/cptr.onyx
core/os/path.onyx
core/runtime/info/global_tags.onyx
core/runtime/info/helper.onyx
core/runtime/info/proc_tags.onyx
core/runtime/platform/onyx/fs.onyx
core/runtime/platform/onyx/net.onyx
core/runtime/platform/wasi/platform.onyx
core/runtime/platform/wasi/wasi_env.onyx
core/runtime/platform/wasi/wasi_fs.onyx
core/runtime/platform/wasi/wasix_net.onyx
core/string/buffer.onyx
core/string/string.onyx
core/time/time.onyx
examples/03_basics.onyx
examples/04_fixed_arrays.onyx
examples/05_slices.onyx
examples/06_dynamic_arrays.onyx
examples/07_structs.onyx
examples/09_for_loops.onyx
examples/12_varargs.onyx
examples/14_overloaded_procs.onyx
examples/15_polymorphic_procs.onyx
examples/18_macros.onyx
examples/19_do_blocks.onyx
examples/20_auto_return.onyx
scripts/onyx-pkg.onyx
scripts/run_tests.onyx
tests/aoc-2020/day1.onyx
tests/aoc-2020/day10.onyx
tests/aoc-2020/day11.onyx
tests/aoc-2020/day13.onyx
tests/aoc-2020/day14.onyx
tests/aoc-2020/day15.onyx
tests/aoc-2020/day16.onyx
tests/aoc-2020/day17.onyx
tests/aoc-2020/day19.onyx
tests/aoc-2020/day2.onyx
tests/aoc-2020/day20.onyx
tests/aoc-2020/day21.onyx
tests/aoc-2020/day22.onyx
tests/aoc-2020/day23.onyx
tests/aoc-2020/day24.onyx
tests/aoc-2020/day25.onyx
tests/aoc-2020/day3.onyx
tests/aoc-2020/day4.onyx
tests/aoc-2020/day5.onyx
tests/aoc-2020/day6.onyx
tests/aoc-2020/day7.onyx
tests/aoc-2020/day8.onyx
tests/aoc-2020/day9.onyx
tests/aoc-2021/day01.onyx
tests/aoc-2021/day02.onyx
tests/aoc-2021/day03.onyx
tests/aoc-2021/day04.onyx
tests/aoc-2021/day05.onyx
tests/aoc-2021/day06.onyx
tests/aoc-2021/day07.onyx
tests/aoc-2021/day08.onyx
tests/aoc-2021/day09.onyx
tests/aoc-2021/day10.onyx
tests/aoc-2021/day11.onyx
tests/aoc-2021/day12.onyx
tests/aoc-2021/day13.onyx
tests/aoc-2021/day14.onyx
tests/aoc-2021/day15.onyx
tests/aoc-2021/day16.onyx
tests/aoc-2021/day17.onyx
tests/aoc-2021/day18.onyx
tests/array_struct_robustness.onyx
tests/atomics.onyx
tests/baked_parameters.onyx
tests/bucket_array.onyx
tests/bugs/fallthrough_defer_interaction.onyx
tests/float_parsing.onyx
tests/lazy_iterators.onyx
tests/multiple_returns_robustness.onyx
tests/named_arguments_test.onyx
tests/operator_overload.onyx
tests/poly_structs_with_values.onyx
tests/polymorphic_array_lengths.onyx
tests/sets.onyx
tests/stdlib/os_path.onyx
tests/string_stream_test.onyx
tests/switch_expressions.onyx
tests/tagged_globals.onyx
tests/tagged_unions.onyx
tests/utf8_test.onyx
tests/vararg_test.onyx

index 9a0638a3427a09500fa98df53fdf31885b957a82..01711e88f3f2889760747b5e2fc7502470b4654f 100644 (file)
@@ -41,6 +41,8 @@ typedef enum TokenType {
     Token_Type_Keyword_Macro,
     Token_Type_Keyword_Interface,
     Token_Type_Keyword_Where,
+    Token_Type_Keyword_As,
+    Token_Type_Keyword_In,
     Token_Type_Keyword_End,
 
     Token_Type_Right_Arrow,
index 347698b1bd8870b1e337cce7255992514dfb1f75..8fed0610304979e76fa0279524fd864dda52270f 100644 (file)
@@ -263,6 +263,8 @@ CheckStatus check_for(AstFor* fornode) {
     builtin_range_type_type = type_build_from_ast(context.ast_alloc, builtin_range_type);
     if (builtin_range_type_type == NULL) YIELD(fornode->token->pos, "Waiting for 'range' structure to be built.");
 
+    Type* given_type = NULL;
+
     fornode->loop_type = For_Loop_Invalid;
     if (types_are_compatible(iter_type, &basic_types[Basic_Kind_I32])) {
         if (fornode->by_pointer) {
@@ -274,7 +276,7 @@ CheckStatus check_for(AstFor* fornode) {
         CHECK(range_literal, &rl);
         fornode->iter = (AstTyped *) rl;
 
-        fornode->var->type = builtin_range_type_type->Struct.memarr[0]->type;
+        given_type = builtin_range_type_type->Struct.memarr[0]->type;
         fornode->var->flags |= Ast_Flag_Cannot_Take_Addr;
         fornode->loop_type = For_Loop_Range;
     }
@@ -285,20 +287,20 @@ CheckStatus check_for(AstFor* fornode) {
 
         // NOTE: Blindly copy the first range member's type which will
         // be the low value.                - brendanfh 2020/09/04
-        fornode->var->type = builtin_range_type_type->Struct.memarr[0]->type;
+        given_type = builtin_range_type_type->Struct.memarr[0]->type;
         fornode->var->flags |= Ast_Flag_Cannot_Take_Addr;
         fornode->loop_type = For_Loop_Range;
 
     }
     else if (iter_type->kind == Type_Kind_Array) {
-        if (fornode->by_pointer) fornode->var->type = type_make_pointer(context.ast_alloc, iter_type->Array.elem);
-        else                     fornode->var->type = iter_type->Array.elem;
+        if (fornode->by_pointer) given_type = type_make_pointer(context.ast_alloc, iter_type->Array.elem);
+        else                     given_type = iter_type->Array.elem;
 
         fornode->loop_type = For_Loop_Array;
     }
     else if (iter_type->kind == Type_Kind_Slice) {
-        if (fornode->by_pointer) fornode->var->type = type_make_pointer(context.ast_alloc, iter_type->Slice.elem);
-        else                     fornode->var->type = iter_type->Slice.elem;
+        if (fornode->by_pointer) given_type = type_make_pointer(context.ast_alloc, iter_type->Slice.elem);
+        else                     given_type = iter_type->Slice.elem;
 
         fornode->loop_type = For_Loop_Slice;
 
@@ -308,14 +310,14 @@ CheckStatus check_for(AstFor* fornode) {
             ERROR_(error_loc, "Cannot iterate by pointer over '%s'.", type_get_name(iter_type));
         }
 
-        fornode->var->type = iter_type->VarArgs.elem;
+        given_type = iter_type->VarArgs.elem;
 
         // NOTE: Slices are VarArgs are being treated the same here.
         fornode->loop_type = For_Loop_Slice;
     }
     else if (iter_type->kind == Type_Kind_DynArray) {
-        if (fornode->by_pointer) fornode->var->type = type_make_pointer(context.ast_alloc, iter_type->DynArray.elem);
-        else                     fornode->var->type = iter_type->DynArray.elem;
+        if (fornode->by_pointer) given_type = type_make_pointer(context.ast_alloc, iter_type->DynArray.elem);
+        else                     given_type = iter_type->DynArray.elem;
 
         fornode->loop_type = For_Loop_DynArr;
     }
@@ -325,10 +327,22 @@ CheckStatus check_for(AstFor* fornode) {
         }
 
         // HACK: This assumes the Iterator type only has a single type argument.
-        fornode->var->type = iter_type->Struct.poly_sln[0].type;
+        given_type = iter_type->Struct.poly_sln[0].type;
         fornode->loop_type = For_Loop_Iterator;
     }
 
+    assert(given_type);
+
+    if (fornode->var->type_node) {
+        fill_in_type((AstTyped *) fornode->var);
+        TYPE_CHECK((AstTyped **) &fornode->var, given_type) {
+            ERROR_(error_loc, "Mismatched type for loop variable. You specified '%s', but it should be '%s'.", type_get_name(fornode->var->type), type_get_name(given_type));
+        }
+
+    } else {
+        fornode->var->type = given_type;
+    }
+
     if (fornode->by_pointer)
         fornode->var->flags |= Ast_Flag_Cannot_Take_Addr;
 
index 81e866bb1769e3dab67304a6a46ae4e29e5e948c..01380167b30f2d11d66bd0d298deb67c4e84253b 100644 (file)
@@ -36,6 +36,8 @@ static const char* token_type_names[] = {
     "macro",
     "interface",
     "where",
+    "as",
+    "in",
     "", // end
 
     "->",
@@ -345,6 +347,7 @@ whitespace_skipped:
     char curr = *tokenizer->curr;
     switch (curr) {
     case 'a':
+        LITERAL_TOKEN("as",          1, Token_Type_Keyword_As);
         LITERAL_TOKEN("alignof",     1, Token_Type_Keyword_Alignof);
         break;
     case 'b':
@@ -374,6 +377,7 @@ whitespace_skipped:
         break;
     case 'i':
         LITERAL_TOKEN("if",          1, Token_Type_Keyword_If);
+        LITERAL_TOKEN("in",          1, Token_Type_Keyword_In);
         LITERAL_TOKEN("interface",   1, Token_Type_Keyword_Interface);
         break;
     case 'm':
index 13d4e1f46cebe4e9c171276b65233d6b54347ce5..3277f2c01ca92e51ee4e9d7610d1ec5666406919 100644 (file)
@@ -949,11 +949,20 @@ static AstTyped* parse_factor(OnyxParser* parser) {
                 if (parse_possible_array_literal(parser, retval, &retval))  return retval;
 
                 consume_token(parser);
-                AstFieldAccess* field = make_node(AstFieldAccess, Ast_Kind_Field_Access);
-                field->token = expect_token(parser, Token_Type_Symbol);
-                field->expr  = retval;
+                if (parser->curr->type == '*') {
+                    AstDereference* deref_node = make_node(AstDereference, Ast_Kind_Dereference);
+                    deref_node->token = expect_token(parser, '*');
+                    deref_node->expr  = retval;
+
+                    retval = (AstTyped *) deref_node;
+
+                } else {
+                    AstFieldAccess* field = make_node(AstFieldAccess, Ast_Kind_Field_Access);
+                    field->token = expect_token(parser, Token_Type_Symbol);
+                    field->expr  = retval;
 
-                retval = (AstTyped *) field;
+                    retval = (AstTyped *) field;
+                }
                 break;
             }
 
@@ -1331,13 +1340,19 @@ static AstFor* parse_for_stmt(OnyxParser* parser) {
         for_node->by_pointer = 1;
     }
 
-    if (next_tokens_are(parser, 2, Token_Type_Symbol, ':')) {
+    if (next_tokens_are(parser, 2, Token_Type_Symbol, Token_Type_Keyword_In)
+        || next_tokens_are(parser, 2, Token_Type_Symbol, ':')
+    ) {
         OnyxToken* local_sym = expect_token(parser, Token_Type_Symbol);
         AstLocal* var_node = make_local(parser->allocator, local_sym, NULL);
 
         for_node->var = var_node;
+        if (peek_token(0)->type == ':') {
+            expect_token(parser, ':');
+            var_node->type_node = parse_type(parser);
+        }
 
-        expect_token(parser, ':');
+        expect_token(parser, Token_Type_Keyword_In);
     } else {
         // HACK
         static char it_name[] = "it ";
@@ -1361,23 +1376,6 @@ static AstSwitchCase* parse_case_stmt(OnyxParser* parser) {
         sc_node->is_default = 1;
 
     } else {
-        if (   next_tokens_are(parser, 3, '&', Token_Type_Symbol, ':')
-            || next_tokens_are(parser, 3, '^', Token_Type_Symbol, ':')
-            || next_tokens_are(parser, 2, Token_Type_Symbol, ':')
-       ) {
-            b32 is_pointer = 0;
-            if (consume_token_if_next(parser, '&') || consume_token_if_next(parser, '^'))
-                is_pointer = 1;
-
-            OnyxToken *capture_symbol = expect_token(parser, Token_Type_Symbol);
-            AstLocal *capture = make_local(parser->allocator, capture_symbol, NULL);
-
-            sc_node->capture = capture;
-            sc_node->capture_is_by_pointer = is_pointer;
-
-            expect_token(parser, ':');
-        }
-
         bh_arr_new(global_heap_allocator, sc_node->values, 1);
 
         parser->parse_quick_functions = 0;
@@ -1391,6 +1389,23 @@ static AstSwitchCase* parse_case_stmt(OnyxParser* parser) {
         }
 
         parser->parse_quick_functions = 1;
+
+        if (   next_tokens_are(parser, 3, Token_Type_Keyword_As, '&', Token_Type_Symbol)
+            || next_tokens_are(parser, 3, Token_Type_Keyword_As, '^', Token_Type_Symbol)
+            || next_tokens_are(parser, 2, Token_Type_Keyword_As, Token_Type_Symbol)
+        ) {
+            expect_token(parser, Token_Type_Keyword_As);
+
+            b32 is_pointer = 0;
+            if (consume_token_if_next(parser, '&') || consume_token_if_next(parser, '^'))
+                is_pointer = 1;
+
+            OnyxToken *capture_symbol = expect_token(parser, Token_Type_Symbol);
+            AstLocal *capture = make_local(parser->allocator, capture_symbol, NULL);
+
+            sc_node->capture = capture;
+            sc_node->capture_is_by_pointer = is_pointer;
+        }
     }
 
     if (consume_token_if_next(parser, Token_Type_Fat_Right_Arrow)) {
index 080bc61a935a821ed6490dfedae7df20b381425c..4b5ab07f116c331076b77d5fecbf78833e577f81 100644 (file)
@@ -41,7 +41,7 @@ array_from_stack :: macro ($T: type_expr, size: u32) -> [] T {
 }
 
 #doc """
-    Moves a value on to the heap. Useful for cases like this:
+    Moves a value on to the heap. Useful for cases like this in
 
         f :: () -> &Foo {
             return alloc.on_heap(Foo.{
index 4a5b7969aaf5c305328c8d3d856e8ff00eee181b..98f97eeb0e8f2a2bb989130c14f52d57b3fe289a 100644 (file)
@@ -109,7 +109,7 @@ memdebug_proc :: (m: &MemDebugState, action: AllocationAction, size: u32, align:
     stack_trace := runtime.info.get_stack_trace();
     if stack_trace {
         slice.init(&trace, stack_trace.count, context.temp_allocator);
-        for i: stack_trace.count {
+        for i in stack_trace.count {
             info := stack_trace[i].info;
             trace[i] = .{
                 info.file, info.line, stack_trace[i].current_line, info.func_name
index d8c94cf0f05972b27f526ded12478619b653e696..b69e95eb3c1562ed5369bbfa182163baafe932dc 100644 (file)
@@ -69,7 +69,7 @@ pool_free :: (pool: &PoolAllocator($Elem), elem: &Elem) {
 make :: (buffer: [] $Elem) -> PoolAllocator(Elem) {
     assert(sizeof Elem >= sizeof rawptr, "Cannot have a pool allocator of a type less than a rawptr in size.");
 
-    for i: 0 .. buffer.count - 1 {
+    for i in 0 .. buffer.count - 1 {
         *(cast(&rawptr) &buffer[i]) = cast(rawptr) &buffer[i + 1];
     }
 
index 425ddda54c320e1f1c824c3876131ffaf1c8ea1f..4f166a45645ccd5613fb80482797bb03afc5fc23 100644 (file)
@@ -40,7 +40,7 @@ dyn_str :: #type [..] u8;
 // This is a special type that the compiler knows how to iterator through.
 // So, one can simply write:
 //
-//      for x: 1 .. 5 { ... }
+//      for x in 1 .. 5 { ... }
 //
 // Although not controllable from the literal syntax, there is a `step`
 // member that allows you control how many numbers to advance each iteration.
index 338ffb9f050ffc8d8dcc15891e7d49084b88c329..421345c07ca1eaa229132f19da27c4cdc809e2d1 100644 (file)
@@ -80,13 +80,13 @@ copy :: #match #locked {
         init(&new_arr, arr.count, allocator);
         new_arr.count = arr.count;
 
-        for i: 0 .. arr.count do new_arr.data[i] = arr.data[i];
+        for i in 0 .. arr.count do new_arr.data[i] = arr.data[i];
         return new_arr;
     },
 
     (arr: [] $T, allocator := context.allocator) -> [] T {
         new_arr := builtin.make([] T, arr.count);
-        for i: 0 .. arr.count do new_arr.data[i] = arr.data[i];
+        for i in 0 .. arr.count do new_arr.data[i] = arr.data[i];
         return new_arr;
     }
 }
@@ -103,7 +103,7 @@ copy_range :: (arr: &[..] $T, r: range, allocator := context.allocator) -> [..]
     init(&new_arr, r.high - r.low, allocator);
     new_arr.count = r.high - r.low;
 
-    for i: r do new_arr.data[i] = arr.data[i];
+    for i in r do new_arr.data[i] = arr.data[i];
     return new_arr;
 }
 
@@ -188,7 +188,7 @@ insert :: (arr: &[..] $T, idx: u32, new_arr: [] T) -> bool {
         i -= 1;
     }
 
-    for i: 0 .. new_arr.count {
+    for i in 0 .. new_arr.count {
         arr.data[i + idx] = new_arr[i];
     }
     return true;
@@ -240,7 +240,7 @@ delete :: (arr: &[..] $T, idx: u32) -> T {
     if idx >= arr.count do return .{};
 
     to_return := arr.data[idx];
-    for i: idx .. arr.count - 1 {
+    for i in idx .. arr.count - 1 {
         arr.data[i] = arr.data[i + 1];
     }
 
index 8df7e88276bab1ad6190c4115f61583d55200291..5c5750dfd197747a06bd3ac719fbb69ef473aeaf 100644 (file)
@@ -40,7 +40,7 @@ init :: (use b: &Bucket_Array($T), elements: i32,
 
 // Frees all the buckets
 clear :: (use b: &Bucket_Array($T)) {
-    for &bucket: &buckets {
+    for &bucket in &buckets {
         raw_free(bucket_allocator, bucket.data);
         bucket.count = 0;
     }
@@ -95,8 +95,8 @@ pop :: (use b: &Bucket_Array($T)) {
 
 // Give you a pointer to the bucket data via 'it'.
 for_each :: macro (b: Bucket_Array($T), body: Code) {
-    for &bucket: b.buckets {
-        for bucket_index: bucket.count {
+    for &bucket in b.buckets {
+        for bucket_index in bucket.count {
             it := &bucket.data[bucket_index];
 
             #unquote body(it);
index a13bc9cff1b133bee780763e9ecafed4f0712ace..c14dbefa12cf9a54472a2b799238012be0661211 100644 (file)
@@ -747,7 +747,7 @@ find :: macro (it: $T/Iterable, predicate: $F) =>
 
 #overload
 find :: (it: Iterator($T), predicate: (T) -> bool) -> ? T {
-    for v: it {
+    for v in it {
         if predicate(v) {
             return v;
         }
@@ -772,7 +772,7 @@ fold :: macro (it: $T/Iterable, init: $R, combine: $S) =>
 fold :: (it: Iterator($T), initial_value: $R, combine: (T, R) -> R) -> R {
     result := initial_value;
 
-    for value: it {
+    for value in it {
         result = combine(value, result);
     }
 
@@ -795,7 +795,7 @@ fold1 :: (it: Iterator($T), combine: (T, T) -> T) -> ? T {
     result, valid := next(it);
     if !valid do return .None;
 
-    for value: it {
+    for value in it {
         result = combine(value, result);
     }
 
@@ -813,7 +813,7 @@ count :: macro (it: $T/Iterable, cond: $F) =>
 #overload
 count :: (it: Iterator($T), cond: (T) -> bool) -> i32 {
     c := 0;
-    for value: it do if cond(value) do c += 1;
+    for value in it do if cond(value) do c += 1;
     return c;
 }
 
@@ -828,7 +828,7 @@ some :: macro (it: $T/Iterable, cond: $F) =>
 
 #overload
 some :: (it: Iterator($T), cond: (T) -> bool) -> bool {
-    for value: it do if cond(value) do return true;
+    for value in it do if cond(value) do return true;
     return false;
 }
 
@@ -842,7 +842,7 @@ every :: macro (it: $T/Iterable, cond: $F) =>
 
 #overload
 every :: (it: Iterator($T), cond: (T) -> bool) -> bool {
-    for value: it do if !cond(value) do return false;
+    for value in it do if !cond(value) do return false;
     return true;
 }
 
@@ -857,7 +857,7 @@ sum :: macro (it: $T/Iterable) =>
 sum :: (it: Iterator($T)) -> T {
     val := T.{};
 
-    for v: it {
+    for v in it {
         val = val + v;
     }
 
@@ -871,7 +871,7 @@ sum :: (it: Iterator($T)) -> T {
 """
 to_array :: (it: Iterator($T), allocator := context.allocator) -> [..] T {
     arr := array.make(T, allocator=allocator);
-    for v: it do array.push(&arr, v);
+    for v in it do array.push(&arr, v);
 
     return arr;
 }
@@ -880,7 +880,7 @@ to_array :: (it: Iterator($T), allocator := context.allocator) -> [..] T {
 """
 to_map :: (it: Iterator(Pair($K, $V)), allocator := context.allocator) -> Map(K, V) {
     m := builtin.make(Map(K, V), allocator=allocator);
-    for p: it {
+    for p in it {
         m->put(p.first, p.second);
     }
     return m;
@@ -962,7 +962,7 @@ comp :: macro (i: Iterator(&$V), value: Code) => {
     it: V;
     a := make([..] typeof #unquote value);
 
-    for __it: i {
+    for __it in i {
         it := *__it;
         a << (#unquote value(it));
     }
index 7aff718ce0e19481904e4fdc40a619556bfefc84..93f11c47c09185c9b968b548e00087dd8222c636 100644 (file)
@@ -228,7 +228,7 @@ update :: macro (map: ^Map, key: map.Key_Type, body: Code) {
     modify memory, so be wary of dangling pointers!
 """
 clear :: (use map: &Map) {
-    for i: 0 .. hashes.count do hashes.data[i] = -1;
+    for i in 0 .. hashes.count do hashes.data[i] = -1;
     entries.count = 0;
 }
 
@@ -357,10 +357,10 @@ as_iter :: (m: &Map) =>
         hashes = builtin.make([] u32, new_size, allocator=allocator);
         array.fill(hashes, -1);
 
-        for &entry: entries do entry.next = -1;
+        for &entry in entries do entry.next = -1;
 
         index := 0;
-        for &entry: entries {
+        for &entry in entries {
             defer index += 1;
 
             hash_index := entry.hash % hashes.count;
index c4bdd55133354c4cc1fc4bef62d874113d4e0f16..c94eb1a45889fda394b3c30863d2e767d73da532 100644 (file)
@@ -47,7 +47,7 @@ use core
         no value is present.
     """
     value_or :: (o: ?$T, default: T) => switch o {
-        case v: .Some => v;
+        case .Some as v => v;
         case #default => default;
     }
 
@@ -65,7 +65,7 @@ use core
     // @Bug should be able to say ? ? $T here.
     flatten :: (o1: ? Optional($T)) -> ? T {
         switch o1 {
-            case o2: .Some {
+            case .Some as o2 {
                 return o2;
             }
 
@@ -78,7 +78,7 @@ use core
     #doc "Monadic chaining operation."
     and_then :: (o: ?$T, transform: (T) -> ?$R) -> ?R {
         return switch o {
-            case v: .Some => transform(v);
+            case .Some as v => transform(v);
             case #default => .None;
         };
     }
@@ -86,7 +86,7 @@ use core
     #doc "Changes the value inside the optional, if present."
     transform :: (o: ?$T, transform: (T) -> $R) -> ?R {
         switch o {
-            case v: .Some do return .{ Some = transform(v) };
+            case .Some as v do return .{ Some = transform(v) };
             case #default do return .None;
         }
     }
@@ -109,7 +109,7 @@ use core
     """
     unwrap :: (o: ?$T) -> T {
         switch o {
-            case v: .Some do return v;
+            case .Some as v do return v;
             case #default {
                 assert(false, "Unwrapping empty Optional.");
             }
@@ -123,7 +123,7 @@ use core
     """
     unwrap_ptr :: (o: & ?$T) -> &T {
         switch o {
-            case &v: .Some do return v;
+            case .Some as &v do return v;
             case #default {
                 assert(false, "Unwrapping empty Optional.");
             }
@@ -137,7 +137,7 @@ use core
     """
     expect :: (o: ?$T, message: str) -> T {
         switch o {
-            case v: .Some do return v;
+            case .Some as v do return v;
             case #default {
                 assert(false, message);
             }
@@ -151,7 +151,7 @@ use core
     """
     expect_ptr :: (o: & ?$T, message: str) -> &T {
         switch o {
-            case &v: .Some do return v;
+            case .Some as &v do return v;
             case #default {
                 assert(false, message);
             }
@@ -161,7 +161,7 @@ use core
     or_return :: #match {
         macro (o: ?$T) -> T {
             switch value := o; value {
-                case v: .Some do return v;
+                case .Some as v do return v;
                 case #default {
                     return return .{};
                 }
@@ -169,7 +169,7 @@ use core
         },
         macro (o: ?$T, return_value: $R) -> T {
             switch value := o; value {
-                case v: .Some do return v;
+                case .Some as v do return v;
                 case #default {
                     return return return_value;
                 }
@@ -179,7 +179,7 @@ use core
 
     catch :: macro (o: ?$T, body: Code) -> T {
         switch value := o; value {
-            case v: .Some do return v;
+            case .Some as v do return v;
             case .None {
                 #unquote body;
             }
@@ -189,7 +189,7 @@ use core
     with :: macro (o: ?$T, body: Code) {
         switch o {
             case .None ---;
-            case it: .Some {
+            case .Some as it {
                 #unquote body(it);
             }
         }
@@ -248,7 +248,7 @@ use core
 
 
     hash :: (o: ?$T/core.hash.Hashable) => switch o {
-        case v: .Some => core.hash.hash(v);
+        case .Some as v => core.hash.hash(v);
         case #default => 0;
     }
 }
@@ -258,20 +258,20 @@ use core
 
     return switch o1 {
         case .None => true;
-        case v1: .Some => v1 == o2->unwrap();
+        case .Some as v1 => v1 == o2->unwrap();
     };
 }
 
 #operator ?? macro (opt: ?$T, default: T) -> T {
     return switch value := opt; value {
-        case v: .Some => v;
+        case .Some as v => v;
         case #default => default;
     };
 }
 
 #operator ?? macro (opt: ?$T, catch: Code) -> T {
     switch value := opt; value {
-        case v: .Some do return v;
+        case .Some as v do return v;
         case #default ---
     }
 
@@ -280,7 +280,7 @@ use core
 
 #operator ? macro (opt: ?$T) -> T {
     switch value := opt; value {
-        case v: .Some do return v;
+        case .Some as v do return v;
         case #default do return return .{};
     }
 }
index a266d0629f8a86be72b109c2620e46f6281bc188..ac3426843c3fb6eb77948698f5b2da37b9d5556d 100644 (file)
@@ -44,7 +44,7 @@ Result :: union (Ok_Type: type_expr, Err_Type: type_expr) {
     #doc "Returns an Optional of the Ok type."
     ok :: (r: #Self) -> Optional(r.Ok_Type) {
         return switch r {
-            case v: .Ok => Optional.make(v);
+            case .Ok as v => Optional.make(v);
             case #default => .{};
         };
     }
@@ -52,7 +52,7 @@ Result :: union (Ok_Type: type_expr, Err_Type: type_expr) {
     #doc "Returns an Optional of the Err type."
     err :: (r: #Self) -> Optional(r.Err_Type) {
         return switch r {
-            case v: .Err => Optional.make(v);
+            case .Err as v => Optional.make(v);
             case #default => .{};
         };
     }
@@ -63,8 +63,8 @@ Result :: union (Ok_Type: type_expr, Err_Type: type_expr) {
     """
     unwrap :: (r: #Self) -> r.Ok_Type {
         switch r {
-            case v: .Ok do return v;
-            case err: .Err {
+            case .Ok as v do return v;
+            case .Err as err {
                 msg := tprintf("Unwrapping Result with error '{}'.", err);
                 assert(false, msg);
                 return .{};
@@ -78,7 +78,7 @@ Result :: union (Ok_Type: type_expr, Err_Type: type_expr) {
     """
     unwrap_or_default :: (r: #Self) -> r.Ok_Type {
         return switch r {
-            case v: .Ok => v;
+            case .Ok as v => v;
             case #default => .{};
         };
     }
@@ -89,7 +89,7 @@ Result :: union (Ok_Type: type_expr, Err_Type: type_expr) {
     """
     expect :: (r: #Self, msg: str) -> r.Ok_Type {
         switch r {
-            case v: .Ok do return v;
+            case .Ok as v do return v;
             case #default {
                 assert(false, msg);
             }
@@ -103,23 +103,23 @@ Result :: union (Ok_Type: type_expr, Err_Type: type_expr) {
     """
     transform :: (r: Result($T, $E), f: (T) -> $R) -> Result(R, E) {
         return switch r {
-            case v: .Ok => .{ Ok = f(v) };
-            case v: .Err => .{ Err = v };
+            case .Ok as v => .{ Ok = f(v) };
+            case .Err as v => .{ Err = v };
         };
     }
 
     #doc "Monadic chaining operation."
     and_then :: (r: #Self, f: (r.Ok_Type) -> Result($R, r.Err_Type)) -> Result(R, r.Err_Type) {
         return switch r {
-            case v: .Ok  => f(v);
-            case v: .Err => .{ Err = v };
+            case .Ok as v  => f(v);
+            case .Err as v => .{ Err = v };
         };
     }
 
     #doc "If the Result contains Err, generate is called to make a value"
     or_else :: (r: #Self, generate: () -> typeof r) => {
         return switch r {
-            case v: .Ok   => v;
+            case .Ok as v   => v;
             case #default => generate();
         };
     }
@@ -142,8 +142,8 @@ Result :: union (Ok_Type: type_expr, Err_Type: type_expr) {
     """
     forward_err :: macro (r: Result($T, $E)) -> T {
         switch res := r; res {
-            case v: .Ok  do return v;
-            case v: .Err do return return .{ Err = v };
+            case .Ok as v  do return v;
+            case .Err as v do return return .{ Err = v };
         }
     }
 
@@ -153,7 +153,7 @@ Result :: union (Ok_Type: type_expr, Err_Type: type_expr) {
     """
     or_return :: macro (r: Result($T, $E), v: $V) -> T {
         switch res := r; res {
-            case v: .Ok  do return v;
+            case .Ok as v  do return v;
             case .Err do return return v;
         }
     }
@@ -168,8 +168,8 @@ Result :: union (Ok_Type: type_expr, Err_Type: type_expr) {
     """
     catch :: macro (r: Result($T, $E), on_err: Code) -> T {
         switch res := r; res {
-            case v: .Ok  do return v;
-            case err: .Err {
+            case .Ok as v  do return v;
+            case .Err as err {
                 #unquote on_err(err);
             }
         }
@@ -182,14 +182,14 @@ __implicit_bool_cast :: macro (r: Result($O, $E)) => cast(Result(O, E).tag_enum,
 
 #operator ? macro (r: Result($T, $E)) -> T {
     switch res := r; res {
-        case v: .Ok do return v;
-        case v: .Err do return return .{ Err = v };
+        case .Ok as v do return v;
+        case .Err as v do return return .{ Err = v };
     }
 }
 
 #operator ?? macro (r: Result($T, $E), v: T) -> T {
     return switch res := r; res {
-        case val: .Ok => val;
+        case .Ok as val => val;
         case .Err => v;
     };
 }
index ab771197a527a651e60fa22f1f9f61a6ec590077..83a4a1b0a35bce9f1fa259759d5052dd79dd2e82 100644 (file)
@@ -192,10 +192,10 @@ as_iter :: (s: &Set) =>
         hashes = builtin.make([] u32, new_size, allocator=allocator);
         array.fill(hashes, -1);
 
-        for &entry: entries do entry.next = -1;
+        for &entry in entries do entry.next = -1;
 
         index := 0;
-        for &entry: entries {
+        for &entry in entries {
             defer index += 1;
 
             hash_index := entry.hash % hashes.count;
index 4eb7ba7cb461d7622f369601c5b14a2b5b0e4d65..45c5a71229df6a3b0f586f1d6c993371a5f0616f 100644 (file)
@@ -161,12 +161,12 @@ set :: (arr: [] $T, idx: i32, value: T) {
 
 contains :: #match #locked {
     (arr: [] $T, x: T) -> bool {
-        for it: arr do if it == x do return true;
+        for it in arr do if it == x do return true;
         return false;
     }, 
 
     macro (arr: [] $T, $cmp: Code) -> bool {
-        for it: arr do if #unquote cmp(it) do return true;
+        for it in arr do if #unquote cmp(it) do return true;
         return false;
     }
 }
@@ -188,14 +188,14 @@ empty :: (arr: [] $T) => arr.count == 0;
 #doc "Uses `+` to sum all elements in the slice."
 sum :: (arr: [] $T, start: T = 0) -> T {
     sum := start;
-    for it: arr do sum += it;
+    for it in arr do sum += it;
     return sum;
 }
 
 #doc "Uses `*` to multiply all elements in the slice."
 product :: (arr: [] $T, start: T = 1) -> T {
     prod := start;
-    for it: arr do prod *= it;
+    for it in arr do prod *= it;
     return prod;
 }
 
@@ -206,7 +206,7 @@ product :: (arr: [] $T, start: T = 1) -> T {
 """
 average :: (arr: [] $T) -> T {
     sum := cast(T) 0;
-    for it: *arr do sum += it;
+    for it in *arr do sum += it;
 
     return sum / cast(T) arr.count;
 }
@@ -215,7 +215,7 @@ average :: (arr: [] $T) -> T {
     Reverses a slice in-place.
 """
 reverse :: (arr: [] $T) {
-    for i: arr.count / 2 {
+    for i in arr.count / 2 {
         tmp := arr[i];
         arr[i] = arr[arr.count - 1 - i];
         arr[arr.count - 1 - i] = tmp;
@@ -235,7 +235,7 @@ sort :: #match #local {}
 
 #overload
 sort :: (arr: [] $T, cmp: (T, T) -> i32) -> [] T {
-    for i: 1 .. arr.count {
+    for i in 1 .. arr.count {
         x := arr.data[i];
         j := i - 1;
 
@@ -258,7 +258,7 @@ sort :: (arr: [] $T, cmp: (T, T) -> i32) -> [] T {
 
 #overload
 sort :: (arr: [] $T, cmp: (&T, &T) -> i32) -> [] T {
-    for i: 1 .. arr.count {
+    for i in 1 .. arr.count {
         j := i;
 
         while j > 0 {
@@ -304,7 +304,7 @@ quicksort :: #match #locked {
         pivot := arr[hi];
         i := lo - 1;
 
-        for j: lo .. hi+1 {
+        for j in lo .. hi+1 {
             if cmp(arr[j], pivot) <= 0 {
                 i += 1;
                 tmp := arr[i];
@@ -321,7 +321,7 @@ quicksort :: #match #locked {
         pivot := &arr[hi];
         i := lo - 1;
 
-        for j: lo .. hi+1 {
+        for j in lo .. hi+1 {
             if cmp(&arr[j], pivot) <= 0 {
                 i += 1;
                 tmp := arr[i];
@@ -378,14 +378,14 @@ fold :: #match #local {}
 #overload
 fold :: (arr: [] $T, init: $R, f: (T, R) -> R) -> R {
     val := init;
-    for it: arr do val = f(it, val);
+    for it in arr do val = f(it, val);
     return val;
 }
 
 #overload
 fold :: macro (arr: [] $T, init: $R, body: Code) -> R {
     acc := init;
-    for it: arr do acc = #unquote body(it, acc);
+    for it in arr do acc = #unquote body(it, acc);
     return acc;
 }
 
@@ -433,7 +433,7 @@ some :: macro (arr: [] $T, predicate_body: Code) -> bool {
     Sets all elements in a slice to be `value`.
 """
 fill :: (arr: [] $T, value: T) {
-    for i: arr.count {
+    for i in arr.count {
         arr[i] = value;
     }
 }
@@ -442,7 +442,7 @@ fill :: (arr: [] $T, value: T) {
     Sets all elements in the range to be `value`.
 """
 fill_range :: (arr: [] $T, r: range, value: T) {
-    for i: r {
+    for i in r {
         if i >= arr.count || i < 0 do continue;
         arr[i] = value;
     }
@@ -454,7 +454,7 @@ fill_range :: (arr: [] $T, r: range, value: T) {
 to_list :: (arr: [] $T, allocator := context.allocator) -> List(T) {
     new_list := list.make(T, allocator);
 
-    for &it: arr {
+    for &it in arr {
         list.push_end(&new_list, *it);
     }
 
@@ -470,7 +470,7 @@ find :: #match #local {}
 
 #overload
 find :: (arr: [] $T, value: T) -> i32 {
-    for i: arr.count {
+    for i in arr.count {
         if value == arr.data[i] do return i;
     }
 
@@ -479,7 +479,7 @@ find :: (arr: [] $T, value: T) -> i32 {
 
 #overload
 find :: macro (arr: [] $T/type_is_struct, pred: Code) -> i32 {
-    for i: arr.count {
+    for i in arr.count {
         it := &arr[i];
         if #unquote pred(it) do return i;
     }
@@ -489,7 +489,7 @@ find :: macro (arr: [] $T/type_is_struct, pred: Code) -> i32 {
 
 #overload
 find :: macro (arr: [] $T, pred: Code) -> i32 {
-    for i: arr.count {
+    for i in arr.count {
         it := arr[i];
         if #unquote pred(it) do return i;
     }
@@ -503,7 +503,7 @@ find :: macro (arr: [] $T, pred: Code) -> i32 {
     Returns `null` if no matching element is found.
 """
 find_ptr :: (arr: [] $T, value: T) -> &T {
-    for &it: arr {
+    for &it in arr {
         if value == *it do return it;
     }
 
@@ -515,7 +515,7 @@ find_ptr :: (arr: [] $T, value: T) -> &T {
 """
 find_opt :: #match {
     macro (arr: [] $T/type_is_struct, cond: Code) -> ? T {
-        for& it: arr {
+        for& it in arr {
             if #unquote cond(it) {
                 return *it;
             }
@@ -524,7 +524,7 @@ find_opt :: #match {
     },
 
     macro (arr: [] $T, cond: Code) -> ? T {
-        for it: arr {
+        for it in arr {
             if #unquote cond(it) {
                 return it;
             }
@@ -551,7 +551,7 @@ first :: #match #locked {
         // This is to preserve the semantics that "it" is
         // not a pointer (same as contains), when T is not a
         // structure.
-        for &it_ptr: arr {
+        for &it_ptr in arr {
             it := *it_ptr;
             if #unquote predicate_body(it) do return it_ptr;
         }
@@ -641,7 +641,7 @@ group_by :: macro (arr_: [] $T, comp: Code, allocator := context.allocator) -> [
 
     start := 0;
     arr := arr_;
-    for i: 1 .. arr.count {
+    for i in 1 .. arr.count {
         if !#unquote comp(arr[start], arr[i]) {
             out << arr[start .. i];
             start = i;
@@ -661,7 +661,7 @@ group_by :: macro (arr_: [] $T, comp: Code, allocator := context.allocator) -> [
 equal :: (arr1: [] $T/HasEquals, arr2: [] T) -> bool {
     if arr1.count != arr2.count do return false;
 
-    for i: arr1.count {
+    for i in arr1.count {
         if !(arr1[i] == arr2[i]) do return false;
     }
 
@@ -673,7 +673,7 @@ equal :: (arr1: [] $T/HasEquals, arr2: [] T) -> bool {
     idx  := 0;
     elem := arr[0];
 
-    for i: 1 .. arr.count {
+    for i in 1 .. arr.count {
         A := &arr[i];
         B := &elem;
         if #unquote cmp {
index 7d58362737bb7cef6662ad07f058b729d18ece09..2878a0ab65d20a23675d3d3b3a4ffd5621cb5bf7 100644 (file)
@@ -176,7 +176,7 @@ i64_to_str :: (n: i64, base: u64, buf: [] u8, min_length := 0, prefix := false)
     }
 
     if min_length > 0 && len < min_length {
-        for i: min_length - len {
+        for i in min_length - len {
             c[0] = #char "0";
             len += 1;
             c -= 1;
@@ -239,7 +239,7 @@ u64_to_str :: (n: u64, base: u64, buf: [] u8, min_length := 0, prefix := false)
     }
 
     if min_length > 0 && len < min_length {
-        for i: min_length - len {
+        for i in min_length - len {
             c[0] = #char "0";
             len += 1;
             c -= 1;
@@ -299,7 +299,7 @@ f64_to_str :: (f: f64, buf: [] u8, digits_after_decimal := 4) -> str {
     dec_part  = math.abs(dec_part);
 
     s1 := i64_to_str(~~int_part, 10, buf);
-    for i: 0 .. s1.count do buf.data[i + len] = s1.data[i];
+    for i in 0 .. s1.count do buf.data[i + len] = s1.data[i];
     len += s1.count;
 
     if digits_after_decimal > 0 {
@@ -308,7 +308,7 @@ f64_to_str :: (f: f64, buf: [] u8, digits_after_decimal := 4) -> str {
 
         digits := "0123456789";
 
-        for i: digits_after_decimal {
+        for i in digits_after_decimal {
             dec_part *= 10;
             v := math.trunc(dec_part);
             dec_part -= v;
index 5438be6e4603372939436769e4d9682f4cb25fb8..741e8766858f24d486d9d857b36225eb4745f180 100644 (file)
@@ -24,7 +24,7 @@ custom_formatters_initialized :: #init () {
     #if Enable_Custom_Formatters {
         use runtime.info {*};
 
-        for type_idx: type_table.count {
+        for type_idx in type_table.count {
             type := type_table[type_idx];
             if type.kind != .Struct do continue;
 
@@ -45,7 +45,7 @@ custom_formatters_initialized :: #init () {
         format_procedures := get_procedures_with_tag(Custom_Format_Proc);
         defer delete(&format_procedures);
 
-        for p: format_procedures {
+        for p in format_procedures {
             custom_format := p.tag;
             custom_formatters[custom_format.type] = *cast(&(&Format_Output, &Format, rawptr) -> void, &p.func);
         }
@@ -54,7 +54,7 @@ custom_formatters_initialized :: #init () {
         parse_procedures := get_procedures_with_tag(Custom_Parse_Proc);
         defer delete(&parse_procedures);
 
-        for p: parse_procedures {
+        for p in parse_procedures {
             custom_parse := p.tag;
             custom_parsers[custom_parse.type] = *cast(&(rawptr, str, Allocator) -> bool, &p.func);
         }
@@ -154,7 +154,7 @@ Format_Output :: struct {
         },
 
         (use output: &Format_Output, s: str) {
-            for c: s {
+            for c in s {
                 if count >= capacity {
                     if flush.func == null_proc                   do return;
                     if !flush.func(flush.data, data[0 .. count]) do return;
@@ -578,12 +578,12 @@ format_any :: (output: &Format_Output, formatting: &Format, v: any) {
                         format.indentation += 4;
                     }
                     
-                    for &member: s.members {
+                    for &member in s.members {
                         if member != s.members.data do output->write(", ");
 
                         if formatting.pretty_printing {
                             output->write(#char "\n");
-                            for i: format.indentation do output->write(#char " ");
+                            for i in format.indentation do output->write(#char " ");
                         }
 
                         output->write(member.name);
@@ -595,7 +595,7 @@ format_any :: (output: &Format_Output, formatting: &Format, v: any) {
                 
                 if formatting.pretty_printing {
                     output->write(#char "\n");
-                    for i: formatting.indentation do output->write(#char " ");
+                    for i in formatting.indentation do output->write(#char " ");
                     output->write("}");
                     
                 } else {
@@ -640,12 +640,12 @@ format_any :: (output: &Format_Output, formatting: &Format, v: any) {
                 format.quote_strings = true;
                 if format.pretty_printing do format.indentation += 4;
 
-                for i: count {
+                for i in count {
                     if i != 0 do output->write(", ");
 
                     if formatting.pretty_printing {
                         output->write("\n");
-                        for _: format.indentation do output->write(#char " ");
+                        for _ in format.indentation do output->write(#char " ");
                     }
 
                     format_any(output, &format, .{ cast([&] u8) data + get_type_info(a.of).size * i, a.of });
@@ -655,7 +655,7 @@ format_any :: (output: &Format_Output, formatting: &Format, v: any) {
                 if formatting.pretty_printing {
                     format.indentation -= 4;
                     output->write("\n");
-                    for _: format.indentation do output->write(#char " ");
+                    for _ in format.indentation do output->write(#char " ");
                     output->write(#char "]");
 
                 } else {
@@ -669,7 +669,7 @@ format_any :: (output: &Format_Output, formatting: &Format, v: any) {
                 a := cast(&Type_Info_Array) info;
                 data := v.data;
 
-                for i: a.count {
+                for i in a.count {
                     if i != 0 do output->write(", ");
 
                     format_any(output, formatting, .{ cast([&] u8) data + get_type_info(a.of).size * i, a.of });
@@ -696,7 +696,7 @@ format_any :: (output: &Format_Output, formatting: &Format, v: any) {
                 }
 
                 if !e.is_flags {
-                    for &member: e.members {
+                    for &member in e.members {
                         if value == member.value {
                             output->write(member.name);
                             break break;
@@ -707,7 +707,7 @@ format_any :: (output: &Format_Output, formatting: &Format, v: any) {
 
                 } else {
                     first := true;
-                    for &member: e.members {
+                    for &member in e.members {
                         if value & member.value != 0 {
                             if !first do output->write(" | ");
                             output->write(member.name);
index d35635a38c8d9bfc05925a7f6253975f8e0d824f..c4163505faee6d240db77fe06ab16bea82b5dc14 100644 (file)
@@ -18,7 +18,7 @@ use core.array
 encode :: (data: [] u8, allocator := context.allocator) -> [] u8 {
     out := array.make(u8, allocator=allocator);
 
-    for i: range.{0, data.count - 2, 3} {
+    for i in range.{0, data.count - 2, 3} {
         c1 := data[i + 0];
         c2 := data[i + 1];
         c3 := data[i + 2];
@@ -57,7 +57,7 @@ decode :: (data: [] u8, allocator := context.allocator) -> [] u8 {
 
     out := array.make(u8, allocator=allocator);
 
-    for i: range.{0, data.count, 4} {
+    for i in range.{0, data.count, 4} {
         c1 := data[i + 0];
         c2 := data[i + 1];
         c3 := data[i + 2];
index ad268e22b297f7acbfcf8f33cfd40a81e11cb029..5adfdd221512713f62321795a93d29f127ff9ac0 100644 (file)
@@ -92,7 +92,7 @@ CSV_Column :: struct {
             header_line := reader->read_line(allocator=context.temp_allocator)
                         |> string.strip_trailing_whitespace();
 
-            for header: string.split_iter(header_line, #char ",") {
+            for header in string.split_iter(header_line, #char ",") {
                 member := array.first(output_type_info.members, [](do {
                     if tag := array.first(it.tags, [t](t.type == CSV_Column)); tag {
                         return any_as(*tag, CSV_Column).name == header;
@@ -105,15 +105,15 @@ CSV_Column :: struct {
             }
 
         } else {
-            for &member: output_type_info.members {
+            for &member in output_type_info.members {
                 any_headers << .{ member.type, member.offset };
             }
         }
 
-        for line: reader->lines(allocator = context.temp_allocator) {
+        for line in reader->lines(allocator = context.temp_allocator) {
             out: csv.Output_Type;
 
-            for entry: string.split_iter(string.strip_trailing_whitespace(line), #char ",")
+            for entry in string.split_iter(string.strip_trailing_whitespace(line), #char ",")
                     |> iter.enumerate()
             {
                 header := &any_headers[entry.index];
@@ -141,7 +141,7 @@ CSV_Column :: struct {
         output_type_info: &Type_Info_Struct = ~~ get_type_info(csv.Output_Type);
 
         if include_headers {
-            for &member: output_type_info.members {
+            for &member in output_type_info.members {
                 if !#first do io.write(writer, ",");
 
                 if tag := array.first(member.tags, [t](t.type == CSV_Column)); tag {
@@ -154,8 +154,8 @@ CSV_Column :: struct {
             io.write(writer, "\n");
         }
 
-        for &it: csv.entries {
-            for &member: output_type_info.members {
+        for &it in csv.entries {
+            for &member in output_type_info.members {
                 if !#first do io.write(writer, ",");
 
                 io.write_format_va(writer, "{}", .[ .{cast([&] u8) it + member.offset, member.type} ]);
index 2feb1991817c3f22991e5c73a95cd0cf87865482..0804e1047e2d0ce57ccbda28a6d5e75d4599ffa4 100644 (file)
@@ -4,7 +4,7 @@ encode :: (s: str, allocator := context.allocator) -> str {
     #persist encode_map := u8.['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
 
     new_str := make([] u8, s.count * 2, allocator);
-    for i: s.count {
+    for i in s.count {
         new_str[2 * i + 0] = encode_map[(s[i] & 0xf0) >> 4];
         new_str[2 * i + 1] = encode_map[s[i] & 0xf];
     }
@@ -16,7 +16,7 @@ decode :: (s: str, allocator := context.allocator) -> str {
     assert(s.count & 1 == 0, "Expected string of even length");
 
     new_str := make([] u8, s.count >> 1, allocator);
-    for i: range.{0, s.count, 2} {
+    for i in range.{0, s.count, 2} {
         new_str[i >> 1] = ~~((digit_to_value(s[i + 0]) << 4) | (digit_to_value(s[i + 1])));
     }
     
index fde2e317b878c6ae38ca1281ff4f0b4c10242d3e..937eb57c80ababc465ddeb6292373ac8e8ebf6ff 100644 (file)
@@ -199,7 +199,7 @@ write_ini_file_inner :: (w: &io.Writer, output: any, leave_empty_strings := fals
             continue;
         }
 
-        for& prop: member_info.members {
+        for& prop in member_info.members {
             if !leave_empty_strings && prop.type == str {
                 if cast(&str, member_data + prop.offset).length == 0 {
                     continue;
index e6fd38c4eb1b20344892e16353e24109f4621b45..4dafbd1a5c88152de4416b4e534724975a1e7e0b 100644 (file)
@@ -68,7 +68,7 @@ encode :: #match {
     (w: ^io.Writer, v: [] $T) -> Encoding_Error {
         io.write_byte(w, #char "[");
 
-        for i: v.count {
+        for i in v.count {
             if i > 0 do io.write_byte(w, #char ",");
 
             err := encode(w, v[i]);
@@ -82,7 +82,7 @@ encode :: #match {
     (w: ^io.Writer, v: [..] $T) -> Encoding_Error {
         io.write_byte(w, #char "[");
 
-        for i: v.count {
+        for i in v.count {
             if i > 0 do io.write_byte(w, #char ",");
 
             err := encode(w, v[i]);
@@ -96,7 +96,7 @@ encode :: #match {
     (w: ^io.Writer, v: Map(str, $T)) -> Encoding_Error {
         io.write_byte(w, #char "{");
 
-        for i: v.entries.count {
+        for i in v.entries.count {
             if i > 0 do io.write_byte(w, #char ",");
             entry := ^v.entries[i];
 
@@ -124,7 +124,7 @@ encode :: #match {
                 io.write_byte(w, #char "{");
                 obj := cast(^_Value_Object) cast(^_Value) v;
 
-                for i: obj.object_.count {
+                for i in obj.object_.count {
                     if i > 0 do io.write_byte(w, #char ",");
 
                     io.write_escaped_str(w, obj.object_[i].key);
@@ -172,7 +172,7 @@ encode :: (w: ^io.Writer, data: any) -> Encoding_Error {
             a := cast(^Type_Info_Array) info;
             arr := data.data;
 
-            for i: a.count {
+            for i in a.count {
                 if i != 0 do io.write(w, ",");
 
                 encode(w, misc.any_subscript(data, i));
@@ -193,7 +193,7 @@ encode :: (w: ^io.Writer, data: any) -> Encoding_Error {
             arr := cast(^core.array.Untyped_Array) data.data;
             count := arr.count;
 
-            for i: count {
+            for i in count {
                 if i != 0 do io.write(w, ",");
 
                 encode(w, misc.any_subscript(data, i));
@@ -217,7 +217,7 @@ encode :: (w: ^io.Writer, data: any) -> Encoding_Error {
 
             io.write(w, "{");
 
-            for ^member: s.members {
+            for ^member in s.members {
                 key := member.name;
                 if tag := array.first(member.tags, [t](t.type == Custom_Key)); tag != null {
                     key = (cast(^Custom_Key) tag.data).key;
@@ -285,13 +285,13 @@ Ignore :: #distinct void
 from_any :: #match #local {}
 
 #overload
-from_any :: macro (in: ^$T, allocator := context.allocator) -> Value {
+from_any :: macro (v: ^$T, allocator := context.allocator) -> Value {
     from_any :: from_any
-    return from_any(T, in, allocator);
+    return from_any(T, v, allocator);
 }
 
 #overload
-from_any :: (type: type_expr, in: rawptr, allocator := context.allocator) -> Value {
+from_any :: (type: type_expr, v: rawptr, allocator := context.allocator) -> Value {
     use runtime.info;
 
     t_info := get_type_info(type);
@@ -299,11 +299,11 @@ from_any :: (type: type_expr, in: rawptr, allocator := context.allocator) -> Val
         case .Basic do switch type {
             // These functions handle the cases where the types do
             // not match, so no additional checks are needed here.
-            case bool     { v := new(_Value_Bool, allocator);    v.bool_  =    *cast(^bool) in; return Value.{v}; }
-            case i32, u32 { v := new(_Value_Integer, allocator); v.int_   = ~~ *cast(^i32)  in; return Value.{v}; }
-            case i64, u64 { v := new(_Value_Integer, allocator); v.int_   =    *cast(^i64)  in; return Value.{v}; }
-            case f32      { v := new(_Value_Float, allocator);   v.float_ = ~~ *cast(^f32)  in; return Value.{v}; }
-            case f64      { v := new(_Value_Float, allocator);   v.float_ =    *cast(^f64)  in; return Value.{v}; }
+            case bool     { v := new(_Value_Bool, allocator);    v.bool_  =    *cast(^bool) v; return Value.{v}; }
+            case i32, u32 { v := new(_Value_Integer, allocator); v.int_   = ~~ *cast(^i32)  v; return Value.{v}; }
+            case i64, u64 { v := new(_Value_Integer, allocator); v.int_   =    *cast(^i64)  v; return Value.{v}; }
+            case f32      { v := new(_Value_Float, allocator);   v.float_ = ~~ *cast(^f32)  v; return Value.{v}; }
+            case f64      { v := new(_Value_Float, allocator);   v.float_ =    *cast(^f64)  v; return Value.{v}; }
         }
 
         case .Array {
@@ -312,8 +312,8 @@ from_any :: (type: type_expr, in: rawptr, allocator := context.allocator) -> Val
             v := new(_Value_Array, allocator);
             array.init(^v.array_, a_info.count, allocator);
 
-            for i: a_info.count {
-                v.array_ << from_any(a_info.of, memory.ptr_add(in, size_of(a_info.of) * i));
+            for i in a_info.count {
+                v.array_ << from_any(a_info.of, memory.ptr_add(v, size_of(a_info.of) * i));
             }
 
             return Value.{v};
@@ -323,17 +323,17 @@ from_any :: (type: type_expr, in: rawptr, allocator := context.allocator) -> Val
             // Strings are handled differently
             if type == str {
                 v := new(_Value_String, allocator);
-                v.str_ = string.alloc_copy(*cast(^str) in, allocator);
+                v.str_ = string.alloc_copy(*cast(^str) v, allocator);
                 return Value.{v};
             }
 
             s_info := cast(^Type_Info_Slice) t_info;
-            s := cast(^core.array.Untyped_Array) in;
+            s := cast(^core.array.Untyped_Array) v;
 
             v := new(_Value_Array, allocator);
             array.init(^v.array_, s.count, allocator);
 
-            for i: s.count {
+            for i in s.count {
                 v.array_ << from_any(s_info.of, memory.ptr_add(s.data, size_of(s_info.of) * i));
             }
 
@@ -346,7 +346,7 @@ from_any :: (type: type_expr, in: rawptr, allocator := context.allocator) -> Val
             v := new(_Value_Object, allocator);
             array.init(^v.object_, s_info.members.count, allocator);
 
-            for^ member: s_info.members {
+            for^ member in s_info.members {
                 key := member.name;
                 if tag := array.first(member.tags, [t](t.type == Custom_Key)); tag != null {
                     key = (cast(^Custom_Key) tag.data).key;
@@ -358,7 +358,7 @@ from_any :: (type: type_expr, in: rawptr, allocator := context.allocator) -> Val
                     }
                 }
 
-                json.set(Value.{v}, key, from_any(member.type, memory.ptr_add(in, member.offset)), dont_copy_key=true);
+                json.set(Value.{v}, key, from_any(member.type, memory.ptr_add(v, member.offset)), dont_copy_key=true);
             }
 
             return Value.{v};
@@ -366,11 +366,11 @@ from_any :: (type: type_expr, in: rawptr, allocator := context.allocator) -> Val
 
         case .Distinct {
             if type == Value {
-                return *cast(^Value) in;
+                return *cast(^Value) v;
             }
 
             d_info := cast(^Type_Info_Distinct) t_info;
-            return from_any(d_info.base_type, in);
+            return from_any(d_info.base_type, v);
         }
 
         case .Union {
@@ -379,11 +379,11 @@ from_any :: (type: type_expr, in: rawptr, allocator := context.allocator) -> Val
             }
 
             u := t_info->as_union();
-            tag := *cast(&Optional(void).tag_enum) in;
+            tag := *cast(&Optional(void).tag_enum) v;
             if tag != .Some {
                 return null_value();
             } else {
-                return from_any(u.variants[1].type, memory.ptr_add(in, u.alignment), allocator);
+                return from_any(u.variants[1].type, memory.ptr_add(v, u.alignment), allocator);
             }
         }
     }
@@ -428,7 +428,7 @@ as_any :: (value: Value, type: type_expr, out: rawptr) {
         case .Array {
             a_info := cast(^Type_Info_Array) t_info;
 
-            for i: a_info.count {
+            for i in a_info.count {
                 to_any(value[i], a_info.of, memory.ptr_add(out, size_of(a_info.of) * i));
             }
         }
@@ -457,7 +457,7 @@ as_any :: (value: Value, type: type_expr, out: rawptr) {
                 s.count = to_copy.count;
             }
 
-            for i: s.count {
+            for i in s.count {
                 to_any(value[i], s_info.of, memory.ptr_add(s.data, size_of(s_info.of) * i));
             }
         }
@@ -465,7 +465,7 @@ as_any :: (value: Value, type: type_expr, out: rawptr) {
         case .Struct {
             s_info := cast(^Type_Info_Struct) t_info;
 
-            for^ member: s_info.members {
+            for^ member in s_info.members {
                 key := member.name;
                 if tag := array.first(member.tags, [t](t.type == Custom_Key)); tag != null {
                     key = (cast(^Custom_Key) tag.data).key;
index 72a73048519ac36fcae8d3934f24acdf7023a64e..b3ea5fe0408b967cd66627e04fe0e94b3d0dd6bc 100644 (file)
@@ -132,7 +132,7 @@ parse_array :: (use parser: ^Parser) -> (Value, Error) {
     // This uses the context allocators because the array resizing needs to happen in a general purpose heap allocator
     arr := array.make(Value, allocator=context.allocator);
     defer if err.kind != .None {
-        for elem: arr {
+        for elem in arr {
             free(elem, allocator);
         }
 
@@ -200,7 +200,7 @@ parse_object :: (use parser: ^Parser) -> (Value, Error) {
 
         // Checking for duplicate keys. I have it disabled for the moment.
         #if false {
-            for elem: value.object_ {
+            for elem in value.object_ {
                 if elem.key == key {
                     err.kind = .Duplicate_Keys;
                     err.pos  = key_token.pos;
@@ -240,7 +240,7 @@ unescape_string :: (token: Token, allocator: Allocator) -> str {
     s = s.data[1 .. s.count - 1];
 
     i := 0;
-    for c: s {
+    for c in s {
         if c == #char "\\" || c == #char "\"" || c < #char " " {
             break;
         }
@@ -335,7 +335,7 @@ parse_and_write_utf8_character :: (s: str, out: [&] u8) -> (i32, i32) {
     chars := 0;
     codepoint: u32 = 0;
 
-    for c: s[0 .. 4] {
+    for c in s[0 .. 4] {
         codepoint = codepoint << 4;
         codepoint |= digit_to_hex(c);
     }
@@ -384,7 +384,7 @@ parse_and_write_utf8_character :: (s: str, out: [&] u8) -> (i32, i32) {
     second_codepoint: u32 = 0;
     if s[4 .. 6] != "\\u" do return 0, 0;
 
-    for c: s[6 .. 10] {
+    for c in s[6 .. 10] {
         second_codepoint = second_codepoint << 4;
         second_codepoint |= digit_to_hex(c);
     }
index 10d00554c2152e7f8830319457fe43d28c10899e..3e6813822a6fd2a05a616e50008b5ac0bb0f635f 100644 (file)
@@ -202,7 +202,7 @@ skip_numeric :: (use tkn: ^Tokenizer) {
 skip_escape :: (use tkn: ^Tokenizer) {
     switch data[offset] {
         case #char "u" {
-            for i: 4 {
+            for i in 4 {
                 ch, _ := next_character(tkn);
                 switch ch {
                     case #char "0" .. #char "9",
index 6cce0a1bf2401ecece033abf8e5feac5e13412fb..bc5d47c8c55637666ee257229ffdb2da737b3578 100644 (file)
@@ -202,7 +202,7 @@ get :: (v: Value, key: str) -> Value {
     v_ := cast(^_Value) v;
     if v_.type != .Object do return Value.{^_null_value};
 
-    for ^entry: (cast(^_Value_Object) v_).object_ {
+    for ^entry in (cast(^_Value_Object) v_).object_ {
         if entry.key == key do return entry.value;
     }
     return Value.{^_null_value};
@@ -285,7 +285,7 @@ free :: (v: Value, allocator: Allocator) {
 
         case .Array {
             v_arr := cast(^_Value_Array) v_;
-            for elem: v_arr.array_ {
+            for elem in v_arr.array_ {
                 free(elem, allocator);
             }
             array.free(^v_arr.array_);
@@ -293,7 +293,7 @@ free :: (v: Value, allocator: Allocator) {
 
         case .Object {
             v_obj := cast(^_Value_Object) v_;
-            for ^entry: v_obj.object_ {
+            for ^entry in v_obj.object_ {
                 if !entry.dont_free_key do raw_free(allocator, entry.key.data);
                 free(entry.value, allocator);
             }
index 8ea46d1beaf47692f32d7d3672d7fc33a5d4b489..b52de03ed09487eaeb716fbd01659767bbeec18e 100644 (file)
@@ -55,17 +55,17 @@ write_value :: (v: Value, w: &io.Writer) {
     });
 
     switch v.data {
-        case s: .String {
+        case .String as s {
             io.write_format(w, "{\"}", s);
         }
 
-        case n: .Number do switch n {
-            case i: .Integer do io.write_format(w, "{}", i);
-            case f: .Float   do io.write_format(w, "{}", f);
-            case s: .String  do io.write_format(w, "{\"}", s);
+        case .Number as n do switch n {
+            case .Integer as i do io.write_format(w, "{}", i);
+            case .Float as f   do io.write_format(w, "{}", f);
+            case .String as s  do io.write_format(w, "{\"}", s);
         }
 
-        case b: .Boolean {
+        case .Boolean as b {
             io.write_format(w, "{}", b);
         }
 
index f2ee270a0cb860f28edc09721ee5da194d53cb60..99d2ed9effc79362f00dba931b2c8f606aabfda9 100644 (file)
@@ -109,7 +109,7 @@ free_node :: (al: Allocator, n: &Node) {
     string.free(n.node, al);
     n.type_annotation->with([t] { string.free(t, al); });
 
-    for& v: n.values do free_value(al, v);
+    for& v in n.values do free_value(al, v);
     delete(&n.values); // This should use the allocator inside of the array
 
     for n.props->as_iter() {
@@ -126,12 +126,12 @@ free_value :: (al: Allocator, v: &Value) {
     v.type_annotation->with([t] { string.free(t, al); });
 
     switch v.data {
-        case s: .String {
+        case .String as s {
             string.free(s, al);
         }
 
-        case num: .Number do switch num {
-            case s: .String {
+        case .Number as num do switch num {
+            case .String as s {
                 string.free(s, al);
             } 
 
index 1df3af36070362cbdad04f584d31aff30593cb74..4b07d9bb56a6d5f315435eed65fb895169996e05 100644 (file)
@@ -143,7 +143,7 @@ query_selector_matches :: (s: &Selector, trail: [] QueryStack) -> bool {
     }
 
     node_index -= 1;
-    for segment: s.segments[1 .. s.segments.length] {
+    for segment in s.segments[1 .. s.segments.length] {
         switch segment.op->unwrap() {
             case .Child, .Descendant {
                 while node_index >= 0 {
@@ -360,7 +360,7 @@ parse_selector :: (p: &QueryParser) -> &Selector {
         skip_whitespace(p);
 
         switch parse_matcher(p) {
-            case matcher: .Some {
+            case .Some as matcher {
                 segment := p.al->move(SelectorSegment.{
                     matcher = matcher
                 });
index ba3f7fe534e84ff61e347617c436257c86360bec..f131ed8b3f45994ee00ae8906dc35787c235928d 100644 (file)
@@ -422,20 +422,20 @@ Parse_Error :: union {
 
     parse_value :: (self: &#Self, token: Token) -> ? Value {
         switch token {
-            case s: .Raw_String {
+            case .Raw_String as s {
                 return Value.{
                     data = .{ String = string.alloc_copy(s, self.result_allocator) }
                 };
             }
 
-            case s: .String {
+            case .String as s {
                 // TODO: Handle escaped strings here
                 return Value.{
                     data = .{ String = string.alloc_copy(s, self.result_allocator) }
                 };
             }
             
-            case w: .Word {
+            case .Word as w {
                 if w == "null" {
                     return Value.{
                         data = .{ Null = .{} }
index aaa63d5e9d95e517eeeb798ad61e3f6d5e5b7c82..70c007937b4ad41a9b0236425dfd34dda4ae4dad 100644 (file)
@@ -102,7 +102,7 @@ serialize :: (v: any, w: &io.Writer) -> bool {
 
             base: [&] u8 = ~~v.data;
 
-            for& member: s_info.members {
+            for& member in s_info.members {
                 try(serialize(any.{ base + member.offset, member.type }, w));
             }
         }
@@ -234,7 +234,7 @@ deserialize :: (target: rawptr, type: type_expr, r: &io.Reader, allocator := con
 
             base: [&] u8 = target;
 
-            for& member: s_info.members {
+            for& member in s_info.members {
                 try(deserialize(base + member.offset, member.type, r, allocator));
             }
         }
index 1a5e596a5a1975a2eb278ee53fbe27f669132108..08fab5bf21179399411a30c415c5bf8c95384fca 100644 (file)
@@ -37,7 +37,7 @@ hash :: #match -> u32 {
     (key: i64)    -> u32 { return cast(u32) (cast(u64) 0xcbf29ce7 ^ cast(u64) key); },
     (key: str)    -> u32 {
         hash: u32 = 5381;
-        for ch: key do hash += (hash << 5) + ~~ch;
+        for ch in key do hash += (hash << 5) + ~~ch;
         return hash;
     },
     (key: type_expr) -> u32 { return hash(cast(u32) key); },
index 3255bfe72d4fd0c4524727a09d5d8739b189e173..93b373b1985283e97adf4a4d0f201b68c301fdde 100644 (file)
@@ -82,20 +82,20 @@ MD5_Digest :: struct {
     #doc "Returns a temporary byte array of the hash."
     as_str :: (self: #Self) -> [] u8 {
         result := make_temp([] u8, 16);
-        for i: 0  .. 4  do result[i] = ~~((self.a & (0xff << shift(i))) >> shift(i));
-        for i: 4  .. 8  do result[i] = ~~((self.b & (0xff << shift(i))) >> shift(i));
-        for i: 8  .. 12 do result[i] = ~~((self.c & (0xff << shift(i))) >> shift(i));
-        for i: 12 .. 16 do result[i] = ~~((self.d & (0xff << shift(i))) >> shift(i));
+        for i in 0  .. 4  do result[i] = ~~((self.a & (0xff << shift(i))) >> shift(i));
+        for i in 4  .. 8  do result[i] = ~~((self.b & (0xff << shift(i))) >> shift(i));
+        for i in 8  .. 12 do result[i] = ~~((self.c & (0xff << shift(i))) >> shift(i));
+        for i in 12 .. 16 do result[i] = ~~((self.d & (0xff << shift(i))) >> shift(i));
         return result;
     }
 
     #doc "Returns a temporary string of the hash."
     as_hex_str :: (self: #Self) -> str {
         result := make_temp([..] u8, 32);
-        for i: 0  .. 4  do conv.format(&result, "{w2b16}", (self.a & (0xff << shift(i)) >> shift(i)));
-        for i: 4  .. 8  do conv.format(&result, "{w2b16}", (self.b & (0xff << shift(i)) >> shift(i)));
-        for i: 8  .. 12 do conv.format(&result, "{w2b16}", (self.c & (0xff << shift(i)) >> shift(i)));
-        for i: 12 .. 16 do conv.format(&result, "{w2b16}", (self.d & (0xff << shift(i)) >> shift(i)));
+        for i in 0  .. 4  do conv.format(&result, "{w2b16}", (self.a & (0xff << shift(i)) >> shift(i)));
+        for i in 4  .. 8  do conv.format(&result, "{w2b16}", (self.b & (0xff << shift(i)) >> shift(i)));
+        for i in 8  .. 12 do conv.format(&result, "{w2b16}", (self.c & (0xff << shift(i)) >> shift(i)));
+        for i in 12 .. 16 do conv.format(&result, "{w2b16}", (self.d & (0xff << shift(i)) >> shift(i)));
         return result;
     }
 }
@@ -114,7 +114,7 @@ do_cycle :: (digest: &MD5_Digest, bytes: [64] u8, accumulate := true) {
     c := digest.c;
     d := digest.d;
 
-    for i: 0 .. 64 {
+    for i in 0 .. 64 {
         F, g: u32;
         if 0 <= i && i <= 15 {
             F = (b & c) | (~b & d);
index 30fa09678f18b1b442398c54a3b0fd589528b023..1492f52e4aab7718536b42b12d028ddf7188cacc 100644 (file)
@@ -30,7 +30,7 @@ Hasher :: struct {
     }
 
     update :: (self: &#Self, data: [] u8) {
-        for i: 0 .. data.count {
+        for i in 0 .. data.count {
             self.data[self.data_length] = data[i];
             self.data_length += 1;
 
@@ -75,7 +75,7 @@ Hasher :: struct {
         self.data[56] = cast(u8, self.bit_length >> 56);
         do_cycle(self, self.data);
 
-        for i: 0 .. 4 {
+        for i in 0 .. 4 {
             out[i + 0]  = ~~((self.state[0] >> (24 - i * 8)) & 0xff);
             out[i + 4]  = ~~((self.state[1] >> (24 - i * 8)) & 0xff);
             out[i + 8]  = ~~((self.state[2] >> (24 - i * 8)) & 0xff);
@@ -104,7 +104,7 @@ hash :: (x: str) -> [BLOCK_SIZE] u8 {
 do_cycle :: (self: &Hasher, data: [] u8) {
     m: [64] u32;
 
-    for i: 0 .. 16 {
+    for i in 0 .. 16 {
         j := 4 * i;
         m[i] = (cast(u32, data[j]) << 24)
              | (cast(u32, data[j + 1]) << 16)
@@ -112,7 +112,7 @@ do_cycle :: (self: &Hasher, data: [] u8) {
              | (cast(u32, data[j + 3]));
     }
 
-    for i: 16 .. 64 {
+    for i in 16 .. 64 {
         m[i] = SIG1(m[i - 2]) + m[i - 7] + SIG0(m[i - 15]) + m[i - 16];
     }
 
@@ -125,7 +125,7 @@ do_cycle :: (self: &Hasher, data: [] u8) {
     g := self.state[6];
     h := self.state[7];
 
-    for i: 0 .. 64 {
+    for i in 0 .. 64 {
         t1 := h + EP1(e) + CH(e, f, g) + k[i] + m[i];
         t2 := EP0(a) + MAJ(a, b, c);
         h = g;
index 53f84366f52f011121265bdbc6b261e833f01a88..1f690421897544ec1eb0c6b3b1c85f142d88f697 100644 (file)
@@ -142,7 +142,7 @@ __byte_dump :: (ptr: rawptr, byte_count: u32, bytes_per_line := 8) {
     temp: [3] u8;
 
     u8_ptr := cast([&] u8) ptr;
-    for i: byte_count {
+    for i in byte_count {
         val := u8_ptr[i];
 
         temp[0] = map_to_ascii(val >> 4);
index 4063f2e915ae485552fe03ad0dc77017e52ab13b..ecea555936b3a2820fec92b0703d1b177731c4c6 100644 (file)
@@ -164,7 +164,7 @@ stream_poll :: (use s: &Stream, ev: PollEvent, timeout: i32) -> (Error, bool) {
 // BufferStream
 //
 // In older times of the standard library, there were two string
-// streams that existed for different purposes: StringStream and
+// streams that existed for different purposes in StringStream and
 // DynamicStringStream. I have since merged them into one stream
 // called, BufferStream. Besides the names being confusing and
 // long, I thought it was needlessly complicated to have two
index ad94c566bb75f321269f0be2b0b1b947cb7c721c..9dd0fc29b0190fe3a6617d1f1f6dd6d1e4200392 100644 (file)
@@ -138,7 +138,7 @@ write_ptr :: (use writer: &Writer, p: &void) {
 }
 
 write_range :: (use writer: &Writer, r: range, sep := " ") {
-    for i: r {
+    for i in r {
         write_i32(writer, i);
         if i + r.step < r.high do write_str(writer, sep);
     }
index 1bb168ed7bea066fb0cbab9c49e17ec7c335b97e..e313ad05c20822aecba1adacf234efbbf431181c 100644 (file)
@@ -341,11 +341,11 @@ choose :: (n: $T, k: T) -> T {
     assert(T == i32 || T == i64 || T == u32 || T == u64, "bad type for choose function");
 
     ret := 1;
-    for i: (n - k + 1) .. (n + 1) {
+    for i in (n - k + 1) .. (n + 1) {
         ret *= i;
     }
 
-    for i: 1 .. (k + 1) {
+    for i in 1 .. (k + 1) {
         ret /= i;
     }
 
index cdf7054d01f4b2629fa77adc51a0859af8312e87..edc8c547c029d11a38839c4b212ccee100c9ee62 100644 (file)
@@ -42,9 +42,9 @@ arg_parse :: (c_args: [] cstr, output: any) -> bool {
 
     data_base := *cast(&rawptr) output.data;
 
-    for #no_close arg: arg_iter {
-        for &member: arg_type.members {
-            for &tag: member.tags {
+    for #no_close arg in arg_iter {
+        for &member in arg_type.members {
+            for &tag in member.tags {
                 if tag.type != str do continue;
 
                 to_match := *cast(&str) tag.data;
index b0d27b7382070900170ba43e13e508526779e95b..8918d82675d7e47cdcecee268a355a50d625275d 100644 (file)
@@ -104,18 +104,18 @@ SocketAddress :: union {
 #inject
 SocketAddress.addr_as_str :: (this: &SocketAddress, allocator := context.allocator) -> str {
     return switch *this {
-        case path: .Unix => string.as_str(cast(cstr) path);
-        case inet: .Inet => do {
+        case .Unix as path => string.as_str(cast(cstr) path);
+        case .Inet as inet => do {
             str_addr := ipv4_to_str(inet.addr);
             out := make(dyn_str, allocator);
             return conv.format(&out, "{}:{}", str_addr, inet.port);
         }
-        case inet6: .Inet6 => do {
+        case .Inet6 as inet6 => do {
             str_addr := ipv6_to_str(inet6.addr);
             out := make(dyn_str, allocator);
             return conv.format(&out, "{}:{}", str_addr, inet6.port);
         }
-        case host: .HostPort => do {
+        case .HostPort as host => do {
             out := make(dyn_str, allocator);
             return conv.format(&out, "{}:{}", host.host, host.port);
         }
@@ -246,15 +246,15 @@ socket_poll_all :: (sockets: [] &Socket, stat_buff: [] Socket_Poll_Status, timeo
     if sockets.count > stat_buff.count do return;
 
     handles := alloc.array_from_stack(runtime.platform.PollDescription, sockets.count);
-    for i: sockets.count {
+    for i in sockets.count {
         handles[i] = .{
             ~~cast(i32) sockets[i].handle, .Read
         };
     }
 
     runtime.platform.__poll(handles, timeout);
-    for i: sockets.count {
-        stat_buff[i] = switch handles[i].out {
+    for i in sockets.count {
+        stat_buff[i] = switch handles[i].out_events {
             case .None => .No_Change
             case .Read => .Readable
             case .Closed => .Closed
@@ -269,7 +269,7 @@ socket_poll :: (socket: &Socket, timeout := -1) -> Socket_Poll_Status {
 
     runtime.platform.__poll(fds, timeout);
 
-    return switch fds[0].out {
+    return switch fds[0].out_events {
         case .None => .No_Change
         case .Read => .Readable
         case .Closed => .Closed
index 7f80c7643630fb0b4d039fc237efda65065e9bb6..b314f3add990bbb604de161e38179e5b15062da7 100644 (file)
@@ -377,7 +377,7 @@ wait_to_get_client_messages :: (use server: &TCP_Server) -> [] &TCP_Server.Clien
     socket_poll_all(cast([] &Socket) active_clients, status_buffer, pulse_time_ms);
 
     recv_clients: [..] &TCP_Server.Client;
-    for it: client_count {
+    for it in client_count {
         if status_buffer[it] == .Readable {
             //
             // If there is already a Ready event present for this client,
index 360f20139a8568e00209b898c484a60156586bda..d2e81a78042915803a08aa00fe3b3f3aace848ab 100644 (file)
@@ -92,7 +92,7 @@ Binding_Config :: struct {
 
 generate_c_binding :: (use binding_config: Binding_Config) -> bool {
     wrote := false;
-    for file: os.with_file(output_file, .Write) {
+    for file in os.with_file(output_file, .Write) {
         writer := io.writer_make(file);
         defer io.writer_free(&writer);
 
@@ -101,7 +101,7 @@ generate_c_binding :: (use binding_config: Binding_Config) -> bool {
         write_file_introduction(&writer, preamble, fb.module_name);
 
         for fb.funcs {
-            for impl: custom_implementations {
+            for impl in custom_implementations {
                 if impl.name == it.name {
                     io.write(&writer, impl.impl);
                     io.write(&writer, "\n");
@@ -204,7 +204,7 @@ compile_c_file :: (
         io.write_format(writer, "// THIS FILE WAS AUTOMATICALLY GENERATED.\n");
         io.write_format(writer, "//\n");
 
-        for text: preamble {
+        for text in preamble {
             io.write_format(writer, "{}\n", text);
         }
 
@@ -247,7 +247,7 @@ compile_c_file :: (
         switch slice.find_opt(ff.tags, [it](it.type == func_body))
                    ->transform(x => misc.any_as(x, func_body).body)
         {
-            case body: .Some {
+            case .Some as body {
                 io.write(writer, body);
                 io.write(writer, "    return NULL;");
             }
@@ -305,7 +305,7 @@ compile_c_file :: (
                 defer delete(&call_signature);
 
                 func_info := it_info->as_function();
-                for p: func_info.parameter_types {
+                for p in func_info.parameter_types {
                     map_to_dyncall(p, &call_signature);
                 }
 
@@ -355,7 +355,7 @@ compile_c_file :: (
 
             } else {
                 matched := false;
-                for& m: cast_map {
+                for& m in cast_map {
                     if m.type == it {
                         io.write_format(&callw, "({}) P({}, {})", m.name, param_num, type_to_wasm_type(it));
                         matched = true;
index c126a0eb38674e49a2d8f45701ae3e5733423e21..018a52581c2aebd96ab29923cf40fa8260187983 100644 (file)
@@ -83,7 +83,7 @@ cptr :: struct (T: type_expr) {
         return ~~(this.data - mem_base_ptr + 1);
     }
 
-    as :: (this: cptr($T), $new_type: type_expr) -> cptr(new_type) {
+    as_unsafe :: (this: cptr($T), $new_type: type_expr) -> cptr(new_type) {
         return .{ this.data };
     }
 
index a14c1e1087ff85dcf862d8c6ba90bcab0b88bb01..58c2818fc9ff1107f05c514b5c3ab9915476b08e 100644 (file)
@@ -81,7 +81,7 @@ path_clean :: (path: str, allocator := Path_Allocator) -> str {
 path_join :: (path: ..str) -> str {
     out := make(dyn_str, allocator=context.temp_allocator);
     
-    for p: path {
+    for p in path {
         conv.format(&out, "{}{}", p, PATH_SEP);
     }
 
@@ -106,7 +106,7 @@ path_directory :: (path: str) -> str {
         path_extension("foo/bar.txt") -> "txt"
 """
 path_extension :: (path: str) -> str {
-    for i: range.{ path.length - 1, 0, -1 } {
+    for i in range.{ path.length - 1, 0, -1 } {
         if path[i] == PATH_SEP do break;
         if path[i] == '.' do return path[i .. path.length];
     }
index 0993f50706076aa4faef1fd072f69549ee55f942..0e5db7c68b5c02732226d2a93537c6ba3c900b97 100644 (file)
@@ -21,7 +21,7 @@ Tagged_Global :: struct {
 get_globals_with_tag :: ($tag_type: type_expr) -> [] GGWT_Result(tag_type) {
     results := make([..] GGWT_Result(tag_type));
 
-    for glob: tagged_globals {
+    for glob in tagged_globals {
         slice.find_opt(glob.tags, [v](v.type == tag_type))->with([tag] {
             array.push(&results, .{
                 data = glob.data,
index ac8a6c410aac18ed03cbb19c4684cb9df30543aa..a3ce05da52f731d479f8eb2196cfc3ffc8da6bba 100644 (file)
@@ -112,7 +112,7 @@ write_type_name :: (writer: &io.Writer, t: type_expr) {
             io.write_str(writer, "(");
 
             i := 0;
-            for type: comp.components {
+            for type in comp.components {
                 if i != 0 do io.write_str(writer, ", ");
 
                 write_type_name(writer, type);
@@ -126,7 +126,7 @@ write_type_name :: (writer: &io.Writer, t: type_expr) {
             io.write_str(writer, "(");
 
             i := 0;
-            for type: f.parameter_types {
+            for type in f.parameter_types {
                 if i != 0 do io.write_str(writer, ", ");
 
                 write_type_name(writer, type);
@@ -213,7 +213,7 @@ offset_of :: (T: type_expr, member_name: str) -> u32 {
     if info.kind != .Struct do return 0;
 
     struct_info := cast(&Type_Info_Struct) info;
-    for &m: struct_info.members {
+    for &m in struct_info.members {
         if m.name == member_name do return m.offset;
     }
 
@@ -287,7 +287,7 @@ enum_name :: (value: $Backing_Type) -> str {
     if info.kind != .Enum do return null_str;
 
     etype := cast(&Type_Info_Enum) info;
-    for &member: etype.members {
+    for &member in etype.members {
         if member.value == ~~value do return member.name;
     }
     
@@ -299,7 +299,7 @@ enum_value :: ($E: type_expr, name: str) -> E {
     if info.kind != .Enum do return ~~0;
 
     etype := cast(&Type_Info_Enum) info;
-    for &member: etype.members {
+    for &member in etype.members {
         if member.name == name do return ~~member.value;
     }
 
@@ -338,7 +338,7 @@ populate_struct_vtable :: (table: &$Table_Type, struct_type: type_expr, safe :=
     v_info := cast(&Type_Info_Struct) get_type_info(Table_Type);
     if v_info.kind != .Struct do return;
 
-    for& member: v_info.members {
+    for& member in v_info.members {
         if get_type_info(member.type).kind != .Function do continue;
 
         struct_method := get_struct_method(struct_type, member.name);
index 42dfc491bb9bd4b5d025c2ceb87bae23d3f2ef38..b0c424348cae55f7ad204f0c18af7bdebc222693 100644 (file)
@@ -34,7 +34,7 @@ get_tags_for_procedure :: (func: $T) -> [] any {
 get_procedures_with_tag :: ($tag_type: type_expr) -> [] GPWT_Result(tag_type) {
     results := make([..] GPWT_Result(tag_type));
 
-    for proc: tagged_procedures {
+    for proc in tagged_procedures {
         if tag := array.first(proc.tags, [v](v.type == tag_type)); tag != null {
             array.push(&results, .{
                 func = proc.func,
index ccc1398cebf5517b627278492e099f67df64a1b5..0e9e45947b9b2c87ed4b3e6b1d9e17aba6ce3931 100644 (file)
@@ -7,8 +7,8 @@ DirectoryData :: #distinct u64
 
 PollDescription :: struct {
     fd: u64;
-    in: io.PollEvent;
-    out: io.PollEvent;
+    in_events: io.PollEvent;
+    out_events: io.PollEvent;
 }
 
 #foreign "onyx_runtime" {
@@ -145,16 +145,16 @@ __file_stream_vtable := io.Stream_Vtable.{
         fds: [1] PollDescription;
         fds[0] = .{
             fd = ~~data,
-            in = ev
+            in_events = ev
         };
 
         __poll(fds, timeout);
 
-        if fds[0].out == .Closed {
+        if fds[0].out_events == .Closed {
             return .EOF, ev == .Closed;
         }
 
-        return .None, fds[0].out == ev;
+        return .None, fds[0].out_events == ev;
     }
 };
 
index 41518b7c1dc16a5b39754b0f83de9bd46b17b9b1..8828cd5f17e9ccd55917123eaecc471b54323800 100644 (file)
@@ -41,15 +41,15 @@ __net_sock_opt_size :: (s: SocketData, sockopt: SocketOption, size: i64) -> bool
 
 __net_sock_bind :: (s: SocketData, addr: &SocketAddress) -> bool {
     switch *addr {
-        case &path: .Unix {
+        case .Unix as &path {
             return __net_bind_unix(s, ~~path);
         }
 
-        case ipv4: .Inet {
+        case .Inet as ipv4 {
             return __net_bind_ipv4(s, ipv4.addr, ipv4.port);
         }
 
-        case host: .HostPort {
+        case .HostPort as host {
             return __net_bind_host(s, host.host, host.port);
         }
 
@@ -84,22 +84,22 @@ __net_sock_accept :: (s: SocketData, out: &SocketAddress) -> Result(SocketData,
 
 __net_sock_connect :: (s: SocketData, addr: &SocketAddress) -> io.Error {
     switch *addr {
-        case &path: .Unix {
+        case .Unix as &path {
             return __net_connect_unix(s, ~~path)
                 |> translate_error();
         }
 
-        case i: .Inet {
+        case .Inet as i {
             return __net_connect_ipv4(s, i.addr, i.port)
                 |> translate_error();
         }
 
-        case i: .Inet6 {
+        case .Inet6 as i {
             return __net_connect_ipv6(s, i.addr, i.port)
                 |> translate_error();
         }
 
-        case h: .HostPort {
+        case .HostPort as h {
             return __net_connect_host(s, h.host, h.port)
                 |> translate_error();
         }
@@ -135,10 +135,10 @@ __net_sock_recv_from :: (s: SocketData, buf: [] u8, out: &SocketAddress) -> Resu
 
 __net_sock_send_to :: (s: SocketData, buf: [] u8, addr: &SocketAddress) -> Result(i32, io.Error) {
     sent := switch *addr {
-        case &path: .Unix => __net_sendto_unix(s, buf, ~~path);
-        case i: .Inet     => __net_sendto_ipv4(s, buf, i.addr, i.port);
-        case i: .Inet6    => __net_sendto_ipv6(s, buf, i.addr, i.port);
-        case h: .HostPort => __net_sendto_host(s, buf, h.host, h.port);
+        case .Unix as &path => __net_sendto_unix(s, buf, ~~path);
+        case .Inet as i     => __net_sendto_ipv4(s, buf, i.addr, i.port);
+        case .Inet6 as i    => __net_sendto_ipv6(s, buf, i.addr, i.port);
+        case .HostPort as h => __net_sendto_host(s, buf, h.host, h.port);
     };
 
     if sent == -1
index 8fc62715f0790920d62bf27d95f2acc14a1d6261..17bc1757995e676a81f8729f88d74e0e49b0a4fd 100644 (file)
@@ -167,7 +167,7 @@ __poll :: (fds: [] PollDescription, timeout: i32) -> void {
     }
 
     subs := core.alloc.array_from_stack(wasi.Subscription, count);
-    for i: fds.count {
+    for i in fds.count {
         subs[i].userdata = ~~ i;
         subs[i].u.tag = switch fds[i].in {
             case .None => .FDRead;
@@ -195,7 +195,7 @@ __poll :: (fds: [] PollDescription, timeout: i32) -> void {
     if error_code != .Success do return;
 
     if number_of_events == 0 do return;
-    for ev: events[0 .. number_of_events] {
+    for ev in events[0 .. number_of_events] {
         if ev.type !=.Clock {
             if ev.fd_readwrite.nbytes > 0 {
                 i := cast(i32) ev.userdata;
index 3ff2d07f86fd5db72517ed5692707deee99ebfd7..2fe2e560bd5b4902433f99bc144cf6b6dd061598 100644 (file)
@@ -28,7 +28,7 @@ __lookup_all_envs :: () {
     }
 
     result := make([..] Pair(str, str), env_count, allocator);
-    for env: env_var {
+    for env in env_var {
         s := string.from_cstr(env);
         var, val := string.bisect(s, '=');
         result << .{var, val};
index b963188ceddb1339a56676e6a1e8734b666c063e..ba6f0b8654f03dcfc0200d2b149808004c1f1f1b 100644 (file)
@@ -83,7 +83,7 @@ __file_open :: (path: str, mode := os.OpenMode.Read) -> (FileData, os.FileError)
 
     // Currently the directory's file descriptor appears to always be 3
     // However, this is not necessarily correct, so also try a preopened directory
-    for DIR_FD: .[ 3, 4 ] {
+    for DIR_FD in .[ 3, 4 ] {
         if err := wasi.path_open(
             DIR_FD,
             .SymLinkFollow,
index 6abcc07c7e2d045b645966fcc4154eaf38745797..ee47f6d8cdc270fff829dbf8e73e31a3c310e4fd 100644 (file)
@@ -183,15 +183,15 @@ __net_resolve :: (host: str, port: u16, out_addrs: [] SocketAddress) -> i32 {
 #package {
     socket_addr_to_wasix_addr :: (in: &SocketAddress, out: &wasi.AddrPort) {
         switch *in {
-            case &path: .Unix {
+            case .Unix as &path {
                 *out = .{ Unix = .{ *cast(&[108] u8) path } };
             }
 
-            case &inet: .Inet {
+            case .Inet as &inet {
                 *out = .{ Ipv4 = .{ inet.port, *cast(&wasi.AddrIPv4)&inet.addr } };
             }
 
-            case &inet: .Inet6 {
+            case .Inet6 as &inet {
                 // Not entirely right...
                 *out = .{ Ipv6 = .{ inet.port, *cast(&wasi.AddrIPv6)&inet.addr } };
             }
@@ -204,15 +204,15 @@ __net_resolve :: (host: str, port: u16, out_addrs: [] SocketAddress) -> i32 {
         switch *in {
             case .Unspec ---
 
-            case &inet: .Ipv4 {
+            case .Ipv4 as &inet {
                 *out = .{ Inet = .{ inet.port, *cast(&u32)&inet.addr } };
             }
 
-            case &inet: .Ipv6 {
+            case .Ipv6 as &inet {
                 *out = .{ Inet6 = .{ inet.port, *cast(&[16] u8)&inet.addr } };
             }
 
-            case &unix: .Unix {
+            case .Unix as &unix {
                 p: [256] u8 = *cast(&[256] u8) &unix.path;
                 *out = .{ Unix = p };
             }
index 77690673997fb61848738dd9be6d7009af1c2b60..07faf1a9a9e8e0c76f3ed1fe974728d5b49ff8ed 100644 (file)
@@ -24,7 +24,7 @@ buffer_make :: (buffer_memory: [] u8, initial_str := null_str) -> String_Buffer
         initial_length := math.min(initial_str.count, buffer.capacity);
         buffer.count += initial_length;
 
-        for i: initial_length { 
+        for i in initial_length { 
             buffer.data[i] = initial_str.data[i];
         }
     }
@@ -50,7 +50,7 @@ buffer_insert :: (use buffer: &String_Buffer, position: i32, ch: u8) -> bool {
 buffer_append :: (use buffer: &String_Buffer, end: str) -> bool {
     if count + end.count > capacity do return false;
 
-    for i: end.count {
+    for i in end.count {
         data[i + count] = end[i];
     }
 
index 7e67e9253d826ae2c6d55f31f7db5ec97d8feae9..86cca236151ccaec4b073312f189bae9e0aa2f9c 100644 (file)
@@ -111,11 +111,11 @@ concat :: (s1: str, s2: str, allocator := context.allocator) -> str {
 #overload
 concat :: (allocator: Allocator, strings: ..str) -> str {
     total_length := 0;
-    for s: strings do total_length += s.count;
+    for s in strings do total_length += s.count;
 
     data := cast([&] u8) raw_alloc(allocator, total_length);
     offset := 0;
-    for s: strings {
+    for s in strings {
         memory.copy(data + offset, s.data, s.count);
         offset += s.count;
     }
@@ -126,7 +126,7 @@ concat :: (allocator: Allocator, strings: ..str) -> str {
 #overload
 concat :: (buffer: [] u8, strings: ..str) -> str {
     total_copied := 0;
-    for s: strings {
+    for s in strings {
         // Should never greater than, but better safe than sorry.
         if total_copied >= buffer.count do break;
 
@@ -140,7 +140,7 @@ concat :: (buffer: [] u8, strings: ..str) -> str {
 
 #overload
 concat :: (into: &[..] u8, strings: ..str) -> str {
-    for s: strings {
+    for s in strings {
         array.ensure_capacity(into, into.count + s.count);
         memory.copy(into.data + into.count, s.data, s.count);
         into.count += s.count;
@@ -151,7 +151,7 @@ concat :: (into: &[..] u8, strings: ..str) -> str {
 #overload
 concat :: (into: &[..] u8, chars: ..u8) -> str {
     array.ensure_capacity(into, into.count + chars.count);
-    for c: chars {
+    for c in chars {
         memory.copy(into.data + into.count, cast(rawptr) &.[c], 1);
         into.count += 1;
     }
@@ -163,7 +163,7 @@ contains :: #match #local {}
 
 #overload
 contains :: (s: str, c: u8) -> bool {
-    for ch: s do if ch == c do return true;
+    for ch in s do if ch == c do return true;
     return false;
 }
 
@@ -367,7 +367,7 @@ strip_trailing_whitespace :: (s: str) -> str {
 }
 
 to_uppercase :: (s: str) -> str {
-    for& ch: s {
+    for& ch in s {
         if *ch >= #char "a" && *ch <= #char "z" {
             *ch -= 32;
         }
@@ -377,7 +377,7 @@ to_uppercase :: (s: str) -> str {
 }
 
 to_lowercase :: (s: str) -> str {
-    for& ch: s {
+    for& ch in s {
         if *ch >= #char "A" && *ch <= #char "Z" {
             *ch += 32;
         }
@@ -444,7 +444,7 @@ advance :: (s: str, chars := 1) -> str {
 }
 
 replace :: (s: str, to_replace: u8, replace_with: u8) {
-    for &c: s {
+    for &c in s {
         if *c == to_replace do *c = replace_with;
     }
 }
@@ -460,7 +460,7 @@ read_until :: (s: &str, upto: u8, skip := 0) -> str {
     out.count = 0;
 
     rem := skip;
-    for ch: *s {
+    for ch in *s {
         if ch == upto {
             if rem <= 0 do break;
             else do rem -= 1;
@@ -524,7 +524,7 @@ read_alphanum :: (s: &str) -> str {
     out.data = s.data;
     out.count = 0;
 
-    for ch: *s {
+    for ch in *s {
         switch ch {
             case #char "a" .. #char "z",
                  #char "A" .. #char "Z",
@@ -552,8 +552,8 @@ read_until_any :: (s: &str, skip: u32, uptos: ..u8) -> str {
     out.count = 0;
 
     rem := skip;
-    for ch: *s {
-        for upto: uptos {
+    for ch in *s {
+        for upto in uptos {
             if ch == upto {
                 if rem <= 0 do break break;
                 else do rem -= 1;
@@ -581,14 +581,14 @@ advance_line :: (s: &str) {
 
 split :: (s: str, delim: u8, allocator := context.allocator) -> []str {
     delim_count := 0;
-    for i: 0 .. s.count do if s[i] == delim do delim_count += 1;
+    for i in 0 .. s.count do if s[i] == delim do delim_count += 1;
 
     strarr := cast([&] str) raw_alloc(allocator, sizeof str * (delim_count + 1));
 
     curr_str := 0;
     begin := 0;
 
-    for i: 0 .. s.count {
+    for i in 0 .. s.count {
         if s[i] == delim {
             strarr[curr_str] = s.data[begin .. i];
             begin = i + 1;
index 2746230acc0f5b562aa741418371022132efc94c..c02f57cfd44171225b783e62e39ffb19ad783bd9 100644 (file)
@@ -289,7 +289,7 @@ strptime :: (buf_: [] u8, format_: [] u8, tm: &Timestamp) -> bool {
                 string.advance(&format);
                 switch format[0] {
                     case #char "a", #char "A" {
-                        for i: weekdays.count {
+                        for i in weekdays.count {
                             w := weekdays[i];
                             if string.equal_insensitive(w, buf[0 .. w.length]) {
                                 string.advance(&buf, w.length);
@@ -308,7 +308,7 @@ strptime :: (buf_: [] u8, format_: [] u8, tm: &Timestamp) -> bool {
                     }
 
                     case #char "b", #char "B", #char "h" {
-                        for i: monthnames.count {
+                        for i in monthnames.count {
                             m := monthnames[i];
                             if string.equal_insensitive(m, buf[0 .. m.length]) {
                                 string.advance(&buf, m.length);
index 1e34a831dbcc5a995de2dc4be4f472a700400d9b..2172719bea21b99ad6bedd87baa565543112adbf 100644 (file)
@@ -56,7 +56,7 @@ main :: () {
     // of creating and using a fixed size array. This uses a for-loop which we have not
     // looked at yet, but the example should be self-explanatory.
     fixed_arr : [10] i32;
-    for i: 0 .. 10 {
+    for i in 0 .. 10 {
         fixed_arr[i] = i * i;
     }
     core.printf("fixed_arr[3] is {}\n", fixed_arr[3]);
@@ -95,7 +95,7 @@ main :: () {
     core.array.init(^dyn_arr);
     defer core.array.free(^dyn_arr);
 
-    for i: 0 .. 10 {
+    for i in 0 .. 10 {
         core.array.push(^dyn_arr, i * i * i);
     }
 
index 5c9fc860a701c6fba014af164940a6bf3a476ffa..972a62f3b5f85f799ef6ef87f381faeed87f744a 100644 (file)
@@ -25,7 +25,7 @@ main :: (args: [] cstr) {
     // with a for loop. Note, the `^` after the for keyword means we are iterating by
     // pointer.
     arr : [10] i32;
-    for ^elem: arr do *elem = 0;
+    for ^elem in arr do *elem = 0;
 
     // To access certain elements of the array, simply use the array access operator,
     // [...], as so. This sets the fourth element of the array to be 1234.
@@ -33,7 +33,7 @@ main :: (args: [] cstr) {
     printf("arr[3] is {}\n", arr[3]);
 
     // Fixed-size arrays can be iterated over using a `for` loop as so.
-    for element: arr {
+    for element in arr {
         printf("{} ", element);
     }
     print("\n");
@@ -43,13 +43,13 @@ main :: (args: [] cstr) {
     // the array `arr` is passed by reference so when the for loop changes the
     // contents of `array_param`, the contents of `arr` are changed as well.
     array_proc :: (array_param: [10] i32) {
-        for i: 0 .. 10 {
+        for i in 0 .. 10 {
             array_param[i] = 1000 + i;
         }
     }
 
     array_proc(arr);
-    for element: arr {
+    for element in arr {
         printf("{} ", element);
     }
 
@@ -59,7 +59,7 @@ main :: (args: [] cstr) {
     // array. Slices and dynamic arrays do not operate this way.
     other_arr : [10] i32;
     other_arr = arr;
-    for other_element: other_arr do printf("{} ", other_element);
+    for other_element in other_arr do printf("{} ", other_element);
     print("\n");
 
     // This does mean that the following pattern of double buffering arrays (which
@@ -84,7 +84,7 @@ main :: (args: [] cstr) {
     // OR
     arr_lit := i32.[ 2, 3, 5, 7, 11 ];
     
-    for elem: arr_lit do printf("{} ", elem);
+    for elem in arr_lit do printf("{} ", elem);
     print("\n");
 
     // The type of the elements of the array is given right before the `.`. The
index 2b218d3742bc6b84617ada48e3a1dbcf85082595..218a4ac84d3b69116e3cfbff85a76f31f2f797bf 100644 (file)
@@ -23,7 +23,7 @@ main :: (args: [] cstr) {
     slice.count = 4;
 
     // You can iterate over slices directly using a for-loop.
-    for elem: slice do printf("{} ", elem);
+    for elem in slice do printf("{} ", elem);
     print("\n");
 
     // Another equivalent way of writing lines 22 and 23 is to
@@ -33,7 +33,7 @@ main :: (args: [] cstr) {
     slice = arr[3 .. 7];
 
     // Printing it out to verify it is the same.
-    for elem: slice do printf("{} ", elem);
+    for elem in slice do printf("{} ", elem);
     print("\n");
 
     // Since strings are represented as slices in Onyx, substrings
index cd1e1d96adfff3cd4afa2bfdc122c7772a450267..3c609a53af288a92fc860a8b7a50faa1ca3909ee 100644 (file)
@@ -32,17 +32,17 @@ main :: (args: [] cstr) {
     // to use it. The most common function you will probably use
     // is array.push. It simply appends a new element to end of
     // the array.
-    for i: 0 .. 10 do array.push(^arr, i);
+    for i in 0 .. 10 do array.push(^arr, i);
 
     // Now if we print the array, we will see the numbers from 0 to 9.
     println(arr);
 
     // We can remove elements from the end using array.pop.
-    for i: 0 .. 4 do array.pop(^arr);
+    for i in 0 .. 4 do array.pop(^arr);
     println(arr);
 
     // We can insert elements at the beginning using array.insert.
-    for i: 6 .. 10 do array.insert(^arr, 0, i);
+    for i in 6 .. 10 do array.insert(^arr, 0, i);
     println(arr);
 
     // There are many other useful functions in the core.array package.
index 44601ee536fae7647b1c956f9eb11a2e7b592ee7..25e9888ce16ff85a33ccd1b546b04e254d9e72a3 100644 (file)
@@ -159,7 +159,7 @@ main :: (args: [] cstr) {
 
     println("param_struct_instance values:");
     println(param_struct_instance.t_member);
-    for elem: param_struct_instance.array_of_T do printf("{} ", elem);
+    for elem in param_struct_instance.array_of_T do printf("{} ", elem);
     print("\n");
 
 
index 99a0f9d363636e2d940fbaae2a10791b006ae7e8..9d024c83d2a3e6b399d32583b5707d18cdda681b 100644 (file)
@@ -9,18 +9,18 @@
 use core {package, *}
 
 main :: (args: [] cstr) {
-    // Currently, for loops can iterate over five kinds of data structures in Onyx:
+    // Currently, for loops can iterate over five kinds of data structures in Onyx in
     //      * Ranges
     //      * Fixed arrays
     //      * Slices
     //      * Dynamic arrays
     //      * Custom iterators
 
-    // The syntax of for loops is very simple:
-    // for ^? <iteration variable>: <iterator> <block>
+    // The syntax of for loops is very simple in
+    // for ^? <iteration variable> in <iterator> <block>
 
     // For example, this will print out the numbers in the array literal:
-    for i: u32.[ 10, 20, 30, 40, 50 ] {
+    for i in u32.[ 10, 20, 30, 40, 50 ] {
         println(i);
     }
     print("\n\n");
@@ -34,7 +34,7 @@ main :: (args: [] cstr) {
     // so:
 
     primes := u32.[ 2, 3, 5, 7, 11, 13, 17 ];
-    for ^prime: primes {
+    for ^prime in primes {
         *prime *= 2;
     }
 
@@ -70,7 +70,7 @@ main :: (args: [] cstr) {
         iterator: Iterator(i32) = .{ data = ^value, next = next, close = close };
 
         // Simply use the iterator.
-        for v: iterator {
+        for v in iterator {
             println(v);
         }
     }
index 5aef693533a38d1ad0af000dbc86e55865b6bb64..96668e4f591b5322daab8c8cc76551df31f73d7e 100644 (file)
@@ -28,7 +28,7 @@ main :: (args: [] cstr) {
     // and will "disappear" when the procedure returns.
     typed_varargs :: (args: ..i32) {
         print("Typed variadic arguments: ");
-        for x: args {
+        for x in args {
             printf("{} ", x);
         }
         print("\n");
@@ -83,7 +83,7 @@ main :: (args: [] cstr) {
     any_varargs :: (args: ..any) {
         print("Any variadic arguments: ");
 
-        for arg: args {
+        for arg in args {
             printf("{}, ", arg.type);
         }
 
index 1ebac42edc37eaba76dfd3f0432d27358177a02a..b37a61cdf3de0ffff4cf12d7241ed57378d63e15 100644 (file)
@@ -56,7 +56,7 @@ main :: (args: [] cstr) {
     person_set << .{ "Joe", 38 };
 
     // "Joe" will only be printed once.
-    for person: set.as_iter(^person_set) {
+    for person in set.as_iter(^person_set) {
         println(person);
     }
 }
@@ -70,7 +70,7 @@ print_type :: #match {
 
 // print_type is a little silly to have in this language because Onyx has complete
 // type knowledge at runtime. To rectify this, let's add a new case that makes
-// this work for any type:
+// this work for any type in
 
 #match #order 10 print_type (x: $T) {
     printf("Fallback case: called with a {} ({})\n", T, x);
@@ -93,7 +93,7 @@ print_type :: #match {
 
 Person :: struct { name: str; age: i32; }
 
-// The overload option for hashing a person:
+// The overload option for hashing a person in
 #match hash.to_u32 (use p: Person) -> u32 {
     return hash.to_u32(name) * 16239563 + age;
 }
index 9ce5e24baf142ba0a2afb80b39c2a67e0de858f9..02641dee9547338f693799e5de27dde355d85f67 100644 (file)
@@ -6,7 +6,7 @@
 // If you are unfamiliar, polymorphic procedures allow you to write code that applies
 // to all types, instead of to only a particular type. For example, you will probably
 // want something like a max function that returns the larger of its two arguments.
-// You might start by writing it for just integer types as so:
+// You might start by writing it for just integer types as so in
 
 max :: (a: i32, b: i32) -> i32 {
     return a if a > b else b;
index 266ee73a7e72f301610e945e538c87c28c24e70e..04d6c3140d398e5df70398eb0f954b50a8de705f 100644 (file)
@@ -81,7 +81,7 @@ main :: (args: [] cstr) {
     }
 
     // You can then use the '#unquote' directive to place the code wherever you need it.
-    // We can paste it 3 times for examples:
+    // We can paste it 3 times for examples in
     #unquote simple_code;
     #unquote simple_code;
     #unquote simple_code;
index 1c48671f3c3dd15d4984a634883c09f51e7fe393..ba62cb8aebaaf5bfc49c09ccfcc4f79b4d0e7b16 100644 (file)
@@ -35,7 +35,7 @@ main :: (args: [] cstr) {
     // I forget that it exists. It isn't something that is very useful,
     // and can lead to some code-smells, if do-blocks are used in strange
     // places, like as arguments. However, during the Advent of Code 2021
-    // I had a real use-case for them and it looked like this:
+    // I had a real use-case for them and it looked like this in
 
 #if false {
     left, right := do {
index a56ac4df5031577907efe13a5682e75101d0692d..9451735d5977c9f706af2e71eb76d0e16814f87e 100644 (file)
@@ -30,7 +30,7 @@ main :: (args: [] cstr) {
     consume :: (it: $T) -> #auto where iter.Iterable(T) {
         consume_inner :: macro (it: Iterator($V)) -> [] V {
             arr: [..] V;
-            for v: it do arr << v;
+            for v in it do arr << v;
             return arr;
         }
 
index 468855c787b1a315e29e4550e2d2fc6f248dec36..6438c807816ec853bf5978cfa3d7f5ad93b32070 100644 (file)
@@ -98,7 +98,7 @@ Command :: struct {
 #tag Command.{ "help", "Show help.", "", require_config_file=false }
 run_help_command :: (args: [] cstr) {
     printf("onyx pkg version {}\n", Version);
-    printf("Package dependency resolver and synchronizer for Onyx.\n\nUsage:\n");
+    printf("Package dependency resolver and synchronizer for Onyx.\n\nUsage in\n");
 
     command_procedures := runtime.info.get_procedures_with_tag(Command);
     defer delete(&command_procedures);
@@ -110,7 +110,7 @@ run_help_command :: (args: [] cstr) {
             lines := string.split(it.tag.argument_descriptions, #char "\n", context.temp_allocator);
 
             print("\n");
-            for line: lines {
+            for line in lines {
                 if line.count == 0 do continue;
                 printf("        {}\n", line);
             }
@@ -975,7 +975,7 @@ Package :: struct {
 Git :: struct {
     get_full_repo_uri :: (package_search: str) -> str {
         for Known_Repositories {
-            for proto: Protocols {
+            for proto in Protocols {
                 r := tprintf("{}{}", proto, tprintf(it, package_search));
                 git_proc := os.process_spawn(git_path, .["ls-remote", "--tags", r]);
                 if os.process_wait(&git_proc) == .Success {
@@ -1045,7 +1045,7 @@ Git :: struct {
         os.remove_directory(temporary_dest);
 
         successfully_cloned := do -> bool {
-            for proto: Protocols {
+            for proto in Protocols {
                 // Use 'git clone' to clone the bare minimum amount to get the released version.
                 proto_repo  := tprintf("{}{}", proto, repo);
                 git_proc    := os.process_spawn(git_path, .["clone", "--single-branch", "--depth", "1", "-b", version_str, proto_repo, temporary_dest]);
@@ -1328,7 +1328,7 @@ store_config :: (path: str) -> bool {
             dep_node->add_value(.{ String = tprintf("{}", it.value.version) });
 
             switch it.value.source {
-                case s: .Git {
+                case .Git as s {
                     dep_node.props["git"] = .{ data = .{ String = s } };
                 }
 
index 64bd5a51352dc573468284ae41d6d16261352a95..fba10abb6f90b20dc966c49ed1d8a86933fe4656 100644 (file)
@@ -151,7 +151,7 @@ main :: (args) => {
 
         if thread_data.compile_only do continue;
 
-        for expected_file: os.with_file(it.expected_file) {
+        for expected_file in os.with_file(it.expected_file) {
             expected_reader := io.reader_make(expected_file);
             expected_output := io.read_all(&expected_reader);
 
index 4e5fdcd5827f5df1d389929ff917b2f21fc44af5..82da7edd9a3188dc357932c89d925f5950befd34 100644 (file)
@@ -19,7 +19,7 @@ main :: (args: [] cstr) {
         if num != 0 do array.push(&nums, num);
     }
 
-    for i: nums do for j: nums do for k: nums {
+    for i in nums do for j in nums do for k in nums {
         if j + i + k == 2020 {
             printf("Answer: {}\n", i * j * k);
 
index eca37c87de679a6dcaa7e42d9a0741300c1fa18f..464be807e74ee3060d32db6536aaf350432007e0 100644 (file)
@@ -6,11 +6,11 @@ count_ending_paths :: (nums: [..] u32) -> u64 {
     tally := array.make(u64, nums.count);
     defer array.free(&tally);
 
-    for &t: tally do *t = 0;
+    for &t in tally do *t = 0;
     tally[nums.count - 1] = 1;
 
     while i := cast(i32) (nums.count - 2); i >= 0 {
-        for diff: 1 .. 4 {
+        for diff in 1 .. 4 {
             if i + diff >= nums.count do continue;
 
             if nums[i + diff] - nums[i] <= 3 do tally[i] += tally[i + diff];
@@ -41,8 +41,8 @@ main :: (args: [] cstr) {
     array.sort(nums, (a, b) => a - b);
 
     diffs: [3] u32;
-    for &d: diffs do *d = 0;
-    for i: 1 .. nums.count do diffs[nums[i] - nums[i - 1] - 1] += 1;
+    for &d in diffs do *d = 0;
+    for i in 1 .. nums.count do diffs[nums[i] - nums[i - 1] - 1] += 1;
     diffs[2] += 1;
 
     printf("Diff prod: {}\n", diffs[0] * diffs[2]);
index 6210c986082089f6fe7dcde2788b802ac703c32e..24d6e940bd3d29720da85ade2df31bc43d7b2083 100644 (file)
@@ -17,8 +17,8 @@ gos_get_seat :: (use gos: &GameOfSeats, x: i32, y: i32) -> SeatState {
 gos_neighbors :: (use gos: &GameOfSeats, x: i32, y: i32, state := SeatState.Occupied) -> u32 {
     count := 0;
 
-    for dy: -1 .. 2 {
-        for dx: -1 .. 2 {
+    for dy in -1 .. 2 {
+        for dx in -1 .. 2 {
             if dy == 0 && dx == 0 do continue;
 
             t := 1;
@@ -36,11 +36,11 @@ gos_neighbors :: (use gos: &GameOfSeats, x: i32, y: i32, state := SeatState.Occu
 }
 
 gos_iter :: (use gos: &GameOfSeats) -> bool {
-    for i: 0 .. seats.count do temp[i] = seats[i];
+    for i in 0 .. seats.count do temp[i] = seats[i];
 
     changed := false;
-    for y: 0 .. height {
-        for x: 0 .. width {
+    for y in 0 .. height {
+        for x in 0 .. width {
             occ_neighbors := gos_neighbors(gos, x, y);
 
             switch gos_get_seat(gos, x, y) {
@@ -57,7 +57,7 @@ gos_iter :: (use gos: &GameOfSeats) -> bool {
         }
     }
 
-    for i: 0 .. seats.count do seats[i] = temp[i];
+    for i in 0 .. seats.count do seats[i] = temp[i];
 
     return changed;
 }
@@ -75,7 +75,7 @@ main :: (args: [] cstr) {
 
     while !string.empty(file) {
         line, file~ := string.bisect(file, #char "\n");
-        for ch: line do switch ch {
+        for ch in line do switch ch {
             case #char "." do array.push(&gos.seats, SeatState.Floor);
             case #char "L" do array.push(&gos.seats, SeatState.Empty);
             case #char "#" do array.push(&gos.seats, SeatState.Occupied);
@@ -91,7 +91,7 @@ main :: (args: [] cstr) {
     while gos_iter(&gos) ---
 
     occupied := 0;
-    for s: gos.seats do if s == SeatState.Occupied do occupied += 1;
+    for s in gos.seats do if s == SeatState.Occupied do occupied += 1;
     
     printf("Occupied: {}\n", occupied);
 }
index 00995587bca3e75572b197dee3513c1db19ed0df..101037a455523c0b6d7d62f6ea779ffd17b87e46 100644 (file)
@@ -24,10 +24,10 @@ inv_mod :: (a_: i64, m_: i64) -> i64 {
 
 chinese_remainder_theorem :: (mods: [..] i64, rems: [..] i64) -> i64 {
     N: i64 = 1;
-    for n: mods do N *= n;
+    for n in mods do N *= n;
     
     res: i64 = 0;
-    for i: 0 .. mods.count {
+    for i in 0 .. mods.count {
         n := N / mods[i];
         res += rems[i] * inv_mod(n, mods[i]) * n;
     }
@@ -70,8 +70,8 @@ main :: (args: [] cstr) {
     // take_bus := 0;
     // depart   := 0;
 
-    // for i: 0 .. min {
-    //     for bus: buses {
+    // for i in 0 .. min {
+    //     for bus in buses {
     //         if (i + est) % bus == 0 {
     //             take_bus = bus;
     //             depart = i + est;
index 9a094958a87b67fe3b608369e05e51851ca95d2b..aa435d0d62aaaaf509bdf8bacf546889dfd9e2e4 100644 (file)
@@ -9,7 +9,7 @@ Bitmask :: [MASK_SIZE] u8;
 bitmask_p1 :: (mask: Bitmask, val: u64) -> u64 {
        res: u64 = 0;
        bit: u64 = 1;
-       for m: mask {
+       for m in mask {
                switch m {
                        case 1 do res |= bit;
                        case 2 do res |= (val & bit);
@@ -34,7 +34,7 @@ bitmask_p2 :: (mask: Bitmask, val: u64) -> Iterator(u64) {
         bmi := cast(&BitmaskIter) data;
         if bmi.done do return 0, false;
 
-               for ind: bmi.floating_indicies {
+               for ind in bmi.floating_indicies {
                        is_set := (bmi.val & (1 << cast(u64) ind)) != 0;
 
                        bmi.val ^= 1 << cast(u64) ind;
@@ -58,7 +58,7 @@ bitmask_p2 :: (mask: Bitmask, val: u64) -> Iterator(u64) {
     array.init(&bmi.floating_indicies, 8);
 
        v := val;
-       for i: 0 .. MASK_SIZE {
+       for i in 0 .. MASK_SIZE {
                if mask[i] == 1 do v |= 1 << cast(u64) i;
 
                if mask[i] == 2 {
@@ -81,7 +81,7 @@ main :: (args: [] cstr) {
        defer map.free(&mem);
 
        mask : Bitmask;
-       for &m: mask do *m = 2;
+       for &m in mask do *m = 2;
 
        while !string.empty(file) {
                word := string.read_alphanum(&file);
@@ -90,7 +90,7 @@ main :: (args: [] cstr) {
 
                        i := 35;
             m, file~ := string.bisect(file, #char "\n");
-            for ch: m {
+            for ch in m {
                                switch ch {
                                        case #char "0" do mask[i] = 0;
                                        case #char "1" do mask[i] = 1;
@@ -112,7 +112,7 @@ main :: (args: [] cstr) {
                        // map.put(&mem, addr, bitmask_p1(mask, val));
 
                        // Part 2
-            for real_addr: bitmask_p2(mask, addr) {
+            for real_addr in bitmask_p2(mask, addr) {
                 map.put(&mem, real_addr, val);
             }
 
@@ -121,7 +121,7 @@ main :: (args: [] cstr) {
        }       
 
        s: u64 = 0;
-       for e: mem.entries do s += e.value;
+       for e in mem.entries do s += e.value;
 
        printf("Sum: {}\n", s);
 }
index 0ce1b716f3809f87e33f7e60e87872a48d970548..8f8b303e37952437004535783b378a5f1eeaad2e 100644 (file)
@@ -19,7 +19,7 @@ main :: (args: [] cstr) {
     turn := 1;
     last_num := 0;
 
-    for n: initial_numbers {
+    for n in initial_numbers {
         map.put(&nums, n, .{ recent = turn });
         turn += 1;
         last_num = n;
index 73088aafc35a88ac53fac0c4ce8b26dc9c9ccd72..6a4c3790dabe5709763e30e8c83825edde5ccd31 100644 (file)
@@ -22,14 +22,14 @@ total_scanning_error := 0;
 read_ticket_and_validate :: (file: &str, fields: [..] Field, ticket_store: [&] u32) -> bool {
        retval := true;
 
-       for i: 0 .. fields.count {
+       for i in 0 .. fields.count {
                n := cast(u32, conv.parse_int(file));
                ticket_store[i] = n;
 
                if file.data[0] == #char "," do string.advance(file, 1);
 
                valid_count := 0;
-               for &field: fields {
+               for &field in fields {
                        if field_valid(field, n) do valid_count += 1;
                }
 
@@ -73,13 +73,13 @@ main :: (args: [] cstr) {
                array.push(&fields, field);
        }
 
-       for i: 0 .. 2 do string.advance_line(&file);
+       for i in 0 .. 2 do string.advance_line(&file);
 
        my_ticket := array.make(u32, fields.count);
        defer array.free(&my_ticket);
        read_ticket_and_validate(&file, fields, my_ticket.data);
 
-       for i: 0 .. 2 do string.advance_line(&file);
+       for i in 0 .. 2 do string.advance_line(&file);
 
        ticket_data := array.make(u32, 1024);
        defer array.free(&ticket_data);
@@ -96,18 +96,18 @@ main :: (args: [] cstr) {
        cols_to_assign := array.make(u32, fields.count);
        defer array.free(&cols_to_assign);
 
-       for i: 0 .. fields.count do array.push(&cols_to_assign, i);
+       for i in 0 .. fields.count do array.push(&cols_to_assign, i);
 
        while cols_to_assign.count > 0 {
-               for col: cols_to_assign {
+               for col in cols_to_assign {
                        work_count := 0;
                        recent_work: &Field = null;
 
-                       for &field: fields {
+                       for &field in fields {
                                if field.column != -1 do continue;
                                works := true;
 
-                               for row: 0 .. (ticket_data.count / fields.count) {
+                               for row in 0 .. (ticket_data.count / fields.count) {
                                        if !field_valid(field, ticket_data[col + fields.count * row]) {
                                                works = false;
                                                break;
@@ -129,7 +129,7 @@ main :: (args: [] cstr) {
        }
 
        prod: u64 = 1;
-       for &field: fields {
+       for &field in fields {
                if string.starts_with(field.name, "departure") do prod *= ~~my_ticket[field.column];
        }
 
index 5cf9434efe0f8c303afa1d25872e636ac72491bf..a859448bfa2fd852c8bdf7f5edd98010654c3119 100644 (file)
@@ -40,7 +40,7 @@ CubeState :: struct {
 get_neighbor_count :: (cubes: &Map(CubePos, CubeState), pos: CubePos) -> u32 {
     count := 0;
 
-    for x: -1 .. 2 do for y: -1 .. 2 do for z: -1 .. 2 do for w: -1 .. 2 {
+    for x in -1 .. 2 do for y in -1 .. 2 do for z in -1 .. 2 do for w in -1 .. 2 {
         if x == 0 && y == 0 && z == 0 && w == 0 do continue;
         key := CubePos.{ pos.x + x, pos.y + y, pos.z + z, pos.w + w };
         map.get(cubes, key)->with([s] {
@@ -64,7 +64,7 @@ main :: (args: [] cstr) {
         line, file~ := string.bisect(file, #char "\n");
 
         x := 0;
-        for ch: line {
+        for ch in line {
             if ch == #char "#" do map.put(&cubes, .{ x, 0, z, 0 }, .{ alive = true });
 
             x += 1;
@@ -76,10 +76,10 @@ main :: (args: [] cstr) {
     cubes_to_consider := array.make(CubePos);
     defer array.free(&cubes_to_consider);
 
-    for i: 0 .. 6 {
-        for &cube_entry: cubes.entries {
+    for i in 0 .. 6 {
+        for &cube_entry in cubes.entries {
             if cube_entry.value.alive {
-                for x: -1 .. 2 do for y: -1 .. 2 do for z: -1 .. 2 do for w: -1 .. 2 {
+                for x in -1 .. 2 do for y in -1 .. 2 do for z in -1 .. 2 do for w in -1 .. 2 {
                     array.push(&cubes_to_consider, .{
                         cube_entry.key.x + x,
                         cube_entry.key.y + y,
@@ -90,7 +90,7 @@ main :: (args: [] cstr) {
             }
         }
 
-        for &cube: cubes_to_consider {
+        for &cube in cubes_to_consider {
             state  := map.get(&cubes, *cube) ?? .{};
             ncount := get_neighbor_count(&cubes, *cube);
             
@@ -103,7 +103,7 @@ main :: (args: [] cstr) {
             map.put(&cubes, *cube, state);
         }
 
-        for &cube: cubes_to_consider {
+        for &cube in cubes_to_consider {
             state := map.get(&cubes, *cube) ?? .{};
             state.alive = state.next;
             map.put(&cubes, *cube, state);
@@ -113,7 +113,7 @@ main :: (args: [] cstr) {
     }
 
     active_count := 0;
-    for &cube_entry: cubes.entries do if cube_entry.value.alive do active_count += 1;
+    for &cube_entry in cubes.entries do if cube_entry.value.alive do active_count += 1;
 
     printf("Active count: {}\n", active_count);
 }
index ec61e74425477870416d002fb2ccaab388af722b..f1a89651c947a48e82f2fe1f54532296db52bb59 100644 (file)
@@ -48,14 +48,14 @@ grammar_free :: (use g: &Grammar) {
 
 grammar_prepare :: (use g: &Grammar) {
     // Not full-proof, but good enough for AOC.
-    for &solo: unit_rules {
-        for &prod: production_rules {
+    for &solo in unit_rules {
+        for &prod in production_rules {
             if prod.nt0 == solo.nt1 {
                 array.push(&production_rules, Prod.{ solo.nt0, prod.nt1, prod.nt2 });
             }
         }
 
-        for &unit: terminate_rules {
+        for &unit in terminate_rules {
             if unit.nt == solo.nt1 {
                 array.push(&terminate_rules, Term.{ solo.nt0, unit.t });
             } 
@@ -80,18 +80,18 @@ cyk_algorithm :: (use grammar: &Grammar, input: str) -> bool {
     defer cfree(T);
     memory.set(T, ~~false, mem_size);
 
-    for s: 0 .. input.count {
-        for &term: terminate_rules {
+    for s in 0 .. input.count {
+        for &term in terminate_rules {
             if term.t == input[s] {
                 T[0 * dim_0 + s * dim_1 + term.nt * dim_2] = true;
             }
         }
     }
 
-    for l: 1 .. input.count {
-        for s: 0 .. input.count - l {
-            for p: 1 .. l + 1 {
-                for &prod: production_rules {
+    for l in 1 .. input.count {
+        for s in 0 .. input.count - l {
+            for p in 1 .. l + 1 {
+                for &prod in production_rules {
                     if    T[(p - 1) * dim_0 + s       * dim_1 + prod.nt1 * dim_2]
                        && T[(l - p) * dim_0 + (s + p) * dim_1 + prod.nt2 * dim_2] {
                         T[l * dim_0 + s * dim_1 + prod.nt0 * dim_2] = true;
index 4ab43dfb8de95dbb728ac4d14b07ce3cdd6128c4..393f2260b95ca187c5bab3ab5b8d65a9babd8a34 100644 (file)
@@ -25,7 +25,7 @@ main :: (args: [] cstr) {
 
         // Part 1
         // count := 0;
-        // for c: pw do if c == ch do count += 1;
+        // for c in pw do if c == ch do count += 1;
         // if count >= lo && count <= hi do valid += 1;
 
         // Part 2
index dc7b75020d11a0dc239730dd63346b2e39e9a9cd..245754edb4cd35463a712473dd9ed6a05522a8ed 100644 (file)
@@ -55,7 +55,7 @@ tile_orientation_table := ([8] TO).[
 reverse_binary :: (n_: u32, digits := TILE_DATA_WIDTH) -> u32 {
        res := 0;       
        n := n_;
-       for _: 0 .. digits {
+       for _ in 0 .. digits {
                res <<= 1;
                res |= (n & 1);
                n >>= 1;
@@ -68,9 +68,9 @@ build_edges :: (tile: [] bool, a := context.allocator) -> [] u32 {
        edges : [..] u32;
     array.init(&edges, 8, allocator=a);
 
-       for y: u32.[0, 9] {
+       for y in u32.[0, 9] {
                edge := 0;
-               for x: 0 .. 10 {
+               for x in 0 .. 10 {
                        edge <<= 1;
                        if tile[x + y * TILE_DATA_WIDTH] do edge |= 1;
                }
@@ -78,9 +78,9 @@ build_edges :: (tile: [] bool, a := context.allocator) -> [] u32 {
         array.push(&edges, edge);
        }       
 
-       for x: u32.[0, 9] {
+       for x in u32.[0, 9] {
                edge := 0;
-               for y: 0 .. 10 {
+               for y in 0 .. 10 {
                        edge <<= 1;
                        if tile[x + y * TILE_DATA_WIDTH] do edge |= 1;
                }
@@ -88,7 +88,7 @@ build_edges :: (tile: [] bool, a := context.allocator) -> [] u32 {
         array.push(&edges, edge);
        }       
 
-       for i: 0 .. 4 do array.push(&edges, reverse_binary(edges[i]));
+       for i in 0 .. 4 do array.push(&edges, reverse_binary(edges[i]));
 
        return edges.data[0 .. 8];
 }
@@ -109,7 +109,7 @@ side_relations := ([4] TO).[
 has_matching_edges :: (t1: &Tile, t2: &Tile) -> bool {
     match := false;
 
-       for e_idx: 0 .. t1.edges.count / 2 do for e2_idx: 0 .. t2.edges.count {
+       for e_idx in 0 .. t1.edges.count / 2 do for e2_idx in 0 .. t2.edges.count {
         if t1.edges[e_idx] == t2.edges[e2_idx] {
             match = true;
 
@@ -204,12 +204,12 @@ sea_monster := u8.[
 scan_for_monsters :: (forest: [&] u8, ori: TO, width: u32, height: u32) -> bool {
     found_monsters := false;
 
-    for y: 0 .. height - sea_monster_height {
-        for x: 0 .. width - sea_monster_width {
+    for y in 0 .. height - sea_monster_height {
+        for x in 0 .. width - sea_monster_width {
             is_monster := true;
 
-            for my: 0 .. sea_monster_height {
-                for mx: 0 .. sea_monster_width {
+            for my in 0 .. sea_monster_height {
+                for mx in 0 .. sea_monster_width {
                     if sea_monster[mx + my * sea_monster_width] != #char "#" do continue;
                     if *index_square_with_orientation(forest, ori, width, x + mx, y + my) != #char "." do continue;
 
@@ -219,8 +219,8 @@ scan_for_monsters :: (forest: [&] u8, ori: TO, width: u32, height: u32) -> bool
             }
 
             if is_monster {
-                for my: 0 .. sea_monster_height {
-                    for mx: 0 .. sea_monster_width {
+                for my in 0 .. sea_monster_height {
+                    for mx in 0 .. sea_monster_width {
                         if sea_monster[mx + my * sea_monster_width] != #char "#" do continue;
                         if *index_square_with_orientation(forest, ori, width, x + mx, y + my) != #char "#" do continue;
 
@@ -265,10 +265,10 @@ main :: (args: [] cstr) {
 
                td := cast([&] bool) raw_alloc(tile_allocator, sizeof TileData);
 
-               for y: 0 .. 10 {
+               for y in 0 .. 10 {
                        line, file~ := string.bisect(file, #char "\n");
 
-                       for x: 0 .. 10 {
+                       for x in 0 .. 10 {
                                td[x + y * TILE_DATA_WIDTH] = (line[x] == #char "#");
                        }
                }
@@ -286,15 +286,15 @@ main :: (args: [] cstr) {
                string.advance_line(&file);
        }
 
-    for &t: tiles do map.put(&tile_map, t.id, t);
+    for &t in tiles do map.put(&tile_map, t.id, t);
 
        prod: u64 = 1;
     top_left_id := 0;
 
-       for i: 0 .. tiles.count - 1 {
+       for i in 0 .. tiles.count - 1 {
                matching_count := 0;
 
-               for j: 0 .. tiles.count {
+               for j in 0 .. tiles.count {
                        if i == j do continue;
                        if has_matching_edges(&tiles[i], &tiles[j]) {
                                matching_count += 1;
@@ -345,12 +345,12 @@ main :: (args: [] cstr) {
     }
 
     forest : [12 * 8 * 12 * 8] u8;
-    for y: 0 .. 12 {
-        for x: 0 .. 12 {
+    for y in 0 .. 12 {
+        for x in 0 .. 12 {
             tile := map.get(&tile_map, grid[y * 12 + x])->unwrap();
 
-            for fy: 0 .. 8 {
-                for fx: 0 .. 8 {
+            for fy in 0 .. 8 {
+                for fx in 0 .. 8 {
                     res := *index_square_with_orientation(cast([&] bool) tile.data.data, tile.orientation, 10, fx + 1, fy + 1);
                     loc := (y * 12 * 8 * 8) + (fy * 12 * 8) + (x * 8) + fx;
                     if res do forest[loc] = #char "#";
@@ -360,12 +360,12 @@ main :: (args: [] cstr) {
         }
     }
 
-    for ori: .[ TO.N, TO.R90, TO.R180, TO.R270, TO.F, TO.FR90, TO.FR180, TO.FR270 ] {
+    for ori in .[ TO.N, TO.R90, TO.R180, TO.R270, TO.F, TO.FR90, TO.FR180, TO.FR270 ] {
         if scan_for_monsters(cast([&] u8) forest, ori, 12 * 8, 12 * 8) do break;
     }
     
     safe_count := 0;
-    for c: forest do if c == #char "#" do safe_count += 1;
+    for c in forest do if c == #char "#" do safe_count += 1;
 
     printf("Safe count: {}\n", safe_count);
 }
index 05889f7a72f4290aeff755657b40d1efed606392..d5b733e0b58cf45a460b6107638237b188ae0638 100644 (file)
@@ -94,18 +94,18 @@ main :: (args: [] cstr) {
     definitely_safe := array.make(str);
     defer array.free(&definitely_safe);
 
-    for &ingredient_entry: ingredient_map.entries {
+    for &ingredient_entry in ingredient_map.entries {
         potential_allergens := array.make(str);
         defer array.free(&potential_allergens);
 
-        for food_num: ingredient_entry.value.appears_on {
-            for &allergen_name: foods[food_num].allergens {
+        for food_num in ingredient_entry.value.appears_on {
+            for &allergen_name in foods[food_num].allergens {
                 array.push(&potential_allergens, *allergen_name);
             }
         }
 
         potential_allergen_count := 0;
-        for &allergen_name: potential_allergens {
+        for &allergen_name in potential_allergens {
             c := array_count_contains(&potential_allergens, *allergen_name, string.equal);
             allergen := map.get(&allergen_map, *allergen_name)->unwrap();
             if c == allergen.appears_on.count {
@@ -119,7 +119,7 @@ main :: (args: [] cstr) {
     }
 
     total_safe := 0;
-    for safe: definitely_safe {
+    for safe in definitely_safe {
         ingredient := map.get(&ingredient_map, safe)->unwrap();
         total_safe += ingredient.appears_on.count;
 
@@ -132,14 +132,14 @@ main :: (args: [] cstr) {
     defer array.free(&matched_ingredients);
 
     while !map.empty(&ingredient_map) {
-        for &allergen_entry: allergen_map.entries {
+        for &allergen_entry in allergen_map.entries {
             match_count := 0;
             matching_ingredient_name := str.{ null, 0 };
 
-            for &ingredient_entry: ingredient_map.entries {
+            for &ingredient_entry in ingredient_map.entries {
                 matches := true;
 
-                for ap: allergen_entry.value.appears_on {
+                for ap in allergen_entry.value.appears_on {
                     if !array.contains(ingredient_entry.value.appears_on, ap) do matches = false;
                 }
 
@@ -161,13 +161,13 @@ main :: (args: [] cstr) {
 
     array.sort(matched_ingredients, (i1: &Ingredient, i2: &Ingredient) => string.compare(i1.allergen, i2.allergen));
 
-    for &mi: matched_ingredients do printf("{} -> {}\n", mi.name, mi.allergen);
-    for &mi: matched_ingredients do printf("{},", mi.name);
+    for &mi in matched_ingredients do printf("{} -> {}\n", mi.name, mi.allergen);
+    for &mi in matched_ingredients do printf("{},", mi.name);
     println("\n(Don't copy the last ','!)");
 }
 
 array_count_contains :: (arr: &[..] $T, x: T, equal: (T, T) -> bool) -> u32 {
     count := 0;
-    for &it: *arr do if equal(*it, x) do count += 1;
+    for &it in *arr do if equal(*it, x) do count += 1;
     return count;
 }
index e05ca22fe53af7b6a09e1a0c484efecc7cdb1c60..5ecff2746e06943c6b70572182983ee4eaf658df 100644 (file)
@@ -8,7 +8,7 @@ key_alloc : Allocator;
 score_player :: (p: &[..] u32) -> u32 {
     count := 0;
     mul := p.count;
-    for c: *p {
+    for c in *p {
         count += c * mul;
         mul -= 1;
     }
@@ -45,12 +45,12 @@ encode_hands :: (alloc: Allocator, p1: &[..] u32, p2: &[..] u32) -> str {
     stream := io.buffer_stream_make(256, alloc);
     writer := io.writer_make(&stream, 0);
 
-    for n: *p1 {
+    for n in *p1 {
         io.write_i64(&writer, ~~n, 64);
         io.write_str(&writer, ",");
     }
     io.write_str(&writer, "|");
-    for n: *p2 {
+    for n in *p2 {
         io.write_i64(&writer, ~~n, 64);
         io.write_str(&writer, ",");
     }
index 6c185f3e5f6d061ce094965e1bf9c2c065c15e4e..310fdb71de698528c83c25b8cffde3cf90dae21e 100644 (file)
@@ -14,7 +14,7 @@ w :: (idx: $T, mod := cups.count) -> T {
 }
 
 get_idx :: (cups: [] i32, cup: i32) -> i32 {
-    for i: 0 .. cups.count do if cups[i] == cup do return i;
+    for i in 0 .. cups.count do if cups[i] == cup do return i;
     return -1;
 }
 
@@ -22,11 +22,11 @@ simulate :: (cups: [] i32, moves := 100) {
     cw := memory.make_slice(i32, cups.count);
     defer cfree(cw.data);
 
-    for i: 0 .. cups.count do cw[cups[i]] = cups[w(i + 1)];
+    for i in 0 .. cups.count do cw[cups[i]] = cups[w(i + 1)];
 
     current_cup := cups[0];
 
-    for move: 0 .. moves {
+    for move in 0 .. moves {
         next_1 := cw[current_cup];
         next_2 := cw[next_1];
         next_3 := cw[next_2];
@@ -46,7 +46,7 @@ simulate :: (cups: [] i32, moves := 100) {
     }
 
     cup := 0;
-    for i: 0 .. cups.count {
+    for i in 0 .. cups.count {
         cups[i] = cup;
         cup = cw[cup];
     }
@@ -56,26 +56,26 @@ main :: (args: [] cstr) {
     cups_data := i32.[ 9, 6, 2, 7, 1, 3, 8, 5, 4 ];
 
     // Easier think about in zero-indexed
-    for &cup: cups_data do *cup -= 1;
+    for &cup in cups_data do *cup -= 1;
 
     array.init(&cups, 1000000);
     defer array.free(&cups);
 
-    for cup: cups_data do array.push(&cups, cup);
+    for cup in cups_data do array.push(&cups, cup);
 
     // Part 1
     // simulate(array.to_slice(&cups));
     
     // Part 2
-    for i: 9 .. 1000000 do array.push(&cups, i);
+    for i in 9 .. 1000000 do array.push(&cups, i);
     simulate(cups, 10000000);
 
     // Undo the zero-indexing
-    for &cup: cups do *cup += 1;
+    for &cup in cups do *cup += 1;
 
     // Part 1
     // one_idx := get_idx(array.to_slice(&cups), 1);
-    // for i: 1 .. 9 {
+    // for i in 1 .. 9 {
     //     printf("{}", cast(i32) cups[w(one_idx + i)]);
     // }
     // printf("\n");
index a5f937f59ced38bce29e13c1eea7bf43a73ba679..e187343b9d67d561109d79ab858378f3332b877d 100644 (file)
@@ -39,7 +39,7 @@ main :: (args: [] cstr) {
 
                loc := Vec2.{ 0, 0 };
                s := 0;
-               for ch: line do switch s {
+               for ch in line do switch s {
                        case 0 do switch ch {
                                case #char "e" do loc.x += 1;
                                case #char "w" do loc.x -= 1;
@@ -71,7 +71,7 @@ main :: (args: [] cstr) {
 
        // Part 1
        black_count := 0;
-       for &cell: grid.entries {
+       for &cell in grid.entries {
                if cell.value.alive do black_count += 1;
        }       
        printf("Black count: {}\n", black_count);
@@ -80,12 +80,12 @@ main :: (args: [] cstr) {
        cells_to_consider := array.make(Vec2);
        defer array.free(&cells_to_consider);
 
-       for i: 0 .. 100 {
-               for &cell: grid.entries {
+       for i in 0 .. 100 {
+               for &cell in grid.entries {
                        if cell.value.alive {
                                array.push(&cells_to_consider, cell.key);
 
-                               for &dir: Hex_Directions {
+                               for &dir in Hex_Directions {
                                        array.push(&cells_to_consider, .{
                                                x = cell.key.x + dir.x,
                                                y = cell.key.y + dir.y,
@@ -94,7 +94,7 @@ main :: (args: [] cstr) {
                        }
                }
 
-               for &cell: cells_to_consider {
+               for &cell in cells_to_consider {
                        state  := map.get(&grid, *cell) ?? .{};
                        ncount := get_neighbor_count(&grid, *cell);
 
@@ -107,7 +107,7 @@ main :: (args: [] cstr) {
                        map.put(&grid, *cell, state);
                }
 
-               for &cell: cells_to_consider {
+               for &cell in cells_to_consider {
                        map.update(&grid, *cell, [v]{ v.alive = v.next; });
                }
 
@@ -115,7 +115,7 @@ main :: (args: [] cstr) {
        }
 
        black_count = 0;
-       for &cell: grid.entries {
+       for &cell in grid.entries {
                if cell.value.alive do black_count += 1;
        }       
        printf("GOL black count: {}\n", black_count);
@@ -124,7 +124,7 @@ main :: (args: [] cstr) {
 get_neighbor_count :: (grid: &map.Map(Vec2, Cell), pos: Vec2) -> u32 {
        count := 0;
 
-       for &dir: Hex_Directions {
+       for &dir in Hex_Directions {
                cell := map.get(grid, Vec2.{ x = pos.x + dir.x, y = pos.y + dir.y }) ?? .{};
                if cell.alive do count += 1;
        }
index 1d31169e6f52fa28ad1446e7bff4106395ba00bd..047dce91e7e9fedd303065ae2d319df5833fc0e8 100644 (file)
@@ -25,7 +25,7 @@ dlp_bsgs :: (n: u32, a: u32, b: u32) -> u32 {
     defer map.free(&t);
 
     tmp: u64 = 1;
-    for i: 0 .. m {
+    for i in 0 .. m {
         map.put(&t, ~~tmp, i);
         tmp = (tmp * ~~a) % ~~n;
     }
@@ -33,7 +33,7 @@ dlp_bsgs :: (n: u32, a: u32, b: u32) -> u32 {
     f := power_mod(a, n - 1 - m, n);
 
     tmp = ~~b;
-    for i: 0 .. m {
+    for i in 0 .. m {
         if map.has(&t, ~~tmp) {
             v := map.get(&t, ~~tmp) ?? 0;
             return i * m + v; 
@@ -47,7 +47,7 @@ dlp_bsgs :: (n: u32, a: u32, b: u32) -> u32 {
 
 transform_subject :: (subject: u32, loop_size: u32) -> u32 {
     value: u64 = 1;
-    for i: 0 .. loop_size do value = (value * ~~subject) % 20201227;
+    for i in 0 .. loop_size do value = (value * ~~subject) % 20201227;
     return cast(u32) value;
 }
 
index 2ab75cbba5aa52db9fafeb932aaeae97dc4f814a..5b46bbdab33e6784c234d55a33e099255561e4cf 100644 (file)
@@ -31,7 +31,7 @@ main :: (args: [] cstr) {
         width = line.count;
         height = height + 1;
 
-        for ch: line do array.push(&forest, ch);
+        for ch in line do array.push(&forest, ch);
     }
 
     lis := LineInterp.[
@@ -44,7 +44,7 @@ main :: (args: [] cstr) {
 
     tree_prod: u64 = 1;
 
-    for li: lis {
+    for li in lis {
         tree_count: u64 = 0;
         while i := 0; true {
             p := line_interp_at(li, i); 
index dbec2f5ab0b2403c73ec20e4c2aac753857f4c11..aa1cee3c38985d3d16e278bf7324d0c69122e022 100644 (file)
@@ -14,7 +14,7 @@ process_passport :: (contents: &str) -> u32 {
         fields := string.split(line, #char " ");
         defer cfree(fields.data);
 
-        for field: fields {
+        for field in fields {
             data := string.split(field, #char ":");
             defer cfree(data.data);
 
index e725110388830389b9c293fcc7eb30cef3a3fea7..d7e2b539003240b36c3caf37780de6dab13e6e98 100644 (file)
@@ -16,7 +16,7 @@ main :: (args: [] cstr) {
         if line.count == 0 do break;
 
         val := 0;
-        for ch: line {
+        for ch in line {
             val *= 2;
             if ch == #char "B" || ch == #char "R" do val += 1;
         }
@@ -27,7 +27,7 @@ main :: (args: [] cstr) {
 
     missing := 0;
     array.sort(vals, cmp_asc);
-    for i: 0 .. vals.count - 1 {
+    for i in 0 .. vals.count - 1 {
         if vals[i + 1] - vals[i] != 1 do missing = vals[i] + 1;
     }
 
index aaecf0ed93f7b3ce91cc56eb532bf1359c9e0664..3cbc5b173bfc99ccd4bd6d437236ab83cdee3aed 100644 (file)
@@ -4,25 +4,25 @@ use core {*}
 
 part_1 :: (contents: &str) -> u32 {
     chars : [26] bool;
-    for &ch: chars do *ch = false;
+    for &ch in chars do *ch = false;
 
     while true {
         line := string.read_until(contents, #char "\n");
         string.advance(contents, 1);
         if line.count == 0 do break;
 
-        for ch: line do chars[~~ch - cast(u32) #char "a"] = true;
+        for ch in line do chars[~~ch - cast(u32) #char "a"] = true;
     }
 
     sum := 0;
-    for ch: chars do if ch do sum += 1;
+    for ch in chars do if ch do sum += 1;
 
     return sum;
 }
 
 part_2 :: (contents: &str) -> u32 {
     chars : [26] u32;
-    for &ch: chars do *ch = 0;
+    for &ch in chars do *ch = 0;
 
     person_count := 0;
     while true {
@@ -32,11 +32,11 @@ part_2 :: (contents: &str) -> u32 {
         
         person_count += 1;
 
-        for ch: line do chars[~~ch - cast(u32) #char "a"] += 1;
+        for ch in line do chars[~~ch - cast(u32) #char "a"] += 1;
     }
 
     sum := 0;
-    for ch: chars do if ch == person_count do sum += 1;
+    for ch in chars do if ch == person_count do sum += 1;
 
     return sum;
 }
index b1b6f71eee60e8cfe3e3a88c843624abc875fb41..d2dca4497dfb34e023d388055151a358c8711723 100644 (file)
@@ -103,7 +103,7 @@ main :: (args: [] cstr) {
     //     bag := array.pop(&to_process_bags);
     //     array.push(&processed_bags, bag);
     //     
-    //     for container: bag.contained_in {
+    //     for container in bag.contained_in {
     //         if !array.contains(&processed_bags, container.bag) && !array.contains(&to_process_bags, container.bag) {
     //             // printf("Adding {} to process.\n", container.bag.color);
     //             array.push(&to_process_bags, container.bag);
@@ -125,7 +125,7 @@ main :: (args: [] cstr) {
         mul := array.pop(&multiplier);
         count += mul;
 
-        for bc: bag.contain {
+        for bc in bag.contain {
             array.push(&to_process, bc.bag);
             array.push(&multiplier, bc.count * mul);
         }
index 294661fa28844470e1ddcbcba2268312bc5e0a6f..c657512a39a36e6ff4e851ec6066d152b25a13cc 100644 (file)
@@ -71,7 +71,7 @@ main :: (args: [] cstr) {
     }
 
     acc: i32;
-    for &instr: instrs {
+    for &instr in instrs {
         if     instr.opcode == OpCode.Nop do instr.opcode = OpCode.Jmp;
         elseif instr.opcode == OpCode.Jmp do instr.opcode = OpCode.Nop;
 
index f69569b120d0a514262ebfa0849df71b846ced57..cb857b32a6f357d6af8b1a577a7b94081454414f 100644 (file)
@@ -7,7 +7,7 @@ find_contiguous_subarray_with_sum :: (nums: [..] u64, sum: u64) -> (i32, i32) {
     end   := 0;
     con_sum: u64 = nums[0];
 
-    for i: 1 .. nums.count {
+    for i in 1 .. nums.count {
         end += 1;
         con_sum += nums[end];
 
@@ -40,12 +40,12 @@ main :: (args: [] cstr) {
     preamble_length :: 25;
 
     invalid: u64;
-    for i: 0 .. nums.count {
+    for i in 0 .. nums.count {
         if i < preamble_length do continue;
 
         success := false;
-        for j: 0 .. preamble_length - 1 {
-            for k: j + 1 .. preamble_length {
+        for j in 0 .. preamble_length - 1 {
+            for k in j + 1 .. preamble_length {
                 if nums[i - j - 1] + nums[i - k - 1] == nums[i] {
                     success = true;
                     break break;
index 8f2bc6028c0d22cafbd691d8f110e829f38c4839..e408c798e57f315793538f6176a8750423b1eb3b 100644 (file)
@@ -33,9 +33,9 @@ main :: (args) => {
 
     { // Part 2
         windows: [..] i32;
-        for i: range.{ 0, nums.count - 2 } {
+        for i in range.{ 0, nums.count - 2 } {
             sum := 0;
-            for k: i .. i+3 do sum += nums[k];
+            for k in i .. i+3 do sum += nums[k];
             windows << sum;
         }
 
index 1921e7bf888725375587c12374dbb4289e8e54fe..edb46ed5d35046b2f5d600ff7b3d61d9e1790064 100644 (file)
@@ -3,7 +3,7 @@ PART :: 2
 use core {*}
 
 main :: (args) => {
-    for file: os.with_file("tests/aoc-2021/input/day02.txt") {
+    for file in os.with_file("tests/aoc-2021/input/day02.txt") {
         reader := io.reader_make(file);
 
         #if PART == 1 {
index 2665d7a3d196d3aed8cbfdde68f7a23bf919d449..9228403ff80f0ef1e8580ce5f7a7fd49164b5bdf 100644 (file)
@@ -37,7 +37,7 @@ main :: (args) => {
         num1 := 0;
         for BITS {
             one_count := 0;
-            for num: nums {
+            for num in nums {
                 if num & (1 << it) != 0 do one_count += 1;
             }
 
index 9566b3ef75c443bbd76cad124f2058ed1687f0c9..831dff83592cb59a03181b2d825de04fbd957d33 100644 (file)
@@ -41,8 +41,8 @@ main :: (args) => {
         winning_board: &Board = null;
         worst_board  : &Board = null;
 
-        for called: numbers {
-            for & board: boards {
+        for called in numbers {
+            for & board in boards {
                 if board.has_won do continue;
 
                 // Whatever the last board we touch is must be the worst one.
index ae8761e56aad01fae905e730e50b365d2246e4ab..a9745fb15b2d156a5dac057108bcf76c216ef72a 100644 (file)
@@ -43,7 +43,7 @@ Point :: struct {x, y: u32;}
 #operator == (p1, p2: Point) => p1.x == p2.x && p1.y == p2.y;
 
 main :: (args) => {
-    for file: os.with_file("./tests/aoc-2021/input/day05.txt") {
+    for file in os.with_file("./tests/aoc-2021/input/day05.txt") {
         reader := io.reader_make(file);
 
         lines: [..] Line;
@@ -64,8 +64,8 @@ main :: (args) => {
 
         point_count: Map(Point, u32);
 
-        for &line: lines {
-            for p: line_points(*line) {
+        for &line in lines {
+            for p in line_points(*line) {
                 point_count[p] = (point_count[p] ?? 0) + 1;
             }
         }
index 462747bdb76b5d0d7c57a0065a6fea0359174add..d5e9f6c60eb6da237d3edffd75074d3944e78c57 100644 (file)
@@ -3,7 +3,7 @@
 use core {*}
 
 main :: (args) => {
-    for file: os.with_file("./tests/aoc-2021/input/day06.txt") {
+    for file in os.with_file("./tests/aoc-2021/input/day06.txt") {
         reader := io.reader_make(file);
         start_str := io.read_all(&reader);
 
@@ -15,7 +15,7 @@ main :: (args) => {
             fish[value] += 1;
         }
 
-        for day: 256 {
+        for day in 256 {
             new_fish := fish[0];
             for 8 do fish[it] = fish[it + 1];
             fish[6] += new_fish;
index dc72f98a25a7186000c9a676945a5b326c26d22a..029653d64a754179d5efaff6cf65e02737896e1b 100644 (file)
@@ -3,7 +3,7 @@
 use core {*}
 
 main :: (args) => {
-    for file: os.with_file("./tests/aoc-2021/input/day07.txt") {
+    for file in os.with_file("./tests/aoc-2021/input/day07.txt") {
         reader := io.reader_make(file);
         nums := io.read_all(&reader)
             |> string.split(#char ",")
@@ -16,7 +16,7 @@ main :: (args) => {
 
         min_cost := 0x7fffffff;
         best_middle := 0;
-        for middle: min .. max {
+        for middle in min .. max {
             total_cost := 0;
             for nums {
                 dist := math.abs(it - middle);
index 25f60f7a913abe2f3bb4626e3d3aeb9c054f2ce8..e5f954bd32a823a39b6345fe3214445ada866a66 100644 (file)
@@ -38,7 +38,7 @@ decode_line :: (left, right: str) -> u32 {
     seven_data := *array.first(left_segments, (x) => x.count == 3);
 
     // Solve the top segment
-    for s: seven_data {
+    for s in seven_data {
         if !array.contains(one_data, s) {
             solved_segments[s] = 1;
         }
@@ -49,7 +49,7 @@ decode_line :: (left, right: str) -> u32 {
         if it.count != 5 do continue;
 
         in_count := 0;
-        for a: one_data do if array.contains(it, a) do in_count += 1;
+        for a in one_data do if array.contains(it, a) do in_count += 1;
 
         if in_count == 2 {
             three_data = it;
@@ -61,8 +61,8 @@ decode_line :: (left, right: str) -> u32 {
     four_data := *array.first(left_segments, (x) => x.count == 4);
 
     // Solve for middle segment
-    for f: four_data {
-        for t: three_data {
+    for f in four_data {
+        for t in three_data {
             if t == f {
                 if !array.contains(one_data, t) {
                     solved_segments[t] = 4;
@@ -76,7 +76,7 @@ decode_line :: (left, right: str) -> u32 {
     for three_data {
         if solved_segments[it] ?? 0 == 4 do continue;
         if solved_segments[it] ?? 0 == 1 do continue;
-        for o: one_data do if it == o do continue continue;
+        for o in one_data do if it == o do continue continue;
 
         solved_segments[it] = 7;
         break;
@@ -84,12 +84,12 @@ decode_line :: (left, right: str) -> u32 {
 
     // Look for 5.
     five_data: str;
-    for seg: left_segments {
+    for seg in left_segments {
         if seg.count != 5 do continue;
 
         for four_data {
             if solved_segments[it] ?? 0 == 4 do continue;
-            for o: one_data do if it == o do continue continue;
+            for o in one_data do if it == o do continue continue;
 
             if array.contains(seg, it) {
                 five_data = seg; 
@@ -99,7 +99,7 @@ decode_line :: (left, right: str) -> u32 {
     }
 
     for five_data {
-        for o: one_data do if it == o {
+        for o in one_data do if it == o {
             solved_segments[it] = 6;
             break;
         }
@@ -126,10 +126,10 @@ decode_line :: (left, right: str) -> u32 {
         string.strip_whitespace(it);
         
         num_segments : [7] bool;
-        for w: *it do num_segments[solved_segments[w] ?? 0 - 1] = true;
+        for w in *it do num_segments[solved_segments[w] ?? 0 - 1] = true;
 
         sum *= 10;
-        for i: 10 {
+        for i in 10 {
             if segments[i] == num_segments {
                 sum += i;
                 break;
@@ -143,7 +143,7 @@ decode_line :: (left, right: str) -> u32 {
 // Nicer way of printing a Map.
 #match io.write (w: &io.Writer, x: &Map($K, $V)) {
     io.write(w, "{\n");
-    for e: x.entries {
+    for e in x.entries {
         io.write(w, "    {} => {}\n", e.key, e.value);
     }
     io.write(w, "}");
@@ -153,12 +153,12 @@ decode_line :: (left, right: str) -> u32 {
 
 #operator == (a, b: [] $T) -> bool {
     if a.count != b.count do return false;
-    for i: a.count do if a[i] != b[i] do return false;
+    for i in a.count do if a[i] != b[i] do return false;
     return true;
 }
 
 main :: (args) => {
-    for file: os.with_file("./tests/aoc-2021/input/day08.txt") {
+    for file in os.with_file("./tests/aoc-2021/input/day08.txt") {
         reader := io.reader_make(file);
 
         answer := 0; 
index 08e8c88ef18803bf491cdfa8789e5e15df85c995..54ee6a3b95bfe17a70ce8e9ed59d06f1098be297 100644 (file)
@@ -46,7 +46,7 @@ find_span :: macro (low: Pos) -> u32 {
             }
         }
 
-        for p: potential {
+        for p in potential {
             if !array.contains(included, p) && !array.contains(queued, p) {
                 queued << p;
             }
@@ -58,14 +58,14 @@ find_span :: macro (low: Pos) -> u32 {
 
 #match io.write (w: &io.Writer, x: &Map($K, $V)) {
     io.write(w, "{\n");
-    for e: x.entries {
+    for e in x.entries {
         io.write(w, "    {} => {}\n", e.key, e.value);
     }
     io.write(w, "}");
 }
 
 main :: (args) => {
-    for file: os.with_file("./tests/aoc-2021/input/day09.txt") {
+    for file in os.with_file("./tests/aoc-2021/input/day09.txt") {
         reader := io.reader_make(file);
 
         heightmap: Map(Pos, Cell);
@@ -83,12 +83,12 @@ main :: (args) => {
             height += 1;
         }
 
-        for y: height - 1 do for x: width {
+        for y in height - 1 do for x in width {
             map.update(&heightmap, .{x,y}) {
                 it.dy = it.height - heightmap[Pos.{x,y+1}]->unwrap().height;
             }
         }
-        for x: width - 1 do for y: height {
+        for x in width - 1 do for y in height {
             map.update(&heightmap, .{x,y}) {
                 it.dx = it.height - heightmap[Pos.{x+1,y}]->unwrap().height;
             }
@@ -96,7 +96,7 @@ main :: (args) => {
 
         lowest: [..] Pos;
         risk_sum := 0;
-        for y: height do for x: width {
+        for y in height do for x in width {
             h := &heightmap[Pos.{x,y}];
             if x < width  - 1 && h.dx >= 0 do continue;
             if y < height - 1 && h.dy >= 0 do continue;
@@ -116,7 +116,7 @@ main :: (args) => {
         printf("Part 1: {}\n", risk_sum);
 
         lowest_count: Map(Pos, i32);
-        for low: lowest do lowest_count[low] = find_span(low);
+        for low in lowest do lowest_count[low] = find_span(low);
 
         array.quicksort(lowest_count.entries, (a, b) => b.value - a.value);
 
index fa98a02159e61578885414996f74bc4ede97daa6..d8cbf89695be22971e10a4b68abb48a67d3439e4 100644 (file)
@@ -3,7 +3,7 @@
 use core {*}
 
 main :: (args) => {
-    for file: os.with_file("./tests/aoc-2021/input/day10.txt") {
+    for file in os.with_file("./tests/aoc-2021/input/day10.txt") {
         reader := io.reader_make(file);
 
         bracket_map: Map(u8, u8);
@@ -26,7 +26,7 @@ main :: (args) => {
 
             char_stack: [..] u8;
             defer array.free(&char_stack);
-            for ch: line {
+            for ch in line {
                 switch ch {
                     case #char "(", #char "[", #char "<", #char "{" {
                         char_stack << bracket_map[ch]->unwrap();
index 9a492d9b09df33467ed3d7d173f8ea648fb0f1b7..9aebe9819202f62be63cbf7dff022ee0f5f756b0 100644 (file)
@@ -7,7 +7,7 @@ Pos :: struct {x, y:i32;}
 #operator == (p1, p2: Pos) => p1.x == p2.x && p1.y == p2.y;
 
 main :: (args) => {
-    for file: os.with_file("./tests/aoc-2021/input/day11.txt") {
+    for file in os.with_file("./tests/aoc-2021/input/day11.txt") {
         reader := io.reader_make(file);
 
         octopuses: [..] u32;
@@ -15,7 +15,7 @@ main :: (args) => {
             line := io.read_line(&reader, consume_newline=false, inplace=true);
             io.skip_whitespace(&reader);
 
-            for ch: line do octopuses << ~~(ch - #char "0");
+            for ch in line do octopuses << ~~(ch - #char "0");
         }
 
         get_octopus :: macro (x, y) => {
@@ -41,17 +41,17 @@ main :: (args) => {
         sync_step := 0;
         while true {
             step += 1;
-            for &o: octopuses do *o += 1;
+            for &o in octopuses do *o += 1;
 
             #persist to_flash: Set(Pos);
-            for y: 10 do for x: 10 {
+            for y in 10 do for x in 10 {
                 if get_octopus(x, y) >= 10 {
                     to_flash << .{x, y};
                 }
             }
 
-            for flash: iter.as_iter(&to_flash) {
-                for y: -1 .. 2 do for x: -1 .. 2 {
+            for flash in iter.as_iter(&to_flash) {
+                for y in -1 .. 2 do for x in -1 .. 2 {
                     if y == 0 && x == 0 do continue;
 
                     if inc_octopus(flash.x + x, flash.y + y) >= 10 {
@@ -60,7 +60,7 @@ main :: (args) => {
                 }
             }
 
-            for flash: iter.as_iter(&to_flash) {
+            for flash in iter.as_iter(&to_flash) {
                 set_octopus(flash.x, flash.y, 0);
                 if step <= 100 do flash_count += 1;
             }
index d485bf3ffd2484a8c9657e4aa5340a68fb32aa24..b61ef3dab9c85ad0a9c97e9b9f5e24b83d3ab4ba 100644 (file)
@@ -17,7 +17,7 @@ Communative_Pair :: struct (T: type_expr) where hash.Hashable(T) {
 }
 
 main :: (args) => {
-    for file: os.with_file("./tests/aoc-2021/input/day12.txt") {
+    for file in os.with_file("./tests/aoc-2021/input/day12.txt") {
         reader := io.reader_make(file);
 
         verticies: Set(str);
@@ -58,7 +58,7 @@ main :: (args) => {
         }
 
         edge_map: Map(str, [] str);
-        for v: iter.as_iter(&verticies) {
+        for v in iter.as_iter(&verticies) {
             edge_map[*v] = children_of(&edges, *v) |> iter.to_array();
         }
 
index bfdbc68b6fd32bb1a66d02f278e06060c5dbb7e6..e04916c0ef3084625895f60cce746affaed97e8c 100644 (file)
@@ -23,7 +23,7 @@ apply_fold :: (dots: &[] Point, axis_name: str, axis_value: i32) {
 }
 
 main :: (args) => {
-    for file: os.with_file("./tests/aoc-2021/input/day13.txt") {
+    for file in os.with_file("./tests/aoc-2021/input/day13.txt") {
         reader := io.reader_make(file);
 
         dots: [..] Point;
@@ -61,8 +61,8 @@ main :: (args) => {
         printf("Part 1: {}\n", part_1_answer);
 
         printf("Part 2:\n");
-        for y: 7 {
-            for x: 50 {
+        for y in 7 {
+            for x in 50 {
                 print("X" if array.contains(dots, .{x, y}) else " ");
             }
 
index 64a9327fcf5e067933aa383b1ecca8b911eeae0a..ee836e6330f6d8aebc9927ad496ce8803e8498cd 100644 (file)
@@ -14,14 +14,14 @@ State :: struct {
 // Nicer way of printing a Map.
 #match io.write (w: &io.Writer, x: &Map($K, $V)) {
     io.write(w, "{\n");
-    for e: x.entries {
+    for e in x.entries {
         io.write(w, "    {} => {}\n", e.key, e.value);
     }
     io.write(w, "}");
 }
 
 main :: (args) => {
-    for file: os.with_file("./tests/aoc-2021/input/day14.txt") {
+    for file in os.with_file("./tests/aoc-2021/input/day14.txt") {
         reader := io.reader_make(file);
 
         start_polymer := io.read_line(&reader, consume_newline=false);
@@ -62,7 +62,7 @@ main :: (args) => {
         step_state();
 
         for 40 {
-            for& rule: rules {
+            for& rule in rules {
                 pair_count := &polymer_state[rule.pair];
                 if pair_count != null {
                     if pair_count.now > 0 {
index a2edaf12ecd2136266af2e12c7f9e39b3614d6f6..cd431f07db101f5d256b115ea8448a336fb15312 100644 (file)
@@ -10,7 +10,7 @@ pos :: struct { x, y: i32; }
 #operator == (p1, p2: pos) => p1.x == p2.x && p1.y == p2.y;
 
 main :: (args) => {
-    for file: os.with_file("./tests/aoc-2021/input/day15.txt") {
+    for file in os.with_file("./tests/aoc-2021/input/day15.txt") {
         reader := io.reader_make(file);
 
         cells: [..] u8;
@@ -69,7 +69,7 @@ main :: (args) => {
         min_paths.count = cells.count * 25;
         memory.set(min_paths.data, 0, sizeof u32 * min_paths.count * 25);
 
-        for y: height * 5 do for x: width * 5 {
+        for y in height * 5 do for x in width * 5 {
             if y == 0 && x == 0 do continue;
 
             a, b := 100000, 100000;
index 314d8798ad1ddd9fbfbac60c6b5157ecf1ccdf0a..484e6fc1529752054994679e84abc65826c0454f 100644 (file)
@@ -191,12 +191,12 @@ packet_reduce :: (p: &Packet) -> u64 {
 
 
 main :: (args) => {
-    for file: os.with_file("./tests/aoc-2021/input/day16.txt") {
+    for file in os.with_file("./tests/aoc-2021/input/day16.txt") {
         reader := io.reader_make(file);
         line   := io.read_line(&reader, consume_newline=false, inplace=true);
 
         transmission: [..] u8;
-        for i: range.{ 0, line.count, 2 } {
+        for i in range.{ 0, line.count, 2 } {
             transmission << ~~(base16_to_hex(line[i .. i + 2]));
         }
 
index 2cd92b96147510b3a20898dd74e16ec425e3b01a..8c058e4394d9113949c4efd05b6e622d8edaa2e6 100644 (file)
@@ -30,7 +30,7 @@ simulate :: (dx, dy: i32) -> (i32, bool) {
 
 main :: (args) => {
 
-    for file: os.with_file("./tests/aoc-2021/input/day17.txt") {
+    for file in os.with_file("./tests/aoc-2021/input/day17.txt") {
         reader := io.reader_make(file);
 
         io.skip_bytes(&reader, 15);
@@ -46,8 +46,8 @@ main :: (args) => {
     max := 0;
     count := 0;
 
-    for dx: 1 .. 1000 {
-        for dy: -1000 .. 1000 {
+    for dx in 1 .. 1000 {
+        for dy in -1000 .. 1000 {
             my, s := simulate(dx, dy);
             if s {
                 max = math.max(my, max);
index 6ad6aeaa2f64feb73eed62f174997abe6abc453e..1f708d1dcf00fa5b83ebd89ac8db6a0d43975be5 100644 (file)
@@ -233,13 +233,13 @@ main :: () {
     
     conv.register_custom_formatter(SnailNum.format);
 
-    for file: os.with_file("./tests/aoc-2021/input/day18.txt") {
+    for file in os.with_file("./tests/aoc-2021/input/day18.txt") {
         r := io.reader_make(file);
 
         #if PART == 1 {
             s: &SnailNum = null;
             
-            for line: r->lines() {
+            for line in r->lines() {
                 n := SnailNum.parse(&line);
                 s = s->add(n);
             }
@@ -249,15 +249,15 @@ main :: () {
 
         #if PART == 2 {
             nums := make([..] &SnailNum);
-            for line: r->lines() {
+            for line in r->lines() {
                 nums << SnailNum.parse(&line);
             }
 
             maximum := 0;
             max_i, max_j : i32;
 
-            for i: nums.count {
-                for j: nums.count {
+            for i in nums.count {
+                for j in nums.count {
                     if i == j do continue;
 
                     n1 := nums[i]->clone();
index 965b8d6262ab0a21840ddb71ba3ed458c3e81881..959e7fd82ce8ceff268dc3608af726e351bda42d 100644 (file)
@@ -18,7 +18,7 @@ calc_vecs :: (n := 0) -> [4] Vec2 {
     vecs : [4] Vec2;
 
     i := n;
-    for &v: vecs {
+    for &v in vecs {
         v.x = i * i;
         v.y = i * i * i;
         i += 1;
@@ -32,7 +32,7 @@ main :: (args: [] cstr) {
     {
         println("Array of structs on the stack.");
         vecs : [8] Vec2;
-        for &v: vecs {
+        for &v in vecs {
             v.x = 4039;
             v.y = 7782;
         }
@@ -44,7 +44,7 @@ main :: (args: [] cstr) {
     {
         println("Array of structs from function call.");
         vecs := calc_vecs();
-        for &v: vecs do println(*v);
+        for &v in vecs do println(*v);
     }
 
     // Array of structs on a struct
@@ -88,7 +88,7 @@ main :: (args: [] cstr) {
 
         nums : [100] u32;
         i := 1;
-        for &n: nums {
+        for &n in nums {
             *n = i * i;
             i += 5;
         }
@@ -104,8 +104,8 @@ main :: (args: [] cstr) {
 
         set_vecs :: (vecs: &[2][4] Vec2) {
             i := 0;
-            for &row: *vecs {
-                for &v: *row {
+            for &row in *vecs {
+                for &v in *row {
                     *v = .{ 1000 + i, 2000 + i * i };
                     i += 1;
                 }
@@ -115,7 +115,7 @@ main :: (args: [] cstr) {
         set_vecs(vecs);
 
         print_vecs :: (vecs: &[4] Vec2) {
-            for &v: *vecs do println(*v);
+            for &v in *vecs do println(*v);
         }
 
         print_vecs(&(*vecs)[0]);
index 0e08f584c980bc06735a2d0be6c93794887562ad..a506be3fcb699b7746f5752c43a88fc219713a1c 100644 (file)
@@ -20,16 +20,16 @@ test_var := 5678;
 
 print_from_other_thread :: (sd) => {
     // Creating high contention for the shared resource
-    for i: 10000 {
+    for i in 10000 {
         sync.scoped_mutex(&shared_mutex);
-        for &v: sd.arr {
+        for &v in sd.arr {
             *v += 1;
         }
     }
 
     // Using the thread-local variable
     partial_arr = make([] i32, 5);
-    for i: 5 do partial_arr[i] = i * i;
+    for i in 5 do partial_arr[i] = i * i;
     
     // Not printing on threads since the test case looks for EXACT string matches
     // printf("On a worker thread: {}\n", partial_arr);
@@ -46,16 +46,16 @@ main :: (args) => {
     array.fill(sd.arr, 0);
 
     threads : [4] thread.Thread;
-    for &t: threads {
+    for &t in threads {
         thread.spawn(t, &sd, print_from_other_thread);
         printf("Spawned thread {}\n", t.id);
     }
 
     memory.alloc_slice(&partial_arr, 10);
-    for i: 10 do partial_arr[i] = i;
+    for i in 10 do partial_arr[i] = i;
 
     printf("Waiting...\n");
-    for &t: threads {
+    for &t in threads {
         thread.join(t);
         printf("Thread {} joined!\n", t.id);
     }
index c6d8e5ba764d0abc7f12c276ed13c67389ed813e..47d9526421694f0d5788eee145b7cc6c96806eb4 100644 (file)
@@ -3,7 +3,7 @@
 use core {*}
 
 count_to :: ($N: i32) {
-    for i: 0 .. N do printf("{} ", i);
+    for i in 0 .. N do printf("{} ", i);
     print("\n");
 }
 
index fd1603986ebc38256615ce25ffa30b466901ef9c..eb3dc865b4f81061158a532bcff90683946ef935 100644 (file)
@@ -4,7 +4,7 @@ use core {*}
 
 main :: (args: [] cstr) {
     ba := bucket_array.make(i32, 4);
-    for i: 24 do ba << i;
+    for i in 24 do ba << i;
 
     printf("ba[10] is {}.\n", ba[10]);
 
@@ -14,7 +14,7 @@ main :: (args: [] cstr) {
         sum += *value;
     });
 
-    for it: bucket_array.as_iter(&ba) {
+    for it in bucket_array.as_iter(&ba) {
         printf("{}\n", it);
     }
 
index 68ce1de1a611ed6862da77ab4949153c882301b6..8653e96f736c305dcc5f334ebd9a34882d211ca4 100644 (file)
@@ -26,7 +26,7 @@ main :: (args: [] cstr) {
 
         case 10 {
             count := 5;
-            for i: custom_iterator() {
+            for i in custom_iterator() {
                 println(i);
                 defer println("World");
 
index b2dc9dfc89225519746165a3b0c0e0bd2cacbe71..e6fc8232395dc13d6d4aa3c7add72e88945c8db8 100644 (file)
@@ -45,7 +45,7 @@ main :: (args: [] cstr) {
         // "-1e-500000",
     ];
 
-    for s: strings {
+    for s in strings {
         value := conv.str_to_f64(s);
         println(value);
     }
index 5dd8caedacc104ecc67e4c332c5f4e9c8580457b..3fd0b2b4feb0b6f6f263efc370c0d6a35547ee17 100644 (file)
@@ -35,7 +35,7 @@ main :: (args: [] cstr) {
                     |> iter.map((x, [addition]) => x + ~~addition)
                     |> iter.take(5);
 
-        for v: quick_iterator {
+        for v in quick_iterator {
             println(v);
         }
     }
@@ -46,7 +46,7 @@ main :: (args: [] cstr) {
                 |> iter.map((x: i32) -> i32     { return x + 42; });
 
     println("Starting the iteration...");
-    for i: iterator do println(i);
+    for i in iterator do println(i);
 
     arr := count_iterator(1, 10)
             |> iter.map((x: i32) -> i32     { return x * 2; })
@@ -63,7 +63,7 @@ main :: (args: [] cstr) {
                 |> iter.map(x => x + 42)
                 |> iter.zip(iter.const(42.0f));
 
-    for value: zipped_iterator {
+    for value in zipped_iterator {
         printf("{}   {}\n", value.first, value.second);
     }
 }
index f9f99f948401cbcc65d611d9ee8f8c92b579ca83..a75713fe17b82f0f29b1c3288ffd20d375431143 100644 (file)
@@ -15,7 +15,7 @@ get_extrema :: (arr: [$N] $T) -> (T, T) {
     min := arr[0];
     max := arr[0];
 
-    for e: arr {
+    for e in arr {
         if e < min do min = e;
         if e > max do max = e;
     }
@@ -48,7 +48,7 @@ main :: (args: [] cstr) {
     array_print(farr);
 
     array_print :: (arr: [$N] $T) {
-        for &e: arr {
+        for &e in arr {
             print(*e);
             print(" ");
         }
index 918cc5c6bc79793b1dba5f25dcfc452a4b1bbc23..63cd648abf38259f874abb6723ca0c2ffdf573de 100644 (file)
@@ -42,7 +42,7 @@ main :: (args: [] cstr) {
         println(x);
         println(y);
 
-        for elem: z do printf("{} ", elem);
+        for elem in z do printf("{} ", elem);
         print("\n");
     }
 
index 971694d8322bc6f081b41d3dc93299e7a7918de4..0352a99541e8aa518305c030281d326c1999c313 100644 (file)
@@ -29,32 +29,32 @@ Vec :: struct (T: type_expr, N: i32) {
 
 #operator+ (a: Vec($T, $N), b: Vec(T, N)) -> Vec(T, N) {
     out : Vec(T, N);
-    for i: 0 .. N do out.data[i] = a.data[i] + b.data[i];
+    for i in 0 .. N do out.data[i] = a.data[i] + b.data[i];
     return out;
 }
 
 #operator- (a: Vec($T, $N), b: Vec(T, N)) -> Vec(T, N) {
     out : Vec(T, N);
-    for i: 0 .. N do out.data[i] = a.data[i] - b.data[i];
+    for i in 0 .. N do out.data[i] = a.data[i] - b.data[i];
     return out;
 }
 
 #operator* (a: Vec($T, $N), s: T) -> Vec(T, N) {
     out : Vec(T, N);
-    for i: 0 .. N do out.data[i] = a.data[i] * s;
+    for i in 0 .. N do out.data[i] = a.data[i] * s;
     return out;
 }
 
 #operator* (a: Vec($T, $N), b: Vec(T, N)) -> T {
     res := T.{};
-    for i: 0 .. N do res += a.data[i] * b.data[i];
+    for i in 0 .. N do res += a.data[i] * b.data[i];
     return res;
 }
 
 join :: (a: Vec($T, $N), b: Vec(T, $M)) -> Vec(T, N + M) {
     out : Vec(T, N + M);
-    for i: 0 .. N do out.data[i]     = a.data[i]; 
-    for i: 0 .. M do out.data[i + N] = b.data[i]; 
+    for i in 0 .. N do out.data[i]     = a.data[i]; 
+    for i in 0 .. M do out.data[i + N] = b.data[i]; 
     return out;
 }
 
@@ -85,7 +85,7 @@ main :: (args: [] cstr) {
 
         d := make_vec(f32.[2, 3, 5, 7]);
         e := join(d, c);
-        for v: e.data do printf("{} ", v);
+        for v in e.data do printf("{} ", v);
         print("\n");
     }
 
index 67525943160080665923705a49f1b570ddcdc330..156f5d1d208eb513f9677acea101a6f286bc6c6d 100644 (file)
@@ -10,10 +10,10 @@ main :: (args: [] cstr) {
 
     nps : NewPolyStruct(i32, 4);
 
-    for &x: nps.x do *x = 12345;
-    for &y: nps.y do *y = 67890;
+    for &x in nps.x do *x = 12345;
+    for &y in nps.y do *y = 67890;
 
-    for x: nps.x do println(x);
+    for x in nps.x do println(x);
 
 
 
index e813bf052091daee111ac23d5716448aeb615b01..bea44e83bd517aff4fddf8329fcfadc32a8dd69b 100644 (file)
@@ -4,19 +4,19 @@ use core {*}
 
 main :: (args: [] cstr) {
     arr := u32.[ 1, 2, 3, 4, 5 ];
-    for elem: array_to_slice(arr) do printf("{} ", elem);
+    for elem in array_to_slice(arr) do printf("{} ", elem);
 
     roots : [20] f32;
     compute_roots(roots);
 
-    for root: roots do println(root);
+    for root in roots do println(root);
 
     array_to_slice :: (arr: [$N] $T) -> [] T {
         return (#type [] T).{ ~~arr, N };
     }
 
     compute_roots :: (arr: [$N] f32) {
-        for i: 0 .. N {
+        for i in 0 .. N {
             arr[i] = math.sqrt(cast(f32) i);
         }
     }
index 1918c4729ec8afb6882f21d4a2aa0e5981e2639e..eacb0a7eb87282d6353dc61df678de288df57af5 100644 (file)
@@ -9,12 +9,12 @@ main :: (args: [] cstr) {
     set.insert(&S, 5);
     set.insert(&S, 5);
     set.insert(&S, 6);
-    for entry: S.entries do println(entry.value);
+    for entry in S.entries do println(entry.value);
 
     println(set.has(&S, 5));
 
     println("--------------");
     set.remove(&S, 5);
-    for entry: S.entries do println(entry.value);
+    for entry in S.entries do println(entry.value);
     println(set.has(&S, 5));
 }
\ No newline at end of file
index c216d5d6b1718887b4b8a4aae41d7f98f12abe44..7c417e7df6bf1a0bb648951d0ed3270ad66414da 100644 (file)
@@ -1,7 +1,7 @@
 use core {*}
 
 main :: () {
-    for t: Pair(str, str).[
+    for t in Pair(str, str).[
         .{"", "."},
         .{"abc", "abc"},
         .{"..", ".."},
index c629bea20d768a52016b9ed84144cf0d049ef13d..116b9e70f43648eb752859c5abfaa01f0813e4cb 100644 (file)
@@ -10,7 +10,7 @@ main :: (args: [] cstr) {
     sstream := io.buffer_stream_make(some_string);
     sreader := io.reader_make(&sstream);
 
-    for i: 0 .. 2 {
+    for i in 0 .. 2 {
         word := io.read_word(&sreader, allocator=context.temp_allocator);
         println(word);
     }
index 65f9e9d02ba38a57f9800e77d8b399f3e0c03c3b..efc5d458b9293a0711bbc22d4758cfd40744efa1 100644 (file)
@@ -42,9 +42,9 @@ quick_union_map :: () {
     }
 
     quick_map :: (v: $T) => switch v {
-        case val: .z => val;
-        case val: .y => conv.format("{}", val);
-        case val: .x => conv.format("{}", val);
+        case .z as val => val;
+        case .y as val => conv.format("{}", val);
+        case .x as val => conv.format("{}", val);
     }
 }
 
index 9f1d0f35cc4c764fc160533892241b2dc2f1ac08..3a491d6bf371064a00d806afa480baa6d166e788 100644 (file)
@@ -32,7 +32,7 @@ main :: () {
         *val_ptr = 5678;
         printf("New value is: {*}\n", val_ptr);
 
-        for t: it.tags {
+        for t in it.tags {
             if t.type == str {
                 printf("{*}\n", misc.any_as(t, str));
             }
index 962187480a51dca00621c755870bd83a372ea4fa..9fd306e4a9a3bdc991c81e2ba87749563485e169 100644 (file)
@@ -7,7 +7,7 @@ union_is :: macro (u: $U, $variant: U.tag_enum) -> bool {
 
 extract_variant :: macro (u: $U, $variant: U.tag_enum) => {
     switch u {
-        case v: variant {
+        case variant as v {
             return Optional.make(v);
         }
     }
@@ -44,15 +44,15 @@ extraction_example :: () {
     value := Extraction.{ string = "This works" };
 
     switch value {
-        case int_value: .int {
+        case .int as int_value {
             printf("This is an integer: {}\n", int_value);
         }
 
-        case float_value: .float {
+        case .float as float_value {
             printf("This is a float: {}\n", float_value);
         }
 
-        case string_value: .string {
+        case .string as string_value {
             printf("This is a string: {}\n", string_value);
         }
     }
@@ -66,15 +66,15 @@ method_example :: () {
 
         do_the_thing :: (value: &Methoded) {
             switch *value {
-                case int_value: .int {
+                case .int as int_value {
                     printf("This is an integer: {}\n", int_value);
                 }
 
-                case float_value: .float {
+                case .float as float_value {
                     printf("This is a float: {}\n", float_value);
                 }
 
-                case string_value: .string {
+                case .string as string_value {
                     printf("This is a string: {}\n", string_value);
                 }
             }
@@ -100,7 +100,7 @@ linked_list_example :: () {
             switch walker {
                 case .End do break break;
 
-                case &next: .Next {
+                case .Next as &next {
                     printf("{}\n", next.data);
                     walker = next.next;
                 }
index 760b4e605de83e7f6fad35f758b32c89bac82a42..941679cfab5a885747e0ebd78c787d7474021fa5 100644 (file)
@@ -10,7 +10,7 @@ main :: () {
     output := make(dyn_str);
     defer delete(&output);
 
-    for i: 0x1F0A0 .. 0x1F0E0 {
+    for i in 0x1F0A0 .. 0x1F0E0 {
         utf8.append_rune(&output, i);
     }
 
index 125703aa5df60e38d6587a26858bfe2baa26f183..878a7c03de9a17adff6864d34a6f24e1e7d2c3fa 100644 (file)
@@ -6,13 +6,13 @@ use core {*};
 
 old_va_test :: (prefix: str, va: ..i32) {
     println(prefix);
-    for v: va do println(v);
+    for v in va do println(v);
 }
 
 new_va_test :: (prefix: str, va: ..any) {
     println(prefix);
 
-    for i: 0 .. va.count {
+    for i in 0 .. va.count {
         // The right way to do it is this:
         // x := * misc.any_as(va[i], i32);