From: Brendan Hansen Date: Mon, 6 Mar 2023 02:52:13 +0000 (-0600) Subject: migration: changed tests to use new pointer syntax X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=135d17473b5ae7dd1ba3176446474236a69d9dac;p=onyx.git migration: changed tests to use new pointer syntax --- diff --git a/tests/aoc-2020/day1.onyx b/tests/aoc-2020/day1.onyx index b40a5bff..7162889a 100644 --- a/tests/aoc-2020/day1.onyx +++ b/tests/aoc-2020/day1.onyx @@ -8,12 +8,12 @@ main :: (args: [] cstr) { defer cfree(stream); nums := array.make(u32, 128); - defer array.free(^nums); + defer array.free(&nums); while num := 1; num > 0 { // This sets num to be 0 if there is no number - num = io.read_u32(^reader); - if num != 0 do array.push(^nums, num); + num = io.read_u32(&reader); + if num != 0 do array.push(&nums, num); } for i: nums do for j: nums do for k: nums { diff --git a/tests/aoc-2020/day10.onyx b/tests/aoc-2020/day10.onyx index 2c04665e..8866633a 100644 --- a/tests/aoc-2020/day10.onyx +++ b/tests/aoc-2020/day10.onyx @@ -4,9 +4,9 @@ use package core count_ending_paths :: (nums: [..] u32) -> u64 { tally := array.make(u64, nums.count); - defer array.free(^tally); + defer array.free(&tally); - for ^t: tally do *t = 0; + for &t: tally do *t = 0; tally[nums.count - 1] = 1; while i := cast(i32) (nums.count - 2); i >= 0 { @@ -28,20 +28,20 @@ main :: (args: [] cstr) { file := contents; nums := array.make(u32); - defer array.free(^nums); + defer array.free(&nums); while !string.empty(file) { - array.push(^nums, ~~ conv.parse_int(^file)); - string.advance_line(^file); + array.push(&nums, ~~ conv.parse_int(&file)); + string.advance_line(&file); } // Slight hack, but having 0 in the array makes both parts easier - array.push(^nums, 0); + array.push(&nums, 0); array.sort(nums, (a, b) => a - b); diffs: [3] u32; - for ^d: diffs do *d = 0; + for &d: diffs do *d = 0; for i: 1 .. nums.count do diffs[nums[i] - nums[i - 1] - 1] += 1; diffs[2] += 1; diff --git a/tests/aoc-2020/day11.onyx b/tests/aoc-2020/day11.onyx index a8c189d0..e8be0fa7 100644 --- a/tests/aoc-2020/day11.onyx +++ b/tests/aoc-2020/day11.onyx @@ -11,12 +11,12 @@ GameOfSeats :: struct { SeatState :: enum (u8) { OOB; Floor; Empty; Occupied; } -gos_get_seat :: (use gos: ^GameOfSeats, x: i32, y: i32) -> SeatState { +gos_get_seat :: (use gos: &GameOfSeats, x: i32, y: i32) -> SeatState { if x < 0 || y < 0 || x >= width || y >= height do return SeatState.OOB; return seats[x + y * width]; } -gos_neighbors :: (use gos: ^GameOfSeats, x: i32, y: i32, state := SeatState.Occupied) -> u32 { +gos_neighbors :: (use gos: &GameOfSeats, x: i32, y: i32, state := SeatState.Occupied) -> u32 { count := 0; for dy: -1 .. 2 { @@ -37,7 +37,7 @@ gos_neighbors :: (use gos: ^GameOfSeats, x: i32, y: i32, state := SeatState.Occu return count; } -gos_iter :: (use gos: ^GameOfSeats) -> bool { +gos_iter :: (use gos: &GameOfSeats) -> bool { for i: 0 .. seats.count do temp[i] = seats[i]; changed := false; @@ -70,27 +70,27 @@ main :: (args: [] cstr) { file := contents; gos : GameOfSeats; - array.init(^gos.seats, 32); - defer array.free(^gos.seats); + array.init(&gos.seats, 32); + defer array.free(&gos.seats); gos.height = 0; while !string.empty(file) { line, file' := string.bisect(file, #char "\n"); for ch: 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); + 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); } gos.width = line.count; gos.height += 1; } - array.init(^gos.temp, gos.seats.count); - defer array.free(^gos.temp); + array.init(&gos.temp, gos.seats.count); + defer array.free(&gos.temp); - while gos_iter(^gos) --- + while gos_iter(&gos) --- occupied := 0; for s: gos.seats do if s == SeatState.Occupied do occupied += 1; diff --git a/tests/aoc-2020/day12.onyx b/tests/aoc-2020/day12.onyx index 40b65009..8decca70 100644 --- a/tests/aoc-2020/day12.onyx +++ b/tests/aoc-2020/day12.onyx @@ -10,7 +10,7 @@ Ship :: struct { fy : i32 = 0; } -rotate_left :: (ship: ^Ship) { +rotate_left :: (ship: &Ship) { ofx := ship.fx; ofy := ship.fy; @@ -18,7 +18,7 @@ rotate_left :: (ship: ^Ship) { ship.fy = -ofx; } -rotate_right :: (ship: ^Ship) { +rotate_right :: (ship: &Ship) { ofx := ship.fx; ofy := ship.fy; @@ -26,7 +26,7 @@ rotate_right :: (ship: ^Ship) { ship.fy = ofx; } -turn_around :: (ship: ^Ship) { +turn_around :: (ship: &Ship) { ship.fx = -ship.fx; ship.fy = -ship.fy; } @@ -39,10 +39,10 @@ main :: (args: [] cstr) { ship := Ship.{ fx = 10, fy = -1 }; while !string.empty(file) { dir := file[0]; - string.advance(^file, 1); + string.advance(&file, 1); - val := cast(u32, conv.parse_int(^file)); - string.advance_line(^file); + val := cast(u32, conv.parse_int(&file)); + string.advance_line(&file); switch dir { case #char "N" do ship.fy -= val; @@ -55,15 +55,15 @@ main :: (args: [] cstr) { } case #char "L" do switch val { - case 90 do rotate_left(^ship); - case 180 do turn_around(^ship); - case 270 do rotate_right(^ship); + case 90 do rotate_left(&ship); + case 180 do turn_around(&ship); + case 270 do rotate_right(&ship); } case #char "R" do switch val { - case 90 do rotate_right(^ship); - case 180 do turn_around(^ship); - case 270 do rotate_left(^ship); + case 90 do rotate_right(&ship); + case 180 do turn_around(&ship); + case 270 do rotate_left(&ship); } } } diff --git a/tests/aoc-2020/day13.onyx b/tests/aoc-2020/day13.onyx index 1134d7ba..65fe309a 100644 --- a/tests/aoc-2020/day13.onyx +++ b/tests/aoc-2020/day13.onyx @@ -40,32 +40,32 @@ main :: (args: [] cstr) { file := contents; - est := cast(u32, conv.parse_int(^file)); - string.advance_line(^file); + est := cast(u32, conv.parse_int(&file)); + string.advance_line(&file); buses := array.make(i64); - defer array.free(^buses); + defer array.free(&buses); rems := array.make(i64); - defer array.free(^rems); + defer array.free(&rems); offset: i64 = 0; while !string.empty(file) { if *file.data == #char "x" { - string.advance(^file, 2); + string.advance(&file, 2); } else { - bus := conv.parse_int(^file); - array.push(^buses, ~~bus); - array.push(^rems, bus - offset); + bus := conv.parse_int(&file); + array.push(&buses, ~~bus); + array.push(&rems, bus - offset); - string.advance(^file, 1); + string.advance(&file, 1); } offset += 1; } // Part 1 - // min := array.fold(^buses, 0xffffffff, math.min); + // min := array.fold(&buses, 0xffffffff, math.min); // take_bus := 0; // depart := 0; diff --git a/tests/aoc-2020/day14.onyx b/tests/aoc-2020/day14.onyx index 152e4ced..080c7c1c 100644 --- a/tests/aoc-2020/day14.onyx +++ b/tests/aoc-2020/day14.onyx @@ -31,7 +31,7 @@ BitmaskIter :: struct { bitmask_p2 :: (mask: Bitmask, val: u64) -> Iterator(u64) { iterator_next :: (data: rawptr) -> (u64, bool) { - bmi := cast(^BitmaskIter) data; + bmi := cast(&BitmaskIter) data; if bmi.done do return 0, false; for ind: bmi.floating_indicies { @@ -47,15 +47,15 @@ bitmask_p2 :: (mask: Bitmask, val: u64) -> Iterator(u64) { } iterator_close :: (data: rawptr) { - bmi := cast(^BitmaskIter) data; - array.free(^bmi.floating_indicies); + bmi := cast(&BitmaskIter) data; + array.free(&bmi.floating_indicies); cfree(bmi); } bmi := new(BitmaskIter); bmi.done = false; - array.init(^bmi.floating_indicies, 8); + array.init(&bmi.floating_indicies, 8); v := val; for i: 0 .. MASK_SIZE { @@ -63,7 +63,7 @@ bitmask_p2 :: (mask: Bitmask, val: u64) -> Iterator(u64) { if mask[i] == 2 { v &= ~(1 << cast(u64) i); - array.push(^bmi.floating_indicies, cast(u8) i); + array.push(&bmi.floating_indicies, cast(u8) i); } } @@ -78,15 +78,15 @@ main :: (args: [] cstr) { file := contents; mem := map.make(u64, u64, default=0); - defer map.free(^mem); + defer map.free(&mem); mask : Bitmask; - for ^m: mask do *m = 2; + for &m: mask do *m = 2; while !string.empty(file) { - word := string.read_alphanum(^file); + word := string.read_alphanum(&file); if string.equal(word, "mask") { - string.advance(^file, 3); + string.advance(&file, 3); i := 35; m, file' := string.bisect(file, #char "\n"); @@ -101,22 +101,22 @@ main :: (args: [] cstr) { } } elseif string.equal(word, "mem") { - string.advance(^file, 1); + string.advance(&file, 1); - addr := cast(u64, conv.parse_int(^file)); - string.advance(^file, 4); + addr := cast(u64, conv.parse_int(&file)); + string.advance(&file, 4); - val := cast(u64, conv.parse_int(^file)); + val := cast(u64, conv.parse_int(&file)); // Part 1 - // map.put(^mem, addr, bitmask_p1(mask, val)); + // map.put(&mem, addr, bitmask_p1(mask, val)); // Part 2 for real_addr: bitmask_p2(mask, addr) { - map.put(^mem, real_addr, val); + map.put(&mem, real_addr, val); } - string.advance_line(^file); + string.advance_line(&file); } } diff --git a/tests/aoc-2020/day15.onyx b/tests/aoc-2020/day15.onyx index 61317ff9..1d543650 100644 --- a/tests/aoc-2020/day15.onyx +++ b/tests/aoc-2020/day15.onyx @@ -14,27 +14,27 @@ main :: (args: [] cstr) { // Any changes to the implementation of Map should be tested on this // file to validate if they 1) work and 2) are faster. nums := map.make(u32, spoken_times, .{}); - defer map.free(^nums); + defer map.free(&nums); turn := 1; last_num := 0; for n: initial_numbers { - map.put(^nums, n, .{ recent = turn }); + map.put(&nums, n, .{ recent = turn }); turn += 1; last_num = n; } while turn != 2021 { - st := map.get(^nums, last_num); + st := map.get(&nums, last_num); if st.previous == 0 do last_num = 0; else do last_num = st.recent - st.previous; - st = map.get(^nums, last_num); + st = map.get(&nums, last_num); st.previous = st.recent; st.recent = turn; - map.put(^nums, last_num, st); + map.put(&nums, last_num, st); turn += 1; } diff --git a/tests/aoc-2020/day16.onyx b/tests/aoc-2020/day16.onyx index 452cf76c..35331144 100644 --- a/tests/aoc-2020/day16.onyx +++ b/tests/aoc-2020/day16.onyx @@ -13,13 +13,13 @@ Field :: struct { upper1 : u32 = 0; } -field_valid :: (use field: ^Field, n: u32) -> bool { +field_valid :: (use field: &Field, n: u32) -> bool { return (lower0 <= n && n <= upper0) || (lower1 <= n && n <= upper1); } total_scanning_error := 0; -read_ticket_and_validate :: (file: ^str, fields: [..] Field, ticket_store: ^u32) -> bool { +read_ticket_and_validate :: (file: &str, fields: [..] Field, ticket_store: &u32) -> bool { retval := true; for i: 0 .. fields.count { @@ -29,7 +29,7 @@ read_ticket_and_validate :: (file: ^str, fields: [..] Field, ticket_store: ^u32) if file.data[0] == #char "," do string.advance(file, 1); valid_count := 0; - for ^field: fields { + for &field: fields { if field_valid(field, n) do valid_count += 1; } @@ -49,44 +49,44 @@ main :: (args: [] cstr) { file := contents; fields := array.make(Field, 20); - defer array.free(^fields); + defer array.free(&fields); // Read until the first empty line while file.data[0] != #char "\n" { field := Field.{}; field.name, file = string.bisect(file, #char ":"); - string.advance(^file, 1); - field.lower0 = ~~ conv.parse_int(^file); + string.advance(&file, 1); + field.lower0 = ~~ conv.parse_int(&file); - string.advance(^file, 1); - field.upper0 = ~~ conv.parse_int(^file); + string.advance(&file, 1); + field.upper0 = ~~ conv.parse_int(&file); - string.advance(^file, 4); - field.lower1 = ~~ conv.parse_int(^file); + string.advance(&file, 4); + field.lower1 = ~~ conv.parse_int(&file); - string.advance(^file, 1); - field.upper1 = ~~ conv.parse_int(^file); + string.advance(&file, 1); + field.upper1 = ~~ conv.parse_int(&file); - string.advance_line(^file); + string.advance_line(&file); - array.push(^fields, field); + array.push(&fields, field); } - for i: 0 .. 2 do string.advance_line(^file); + for i: 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); + 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: 0 .. 2 do string.advance_line(&file); ticket_data := array.make(u32, 1024); - defer array.free(^ticket_data); + defer array.free(&ticket_data); while !string.empty(file) { - array.ensure_capacity(^ticket_data, ticket_data.count + fields.count); - if read_ticket_and_validate(^file, fields, ^ticket_data[ticket_data.count]) { + array.ensure_capacity(&ticket_data, ticket_data.count + fields.count); + if read_ticket_and_validate(&file, fields, &ticket_data[ticket_data.count]) { ticket_data.count += fields.count; } } @@ -94,16 +94,16 @@ main :: (args: [] cstr) { printf("Scanning error: {}\n", total_scanning_error); cols_to_assign := array.make(u32, fields.count); - defer array.free(^cols_to_assign); + defer array.free(&cols_to_assign); - for i: 0 .. fields.count do array.push(^cols_to_assign, i); + for i: 0 .. fields.count do array.push(&cols_to_assign, i); while cols_to_assign.count > 0 { for col: cols_to_assign { work_count := 0; - recent_work: ^Field = null; + recent_work: &Field = null; - for ^field: fields { + for &field: fields { if field.column != -1 do continue; works := true; @@ -122,14 +122,14 @@ main :: (args: [] cstr) { if work_count == 1 { recent_work.column = col; - array.remove(^cols_to_assign, col); + array.remove(&cols_to_assign, col); break; } } } prod: u64 = 1; - for ^field: fields { + for &field: fields { if string.starts_with(field.name, "departure") do prod *= ~~my_ticket[field.column]; } diff --git a/tests/aoc-2020/day17.onyx b/tests/aoc-2020/day17.onyx index 6be80307..59f77091 100644 --- a/tests/aoc-2020/day17.onyx +++ b/tests/aoc-2020/day17.onyx @@ -37,7 +37,7 @@ CubeState :: struct { next := false; } -get_neighbor_count :: (cubes: ^Map(CubePos, CubeState), pos: CubePos) -> u32 { +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 { @@ -56,7 +56,7 @@ main :: (args: [] cstr) { file := contents; cubes := map.make(CubePos, CubeState, .{}); - defer map.free(^cubes); + defer map.free(&cubes); z := 0; while !string.empty(file) { @@ -64,7 +64,7 @@ main :: (args: [] cstr) { x := 0; for ch: line { - if ch == #char "#" do map.put(^cubes, .{ x, 0, z, 0 }, .{ alive = true }); + if ch == #char "#" do map.put(&cubes, .{ x, 0, z, 0 }, .{ alive = true }); x += 1; } @@ -73,13 +73,13 @@ main :: (args: [] cstr) { } cubes_to_consider := array.make(CubePos); - defer array.free(^cubes_to_consider); + defer array.free(&cubes_to_consider); for i: 0 .. 6 { - for ^cube_entry: cubes.entries { + for &cube_entry: 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 { - array.push(^cubes_to_consider, .{ + array.push(&cubes_to_consider, .{ cube_entry.key.x + x, cube_entry.key.y + y, cube_entry.key.z + z, @@ -89,9 +89,9 @@ main :: (args: [] cstr) { } } - for ^cube: cubes_to_consider { - state := map.get(^cubes, *cube); - ncount := get_neighbor_count(^cubes, *cube); + for &cube: cubes_to_consider { + state := map.get(&cubes, *cube); + ncount := get_neighbor_count(&cubes, *cube); if state.alive { state.next = ncount == 2 || ncount == 3; @@ -99,20 +99,20 @@ main :: (args: [] cstr) { state.next = ncount == 3; } - map.put(^cubes, *cube, state); + map.put(&cubes, *cube, state); } - for ^cube: cubes_to_consider { - state := map.get(^cubes, *cube); + for &cube: cubes_to_consider { + state := map.get(&cubes, *cube); state.alive = state.next; - map.put(^cubes, *cube, state); + map.put(&cubes, *cube, state); } - array.clear(^cubes_to_consider); + array.clear(&cubes_to_consider); } active_count := 0; - for ^cube_entry: cubes.entries do if cube_entry.value.alive do active_count += 1; + for &cube_entry: cubes.entries do if cube_entry.value.alive do active_count += 1; printf("Active count: {}\n", active_count); } diff --git a/tests/aoc-2020/day18.onyx b/tests/aoc-2020/day18.onyx index 0a8e0cb4..ac8c69ce 100644 --- a/tests/aoc-2020/day18.onyx +++ b/tests/aoc-2020/day18.onyx @@ -2,7 +2,7 @@ use package core -parse_factor :: (file: ^str) -> u64 { +parse_factor :: (file: &str) -> u64 { string.strip_leading_whitespace(file); switch *file.data { @@ -25,7 +25,7 @@ parse_factor :: (file: ^str) -> u64 { return 0; } -parse_expression_add :: (file: ^str) -> u64 { +parse_expression_add :: (file: &str) -> u64 { string.strip_leading_whitespace(file); left := parse_factor(file); @@ -45,7 +45,7 @@ parse_expression_add :: (file: ^str) -> u64 { return left; } -parse_expression_mul :: (file: ^str) -> u64 { +parse_expression_mul :: (file: &str) -> u64 { string.strip_leading_whitespace(file); left := parse_expression_add(file); @@ -71,7 +71,7 @@ main :: (args: [] cstr) { total: u64 = 0; while !string.empty(file) { - total += parse_expression_mul(^file); + total += parse_expression_mul(&file); } printf("Total: {}\n", total); diff --git a/tests/aoc-2020/day19.onyx b/tests/aoc-2020/day19.onyx index 202e53a0..6d14bfb5 100644 --- a/tests/aoc-2020/day19.onyx +++ b/tests/aoc-2020/day19.onyx @@ -32,32 +32,32 @@ Grammar :: struct { max_terminal : u32; } -grammar_init :: (use g: ^Grammar) { - array.init(^terminate_rules); - array.init(^unit_rules); - array.init(^production_rules); +grammar_init :: (use g: &Grammar) { + array.init(&terminate_rules); + array.init(&unit_rules); + array.init(&production_rules); max_terminal = 0; } -grammar_free :: (use g: ^Grammar) { - array.free(^terminate_rules); - array.free(^unit_rules); - array.free(^production_rules); +grammar_free :: (use g: &Grammar) { + array.free(&terminate_rules); + array.free(&unit_rules); + array.free(&production_rules); } -grammar_prepare :: (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: unit_rules { + for &prod: production_rules { if prod.nt0 == solo.nt1 { - array.push(^production_rules, Prod.{ solo.nt0, prod.nt1, prod.nt2 }); + array.push(&production_rules, Prod.{ solo.nt0, prod.nt1, prod.nt2 }); } } - for ^unit: terminate_rules { + for &unit: terminate_rules { if unit.nt == solo.nt1 { - array.push(^terminate_rules, Term.{ solo.nt0, unit.t }); + array.push(&terminate_rules, Term.{ solo.nt0, unit.t }); } } } @@ -70,18 +70,18 @@ grammar_prepare :: (use g: ^Grammar) { terminate_rules[terminate_rules.count - 1].nt) + 1; } -cyk_algorithm :: (use grammar: ^Grammar, input: str) -> bool { +cyk_algorithm :: (use grammar: &Grammar, input: str) -> bool { dim_0 := input.count * max_terminal; dim_1 := max_terminal; dim_2 := 1; mem_size := sizeof bool * input.count * input.count * max_terminal; - T := cast(^bool) calloc(mem_size); + T := cast(&bool) calloc(mem_size); defer cfree(T); memory.set(T, ~~false, mem_size); for s: 0 .. input.count { - for ^term: terminate_rules { + for &term: terminate_rules { if term.t == input[s] { T[0 * dim_0 + s * dim_1 + term.nt * dim_2] = true; } @@ -91,7 +91,7 @@ cyk_algorithm :: (use grammar: ^Grammar, input: str) -> bool { for l: 1 .. input.count { for s: 0 .. input.count - l { for p: 1 .. l + 1 { - for ^prod: production_rules { + for &prod: 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; @@ -110,43 +110,43 @@ main :: (args: [] cstr) { file := contents; grammar : Grammar; - grammar_init(^grammar); - defer grammar_free(^grammar); + grammar_init(&grammar); + defer grammar_free(&grammar); while *file.data != #char "\n" { - nt0 := cast(u32, conv.parse_int(^file)); + nt0 := cast(u32, conv.parse_int(&file)); - string.advance(^file, 2); // ': ' + string.advance(&file, 2); // ': ' if *file.data == #char "\"" { - string.advance(^file, 1); // '"' + string.advance(&file, 1); // '"' t := file[0]; - string.advance(^file, 1); + string.advance(&file, 1); - array.push(^grammar.terminate_rules, Term.{ nt0, t }); + array.push(&grammar.terminate_rules, Term.{ nt0, t }); } else { while true { - nt1 := cast(u32, conv.parse_int(^file)); + nt1 := cast(u32, conv.parse_int(&file)); if *file.data == #char "\n" { - array.push(^grammar.unit_rules, Unit.{ nt0, nt1 }); + array.push(&grammar.unit_rules, Unit.{ nt0, nt1 }); break; } else { - string.advance(^file, 1); // ' ' + string.advance(&file, 1); // ' ' if next_ch := *file.data; next_ch >= #char "0" && next_ch <= #char "9" { - nt2 := cast(u32, conv.parse_int(^file)); - array.push(^grammar.production_rules, Prod.{ nt0, nt1, nt2 }); + nt2 := cast(u32, conv.parse_int(&file)); + array.push(&grammar.production_rules, Prod.{ nt0, nt1, nt2 }); - if *file.data == #char " " do string.advance(^file, 1); + if *file.data == #char " " do string.advance(&file, 1); } else { - array.push(^grammar.unit_rules, Unit.{ nt0, nt1 }); + array.push(&grammar.unit_rules, Unit.{ nt0, nt1 }); } if *file.data == #char "|" { - string.advance(^file, 1); // ' |' + string.advance(&file, 1); // ' |' } else { break; } @@ -154,16 +154,16 @@ main :: (args: [] cstr) { } } - string.advance_line(^file); + string.advance_line(&file); } - grammar_prepare(^grammar); + grammar_prepare(&grammar); valid_count := 0; - string.advance_line(^file); + string.advance_line(&file); while !string.empty(file) { line, file' := string.bisect(file, #char "\n"); - if cyk_algorithm(^grammar, line) do valid_count += 1; + if cyk_algorithm(&grammar, line) do valid_count += 1; } printf("Valid count: {}\n", valid_count); diff --git a/tests/aoc-2020/day2.onyx b/tests/aoc-2020/day2.onyx index 7f1ec0e0..d523ac1a 100644 --- a/tests/aoc-2020/day2.onyx +++ b/tests/aoc-2020/day2.onyx @@ -11,17 +11,17 @@ main :: (args: [] cstr) { valid := 0; - while !io.reader_empty(^reader) { - lo := io.read_u32(^reader); + while !io.reader_empty(&reader) { + lo := io.read_u32(&reader); - io.read_byte(^reader); - hi := io.read_u32(^reader); + io.read_byte(&reader); + hi := io.read_u32(&reader); - io.read_byte(^reader); - ch := io.read_byte(^reader); + io.read_byte(&reader); + ch := io.read_byte(&reader); - io.skip_bytes(^reader, 2); - pw := io.read_line(^reader); + io.skip_bytes(&reader, 2); + pw := io.read_line(&reader); // Part 1 // count := 0; diff --git a/tests/aoc-2020/day20.onyx b/tests/aoc-2020/day20.onyx index 6c4bf7ed..7a4eecd4 100644 --- a/tests/aoc-2020/day20.onyx +++ b/tests/aoc-2020/day20.onyx @@ -66,7 +66,7 @@ reverse_binary :: (n_: u32, digits := TILE_DATA_WIDTH) -> u32 { build_edges :: (tile: [] bool, a := context.allocator) -> [] u32 { edges : [..] u32; - array.init(^edges, 8, allocator=a); + array.init(&edges, 8, allocator=a); for y: u32.[0, 9] { edge := 0; @@ -75,7 +75,7 @@ build_edges :: (tile: [] bool, a := context.allocator) -> [] u32 { if tile[x + y * TILE_DATA_WIDTH] do edge |= 1; } - array.push(^edges, edge); + array.push(&edges, edge); } for x: u32.[0, 9] { @@ -85,10 +85,10 @@ build_edges :: (tile: [] bool, a := context.allocator) -> [] u32 { if tile[x + y * TILE_DATA_WIDTH] do edge |= 1; } - array.push(^edges, edge); + array.push(&edges, edge); } - for i: 0 .. 4 do array.push(^edges, reverse_binary(edges[i])); + for i: 0 .. 4 do array.push(&edges, reverse_binary(edges[i])); return edges.data[0 .. 8]; } @@ -106,7 +106,7 @@ side_relations := ([4] TO).[ TO.[ TO.R90, TO.FR270, TO.F, TO.R180, ], ]; -has_matching_edges :: (t1: ^Tile, t2: ^Tile) -> bool { +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 { @@ -126,7 +126,7 @@ has_matching_edges :: (t1: ^Tile, t2: ^Tile) -> bool { } // This assumes the `t` was in NORMAL orientation to begin with. -apply_orientation :: (t: ^Tile, ori: TO) { +apply_orientation :: (t: &Tile, ori: TO) { new_sides := t.edges_match; switch ori { @@ -179,16 +179,16 @@ apply_orientation :: (t: ^Tile, ori: TO) { t.orientation = ori; } -index_square_with_orientation :: (data: ^$T, ori: TO, size: i32, x: i32, y: i32) -> ^T { +index_square_with_orientation :: (data: &$T, ori: TO, size: i32, x: i32, y: i32) -> &T { switch ori { - case TO.N do return ^data[x + y * size]; - case TO.R90 do return ^data[y + (size - 1 - x) * size]; - case TO.R180 do return ^data[(size - 1 - x) + (size - 1 - y) * size]; - case TO.R270 do return ^data[(size - 1 - y) + x * size]; - case TO.F do return ^data[x + (size - 1 - y) * size]; - case TO.FR90 do return ^data[y + x * size]; - case TO.FR180 do return ^data[(size - 1 - x) + y * size]; - case TO.FR270 do return ^data[(size - 1 - y) + (size - 1 - x) * size]; + case TO.N do return &data[x + y * size]; + case TO.R90 do return &data[y + (size - 1 - x) * size]; + case TO.R180 do return &data[(size - 1 - x) + (size - 1 - y) * size]; + case TO.R270 do return &data[(size - 1 - y) + x * size]; + case TO.F do return &data[x + (size - 1 - y) * size]; + case TO.FR90 do return &data[y + x * size]; + case TO.FR180 do return &data[(size - 1 - x) + y * size]; + case TO.FR270 do return &data[(size - 1 - y) + (size - 1 - x) * size]; } return null; @@ -202,7 +202,7 @@ sea_monster := u8.[ #char" ",#char"#",#char" ",#char" ",#char"#",#char" ",#char" ",#char"#",#char" ",#char" ",#char"#",#char" ",#char" ",#char"#",#char" ",#char" ",#char"#",#char" ",#char" ",#char" ", ]; -scan_for_monsters :: (forest: ^u8, ori: TO, width: u32, height: u32) -> bool { +scan_for_monsters :: (forest: &u8, ori: TO, width: u32, height: u32) -> bool { found_monsters := false; for y: 0 .. height - sea_monster_height { @@ -243,12 +243,12 @@ main :: (args: [] cstr) { file := contents; tiles := array.make(Tile); - defer array.free(^tiles); + defer array.free(&tiles); - tile_map := map.make(u32, ^Tile, null); - defer map.free(^tile_map); + tile_map := map.make(u32, &Tile, null); + defer map.free(&tile_map); - tile_data := cast(^TileData) calloc(200 * sizeof TileData); + tile_data := cast(&TileData) calloc(200 * sizeof TileData); defer cfree(tile_data); // This ring allocator could technically overflow and start @@ -256,15 +256,15 @@ main :: (args: [] cstr) { // should be more than enough space in the allocator to not // run into that problem... Hopefully. tile_data_ring := alloc.ring.make(.{ ~~ tile_data, 200 * sizeof TileData }); - tile_allocator := alloc.ring.make_allocator(^tile_data_ring); + tile_allocator := alloc.ring.make_allocator(&tile_data_ring); while !string.empty(file) { - string.advance(^file, 5); // 'Tile ' - id := cast(u32, conv.parse_int(^file)); + string.advance(&file, 5); // 'Tile ' + id := cast(u32, conv.parse_int(&file)); - string.advance_line(^file); + string.advance_line(&file); - td := cast(^bool) raw_alloc(tile_allocator, sizeof TileData); + td := cast(&bool) raw_alloc(tile_allocator, sizeof TileData); for y: 0 .. 10 { line, file' := string.bisect(file, #char "\n"); @@ -277,17 +277,17 @@ main :: (args: [] cstr) { tile_data := td[0 .. TILE_DATA_HEIGHT * TILE_DATA_WIDTH]; edges := build_edges(tile_data, tile_allocator); - array.push(^tiles, .{ + array.push(&tiles, .{ id = id, orientation = TO.N, data = tile_data, edges = edges, }); - string.advance_line(^file); + string.advance_line(&file); } - for ^t: tiles do map.put(^tile_map, t.id, t); + for &t: tiles do map.put(&tile_map, t.id, t); prod: u64 = 1; top_left_id := 0; @@ -297,7 +297,7 @@ main :: (args: [] cstr) { for j: 0 .. tiles.count { if i == j do continue; - if has_matching_edges(^tiles[i], ^tiles[j]) { + if has_matching_edges(&tiles[i], &tiles[j]) { matching_count += 1; } } @@ -315,7 +315,7 @@ main :: (args: [] cstr) { printf("Corner product: {}\n", prod); grid : [12 * 12] u32; - memory.set(^grid, 0, sizeof [12 * 12] u32); + memory.set(&grid, 0, sizeof [12 * 12] u32); tile_pos_state :: struct { match : SideRelation; @@ -323,36 +323,36 @@ main :: (args: [] cstr) { pos_y : i32; } to_process := array.make(tile_pos_state); - defer array.free(^to_process); + defer array.free(&to_process); - array.push(^to_process, .{ .{ top_left_id, TO.F }, 0, 0 }); + array.push(&to_process, .{ .{ top_left_id, TO.F }, 0, 0 }); while to_process.count > 0 { tid := to_process[0]; - array.delete(^to_process, 0); + array.delete(&to_process, 0); if grid[tid.pos_x + 12 * tid.pos_y] != 0 do continue; - tile_ptr := map.get(^tile_map, tid.match.tile); + tile_ptr := map.get(&tile_map, tid.match.tile); tile_ptr.pos_x = tid.pos_x; tile_ptr.pos_y = tid.pos_y; grid[tid.pos_x + 12 * tid.pos_y] = tid.match.tile; apply_orientation(tile_ptr, tid.match.ori); - if tile_ptr.edges_match.top.tile != 0 do array.push(^to_process, .{ tile_ptr.edges_match.top, tid.pos_x, tid.pos_y - 1 }); - if tile_ptr.edges_match.bottom.tile != 0 do array.push(^to_process, .{ tile_ptr.edges_match.bottom, tid.pos_x, tid.pos_y + 1 }); - if tile_ptr.edges_match.left.tile != 0 do array.push(^to_process, .{ tile_ptr.edges_match.left, tid.pos_x - 1, tid.pos_y }); - if tile_ptr.edges_match.right.tile != 0 do array.push(^to_process, .{ tile_ptr.edges_match.right, tid.pos_x + 1, tid.pos_y }); + if tile_ptr.edges_match.top.tile != 0 do array.push(&to_process, .{ tile_ptr.edges_match.top, tid.pos_x, tid.pos_y - 1 }); + if tile_ptr.edges_match.bottom.tile != 0 do array.push(&to_process, .{ tile_ptr.edges_match.bottom, tid.pos_x, tid.pos_y + 1 }); + if tile_ptr.edges_match.left.tile != 0 do array.push(&to_process, .{ tile_ptr.edges_match.left, tid.pos_x - 1, tid.pos_y }); + if tile_ptr.edges_match.right.tile != 0 do array.push(&to_process, .{ tile_ptr.edges_match.right, tid.pos_x + 1, tid.pos_y }); } forest : [12 * 8 * 12 * 8] u8; for y: 0 .. 12 { for x: 0 .. 12 { - tile := map.get(^tile_map, grid[y * 12 + x]); + tile := map.get(&tile_map, grid[y * 12 + x]); for fy: 0 .. 8 { for fx: 0 .. 8 { - res := *index_square_with_orientation(cast(^bool) tile.data.data, tile.orientation, 10, fx + 1, fy + 1); + 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 "#"; else do forest[loc] = #char "."; @@ -362,7 +362,7 @@ main :: (args: [] cstr) { } for ori: .[ 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; + if scan_for_monsters(cast(&u8) forest, ori, 12 * 8, 12 * 8) do break; } safe_count := 0; diff --git a/tests/aoc-2020/day21.onyx b/tests/aoc-2020/day21.onyx index 6e1c6c03..33abd5f9 100644 --- a/tests/aoc-2020/day21.onyx +++ b/tests/aoc-2020/day21.onyx @@ -35,110 +35,110 @@ main :: (args: [] cstr) { file := contents; - map.init(^ingredient_map, .{}); - map.init(^allergen_map, .{}); + map.init(&ingredient_map, .{}); + map.init(&allergen_map, .{}); defer { - map.free(^ingredient_map); - map.free(^allergen_map); + map.free(&ingredient_map); + map.free(&allergen_map); } foods := array.make(Food); - defer array.free(^foods); + defer array.free(&foods); line_num := 0; while !string.empty(file) { food : Food; - array.init(^food.ingredients, 16); - array.init(^food.allergens); + array.init(&food.ingredients, 16); + array.init(&food.allergens); while *file.data != #char "(" { - ingredient_name := string.read_alphanum(^file); - string.advance(^file, 1); // ' ' + ingredient_name := string.read_alphanum(&file); + string.advance(&file, 1); // ' ' - array.push(^food.ingredients, ingredient_name); + array.push(&food.ingredients, ingredient_name); - ingredient := map.get(^ingredient_map, ingredient_name); + ingredient := map.get(&ingredient_map, ingredient_name); if ingredient.name.data == null { ingredient.name = ingredient_name; - array.init(^ingredient.appears_on, 4); + array.init(&ingredient.appears_on, 4); } - array.push(^ingredient.appears_on, line_num); + array.push(&ingredient.appears_on, line_num); - map.put(^ingredient_map, ingredient_name, ingredient); + map.put(&ingredient_map, ingredient_name, ingredient); } - string.advance(^file, 10); // '(contains ' + string.advance(&file, 10); // '(contains ' while *file.data != #char ")" { - allergen_name := string.read_alphanum(^file); - if *file.data == #char "," do string.advance(^file, 2); // ', ' + allergen_name := string.read_alphanum(&file); + if *file.data == #char "," do string.advance(&file, 2); // ', ' - array.push(^food.allergens, allergen_name); + array.push(&food.allergens, allergen_name); - allergen := map.get(^allergen_map, allergen_name); + allergen := map.get(&allergen_map, allergen_name); if allergen.name.data == null { allergen.name = allergen_name; - array.init(^allergen.appears_on, 4); + array.init(&allergen.appears_on, 4); } - array.push(^allergen.appears_on, line_num); + array.push(&allergen.appears_on, line_num); - map.put(^allergen_map, allergen_name, allergen); + map.put(&allergen_map, allergen_name, allergen); } - array.push(^foods, food); + array.push(&foods, food); - string.advance_line(^file); + string.advance_line(&file); line_num += 1; } definitely_safe := array.make(str); - defer array.free(^definitely_safe); + defer array.free(&definitely_safe); - for ^ingredient_entry: ingredient_map.entries { + for &ingredient_entry: ingredient_map.entries { potential_allergens := array.make(str); - defer array.free(^potential_allergens); + defer array.free(&potential_allergens); for food_num: ingredient_entry.value.appears_on { - for ^allergen_name: foods[food_num].allergens { - array.push(^potential_allergens, *allergen_name); + for &allergen_name: foods[food_num].allergens { + array.push(&potential_allergens, *allergen_name); } } potential_allergen_count := 0; - for ^allergen_name: potential_allergens { - c := array_count_contains(^potential_allergens, *allergen_name, string.equal); - allergen := map.get(^allergen_map, *allergen_name); + for &allergen_name: potential_allergens { + c := array_count_contains(&potential_allergens, *allergen_name, string.equal); + allergen := map.get(&allergen_map, *allergen_name); if c == allergen.appears_on.count { potential_allergen_count += 1; } } if potential_allergen_count == 0 { - array.push(^definitely_safe, ingredient_entry.key); + array.push(&definitely_safe, ingredient_entry.key); } } total_safe := 0; for safe: definitely_safe { - ingredient := map.get(^ingredient_map, safe); + ingredient := map.get(&ingredient_map, safe); total_safe += ingredient.appears_on.count; - map.delete(^ingredient_map, safe); + map.delete(&ingredient_map, safe); } printf("Total safe: {}\n", total_safe); matched_ingredients := array.make(Ingredient); - defer array.free(^matched_ingredients); + defer array.free(&matched_ingredients); - while !map.empty(^ingredient_map) { - for ^allergen_entry: allergen_map.entries { + while !map.empty(&ingredient_map) { + for &allergen_entry: allergen_map.entries { match_count := 0; matching_ingredient_name := str.{ null, 0 }; - for ^ingredient_entry: ingredient_map.entries { + for &ingredient_entry: ingredient_map.entries { matches := true; for ap: allergen_entry.value.appears_on { @@ -152,24 +152,24 @@ main :: (args: [] cstr) { } if match_count == 1 { - ingredient := map.get(^ingredient_map, matching_ingredient_name); - map.delete(^ingredient_map, matching_ingredient_name); + ingredient := map.get(&ingredient_map, matching_ingredient_name); + map.delete(&ingredient_map, matching_ingredient_name); ingredient.allergen = allergen_entry.key; - array.push(^matched_ingredients, ingredient); + array.push(&matched_ingredients, ingredient); } } } - array.sort(matched_ingredients, (i1: ^Ingredient, i2: ^Ingredient) => string.compare(i1.allergen, i2.allergen)); + 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: matched_ingredients do printf("{} -> {}\n", mi.name, mi.allergen); + for &mi: 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 { +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: *arr do if equal(*it, x) do count += 1; return count; } diff --git a/tests/aoc-2020/day22.onyx b/tests/aoc-2020/day22.onyx index 3dcc7c95..ab98c9de 100644 --- a/tests/aoc-2020/day22.onyx +++ b/tests/aoc-2020/day22.onyx @@ -5,7 +5,7 @@ use package core key_arena : alloc.arena.ArenaState; key_alloc : Allocator; -score_player :: (p: ^[..] u32) -> u32 { +score_player :: (p: &[..] u32) -> u32 { count := 0; mul := p.count; for c: *p { @@ -15,7 +15,7 @@ score_player :: (p: ^[..] u32) -> u32 { return count; } -combat :: (player1: ^[..] u32, player2: ^[..] u32) -> u32 { +combat :: (player1: &[..] u32, player2: &[..] u32) -> u32 { while player1.count > 0 && player2.count > 0 { p1 := player1.data[0]; p2 := player2.data[0]; @@ -41,31 +41,31 @@ combat :: (player1: ^[..] u32, player2: ^[..] u32) -> u32 { // into: // 4,5,2,8,|1,3,9,7, // Larger numbers are encoded in base 64. -encode_hands :: (alloc: Allocator, p1: ^[..] u32, p2: ^[..] u32) -> str { +encode_hands :: (alloc: Allocator, p1: &[..] u32, p2: &[..] u32) -> str { stream := io.buffer_stream_make(256, alloc); - writer := io.writer_make(^stream, 0); + writer := io.writer_make(&stream, 0); for n: *p1 { - io.write_i64(^writer, ~~n, 64); - io.write_str(^writer, ","); + io.write_i64(&writer, ~~n, 64); + io.write_str(&writer, ","); } - io.write_str(^writer, "|"); + io.write_str(&writer, "|"); for n: *p2 { - io.write_i64(^writer, ~~n, 64); - io.write_str(^writer, ","); + io.write_i64(&writer, ~~n, 64); + io.write_str(&writer, ","); } - return io.buffer_stream_to_str(^stream); + return io.buffer_stream_to_str(&stream); } -recursive_combat :: (player1: ^[..] u32, player2: ^[..] u32) -> u32 { +recursive_combat :: (player1: &[..] u32, player2: &[..] u32) -> u32 { hand_seen := map.make(str, bool, false); - defer map.free(^hand_seen); + defer map.free(&hand_seen); while player1.count > 0 && player2.count > 0 { enc_hand := encode_hands(key_alloc, player1, player2); - if map.has(^hand_seen, enc_hand) do return 1; - map.put(^hand_seen, enc_hand, true); + if map.has(&hand_seen, enc_hand) do return 1; + map.put(&hand_seen, enc_hand, true); p1 := player1.data[0]; p2 := player2.data[0]; @@ -77,10 +77,10 @@ recursive_combat :: (player1: ^[..] u32, player2: ^[..] u32) -> u32 { if player1.count >= p1 && player2.count >= p2 { p1_copy := array.copy_range(player1, 0 .. p1); p2_copy := array.copy_range(player2, 0 .. p2); - defer array.free(^p1_copy); - defer array.free(^p2_copy); + defer array.free(&p1_copy); + defer array.free(&p2_copy); - round_win = recursive_combat(^p1_copy, ^p2_copy); + round_win = recursive_combat(&p1_copy, &p2_copy); } else { if p1 > p2 do round_win = 1; else do round_win = 2; @@ -106,50 +106,50 @@ main :: (args: [] cstr) { player1 := array.make(u32); player2 := array.make(u32); - defer array.free(^player1); - defer array.free(^player2); + defer array.free(&player1); + defer array.free(&player2); - string.advance_line(^file); // 'Player 1:' + string.advance_line(&file); // 'Player 1:' while *file.data != #char "\n" { - card := cast(u32, conv.parse_int(^file)); - array.push(^player1, card); + card := cast(u32, conv.parse_int(&file)); + array.push(&player1, card); - string.advance_line(^file); + string.advance_line(&file); } - string.advance_line(^file); // '\n' - string.advance_line(^file); // 'Player 2:' + string.advance_line(&file); // '\n' + string.advance_line(&file); // 'Player 2:' while !string.empty(file) { - card := cast(u32, conv.parse_int(^file)); - array.push(^player2, card); + card := cast(u32, conv.parse_int(&file)); + array.push(&player2, card); - string.advance_line(^file); + string.advance_line(&file); } { - player1_copy := array.copy(^player1); - player2_copy := array.copy(^player2); - defer array.free(^player1_copy); - defer array.free(^player2_copy); + player1_copy := array.copy(&player1); + player2_copy := array.copy(&player2); + defer array.free(&player1_copy); + defer array.free(&player2_copy); - combat_score := combat(^player1_copy, ^player2_copy); + combat_score := combat(&player1_copy, &player2_copy); printf("Answer: {}\n", combat_score); } #if false { key_arena = alloc.arena.make(context.allocator, 1 << 14); - key_alloc = alloc.arena.make_allocator(^key_arena); + key_alloc = alloc.arena.make_allocator(&key_arena); - player1_copy := array.copy(^player1); - player2_copy := array.copy(^player2); - defer array.free(^player1_copy); - defer array.free(^player2_copy); + player1_copy := array.copy(&player1); + player2_copy := array.copy(&player2); + defer array.free(&player1_copy); + defer array.free(&player2_copy); - winner := recursive_combat(^player1_copy, ^player2_copy); + winner := recursive_combat(&player1_copy, &player2_copy); score : u32; - if winner == 1 do score = score_player(^player1_copy); - if winner == 2 do score = score_player(^player2_copy); + if winner == 1 do score = score_player(&player1_copy); + if winner == 2 do score = score_player(&player2_copy); printf("Recursive answer: {}\n", score); } diff --git a/tests/aoc-2020/day23.onyx b/tests/aoc-2020/day23.onyx index b51cf013..6440e6dd 100644 --- a/tests/aoc-2020/day23.onyx +++ b/tests/aoc-2020/day23.onyx @@ -56,25 +56,25 @@ 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: cups_data do *cup -= 1; - array.init(^cups, 1000000); - defer array.free(^cups); + array.init(&cups, 1000000); + defer array.free(&cups); - for cup: cups_data do array.push(^cups, cup); + for cup: cups_data do array.push(&cups, cup); // Part 1 - // simulate(array.to_slice(^cups)); + // simulate(array.to_slice(&cups)); // Part 2 - for i: 9 .. 1000000 do array.push(^cups, i); + for i: 9 .. 1000000 do array.push(&cups, i); simulate(cups, 10000000); // Undo the zero-indexing - for ^cup: cups do *cup += 1; + for &cup: cups do *cup += 1; // Part 1 - // one_idx := get_idx(array.to_slice(^cups), 1); + // one_idx := get_idx(array.to_slice(&cups), 1); // for i: 1 .. 9 { // printf("{}", cast(i32) cups[w(one_idx + i)]); // } diff --git a/tests/aoc-2020/day24.onyx b/tests/aoc-2020/day24.onyx index 47a534cb..06367a2d 100644 --- a/tests/aoc-2020/day24.onyx +++ b/tests/aoc-2020/day24.onyx @@ -29,13 +29,13 @@ main :: (args: [] cstr) { contents := #file_contents "./tests/aoc-2020/input/day24.txt"; file_stream := io.buffer_stream_make(contents); - file := io.reader_make(^file_stream); + file := io.reader_make(&file_stream); grid := map.make(Vec2, Cell, .{}); // `true` is black - defer map.free(^grid); + defer map.free(&grid); - while !io.reader_empty(^file) { - line := io.read_line(^file); + while !io.reader_empty(&file) { + line := io.read_line(&file); loc := Vec2.{ 0, 0 }; s := 0; @@ -65,28 +65,28 @@ main :: (args: [] cstr) { } - curr := map.get(^grid, loc); - map.put(^grid, loc, .{ alive = !curr.alive }); + curr := map.get(&grid, loc); + map.put(&grid, loc, .{ alive = !curr.alive }); } // Part 1 black_count := 0; - for ^cell: grid.entries { + for &cell: grid.entries { if cell.value.alive do black_count += 1; } printf("Black count: {}\n", black_count); // Part 2 cells_to_consider := array.make(Vec2); - defer array.free(^cells_to_consider); + defer array.free(&cells_to_consider); for i: 0 .. 100 { - for ^cell: grid.entries { + for &cell: grid.entries { if cell.value.alive { - array.push(^cells_to_consider, cell.key); + array.push(&cells_to_consider, cell.key); - for ^dir: Hex_Directions { - array.push(^cells_to_consider, .{ + for &dir: Hex_Directions { + array.push(&cells_to_consider, .{ x = cell.key.x + dir.x, y = cell.key.y + dir.y, }); @@ -94,9 +94,9 @@ main :: (args: [] cstr) { } } - for ^cell: cells_to_consider { - state := map.get(^grid, *cell); - ncount := get_neighbor_count(^grid, *cell); + for &cell: cells_to_consider { + state := map.get(&grid, *cell); + ncount := get_neighbor_count(&grid, *cell); if state.alive { state.next = ncount == 1 || ncount == 2; @@ -104,27 +104,27 @@ main :: (args: [] cstr) { state.next = ncount == 2; } - map.put(^grid, *cell, state); + map.put(&grid, *cell, state); } - for ^cell: cells_to_consider { - map.update(^grid, *cell, #quote { it.alive = it.next; }); + for &cell: cells_to_consider { + map.update(&grid, *cell, #quote { it.alive = it.next; }); } - array.clear(^cells_to_consider); + array.clear(&cells_to_consider); } black_count = 0; - for ^cell: grid.entries { + for &cell: grid.entries { if cell.value.alive do black_count += 1; } printf("GOL black count: {}\n", black_count); } -get_neighbor_count :: (grid: ^map.Map(Vec2, Cell), pos: Vec2) -> u32 { +get_neighbor_count :: (grid: &map.Map(Vec2, Cell), pos: Vec2) -> u32 { count := 0; - for ^dir: Hex_Directions { + for &dir: Hex_Directions { cell := map.get(grid, Vec2.{ x = pos.x + dir.x, y = pos.y + dir.y }); if cell.alive do count += 1; } diff --git a/tests/aoc-2020/day25.onyx b/tests/aoc-2020/day25.onyx index 75a59049..60f7fee3 100644 --- a/tests/aoc-2020/day25.onyx +++ b/tests/aoc-2020/day25.onyx @@ -22,11 +22,11 @@ dlp_bsgs :: (n: u32, a: u32, b: u32) -> u32 { m := cast(u32) math.ceil(math.sqrt(cast(f64) n)); t := map.make(u32, u32, default=0); - defer map.free(^t); + defer map.free(&t); tmp: u64 = 1; for i: 0 .. m { - map.put(^t, ~~tmp, i); + map.put(&t, ~~tmp, i); tmp = (tmp * ~~a) % ~~n; } @@ -34,8 +34,8 @@ dlp_bsgs :: (n: u32, a: u32, b: u32) -> u32 { tmp = ~~b; for i: 0 .. m { - if map.has(^t, ~~tmp) { - v := map.get(^t, ~~tmp); + if map.has(&t, ~~tmp) { + v := map.get(&t, ~~tmp); return i * m + v; } @@ -56,8 +56,8 @@ main :: (args: [] cstr) { file := contents; - card_pub_key := cast(u32, conv.parse_int(^file)); - door_pub_key := cast(u32, conv.parse_int(^file)); + card_pub_key := cast(u32, conv.parse_int(&file)); + door_pub_key := cast(u32, conv.parse_int(&file)); card_loop_secret := dlp_bsgs(20201227, 7, card_pub_key); door_loop_secret := dlp_bsgs(20201227, 7, door_pub_key); diff --git a/tests/aoc-2020/day3.onyx b/tests/aoc-2020/day3.onyx index ad082a60..7eb37a47 100644 --- a/tests/aoc-2020/day3.onyx +++ b/tests/aoc-2020/day3.onyx @@ -19,19 +19,19 @@ main :: (args: [] cstr) { contents := #file_contents "./tests/aoc-2020/input/day3.txt"; forest := array.make(u8, 1024); - defer array.free(^forest); + defer array.free(&forest); width := 0; height := 0; while true { - line := string.read_until(^contents, #char "\n"); - string.advance(^contents, 1); + line := string.read_until(&contents, #char "\n"); + string.advance(&contents, 1); if line.count == 0 do break; width = line.count; height = height + 1; - for ch: line do array.push(^forest, ch); + for ch: line do array.push(&forest, ch); } lis := LineInterp.[ diff --git a/tests/aoc-2020/day4.onyx b/tests/aoc-2020/day4.onyx index 6b70058a..bb2a01db 100644 --- a/tests/aoc-2020/day4.onyx +++ b/tests/aoc-2020/day4.onyx @@ -3,7 +3,7 @@ use package core // Returns the number of fields -process_passport :: (contents: ^str) -> u32 { +process_passport :: (contents: &str) -> u32 { field_count := 0; while true { @@ -36,7 +36,7 @@ main :: (args: [] cstr) { while true { if contents.count == 0 do break; - field_count := process_passport(^contents); + field_count := process_passport(&contents); if field_count == 7 do valid_passports += 1; } diff --git a/tests/aoc-2020/day5.onyx b/tests/aoc-2020/day5.onyx index 98bc6f36..b2adef19 100644 --- a/tests/aoc-2020/day5.onyx +++ b/tests/aoc-2020/day5.onyx @@ -6,13 +6,13 @@ main :: (args: [] cstr) { contents := #file_contents "./tests/aoc-2020/input/day5.txt"; vals := array.make(u32); - defer array.free(^vals); + defer array.free(&vals); max_val := 0; while true { - line := string.read_until(^contents, #char "\n"); - string.advance(^contents); + line := string.read_until(&contents, #char "\n"); + string.advance(&contents); if line.count == 0 do break; val := 0; @@ -22,7 +22,7 @@ main :: (args: [] cstr) { } max_val = math.max(max_val, val); - array.push(^vals, val); + array.push(&vals, val); } missing := 0; diff --git a/tests/aoc-2020/day6.onyx b/tests/aoc-2020/day6.onyx index a034bbca..c79d69a4 100644 --- a/tests/aoc-2020/day6.onyx +++ b/tests/aoc-2020/day6.onyx @@ -2,9 +2,9 @@ use package core -part_1 :: (contents: ^str) -> u32 { +part_1 :: (contents: &str) -> u32 { chars : [26] bool; - for ^ch: chars do *ch = false; + for &ch: chars do *ch = false; while true { line := string.read_until(contents, #char "\n"); @@ -20,9 +20,9 @@ part_1 :: (contents: ^str) -> u32 { return sum; } -part_2 :: (contents: ^str) -> u32 { +part_2 :: (contents: &str) -> u32 { chars : [26] u32; - for ^ch: chars do *ch = 0; + for &ch: chars do *ch = 0; person_count := 0; while true { @@ -48,7 +48,7 @@ main :: (args: [] cstr) { while true { if contents.count == 0 do break; - unique := part_1(^contents); + unique := part_1(&contents); unique_sum += unique; } diff --git a/tests/aoc-2020/day7.onyx b/tests/aoc-2020/day7.onyx index 5cea2f58..fb9055e3 100644 --- a/tests/aoc-2020/day7.onyx +++ b/tests/aoc-2020/day7.onyx @@ -3,8 +3,8 @@ use package core BagGraph :: struct { - nodes : [..] ^BagNode; - node_map : map.Map(str, ^BagNode); + nodes : [..] &BagNode; + node_map : map.Map(str, &BagNode); } BagNode :: struct { @@ -17,33 +17,33 @@ BagNode :: struct { } BagContainment :: struct { - bag : ^BagNode; + bag : &BagNode; count : u32; } -bg_init :: (use graph: ^BagGraph) { - array.init(^nodes, 16); - map.init(^node_map, null); +bg_init :: (use graph: &BagGraph) { + array.init(&nodes, 16); + map.init(&node_map, null); } -bg_free :: (use graph: ^BagGraph) { - array.free(^nodes); - map.free(^node_map); +bg_free :: (use graph: &BagGraph) { + array.free(&nodes); + map.free(&node_map); } -bg_get_node :: (use graph: ^BagGraph, name: str) -> ^BagNode { - node := map.get(^node_map, name); +bg_get_node :: (use graph: &BagGraph, name: str) -> &BagNode { + node := map.get(&node_map, name); if node == null { node = calloc(sizeof BagNode); // Part 1 - // array.init(^node.contained_in, 2); + // array.init(&node.contained_in, 2); // Part 2 - array.init(^node.contain, 2); + array.init(&node.contain, 2); node.color = name; - array.push(^nodes, node); - map.put(^node_map, node.color, node); + array.push(&nodes, node); + map.put(&node_map, node.color, node); } return node; @@ -55,58 +55,58 @@ main :: (args: [] cstr) { file := contents; graph : BagGraph; - bg_init(^graph); - defer bg_free(^graph); + bg_init(&graph); + defer bg_free(&graph); while true { - name := string.read_until(^file, #char " ", 1); + name := string.read_until(&file, #char " ", 1); if name.count == 0 do break; - container := bg_get_node(^graph, name); + container := bg_get_node(&graph, name); - string.read_until(^file, #char " ", 2); + string.read_until(&file, #char " ", 2); while true { if string.starts_with(file, " no") do break; - count := cast(u32, conv.parse_int(^file)); - string.advance(^file, 1); + count := cast(u32, conv.parse_int(&file)); + string.advance(&file, 1); - contained_name := string.read_until(^file, #char " ", 1); - contained := bg_get_node(^graph, contained_name); + contained_name := string.read_until(&file, #char " ", 1); + contained := bg_get_node(&graph, contained_name); // Part 1 - // array.push(^contained.contained_in, BagContainment.{ + // array.push(&contained.contained_in, BagContainment.{ // bag = container, // count = count // }); // Part 2 - array.push(^container.contain, .{ bag = contained, count = count }); + array.push(&container.contain, .{ bag = contained, count = count }); - bag_word := string.read_until_any(^file, 1, #char " ", #char "\n"); + bag_word := string.read_until_any(&file, 1, #char " ", #char "\n"); if bag_word[bag_word.count - 1] == #char "." do break; } - string.advance_line(^file); + string.advance_line(&file); } // Part 1 - // to_process_bags : [..] ^BagNode; - // processed_bags: [..] ^BagNode; + // to_process_bags : [..] &BagNode; + // processed_bags: [..] &BagNode; - // array.init(^to_process_bags); - // array.init(^processed_bags, 32); - // array.push(^to_process_bags, bg_get_node(^graph, "shiny gold")); + // array.init(&to_process_bags); + // array.init(&processed_bags, 32); + // array.push(&to_process_bags, bg_get_node(&graph, "shiny gold")); // while to_process_bags.count > 0 { - // bag := array.pop(^to_process_bags); - // array.push(^processed_bags, bag); + // bag := array.pop(&to_process_bags); + // array.push(&processed_bags, bag); // // for container: bag.contained_in { - // if !array.contains(^processed_bags, container.bag) && !array.contains(^to_process_bags, container.bag) { + // 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); + // array.push(&to_process_bags, container.bag); // } // } // } @@ -114,20 +114,20 @@ main :: (args: [] cstr) { // printf("Count: {}\n", processed_bags.count - 1); // Part 2 - to_process := array.make(^BagNode); + to_process := array.make(&BagNode); multiplier := array.make(u32); - array.push(^to_process, bg_get_node(^graph, "shiny gold")); - array.push(^multiplier, 1); + array.push(&to_process, bg_get_node(&graph, "shiny gold")); + array.push(&multiplier, 1); count := 0; while to_process.count > 0 { - bag := array.pop(^to_process); - mul := array.pop(^multiplier); + bag := array.pop(&to_process); + mul := array.pop(&multiplier); count += mul; for bc: bag.contain { - array.push(^to_process, bc.bag); - array.push(^multiplier, bc.count * mul); + array.push(&to_process, bc.bag); + array.push(&multiplier, bc.count * mul); } } diff --git a/tests/aoc-2020/day8.onyx b/tests/aoc-2020/day8.onyx index 842c4cd2..e9e1bd6e 100644 --- a/tests/aoc-2020/day8.onyx +++ b/tests/aoc-2020/day8.onyx @@ -12,9 +12,9 @@ Instruction :: struct { } // Returns if the program successfully exited. -get_acc_value :: (instrs: [..] Instruction, ret_acc: ^i32) -> bool { +get_acc_value :: (instrs: [..] Instruction, ret_acc: &i32) -> bool { already_been := map.make(i32, bool, false); - defer map.free(^already_been); + defer map.free(&already_been); ip := 0; acc := 0; @@ -25,8 +25,8 @@ get_acc_value :: (instrs: [..] Instruction, ret_acc: ^i32) -> bool { break; } - if map.has(^already_been, ip) do break; - map.put(^already_been, ip, true); + if map.has(&already_been, ip) do break; + map.put(&already_been, ip, true); switch instrs[ip].opcode { case OpCode.Nop do ip += 1; @@ -48,17 +48,17 @@ main :: (args: [] cstr) { file := contents; instrs := array.make(Instruction, 32); - defer array.free(^instrs); + defer array.free(&instrs); while !string.empty(file) { word := file.data[0 .. 3]; - string.advance(^file, 4); + string.advance(&file, 4); sign := file.data[0]; - string.advance(^file, 1); - val := cast(i32) conv.parse_int(^file); + string.advance(&file, 1); + val := cast(i32) conv.parse_int(&file); - string.advance_line(^file); + string.advance_line(&file); if sign == #char "-" do val *= -1; @@ -67,15 +67,15 @@ main :: (args: [] cstr) { elseif string.equal(word, "acc") do opcode = OpCode.Acc; elseif string.equal(word, "jmp") do opcode = OpCode.Jmp; - array.push(^instrs, .{ opcode, ~~val }); + array.push(&instrs, .{ opcode, ~~val }); } acc: i32; - for ^instr: instrs { + for &instr: instrs { if instr.opcode == OpCode.Nop do instr.opcode = OpCode.Jmp; elseif instr.opcode == OpCode.Jmp do instr.opcode = OpCode.Nop; - if get_acc_value(instrs, ^acc) do break; + if get_acc_value(instrs, &acc) do break; if instr.opcode == OpCode.Nop do instr.opcode = OpCode.Jmp; elseif instr.opcode == OpCode.Jmp do instr.opcode = OpCode.Nop; diff --git a/tests/aoc-2020/day9.onyx b/tests/aoc-2020/day9.onyx index 9acb88f2..7c877233 100644 --- a/tests/aoc-2020/day9.onyx +++ b/tests/aoc-2020/day9.onyx @@ -30,11 +30,11 @@ main :: (args: [] cstr) { file := contents; nums := array.make(u64, 32); - defer array.free(^nums); + defer array.free(&nums); while !string.empty(file) { - num := conv.parse_int(^file); - array.push(^nums, num); + num := conv.parse_int(&file); + array.push(&nums, num); } preamble_length :: 25; diff --git a/tests/aoc-2021/day01.onyx b/tests/aoc-2021/day01.onyx index bc106c9e..838b3e5f 100644 --- a/tests/aoc-2021/day01.onyx +++ b/tests/aoc-2021/day01.onyx @@ -15,13 +15,13 @@ count_increasing :: (arr: [] $T) -> u32 { main :: (args) => { file := os.open("./tests/aoc-2021/input/day01.txt")->expect("Error opening file"); - reader := io.reader_make(^file); - defer os.close(^file); + reader := io.reader_make(&file); + defer os.close(&file); nums: [..] i32; - while !io.reader_empty(^reader) { - nums << io.read_u32(^reader); - io.skip_whitespace(^reader); + while !io.reader_empty(&reader) { + nums << io.read_u32(&reader); + io.skip_whitespace(&reader); } { // Part 1 diff --git a/tests/aoc-2021/day02.onyx b/tests/aoc-2021/day02.onyx index ca1704c1..9c0c55ac 100644 --- a/tests/aoc-2021/day02.onyx +++ b/tests/aoc-2021/day02.onyx @@ -10,9 +10,9 @@ main :: (args) => { #if PART == 1 { horizontal, vertical := 0, 0; - while !io.reader_empty(^reader) { - parts := string.split(io.read_line(^reader, inplace=true), #char " "); - defer memory.free_slice(^parts); + while !io.reader_empty(&reader) { + parts := string.split(io.read_line(&reader, inplace=true), #char " "); + defer memory.free_slice(&parts); value := cast(i32) conv.str_to_i64(parts[1]); switch parts[0] { @@ -28,9 +28,9 @@ main :: (args) => { #if PART == 2 { horizontal, vertical, aim : i64; horizontal, vertical, aim = 0, 0, 0; - while !io.reader_empty(^reader) { - parts := string.split(io.read_line(^reader, inplace=true), #char " "); - defer memory.free_slice(^parts); + while !io.reader_empty(&reader) { + parts := string.split(io.read_line(&reader, inplace=true), #char " "); + defer memory.free_slice(&parts); value := conv.str_to_i64(parts[1]); switch parts[0] { diff --git a/tests/aoc-2021/day03.onyx b/tests/aoc-2021/day03.onyx index 243ea239..7510252e 100644 --- a/tests/aoc-2021/day03.onyx +++ b/tests/aoc-2021/day03.onyx @@ -4,7 +4,7 @@ PART :: 2 use package core -read_binary :: (r: ^io.Reader) -> i32 { +read_binary :: (r: &io.Reader) -> i32 { n := 0; io.skip_whitespace(r); @@ -30,8 +30,8 @@ main :: (args) => { reader := io.reader_make(it); nums: [..] i32; - while !io.reader_empty(^reader) { - nums << read_binary(^reader); + while !io.reader_empty(&reader) { + nums << read_binary(&reader); } num1 := 0; @@ -48,8 +48,8 @@ main :: (args) => { printf("Part 1: {}\n", num1 * num2); - oxygen_array := array.copy(^nums); - co2_array := array.copy(^nums); + oxygen_array := array.copy(&nums); + co2_array := array.copy(&nums); filter_array :: macro (arr: [..] i32, index: i32, comparison: Code) { A := 0; @@ -66,7 +66,7 @@ main :: (args) => { defer i += 1; if (arr[i] & (1 << index)) != expected { - array.fast_delete(^arr, i); + array.fast_delete(&arr, i); i -= 1; } } diff --git a/tests/aoc-2021/day04.onyx b/tests/aoc-2021/day04.onyx index 1fd397a5..4d639b2b 100644 --- a/tests/aoc-2021/day04.onyx +++ b/tests/aoc-2021/day04.onyx @@ -12,7 +12,7 @@ Board :: struct { won_on : Cell; } -board_score :: (use b: ^Board) => { +board_score :: (use b: &Board) => { sum_of_unmarked := 0; for 25 do if !marked[it] do sum_of_unmarked += ~~cells[it]; return sum_of_unmarked * ~~won_on; @@ -22,30 +22,30 @@ main :: (args) => { for os.with_file("./tests/aoc-2021/input/day04.txt") { reader := io.reader_make(it); - numbers_line := io.read_line(^reader, inplace=true, consume_newline=true); + numbers_line := io.read_line(&reader, inplace=true, consume_newline=true); numbers_str := string.split(numbers_line, #char ","); numbers := memory.make_slice(Cell, numbers_str.count); for numbers_str.count do numbers[it] = ~~ conv.parse_int(numbers_str[it]); boards: [..] Board; - while !io.reader_empty(^reader) { - array.insert_empty(^boards, boards.count); - board := ^boards[boards.count - 1]; + while !io.reader_empty(&reader) { + array.insert_empty(&boards, boards.count); + board := &boards[boards.count - 1]; board.has_won = false; - memory.set(^board.marked, 0, sizeof typeof board.marked); + memory.set(&board.marked, 0, sizeof typeof board.marked); for 25 { - board.cells[it] = ~~ io.read_u32(^reader); + board.cells[it] = ~~ io.read_u32(&reader); } - io.skip_whitespace(^reader); + io.skip_whitespace(&reader); } - winning_board: ^Board = null; - worst_board : ^Board = null; + winning_board: &Board = null; + worst_board : &Board = null; for called: numbers { - for ^ board: boards { + for & board: boards { if board.has_won do continue; // Whatever the last board we touch is must be the worst one. diff --git a/tests/aoc-2021/day05.onyx b/tests/aoc-2021/day05.onyx index f5fca8d5..47d68fb9 100644 --- a/tests/aoc-2021/day05.onyx +++ b/tests/aoc-2021/day05.onyx @@ -28,7 +28,7 @@ line_points :: (l: Line) -> Iterator(Point) { c.dx = 1 if l.x2 > l.x1 else -1 if l.x2 < l.x1 else 0; c.dy = 1 if l.y2 > l.y1 else -1 if l.y2 < l.y1 else 0; - next :: (use c: ^Context) -> (Point, bool) { + next :: (use c: &Context) -> (Point, bool) { if curr_t > max_t do return .{0,0}, false; defer curr_t += 1; @@ -48,23 +48,23 @@ main :: (args) => { lines: [..] Line; - while !io.reader_empty(^reader) { - x1 := io.read_u32(^reader); - io.skip_bytes(^reader, 1); - y1 := io.read_u32(^reader); - io.skip_bytes(^reader, 4); + while !io.reader_empty(&reader) { + x1 := io.read_u32(&reader); + io.skip_bytes(&reader, 1); + y1 := io.read_u32(&reader); + io.skip_bytes(&reader, 4); - x2 := io.read_u32(^reader); - io.skip_bytes(^reader, 1); - y2 := io.read_u32(^reader); - io.skip_whitespace(^reader); + x2 := io.read_u32(&reader); + io.skip_bytes(&reader, 1); + y2 := io.read_u32(&reader); + io.skip_whitespace(&reader); lines << .{x1, y1, x2, y2}; } point_count: Map(Point, u32); - for ^line: lines { + for &line: lines { for p: line_points(*line) { if point_count->has(p) { point_count[p] = point_count[p] + 1; @@ -75,7 +75,7 @@ main :: (args) => { } count := 0; - for ^ point_count.entries { + for & point_count.entries { if it.value >= 2 do count += 1; } diff --git a/tests/aoc-2021/day06.onyx b/tests/aoc-2021/day06.onyx index 8bdbb3c5..37c607e6 100644 --- a/tests/aoc-2021/day06.onyx +++ b/tests/aoc-2021/day06.onyx @@ -5,7 +5,7 @@ use package core main :: (args) => { for file: os.with_file("./tests/aoc-2021/input/day06.txt") { reader := io.reader_make(file); - start_str := io.read_all(^reader); + start_str := io.read_all(&reader); start_list := string.split(start_str, #char ","); diff --git a/tests/aoc-2021/day07.onyx b/tests/aoc-2021/day07.onyx index e96d3c57..452cd1e5 100644 --- a/tests/aoc-2021/day07.onyx +++ b/tests/aoc-2021/day07.onyx @@ -5,7 +5,7 @@ use package core main :: (args) => { for file: os.with_file("./tests/aoc-2021/input/day07.txt") { reader := io.reader_make(file); - nums := io.read_all(^reader) + nums := io.read_all(&reader) |> string.split(#char ",") |> iter.as_iter() |> iter.map((x) => cast(i32) conv.parse_int(x)) diff --git a/tests/aoc-2021/day08.onyx b/tests/aoc-2021/day08.onyx index b52bda04..e6dbc762 100644 --- a/tests/aoc-2021/day08.onyx +++ b/tests/aoc-2021/day08.onyx @@ -29,7 +29,7 @@ decode_line :: (left, right: str) -> u32 { solved_segments: Map(u8, u32); left_segments := string.split(left, #char " "); - defer memory.free_slice(^left_segments); + defer memory.free_slice(&left_segments); // Look for 1. one_data := *array.first(left_segments, (x) => x.count == 2); @@ -121,8 +121,8 @@ decode_line :: (left, right: str) -> u32 { sum := 0; words := string.split(right, #char " "); - defer memory.free_slice(^words); - for^ words { + defer memory.free_slice(&words); + for& words { string.strip_whitespace(it); num_segments : [7] bool; @@ -141,7 +141,7 @@ decode_line :: (left, right: str) -> u32 { } // Nicer way of printing a Map. -#match io.write (w: ^io.Writer, x: ^Map($K, $V)) { +#match io.write (w: &io.Writer, x: &Map($K, $V)) { io.write(w, "{\n"); for e: x.entries { io.write(w, " {} => {}\n", e.key, e.value); @@ -162,19 +162,19 @@ main :: (args) => { reader := io.reader_make(file); answer := 0; - while !io.reader_empty(^reader) { - line := io.read_line(^reader, consume_newline=true, inplace=true); + while !io.reader_empty(&reader) { + line := io.read_line(&reader, consume_newline=true, inplace=true); left, right := do { parts := string.split(line, #char "|"); - defer memory.free_slice(^parts); + defer memory.free_slice(&parts); return parts[0], parts[1]; }; - string.strip_whitespace(^left); - string.strip_whitespace(^right); + string.strip_whitespace(&left); + string.strip_whitespace(&right); #if PART == 1 { words := string.split(right, #char " "); - for^ words { + for& words { string.strip_whitespace(it); switch it.count { case 2, 3, 4, 7 do answer += 1; diff --git a/tests/aoc-2021/day09.onyx b/tests/aoc-2021/day09.onyx index 9adce766..f954a54a 100644 --- a/tests/aoc-2021/day09.onyx +++ b/tests/aoc-2021/day09.onyx @@ -3,7 +3,7 @@ use package core Pos :: struct {x,y: i32;} -#match hash.to_u32 (use p: Pos) => x * 13 ^ 17 * y; +#match hash.to_u32 (use p: Pos) => x * 13 & 17 * y; #operator == (p1, p2: Pos) => p1.x == p2.x && p1.y == p2.y; Cell :: struct { @@ -21,14 +21,14 @@ find_span :: macro (low: Pos) -> u32 { while queued.count != 0 { t := queued[0]; - array.delete(^queued, 0); + array.delete(&queued, 0); - top := ^heightmap[t]; + top := &heightmap[t]; if top.height == 9 do continue; included << t; - array.clear(^potential); + array.clear(&potential); if t.x < width - 1 && top.dx < 0 { potential << Pos.{t.x+1,t.y}; } @@ -56,7 +56,7 @@ find_span :: macro (low: Pos) -> u32 { return included.count; } -#match io.write (w: ^io.Writer, x: ^Map($K, $V)) { +#match io.write (w: &io.Writer, x: &Map($K, $V)) { io.write(w, "{\n"); for e: x.entries { io.write(w, " {} => {}\n", e.key, e.value); @@ -71,9 +71,9 @@ main :: (args) => { heightmap: Map(Pos, Cell); height, width := 0, 0; - while !io.reader_empty(^reader) { - line := io.read_line(^reader, consume_newline=false, inplace=true); - io.skip_whitespace(^reader); + while !io.reader_empty(&reader) { + line := io.read_line(&reader, consume_newline=false, inplace=true); + io.skip_whitespace(&reader); for line.count { heightmap[Pos.{it, height}] = Cell.{cast(u32) (line[it] - #char "0")}; @@ -84,12 +84,12 @@ main :: (args) => { } for y: height - 1 do for x: width { - map.update(^heightmap, .{x,y}) { + map.update(&heightmap, .{x,y}) { it.dy = it.height - heightmap[Pos.{x,y+1}].height; } } for x: width - 1 do for y: height { - map.update(^heightmap, .{x,y}) { + map.update(&heightmap, .{x,y}) { it.dx = it.height - heightmap[Pos.{x+1,y}].height; } } @@ -97,7 +97,7 @@ main :: (args) => { lowest: [..] Pos; risk_sum := 0; for y: height do for x: width { - h := ^heightmap[Pos.{x,y}]; + h := &heightmap[Pos.{x,y}]; if x < width - 1 && h.dx >= 0 do continue; if y < height - 1 && h.dy >= 0 do continue; diff --git a/tests/aoc-2021/day10.onyx b/tests/aoc-2021/day10.onyx index 7e0e5450..ab810730 100644 --- a/tests/aoc-2021/day10.onyx +++ b/tests/aoc-2021/day10.onyx @@ -20,12 +20,12 @@ main :: (args) => { corrupted_score := 0; completion_scores: [..] u64; - while !io.reader_empty(^reader) { - line := io.read_line(^reader, consume_newline=false, inplace=true); - io.skip_whitespace(^reader); + while !io.reader_empty(&reader) { + line := io.read_line(&reader, consume_newline=false, inplace=true); + io.skip_whitespace(&reader); char_stack: [..] u8; - defer array.free(^char_stack); + defer array.free(&char_stack); for ch: line { switch ch { case #char "(", #char "[", #char "<", #char "{" { @@ -33,7 +33,7 @@ main :: (args) => { } case #char ")", #char "]", #char ">", #char "}" { - x := array.pop(^char_stack); + x := array.pop(&char_stack); if x != ch { // printf("Expected '{}', found '{}' instead.\n", x, ch); corrupted_score += score_map[ch]; @@ -48,7 +48,7 @@ main :: (args) => { complete_score: u64 = 0; while char_stack.count != 0 { complete_score *= 5; - switch array.pop(^char_stack) { + switch array.pop(&char_stack) { case #char ")" do complete_score += 1; case #char "]" do complete_score += 2; case #char "}" do complete_score += 3; diff --git a/tests/aoc-2021/day11.onyx b/tests/aoc-2021/day11.onyx index c4346348..59451f9d 100644 --- a/tests/aoc-2021/day11.onyx +++ b/tests/aoc-2021/day11.onyx @@ -11,9 +11,9 @@ main :: (args) => { reader := io.reader_make(file); octopuses: [..] u32; - while !io.reader_empty(^reader) { - line := io.read_line(^reader, consume_newline=false, inplace=true); - io.skip_whitespace(^reader); + while !io.reader_empty(&reader) { + line := io.read_line(&reader, consume_newline=false, inplace=true); + io.skip_whitespace(&reader); for ch: line do octopuses << ~~(ch - #char "0"); } @@ -41,7 +41,7 @@ main :: (args) => { sync_step := 0; while true { step += 1; - for ^o: octopuses do *o += 1; + for &o: octopuses do *o += 1; #persist to_flash: Set(Pos); for y: 10 do for x: 10 { @@ -50,7 +50,7 @@ main :: (args) => { } } - for flash: iter.as_iter(^to_flash) { + for flash: iter.as_iter(&to_flash) { for y: -1 .. 2 do for x: -1 .. 2 { if y == 0 && x == 0 do continue; @@ -60,7 +60,7 @@ main :: (args) => { } } - for flash: iter.as_iter(^to_flash) { + for flash: iter.as_iter(&to_flash) { set_octopus(flash.x, flash.y, 0); if step <= 100 do flash_count += 1; } diff --git a/tests/aoc-2021/day12.onyx b/tests/aoc-2021/day12.onyx index 3d701d04..32faed1d 100644 --- a/tests/aoc-2021/day12.onyx +++ b/tests/aoc-2021/day12.onyx @@ -22,12 +22,12 @@ main :: (args) => { verticies: Set(str); edges: Set(Communative_Pair(str)); - while !io.reader_empty(^reader) { - line := io.read_line(^reader, consume_newline=true); + while !io.reader_empty(&reader) { + line := io.read_line(&reader, consume_newline=true); left, right := do { parts := string.split(line, #char "-"); - defer memory.free_slice(^parts); + defer memory.free_slice(&parts); return string.strip_whitespace(parts[0]), string.strip_whitespace(parts[1]); }; @@ -40,7 +40,7 @@ main :: (args) => { node_stack: [..] Node; node_stack << .{ "start", 0, false }; - children_of :: (edges: ^$T, name: str) -> Iterator(str) { + children_of :: (edges: &$T, name: str) -> Iterator(str) { name_copy := make_temp(str); *name_copy = name; @@ -61,8 +61,8 @@ main :: (args) => { } edge_map: Map(str, [] str); - for v: iter.as_iter(^verticies) { - edge_map[*v] = children_of(^edges, *v) |> iter.to_array(); + for v: iter.as_iter(&verticies) { + edge_map[*v] = children_of(&edges, *v) |> iter.to_array(); } paths_count := 0; @@ -79,7 +79,7 @@ main :: (args) => { if cannot_visit_multiple(child) { visit_count := 0; - for^ node_stack { + for& node_stack { if it.name == child do visit_count += 1; } @@ -94,7 +94,7 @@ main :: (args) => { else do node_stack << .{ child, 0, second_visit }; } else { - array.pop(^node_stack); + array.pop(&node_stack); } } diff --git a/tests/aoc-2021/day13.onyx b/tests/aoc-2021/day13.onyx index ed19deb5..7876fb02 100644 --- a/tests/aoc-2021/day13.onyx +++ b/tests/aoc-2021/day13.onyx @@ -12,8 +12,8 @@ cmp_point :: (p1, p2: Point) => { return p1.y - p2.y; } -apply_fold :: (dots: ^[] Point, axis_name: str, axis_value: i32) { - for^ *dots do switch axis_name { +apply_fold :: (dots: &[] Point, axis_name: str, axis_value: i32) { + for& *dots do switch axis_name { case "x" do if it.x > axis_value do it.x = 2 * axis_value - it.x; case "y" do if it.y > axis_value do it.y = 2 * axis_value - it.y; } @@ -28,8 +28,8 @@ main :: (args) => { dots: [..] Point; while true { - line := io.read_line(^reader, consume_newline=true, inplace=true); - string.strip_whitespace(^line); + line := io.read_line(&reader, consume_newline=true, inplace=true); + string.strip_whitespace(&line); if line.count == 0 do break; parts := string.split_iter(line, #char ",") @@ -42,17 +42,17 @@ main :: (args) => { } part_1_answer := -1; - while !io.reader_empty(^reader) { - line := io.read_line(^reader, consume_newline=true, inplace=true); + while !io.reader_empty(&reader) { + line := io.read_line(&reader, consume_newline=true, inplace=true); - string.read_until(^line, #char " ", 1); - string.advance(^line, 1); + string.read_until(&line, #char " ", 1); + string.advance(&line, 1); - axis_name := string.read_until(^line, #char "="); - string.advance(^line, 1); + axis_name := string.read_until(&line, #char "="); + string.advance(&line, 1); axis_value := cast(i32) conv.str_to_i64(line); - apply_fold(~~ ^dots, axis_name, axis_value); + apply_fold(~~ &dots, axis_name, axis_value); if part_1_answer < 0 { part_1_answer = dots.count; } diff --git a/tests/aoc-2021/day14.onyx b/tests/aoc-2021/day14.onyx index 8716771e..d43166f4 100644 --- a/tests/aoc-2021/day14.onyx +++ b/tests/aoc-2021/day14.onyx @@ -12,7 +12,7 @@ State :: struct { } // Nicer way of printing a Map. -#match io.write (w: ^io.Writer, x: ^Map($K, $V)) { +#match io.write (w: &io.Writer, x: &Map($K, $V)) { io.write(w, "{\n"); for e: x.entries { io.write(w, " {} => {}\n", e.key, e.value); @@ -24,31 +24,31 @@ main :: (args) => { for file: os.with_file("./tests/aoc-2021/input/day14.txt") { reader := io.reader_make(file); - start_polymer := io.read_line(^reader, consume_newline=false); - io.skip_whitespace(^reader); + start_polymer := io.read_line(&reader, consume_newline=false); + io.skip_whitespace(&reader); rules: [..] Rule; - while !io.reader_empty(^reader) { + while !io.reader_empty(&reader) { r: Rule; - io.read_bytes(^reader, .{cast(^u8) ^r.pair, 2}); - io.skip_bytes(^reader, 4); - r.insert = io.read_byte(^reader); + io.read_bytes(&reader, .{cast(&u8) &r.pair, 2}); + io.skip_bytes(&reader, 4); + r.insert = io.read_byte(&reader); rules << r; - io.skip_whitespace(^reader); + io.skip_whitespace(&reader); } polymer_state: Map(Pair(u8, u8), State); add_to_state :: macro (pair: Pair(u8, u8), count: u64) { if polymer_state->has(pair) { - (^polymer_state[pair]).next += ~~count; + (&polymer_state[pair]).next += ~~count; } else { polymer_state[pair] = .{ 0, ~~count }; } } step_state :: macro () { - for^ polymer_state.entries { + for& polymer_state.entries { it.value.now = it.value.next; it.value.next = 0; } @@ -62,8 +62,8 @@ main :: (args) => { step_state(); for 40 { - for^ rule: rules { - pair_count := ^polymer_state[rule.pair]; + for& rule: rules { + pair_count := &polymer_state[rule.pair]; if pair_count != null { if pair_count.now > 0 { pair1 := Pair(u8, u8).{ rule.pair.first, rule.insert }; @@ -77,14 +77,14 @@ main :: (args) => { } mode: Map(u8, u64); - for^ polymer_state.entries { + for& polymer_state.entries { mode[it.key.second] = mode[it.key.second] + it.value.now; } maximum := array.fold(mode.entries, cast(u64) 0, (x, y) => math.max(x.value, y)); minimum := array.fold(mode.entries, maximum, (x, y) => math.min(x.value, y)); - println(^mode); + println(&mode); printf("Part 2: {}\n", maximum - minimum - 1); } } diff --git a/tests/aoc-2021/day15.onyx b/tests/aoc-2021/day15.onyx index 86866002..c05ca031 100644 --- a/tests/aoc-2021/day15.onyx +++ b/tests/aoc-2021/day15.onyx @@ -15,9 +15,9 @@ main :: (args) => { cells: [..] u8; height := 0; - while !io.reader_empty(^reader) { - line := io.read_line(^reader, consume_newline=false, inplace=true); - io.skip_whitespace(^reader); + while !io.reader_empty(&reader) { + line := io.read_line(&reader, consume_newline=false, inplace=true); + io.skip_whitespace(&reader); for line do cells << it; height += 1; @@ -32,7 +32,7 @@ main :: (args) => { minimum := 0; while to_try.data.count != 0 { - try := heap.remove_top(^to_try); + try := heap.remove_top(&to_try); tried << .{try.x, try.y}; cell_value := cast(u32) (cells[(try.y % height) * width + (try.x % width)] - #char "0"); diff --git a/tests/aoc-2021/day16.onyx b/tests/aoc-2021/day16.onyx index 30bef44a..941d4abd 100644 --- a/tests/aoc-2021/day16.onyx +++ b/tests/aoc-2021/day16.onyx @@ -25,20 +25,20 @@ BitIterator :: struct { value_idx: u32; bit_idx: i32; - next :: (b: ^BitIterator) -> u32 { + next :: (b: &BitIterator) -> u32 { v, _ := iter.take_one(b.iter, no_close=true); return v; } } -bit_iterator :: (values: [] u8) -> ^BitIterator { +bit_iterator :: (values: [] u8) -> &BitIterator { c := new(BitIterator); c.iter = .{ c, next, cfree }; c.values = values; c.value_idx = 0; c.bit_idx = 7; - next :: (use c: ^BitIterator) -> (u32, bool) { + next :: (use c: &BitIterator) -> (u32, bool) { if value_idx >= values.count do return 0, false; defer { @@ -58,7 +58,7 @@ bit_iterator :: (values: [] u8) -> ^BitIterator { return c; } -read_bits :: (bit_provider: ^BitIterator, count: u32) -> u32 { +read_bits :: (bit_provider: &BitIterator, count: u32) -> u32 { res := 0; for count { res *= 2; @@ -83,10 +83,10 @@ Packet_Literal :: struct { Packet_Operator :: struct { use base: Packet; - subpackets: [] ^Packet; + subpackets: [] &Packet; } -parse_packet :: (bit_provider: ^BitIterator) -> ^Packet { +parse_packet :: (bit_provider: &BitIterator) -> &Packet { version := read_bits(bit_provider, 3); type := read_bits(bit_provider, 3); @@ -109,7 +109,7 @@ parse_packet :: (bit_provider: ^BitIterator) -> ^Packet { } case #default { - packets: [..] ^Packet; + packets: [..] &Packet; l_type := read_bits(bit_provider, 1); if l_type == 0 { @@ -137,13 +137,13 @@ parse_packet :: (bit_provider: ^BitIterator) -> ^Packet { } } -packet_sum_version :: (p: ^Packet) -> u64 { +packet_sum_version :: (p: &Packet) -> u64 { switch p.type { case 4 do return ~~p.version; case #default { sum: u64; - for (cast (^Packet_Operator) p).subpackets { + for (cast (&Packet_Operator) p).subpackets { sum += packet_sum_version(it); } @@ -152,8 +152,8 @@ packet_sum_version :: (p: ^Packet) -> u64 { } } -packet_reduce :: (p: ^Packet) -> u64 { - op := cast(^Packet_Operator) p; +packet_reduce :: (p: &Packet) -> u64 { + op := cast(&Packet_Operator) p; switch p.type { case 0 { return array.fold(op.subpackets, cast(u64) 0, (x, y) => y + packet_reduce(x)); @@ -172,7 +172,7 @@ packet_reduce :: (p: ^Packet) -> u64 { } case 4 { - return (cast(^Packet_Literal) p).value; + return (cast(&Packet_Literal) p).value; } case 5 { @@ -193,7 +193,7 @@ packet_reduce :: (p: ^Packet) -> u64 { main :: (args) => { for file: os.with_file("./tests/aoc-2021/input/day16.txt") { reader := io.reader_make(file); - line := io.read_line(^reader, consume_newline=false, inplace=true); + line := io.read_line(&reader, consume_newline=false, inplace=true); transmission: [..] u8; for i: range.{ 0, line.count, 2 } { diff --git a/tests/aoc-2021/day17.onyx b/tests/aoc-2021/day17.onyx index 03d9f671..529bfbba 100644 --- a/tests/aoc-2021/day17.onyx +++ b/tests/aoc-2021/day17.onyx @@ -33,14 +33,14 @@ main :: (args) => { for file: os.with_file("./tests/aoc-2021/input/day17.txt") { reader := io.reader_make(file); - io.skip_bytes(^reader, 15); - tx0 = io.read_i32(^reader); - io.skip_bytes(^reader, 2); - tx1 = io.read_i32(^reader); - io.skip_bytes(^reader, 4); - ty0 = io.read_i32(^reader); - io.skip_bytes(^reader, 2); - ty1 = io.read_i32(^reader); + io.skip_bytes(&reader, 15); + tx0 = io.read_i32(&reader); + io.skip_bytes(&reader, 2); + tx1 = io.read_i32(&reader); + io.skip_bytes(&reader, 4); + ty0 = io.read_i32(&reader); + io.skip_bytes(&reader, 2); + ty1 = io.read_i32(&reader); } max := 0; diff --git a/tests/aoc-2021/day18.onyx b/tests/aoc-2021/day18.onyx index 77a8a1f1..cc308572 100644 --- a/tests/aoc-2021/day18.onyx +++ b/tests/aoc-2021/day18.onyx @@ -8,8 +8,8 @@ use core.alloc {arena} num_allocator: Allocator; SnailNum :: struct { - parent: ^SnailNum; - left, right: ^SnailNum; + parent: &SnailNum; + left, right: &SnailNum; left_val, right_val: u32; } @@ -29,7 +29,7 @@ SnailNum :: struct { return n; } - clone :: (n: ^SnailNum) -> ^SnailNum { + clone :: (n: &SnailNum) -> &SnailNum { if !n do return null; new_num := SnailNum.make(); @@ -41,7 +41,7 @@ SnailNum :: struct { return new_num; } - add :: (a, b: ^SnailNum) => { + add :: (a, b: &SnailNum) => { if !a do return b; if !b do return a; @@ -54,13 +54,13 @@ SnailNum :: struct { return new_root; } - reduce :: (use n: ^SnailNum) -> (reduced_something: bool) { + reduce :: (use n: &SnailNum) -> (reduced_something: bool) { if r, _ := n->reduce_explodes(); r do return true; if r := n->reduce_splits(); r do return true; return false; } - reduce_explodes :: (use n: ^SnailNum, depth := 0) -> (reduced_something: bool, zero_node: bool) { + reduce_explodes :: (use n: &SnailNum, depth := 0) -> (reduced_something: bool, zero_node: bool) { if depth <= 3 { if left != null { if did_reduce, zero_node := left->reduce_explodes(depth + 1); zero_node { @@ -96,7 +96,7 @@ SnailNum :: struct { return true, true; } - reduce_splits :: (use n: ^SnailNum) -> (reduced_something: bool) { + reduce_splits :: (use n: &SnailNum) -> (reduced_something: bool) { if left { if left->reduce_splits() { return true; @@ -129,26 +129,26 @@ SnailNum :: struct { } } - set_left :: (parent, new_left: ^SnailNum) { + set_left :: (parent, new_left: &SnailNum) { parent.left_val = 0; parent.left = new_left; if new_left do new_left.parent = parent; } - set_right :: (parent, new_right: ^SnailNum) { + set_right :: (parent, new_right: &SnailNum) { parent.right_val = 0; parent.right = new_right; if new_right do new_right.parent = parent; } - number_to_left :: (n: ^SnailNum) -> ^u32 { + number_to_left :: (n: &SnailNum) -> &u32 { while n.parent && n.parent.left == n { n = n.parent; } if !n.parent do return null; - if !n.parent.left do return ^n.parent.left_val; + if !n.parent.left do return &n.parent.left_val; n = n.parent.left; @@ -156,17 +156,17 @@ SnailNum :: struct { n = n.right; } - return ^n.right_val; + return &n.right_val; } - number_to_right :: (n: ^SnailNum) -> ^u32 { + number_to_right :: (n: &SnailNum) -> &u32 { while n.parent && n.parent.right == n { n = n.parent; } if !n.parent do return null; - if !n.parent.right do return ^n.parent.right_val; + if !n.parent.right do return &n.parent.right_val; n = n.parent.right; @@ -174,10 +174,10 @@ SnailNum :: struct { n = n.left; } - return ^n.left_val; + return &n.left_val; } - magnitude :: (use n: ^SnailNum) => { + magnitude :: (use n: &SnailNum) => { if !n { return 0; } @@ -186,7 +186,7 @@ SnailNum :: struct { + 2 * (right_val + right->magnitude()); } - parse :: (line: ^str) -> ^SnailNum { + parse :: (line: &str) -> &SnailNum { string.advance(line); // [ root := SnailNum.make(); @@ -209,7 +209,7 @@ SnailNum :: struct { return root; } - format :: (output: ^conv.Format_Output, s: ^conv.Format, use n: ^SnailNum) { + format :: (output: &conv.Format_Output, s: &conv.Format, use n: &SnailNum) { if !left && !right { conv.format(output, "[{},{}]", left_val, right_val); } @@ -229,7 +229,7 @@ SnailNum :: struct { main :: () { num_arena := arena.make(context.allocator, 256 * 1024); - SnailNum.allocator = alloc.as_allocator(^num_arena); + SnailNum.allocator = alloc.as_allocator(&num_arena); conv.register_custom_formatter(SnailNum.format); @@ -237,10 +237,10 @@ main :: () { r := io.reader_make(file); #if PART == 1 { - s: ^SnailNum = null; + s: &SnailNum = null; for line: r->lines() { - n := SnailNum.parse(^line); + n := SnailNum.parse(&line); s = s->add(n); } @@ -248,9 +248,9 @@ main :: () { } #if PART == 2 { - nums := make([..] ^SnailNum); + nums := make([..] &SnailNum); for line: r->lines() { - nums << SnailNum.parse(^line); + nums << SnailNum.parse(&line); } maximum := 0; diff --git a/tests/aoc-2021/day21.onyx b/tests/aoc-2021/day21.onyx index 639fb6c5..dd552be3 100644 --- a/tests/aoc-2021/day21.onyx +++ b/tests/aoc-2021/day21.onyx @@ -14,7 +14,7 @@ Die :: struct { return .{ 1, 0 }; } - roll :: (d: ^Die) -> u32 { + roll :: (d: &Die) -> u32 { defer d.value += 1; defer d.rolls += 1; return d.value; @@ -27,7 +27,7 @@ Player :: struct { } #inject Player { - move :: (p: ^Player, squares: u32) { + move :: (p: &Player, squares: u32) { p.square += squares; p.square %= 10; @@ -47,8 +47,8 @@ main :: () { _, s1 := string.bisect(l1, #char ":"); _, s2 := string.bisect(l2, #char ":"); - string.strip_whitespace(^s1); - string.strip_whitespace(^s2); + string.strip_whitespace(&s1); + string.strip_whitespace(&s2); p1.square = ~~ (conv.str_to_i64(s1) - 1); p2.square = ~~ (conv.str_to_i64(s2) - 1); @@ -58,7 +58,7 @@ main :: () { losing_score: u32; while true { - play :: macro (player, opponent: ^Player) { + play :: macro (player, opponent: &Player) { r1 := die->roll(); r2 := die->roll(); r3 := die->roll(); @@ -71,8 +71,8 @@ main :: () { } } - play(^p1, ^p2); - play(^p2, ^p1); + play(&p1, &p2); + play(&p2, &p1); } println(losing_score * die.rolls); @@ -159,7 +159,7 @@ calc_wins :: (p1, p2: Player, player_1_turn := true) -> (u64, u64) { w1, w2: u64; if player_1_turn { - for^ cases { + for& cases { n1, n2 := calc_wins_memo( p1->move(it.spaces), p2, @@ -171,7 +171,7 @@ calc_wins :: (p1, p2: Player, player_1_turn := true) -> (u64, u64) { } } else { - for^ cases { + for& cases { n1, n2 := calc_wins_memo( p1, p2->move(it.spaces), @@ -199,8 +199,8 @@ main :: () { _, s1 := string.bisect(l1, #char ":"); _, s2 := string.bisect(l2, #char ":"); - string.strip_whitespace(^s1); - string.strip_whitespace(^s2); + string.strip_whitespace(&s1); + string.strip_whitespace(&s2); p1.square = cast(i32) (conv.str_to_i64(s1) - 1); p2.square = cast(i32) (conv.str_to_i64(s2) - 1); diff --git a/tests/array_struct_robustness.onyx b/tests/array_struct_robustness.onyx index f487e8cd..de454d54 100644 --- a/tests/array_struct_robustness.onyx +++ b/tests/array_struct_robustness.onyx @@ -5,7 +5,7 @@ use package core Vec2 :: struct { x: i32; y: i32; } // Overload print() to print Vec2's. -#match io.write (use writer: ^io.Writer, use v: Vec2) { +#match io.write (use writer: &io.Writer, use v: Vec2) { io.write_format(writer, "Vec2({}, {})", x, y); } @@ -18,7 +18,7 @@ calc_vecs :: (n := 0) -> [4] Vec2 { vecs : [4] Vec2; i := n; - for ^v: vecs { + for &v: 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: 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: 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: nums { *n = i * i; i += 5; } @@ -100,12 +100,12 @@ main :: (args: [] cstr) { println("2D-array from an allocation to a function."); vecs_data: [2][4] Vec2; - vecs := ^vecs_data; // equivalent of heap allocating it + vecs := &vecs_data; // equivalent of heap allocating it - set_vecs :: (vecs: ^[2][4] Vec2) { + set_vecs :: (vecs: &[2][4] Vec2) { i := 0; - for ^row: *vecs { - for ^v: *row { + for &row: *vecs { + for &v: *row { *v = .{ 1000 + i, 2000 + i * i }; i += 1; } @@ -114,11 +114,11 @@ main :: (args: [] cstr) { set_vecs(vecs); - print_vecs :: (vecs: ^[4] Vec2) { - for ^v: *vecs do println(*v); + print_vecs :: (vecs: &[4] Vec2) { + for &v: *vecs do println(*v); } - print_vecs(^(*vecs)[0]); - print_vecs(^(*vecs)[1]); + print_vecs(&(*vecs)[0]); + print_vecs(&(*vecs)[1]); } } diff --git a/tests/arrow_notation.onyx b/tests/arrow_notation.onyx index 5bffa291..dcbbd11b 100644 --- a/tests/arrow_notation.onyx +++ b/tests/arrow_notation.onyx @@ -8,12 +8,12 @@ V2 :: struct { add :: (v1, v2: V2) => V2.{v1.x+v2.x, v1.y+v2.y}; - add_inplace :: (v1: ^V2, v2: V2) { + add_inplace :: (v1: &V2, v2: V2) { v1.x += v2.x; v1.y += v2.y; } - format :: (output: ^conv.Format_Output, _: ^conv.Format, v: ^V2) { + format :: (output: &conv.Format_Output, _: &conv.Format, v: &V2) { conv.format(output, "({}, {})", v.x, v.y); } } diff --git a/tests/atomics.onyx b/tests/atomics.onyx index f935cfac..2bc90761 100644 --- a/tests/atomics.onyx +++ b/tests/atomics.onyx @@ -21,8 +21,8 @@ test_var := 5678; print_from_other_thread :: (sd) => { // Creating high contention for the shared resource for i: 10000 { - sync.scoped_mutex(^shared_mutex); - for ^v: sd.arr { + sync.scoped_mutex(&shared_mutex); + for &v: sd.arr { *v += 1; } } @@ -36,7 +36,7 @@ print_from_other_thread :: (sd) => { } main :: (args) => { - sync.mutex_init(^shared_mutex); + sync.mutex_init(&shared_mutex); test_var = 1234; println(test_var); @@ -46,16 +46,16 @@ main :: (args) => { array.fill(sd.arr, 0); threads : [4] thread.Thread; - for ^t: threads { - thread.spawn(t, ^sd, print_from_other_thread); + for &t: threads { + thread.spawn(t, &sd, print_from_other_thread); printf("Spawned thread {}\n", t.id); } - memory.alloc_slice(^partial_arr, 10); + memory.alloc_slice(&partial_arr, 10); for i: 10 do partial_arr[i] = i; printf("Waiting...\n"); - for ^t: threads { + for &t: threads { thread.join(t); printf("Thread {} joined!\n", t.id); } diff --git a/tests/auto_poly.onyx b/tests/auto_poly.onyx index 6c1a15cb..186c01b4 100644 --- a/tests/auto_poly.onyx +++ b/tests/auto_poly.onyx @@ -2,7 +2,7 @@ use package core -dumb :: (it: Iterator, m: ^Map) { +dumb :: (it: Iterator, m: &Map) { println(it.Iter_Type); println(__autopoly_var_0); println(typeof *m); @@ -14,7 +14,7 @@ Vector2 :: struct (T: type_expr) { vec_add :: (v1: Vector2, v2: typeof v1) => (typeof v1).{ v1.x + v2.x, v1.y + v2.y }; -mappable :: (k: m.Key_Type, m: ^Map, x: $T) { +mappable :: (k: m.Key_Type, m: &Map, x: $T) { printf("{} to {}\n", m.Key_Type, m.Value_Type); println(k); println(x); @@ -24,24 +24,24 @@ Thing :: struct (type: type_expr) { value: type; } -f :: (thing: ^Thing, other: typeof thing) { +f :: (thing: &Thing, other: typeof thing) { printf("type of thing is {}\n", typeof thing); printf("thing is {}\n", *thing); } main :: (args) => { m: Map(i32, str); - dumb(iter.as_iter(1 .. 10), ^m); + dumb(iter.as_iter(1 .. 10), &m); V :: Vector2(i32) v1 := V.{ 1, 0 }; v2 := V.{ 0, 1 }; println(vec_add(v1, v2)); - mappable(1234, ^m, "WOOT WOOT!!!"); + mappable(1234, &m, "WOOT WOOT!!!"); t: Thing(f32); - f(^t, ^t); + f(&t, &t); for iter.as_iter(0 .. 100) |> iter.map(x => x * 2) |> iter.filter(x => x <= 10) { println(it); diff --git a/tests/avl_test.onyx b/tests/avl_test.onyx index a727e494..ab818a3a 100644 --- a/tests/avl_test.onyx +++ b/tests/avl_test.onyx @@ -3,15 +3,15 @@ use package core main :: () { - tree: ^avl_tree.AVL_Tree(i32); + tree: &avl_tree.AVL_Tree(i32); - avl_tree.insert(^tree, 20); - avl_tree.insert(^tree, 5); - avl_tree.insert(^tree, 8); - avl_tree.insert(^tree, 25); - avl_tree.insert(^tree, 0); - avl_tree.insert(^tree, 15); - avl_tree.insert(^tree, 10); + avl_tree.insert(&tree, 20); + avl_tree.insert(&tree, 5); + avl_tree.insert(&tree, 8); + avl_tree.insert(&tree, 25); + avl_tree.insert(&tree, 0); + avl_tree.insert(&tree, 15); + avl_tree.insert(&tree, 10); avl_tree.print(tree); print("\n"); diff --git a/tests/baked_parameters.onyx b/tests/baked_parameters.onyx index f0325ac3..cb0e4cdd 100644 --- a/tests/baked_parameters.onyx +++ b/tests/baked_parameters.onyx @@ -8,7 +8,7 @@ count_to :: ($N: i32) { } alloc_slice :: ($T: type_expr, N: i32) -> [] T { - data := cast(^T) calloc(sizeof T * N); + data := cast(&T) calloc(sizeof T * N); return .{ data, N }; } @@ -25,27 +25,27 @@ main :: (args: [] cstr) { count_to(UP_TO); sl := alloc_slice(i32, 10); - for ^ sl do *it = 1234; + for & sl do *it = 1234; for sl do println(it); // This is so much cleaner than the alternative. ages := map.make(str, u32, default=0); - defer delete(^ages); + defer delete(&ages); - map.put(^ages, "Dwight", 32); - map.put(^ages, "Jim", 25); - map.put(^ages, "Pam", 24); + map.put(&ages, "Dwight", 32); + map.put(&ages, "Jim", 25); + map.put(&ages, "Pam", 24); - print_age :: (ages: ^map.Map(str, u32), name: str) { + print_age :: (ages: &map.Map(str, u32), name: str) { age := map.get(ages, name); printf("{}'s age is {}.\n", name, age); } - print_age(^ages, "Dwight"); - print_age(^ages, "Jim"); - print_age(^ages, "Pam"); - print_age(^ages, "Michael"); + print_age(&ages, "Dwight"); + print_age(&ages, "Jim"); + print_age(&ages, "Pam"); + print_age(&ages, "Michael"); } diff --git a/tests/bucket_array.onyx b/tests/bucket_array.onyx index 550dbfa3..3e06092a 100644 --- a/tests/bucket_array.onyx +++ b/tests/bucket_array.onyx @@ -14,7 +14,7 @@ main :: (args: [] cstr) { sum += *it; }); - for it: bucket_array.as_iter(^ba) { + for it: bucket_array.as_iter(&ba) { printf("{}\n", it); } diff --git a/tests/bugs/anonymous_struct_defaults.onyx b/tests/bugs/anonymous_struct_defaults.onyx index 9bd635d8..81a8d338 100644 --- a/tests/bugs/anonymous_struct_defaults.onyx +++ b/tests/bugs/anonymous_struct_defaults.onyx @@ -11,13 +11,13 @@ S :: struct { main :: (args) => { v: S; - array.init(^v.some_array); + array.init(&v.some_array); - do_something_with_S(^v); + do_something_with_S(&v); - printf("{*p}\n", ^v); + printf("{*p}\n", &v); } -do_something_with_S :: (s: ^S) { +do_something_with_S :: (s: &S) { s.some_array << .{ "Joe", 14 }; } diff --git a/tests/bugs/double_polymorph_yield_error.onyx b/tests/bugs/double_polymorph_yield_error.onyx index 96e4b032..790f5779 100644 --- a/tests/bugs/double_polymorph_yield_error.onyx +++ b/tests/bugs/double_polymorph_yield_error.onyx @@ -2,7 +2,7 @@ use core -q :: (v: ^$C, g: (^C) -> $T) { +q :: (v: &$C, g: (&C) -> $T) { println(*v); println(g(v)); println(T); @@ -11,5 +11,5 @@ q :: (v: ^$C, g: (^C) -> $T) { main :: () { v := 5; - q(^v, _ => false); + q(&v, _ => false); } diff --git a/tests/bugs/macro_auto_return_not_resolved.onyx b/tests/bugs/macro_auto_return_not_resolved.onyx index 3a289d59..691ed8fb 100644 --- a/tests/bugs/macro_auto_return_not_resolved.onyx +++ b/tests/bugs/macro_auto_return_not_resolved.onyx @@ -17,5 +17,5 @@ main :: (args) => { S << Point.{ 2, 3 }; S << Point.{ 1, 2 }; - set.has(^S, Point.{ 1, 2 }) |> println(); + set.has(&S, Point.{ 1, 2 }) |> println(); } diff --git a/tests/bugs/method_call_source_double.onyx b/tests/bugs/method_call_source_double.onyx index bf2a2d38..63866adb 100644 --- a/tests/bugs/method_call_source_double.onyx +++ b/tests/bugs/method_call_source_double.onyx @@ -3,11 +3,11 @@ use core Foo :: struct { - use vtable: ^VTable; + use vtable: &VTable; x: u32; VTable :: struct { - f: (^Foo) -> void; + f: (&Foo) -> void; } } @@ -18,9 +18,9 @@ good_foo := Foo.VTable.{ } } -make_foo :: () -> ^Foo { +make_foo :: () -> &Foo { foo := new(Foo); - foo.vtable = ^good_foo; + foo.vtable = &good_foo; foo.x = 1234; printf("Made foo!\n"); @@ -30,6 +30,6 @@ make_foo :: () -> ^Foo { main :: () { make_foo()->f(); - Foo.{^good_foo, 5678}->f(); + Foo.{&good_foo, 5678}->f(); } diff --git a/tests/caller_location.onyx b/tests/caller_location.onyx index be91947a..fe27a40c 100644 --- a/tests/caller_location.onyx +++ b/tests/caller_location.onyx @@ -20,7 +20,7 @@ main :: (args: [] cstr) { Something :: struct { member := cast(u32) 1234; - method :: (use s: ^Something) { + method :: (use s: &Something) { using_callsite(member); } } diff --git a/tests/compile_time_procedures.onyx b/tests/compile_time_procedures.onyx index abc2cdae..bd51f2cd 100644 --- a/tests/compile_time_procedures.onyx +++ b/tests/compile_time_procedures.onyx @@ -21,7 +21,7 @@ test_vtable2 := Test_VTable.{ Test_Thing :: struct { - vt : ^Test_VTable; + vt : &Test_VTable; data : i32; } @@ -33,19 +33,19 @@ dummy := () { println("hello world!"); } main :: (args: [] cstr) { dummy(); - t := Test_Thing.{ ^test_vtable1, 10 }; - println(do_a_thing(^t)); + t := Test_Thing.{ &test_vtable1, 10 }; + println(do_a_thing(&t)); - t.vt = ^test_vtable2; - println(do_a_thing(^t)); + t.vt = &test_vtable2; + println(do_a_thing(&t)); tmp_vt := Test_VTable.{ first = test_vtable1.second, second = test_vtable2.first, third = math.max_poly }; - t.vt = ^tmp_vt; - println(do_a_thing(^t)); + t.vt = &tmp_vt; + println(do_a_thing(&t)); println(t.vt.first == test_vtable1.second); - do_a_thing :: (use t: ^Test_Thing) -> i32 { + do_a_thing :: (use t: &Test_Thing) -> i32 { if vt.second == null_proc || vt.first == null_proc do return data; res := data |> vt.second() |> vt.first(); diff --git a/tests/complicated_polymorph.onyx b/tests/complicated_polymorph.onyx index 754edbc4..9c985dfb 100644 --- a/tests/complicated_polymorph.onyx +++ b/tests/complicated_polymorph.onyx @@ -45,13 +45,13 @@ main :: (args: [] cstr) { } Guy :: struct { - best_friend: ^Guy; + best_friend: &Guy; favorite_color: Color; } nightmare :: (x: (typeof(z.best_friend), $K) -> void, y: (typeof(x)) -> $R, - z: ^$SomeType, + z: &$SomeType, w: R) { k := y(x); } @@ -60,7 +60,7 @@ main :: (args: [] cstr) { printf("dummy1 got T={}, typeof(a.favorite_color)={}\n", a, typeof(b)); } - dummy2 :: (f: (a: ^Guy, b: $C) -> void) -> C { + dummy2 :: (f: (a: &Guy, b: $C) -> void) -> C { printf("dummy2 got C={}\n", C); other_guy := new(Guy); diff --git a/tests/i32map.onyx b/tests/i32map.onyx index 38cb2574..db403f76 100644 --- a/tests/i32map.onyx +++ b/tests/i32map.onyx @@ -6,24 +6,24 @@ use package core main :: (args: [] cstr) { imap : Map(i32, str); - map.init(^imap, ""); + map.init(&imap, ""); defer { print("Freeing map\n"); - map.free(^imap); + map.free(&imap); } - map.put(^imap, 50, "Hello "); + map.put(&imap, 50, "Hello "); imap->put(1234, "World!"); - println(map.has(^imap, 50)); - println(map.has(^imap, 51)); + println(map.has(&imap, 50)); + println(map.has(&imap, 51)); - printf("{}{}\n", map.get(^imap, 50), map.get(^imap, 1234)); + printf("{}{}\n", map.get(&imap, 50), map.get(&imap, 1234)); - printf("{*p}\n", ^imap); + printf("{*p}\n", &imap); - map.delete(^imap, 50); - println(map.has(^imap, 50)); + map.delete(&imap, 50); + println(map.has(&imap, 50)); - map.clear(^imap); - println(map.has(^imap, 1234)); + map.clear(&imap); + println(map.has(&imap, 1234)); } diff --git a/tests/implicit_initialize_locals.onyx b/tests/implicit_initialize_locals.onyx index 60e9943b..677bd23f 100644 --- a/tests/implicit_initialize_locals.onyx +++ b/tests/implicit_initialize_locals.onyx @@ -13,11 +13,11 @@ main :: (args) => { { arr: [..] i32; - printf("{*p}\n", cast(^array.Untyped_Array) ^arr); + printf("{*p}\n", cast(&array.Untyped_Array) &arr); people: Map(str, i32); people["Joe"] = 12; people["Jane"] = 34; - printf("{*p}\n", ^people.entries); + printf("{*p}\n", &people.entries); } } \ No newline at end of file diff --git a/tests/interfaces.onyx b/tests/interfaces.onyx index 8ba891ef..83a2a92f 100644 --- a/tests/interfaces.onyx +++ b/tests/interfaces.onyx @@ -57,7 +57,7 @@ BitField :: interface (t: $T) { Complex :: struct { x, y: f32; - format :: (output: ^conv.Format_Output, format: ^conv.Format, c: ^Complex) { + format :: (output: &conv.Format_Output, format: &conv.Format, c: &Complex) { conv.format(output, "{.2} + {.2}i", c.x, c.y); } } @@ -76,7 +76,7 @@ consume :: macro (x: $T/iter.Iterable) => { // everything WAY more complicated. consume_inner :: #match { // Iterator over pointers get dereferenced - macro (iter: Iterator(^$T)) -> [..] T { + macro (iter: Iterator(&$T)) -> [..] T { arr := array.make(T); for iter do arr << *it; return arr; @@ -105,7 +105,7 @@ main :: (args: [] cstr) { // println(bit_math(3.0, 4.0)); a := consume(f32.[4,2,4,7,4]); - defer array.free(^a); + defer array.free(&a); println(a); consume(1 .. 10) |> println(); diff --git a/tests/lazy_iterators.onyx b/tests/lazy_iterators.onyx index 42b630f9..8f6fff7d 100644 --- a/tests/lazy_iterators.onyx +++ b/tests/lazy_iterators.onyx @@ -4,7 +4,7 @@ use package core count_iterator :: (lo: $T, hi: T, step: T = 1) -> Iterator(T) { return iter.generator( - ^.{ low = lo, high = hi, step = step, current = lo }, + &.{ low = lo, high = hi, step = step, current = lo }, (ctx) => { if ctx.current <= ctx.high { diff --git a/tests/multiple_returns_robustness.onyx b/tests/multiple_returns_robustness.onyx index 79c3a10d..9ee7330e 100644 --- a/tests/multiple_returns_robustness.onyx +++ b/tests/multiple_returns_robustness.onyx @@ -48,7 +48,7 @@ main :: (args: [] cstr) { array_print(farr); array_print :: (arr: [$N] $T) { - for ^e: arr { + for &e: arr { print(*e); print(" "); } diff --git a/tests/new_struct_behaviour.onyx b/tests/new_struct_behaviour.onyx index 600169ee..5bd6382d 100644 --- a/tests/new_struct_behaviour.onyx +++ b/tests/new_struct_behaviour.onyx @@ -18,7 +18,7 @@ Foo :: struct { member1 := get_a_value(f32); member2 := get_a_value(i32); - get_member2_plus_three :: (foo: ^Foo) -> i32 { + get_member2_plus_three :: (foo: &Foo) -> i32 { return foo.member2 + 3; } @@ -35,7 +35,7 @@ Foo2 :: struct { age : i32; } - get_member2_plus_three :: (foo: ^$T) -> f32 { + get_member2_plus_three :: (foo: &$T) -> f32 { return foo.member2 + 3; } diff --git a/tests/no_types.onyx b/tests/no_types.onyx index 4bc7058f..6a134037 100644 --- a/tests/no_types.onyx +++ b/tests/no_types.onyx @@ -14,7 +14,7 @@ main :: () { }; for 40 { - step_physics(^object, 0.01); + step_physics(&object, 0.01); printf("{}\n", object); } } diff --git a/tests/parallel_for.onyx b/tests/parallel_for.onyx index 32808165..662e3fcd 100644 --- a/tests/parallel_for.onyx +++ b/tests/parallel_for.onyx @@ -4,13 +4,13 @@ main :: () { sum := 0; thread_data := .{ - sum = ^sum, + sum = &sum, mutex = sync.Mutex.{}, }; - sync.mutex_init(^thread_data.mutex); + sync.mutex_init(&thread_data.mutex); - iter.parallel_for(0 .. 10000, 4, ^thread_data) { - sync.scoped_mutex(^thread_data.mutex); + iter.parallel_for(0 .. 10000, 4, &thread_data) { + sync.scoped_mutex(&thread_data.mutex); *thread_data.sum += it; } diff --git a/tests/persist_locals.onyx b/tests/persist_locals.onyx index 8e9108fa..835dab2f 100644 --- a/tests/persist_locals.onyx +++ b/tests/persist_locals.onyx @@ -28,14 +28,14 @@ foo :: (x: i32) -> i32 { cached_fib :: (n: u64) -> u64 { #persist cache : map.Map(u64, u64); - _ :: #init () { map.init(^cache); }; + _ :: #init () { map.init(&cache); }; if n <= 1 do return n; - if map.has(^cache, n) do return map.get(^cache, n); + if map.has(&cache, n) do return map.get(&cache, n); res := cached_fib(n - 1) + cached_fib(n - 2); - map.put(^cache, n, res); + map.put(&cache, n, res); print_cache_size(); diff --git a/tests/poly_structs_with_values.onyx b/tests/poly_structs_with_values.onyx index 9fd5eeb4..21d6b932 100644 --- a/tests/poly_structs_with_values.onyx +++ b/tests/poly_structs_with_values.onyx @@ -10,8 +10,8 @@ main :: (args: [] cstr) { nps : NewPolyStruct(i32, 4); - for ^x: nps.x do *x = 12345; - for ^y: nps.y do *y = 67890; + for &x: nps.x do *x = 12345; + for &y: nps.y do *y = 67890; for x: nps.x do println(x); diff --git a/tests/remove_test.onyx b/tests/remove_test.onyx index ddddedb9..be929078 100644 --- a/tests/remove_test.onyx +++ b/tests/remove_test.onyx @@ -8,7 +8,7 @@ main :: (args) => { println(x); - for iter.as_iter(^x) { + for iter.as_iter(&x) { if it % 2 == 0 { #remove; } diff --git a/tests/sets.onyx b/tests/sets.onyx index aaf1875a..bea6234f 100644 --- a/tests/sets.onyx +++ b/tests/sets.onyx @@ -6,15 +6,15 @@ main :: (args: [] cstr) { S := set.make(i32); - set.insert(^S, 5); - set.insert(^S, 5); - set.insert(^S, 6); + set.insert(&S, 5); + set.insert(&S, 5); + set.insert(&S, 6); for entry: S.entries do println(entry.value); - println(set.has(^S, 5)); + println(set.has(&S, 5)); println("--------------"); - set.remove(^S, 5); + set.remove(&S, 5); for entry: S.entries do println(entry.value); - println(set.has(^S, 5)); + println(set.has(&S, 5)); } \ No newline at end of file diff --git a/tests/string_stream_test.onyx b/tests/string_stream_test.onyx index 9f722810..0e97c870 100644 --- a/tests/string_stream_test.onyx +++ b/tests/string_stream_test.onyx @@ -6,17 +6,17 @@ main :: (args: [] cstr) { some_string := "This is a test string that can be read.\n\n\n\n\n\n1234 4567"; sstream := io.buffer_stream_make(some_string); - sreader := io.reader_make(^sstream); + sreader := io.reader_make(&sstream); for i: 0 .. 2 { - word := io.read_word(^sreader, allocator=context.temp_allocator); + word := io.read_word(&sreader, allocator=context.temp_allocator); println(word); } - println(io.read_line(^sreader, consume_newline=false, allocator=context.temp_allocator)); + println(io.read_line(&sreader, consume_newline=false, allocator=context.temp_allocator)); - a := io.read_u32(^sreader); - b := io.read_u32(^sreader); + a := io.read_u32(&sreader); + b := io.read_u32(&sreader); println(a); println(b); diff --git a/tests/struct_use_pointer_member.onyx b/tests/struct_use_pointer_member.onyx index 14686b20..a2806513 100644 --- a/tests/struct_use_pointer_member.onyx +++ b/tests/struct_use_pointer_member.onyx @@ -2,30 +2,30 @@ use package core Person_Vtable :: struct { - greet: (^Person) -> void; + greet: (&Person) -> void; } Person :: struct { - use vtable: ^Person_Vtable; + use vtable: &Person_Vtable; name: str; } nice_person := Person_Vtable.{ - greet = (use p: ^Person) { + greet = (use p: &Person) { printf("Hello, I am {}!\n", name); } } mean_person := Person_Vtable.{ - greet = (use p: ^Person) { + greet = (use p: &Person) { printf("Go away!! {}\n", typeof greet); } } main :: (args) => { - billy := Person.{ ^nice_person, "Billy" }; - charles := Person.{ ^mean_person, "Charles" }; + billy := Person.{ &nice_person, "Billy" }; + charles := Person.{ &mean_person, "Charles" }; billy->greet(); charles->greet(); diff --git a/tests/vararg_test.onyx b/tests/vararg_test.onyx index d978577a..34ca9c55 100644 --- a/tests/vararg_test.onyx +++ b/tests/vararg_test.onyx @@ -16,7 +16,7 @@ new_va_test :: (prefix: str, va: ..any) { // The right way to do it is this: // x := * misc.any_as(va[i], i32); - x := *cast(^i32, va[i].data); + x := *cast(&i32, va[i].data); println(x); } }