diff --git a/day10.c3 b/day10.c3 index 8371f24..46fb65c 100644 --- a/day10.c3 +++ b/day10.c3 @@ -18,7 +18,7 @@ fn void draw_crt(bool[40][6]* crt) { io::print(pixel ? "#" : " "); } - io::println(); + io::printn(); } } @@ -34,8 +34,7 @@ fn void update_crt(bool[40][6]* crt, int cycle, int x) fn void part2() { - File f; - f.open("code.txt", "rb")!!; + File f = file::open("code.txt", "rb")!!; defer (void)f.close(); bool[40][6] crt; int cycle = 0; @@ -45,7 +44,7 @@ fn void part2() @pool() { String line = f.tgetline(); - String[] commands = str::tsplit(line, " "); + String[] commands = line.tsplit(" "); switch (commands[0]) { case "noop": @@ -66,8 +65,7 @@ fn void part2() } fn void part1() { - File f; - f.open("code.txt", "rb")!!; + File f = file::open("code.txt", "rb")!!; defer (void)f.close(); int cycle = 0; int x = 1; @@ -77,7 +75,7 @@ fn void part1() @pool() { String line = f.tgetline(); - String[] commands = str::tsplit(line, " "); + String[] commands = line.tsplit(" "); switch (commands[0]) { case "noop": diff --git a/day11.c3 b/day11.c3 index c57e8d8..4ac4d84 100644 --- a/day11.c3 +++ b/day11.c3 @@ -25,8 +25,7 @@ fn void print_monkeys(Monkey[] monkeys) fn Monkey[] load_monkeys(Monkey[] monkeys) { - File f; - f.open("monkey.txt", "rb")!!; + File f = file::open("monkey.txt", "rb")!!; defer (void)f.close(); int max_monkey = 0; while (!f.eof()) @@ -36,26 +35,26 @@ fn Monkey[] load_monkeys(Monkey[] monkeys) // Very lazy parsing, assuming a lot about the format. String line = f.tgetline(); if (line.len == 0) continue; - String[] commands = str::tsplit(line, " "); + String[] commands = line.tsplit(" "); int monkey_num = str::to_int(commands[1][..^2])!!; if (monkey_num > max_monkey) max_monkey = monkey_num; Monkey* active_monkey = &monkeys[monkey_num]; line = f.tgetline(); - String[] items = str::tsplit(str::tsplit(line, ": ")[1], ", "); + String[] items = line.tsplit(": ")[1].tsplit(", "); foreach (String item : items) { active_monkey.items[active_monkey.item_count++] = str::to_int(item)!!; } line = f.tgetline(); - String[] op = str::tsplit(str::tsplit(line, "= old ")[1], " "); + String[] op = line.tsplit("= old ")[1].tsplit(" "); active_monkey.op_is_mult = op[0][0] == '*'; active_monkey.other_op = op[1] == "old" ? -1 : str::to_int(op[1])!!; line = f.tgetline(); - active_monkey.test = str::to_int(str::tsplit(line, "by ")[1])!!; + active_monkey.test = str::to_int(line.tsplit("by ")[1])!!; line = f.tgetline(); - active_monkey.on_true = str::to_int(str::tsplit(line, "key ")[1])!!; + active_monkey.on_true = str::to_int(line.tsplit("key ")[1])!!; line = f.tgetline(); - active_monkey.on_false = str::to_int(str::tsplit(line, "key ")[1])!!; + active_monkey.on_false = str::to_int(line.tsplit("key ")[1])!!; }; } return monkeys[..max_monkey]; diff --git a/day12.c3 b/day12.c3 index 2d285bb..2a5954f 100644 --- a/day12.c3 +++ b/day12.c3 @@ -27,7 +27,7 @@ fn WalkedMap* Map.create_temp_empty_walked_map(Map* map) { usz height = map.map.len(); usz width = map.map.get(0).len; - WalkedMap *w = talloc(WalkedMap); + WalkedMap *w = tmalloc(WalkedMap); w.walked = tcalloc(int.sizeof * height * width); w.size = { (int)width, (int)height }; return w; @@ -50,7 +50,7 @@ fn bool WalkedMap.walk(WalkedMap* this, int[<2>] loc, int steps) fn void WalkedMap.show(WalkedMap* this) { - io::println("-----------------"); + io::printn("-----------------"); for (int y = 0; y < this.size[1]; y++) { io::printf("|"); @@ -59,14 +59,13 @@ fn void WalkedMap.show(WalkedMap* this) int val = this.walked[x + y * this.size[0]]; io::printf("%c", val ? val + '0' - 1 : ' '); } - io::println("|"); + io::printn("|"); } } fn Map* load_heightmap() { - File f; - f.open("heightmap.txt", "rb")!!; + File f = file::open("heightmap.txt", "rb")!!; defer (void)f.close(); Map* map = malloc(Map); map.map.init(); diff --git a/day13.c3 b/day13.c3 index a7def5a..db87874 100644 --- a/day13.c3 +++ b/day13.c3 @@ -110,8 +110,7 @@ fn Packet* packet_from_line(String line) } fn PacketPairs* load_packets() { - File f; - f.open("packets.txt", "rb")!!; + File f = file::open("packets.txt", "rb")!!; defer (void)f.close(); PacketPairs* packet = malloc(PacketPairs); packet.init(); diff --git a/day14.c3 b/day14.c3 index 2f8e185..447e9fc 100644 --- a/day14.c3 +++ b/day14.c3 @@ -20,14 +20,13 @@ enum EnvType fn int[<2>]! str_to_coord(String str) { - String[] parts = str::tsplit(str, ","); + String[] parts = str.tsplit(","); return { str::to_int(parts[0]), str::to_int(parts[1]) }; } fn Environment* load_environment(EnvType type) { - File f; - f.open("cave.txt", "rb")!!; + File f = file::open("cave.txt", "rb")!!; defer (void)f.close(); Environment* env = calloc(Environment.sizeof); int max_y = 0; @@ -37,7 +36,7 @@ fn Environment* load_environment(EnvType type) { String line = f.tgetline(); int[<2>] last = { 0, 0 }; - foreach (part : str::tsplit(line, " -> ")) + foreach (part : line.tsplit(" -> ")) { int[<2>] next = str_to_coord(part)!!; if (next[1] > max_y) max_y = next[1]; diff --git a/day15.c3 b/day15.c3 index cd5be32..fab9d56 100644 --- a/day15.c3 +++ b/day15.c3 @@ -8,13 +8,12 @@ define CoordPairList = List][2]>; fn int[<2>]! parse_coord(String s) { - String[] parts = str::tsplit(s, ", y="); + String[] parts = s.tsplit(", y="); return { str::to_int(parts[0]), str::to_int(parts[1]) }; } fn CoordPairList load_sensors() { - File f; - f.open("sensor.txt", "rb")!!; + File f = file::open("sensor.txt", "rb")!!; defer (void)f.close(); CoordPairList list; list.init(); @@ -24,7 +23,7 @@ fn CoordPairList load_sensors() { String line = f.tgetline(); line = line["Sensor at x=".len..]; - String[] parts = str::tsplit(line, ": closest beacon is at x="); + String[] parts = line.tsplit(": closest beacon is at x="); int[<2>] sensor_at = parse_coord(parts[0])!!; int[<2>] beacon_at = parse_coord(parts[1])!!; list.append( { sensor_at, beacon_at }); @@ -118,7 +117,7 @@ fn void part2(CoordPairList list) } } } - io::println("No beacon found."); + io::printn("No beacon found."); } fn void main() diff --git a/day16.c3 b/day16.c3 index e357224..3c4d07e 100644 --- a/day16.c3 +++ b/day16.c3 @@ -34,8 +34,7 @@ fn void populate_tunnels(Valve[] valves, int i, Valve* v, int tunnel, int cost) fn Valve[] load_valves(Valve[100]* available_slots) { - File f; - f.open("valves.txt", "rb")!!; + File f = file::open("valves.txt", "rb")!!; defer (void)f.close(); int count = 0; while (!f.eof()) @@ -43,8 +42,8 @@ fn Valve[] load_valves(Valve[100]* available_slots) @pool() { String line = f.tgetline(); - String[] parts = str::tsplit(line, " "); - String name = str::copy(parts[1]); + String[] parts = line.tsplit(" "); + String name = parts[1].copy(); String rate_part = parts[4]; int val = v.@get_or_set(name, (int)v.count); Valve *valve_entry = &(*available_slots)[val]; @@ -60,7 +59,7 @@ fn Valve[] load_valves(Valve[100]* available_slots) { valve = valve[..^2]; } - val = v.@get_or_set(str::copy(valve), (int)v.count); + val = v.@get_or_set(valve.copy(), (int)v.count); valve_entry.tunnels[valve_entry.tunnel_count++] = val; } }; diff --git a/day17.c3 b/day17.c3 index 5c60b94..150eb6d 100644 --- a/day17.c3 +++ b/day17.c3 @@ -34,8 +34,7 @@ macro bool StateCache.equals(StateCache* cache, StateCache other) fn DString load_jets() { - File f; - f.open("jets.txt", "rb")!!; + File f = file::open("jets.txt", "rb")!!; defer (void)f.close(); return f.getline(); } @@ -156,7 +155,7 @@ fn void land_shape(Shape* shape, int[<2>] location) fn void draw_field() { - io::println("+-----+"); + io::printn("+-----+"); for (int i = find_height(); i >= 0; i--) { GameRow row = game[i]; @@ -164,9 +163,9 @@ fn void draw_field() { io::putchar(row.bit(j) ? '#' : '.'); } - io::println(); + io::printn(); } - io::println("+-----+"); + io::printn("+-----+"); } macro long adjust_lowest_bounds() @@ -273,7 +272,7 @@ fn void solve(String winds, long rocks) fn void main() { DString s = load_jets(); - defer s.destroy(); + defer s.free(); solve(s.str(), 2022); solve(s.str(), 1000000000000i64); } \ No newline at end of file diff --git a/day18.c3 b/day18.c3 index afeef3b..03049ce 100644 --- a/day18.c3 +++ b/day18.c3 @@ -9,14 +9,13 @@ int[MAX][MAX][MAX] locations; fn void load_lava() { - File f; - f.open("lava.txt", "rb")!!; + File f = file::open("lava.txt", "rb")!!; defer (void)f.close(); while (!f.eof()) { @pool() { - String[] parts = str::tsplit(f.tgetline(), ","); + String[] parts = f.tgetline().tsplit(","); locations[str::to_int(parts[0])!!][str::to_int(parts[1])!!][str::to_int(parts[2])!!] = 7; }; } diff --git a/day19.c3 b/day19.c3 index d1e04d3..8c00e75 100644 --- a/day19.c3 +++ b/day19.c3 @@ -31,8 +31,7 @@ struct GameState fn void load_blueprints() { - File f; - f.open("blueprint.txt", "rb")!!; + File f = file::open("blueprint.txt", "rb")!!; blueprints.init(); defer (void)f.close(); while (!f.eof()) @@ -41,18 +40,18 @@ fn void load_blueprints() { Blueprint print; String line = f.tgetline(); - String[] split = str::tsplit(line, "Each ore robot costs "); - split = str::tsplit(split[1], " ore. Each clay robot costs "); + String[] split = line.tsplit("Each ore robot costs "); + split = split[1].tsplit(" ore. Each clay robot costs "); print.ore_cost = { [ORE] = str::to_int(split[0])!! }; - split = str::tsplit(split[1], " ore. Each obsidian robot costs "); + split = split[1].tsplit(" ore. Each obsidian robot costs "); print.clay_cost = { [ORE] = str::to_int(split[0])!! }; - split = str::tsplit(split[1], " clay. Each geode robot costs "); - String[] split2 = str::tsplit(split[0], " ore and "); + split = split[1].tsplit(" clay. Each geode robot costs "); + String[] split2 = split[0].tsplit(" ore and "); print.obsidian_cost = { [ORE] = str::to_int(split2[0])!!, [CLAY] = str::to_int(split2[1])!! }; - split2 = str::tsplit(split[1], " ore and "); + split2 = split[1].tsplit(" ore and "); print.geode_cost = { [ORE] = str::to_int(split2[0])!!, [OBSIDIAN] = str::to_int(split2[1][..^11])!! diff --git a/day1_1.c3 b/day1_1.c3 index 46fb316..26984de 100644 --- a/day1_1.c3 +++ b/day1_1.c3 @@ -3,8 +3,7 @@ import libc; fn void main() { - File f; - f.open("calories.txt", "rb")!!; + File f = file::open("calories.txt", "rb")!!; defer (void)f.close(); usz current_entry = 0; usz max_entry = 0; diff --git a/day1_2.c3 b/day1_2.c3 index 5b759c6..c142da9 100644 --- a/day1_2.c3 +++ b/day1_2.c3 @@ -20,8 +20,7 @@ fn void update_max(int entry) fn void main() { - File f; - f.open("calories.txt", "rb")!!; + File f = file::open("calories.txt", "rb")!!; defer (void)f.close(); int current_entry = 0; while (!f.eof()) diff --git a/day2.c3 b/day2.c3 index 1cb605f..57a4fd4 100644 --- a/day2.c3 +++ b/day2.c3 @@ -49,8 +49,7 @@ fn Select! selectFromString(String line) fn void part1() { - File f; - f.open("solution.txt", "rb")!!; + File f = file::open("solution.txt", "rb")!!; defer (void)f.close(); int points = 0; while (!f.eof()) @@ -79,8 +78,7 @@ fn void part1() fn void part2() { - File f; - f.open("solution.txt", "rb")!!; + File f = file::open("solution.txt", "rb")!!; defer (void)f.close(); int points = 0; while (!f.eof()) diff --git a/day20.c3 b/day20.c3 index 1d405d5..8432b89 100644 --- a/day20.c3 +++ b/day20.c3 @@ -8,8 +8,7 @@ define LongList = List; fn void load_crypto(LongList* list, LongList* pos, long key) { - File f; - f.open("crypto.txt", "rb")!!; + File f = file::open("crypto.txt", "rb")!!; defer (void)f.close(); while (!f.eof()) { @@ -37,7 +36,7 @@ macro print_order(LongList pos) { io::printf("%s ", x); } - io::println(); + io::printn(); } fn void print_list(LongList list, LongList pos) @@ -48,7 +47,7 @@ fn void print_list(LongList list, LongList pos) { io::printf("%s ", value_at_pos(list, pos, i)); } - io::println(); + io::printn(); } diff --git a/day21.c3 b/day21.c3 index 4c765a9..389ea8b 100644 --- a/day21.c3 +++ b/day21.c3 @@ -34,8 +34,7 @@ struct Monkey } fn void load_monkeys(MonkeyList* list, MonkeyId* root_index, MonkeyId *humn_index) { - File f; - f.open("monkeys.txt", "rb")!!; + File f = file::open("monkeys.txt", "rb")!!; defer (void)f.close(); NameMap map; map.init(); @@ -46,8 +45,8 @@ fn void load_monkeys(MonkeyList* list, MonkeyId* root_index, MonkeyId *humn_inde @pool() { String line = f.tgetline(); - String[] parts = str::tsplit(line, ": "); - String name = str::copy(parts[0]); + String[] parts = line.tsplit(": "); + String name = parts[0].copy(); if (name == "root") { *root_index = index; @@ -66,9 +65,9 @@ fn void load_monkeys(MonkeyList* list, MonkeyId* root_index, MonkeyId *humn_inde } else { - parts = str::tsplit(parts[1], " "); - m.other_monkey_unresolved[0] = str::copy(parts[0]); - m.other_monkey_unresolved[1] = str::copy(parts[2]); + parts = parts[1].tsplit(" "); + m.other_monkey_unresolved[0] = parts[0].copy(); + m.other_monkey_unresolved[1] = parts[2].copy(); switch (parts[1][0]) { case '*': m.action = Action.MULT; diff --git a/day22.c3 b/day22.c3 index bc2aded..15ab16a 100644 --- a/day22.c3 +++ b/day22.c3 @@ -24,8 +24,7 @@ int width_spaces; fn void load_map() { - File f; - f.open("map.txt", "rb")!!; + File f = file::open("map.txt", "rb")!!; defer (void)f.close(); int y = 0; width = 0; @@ -41,15 +40,15 @@ fn void load_map() switch (c) { case '#': - map[x][y] = MapType.BLOCK; + map[x][y] = (int)MapType.BLOCK; case '.': if (start[0] < 0) { start = { x, y }; } - map[x][y] = MapType.SPACE; + map[x][y] = (int)MapType.SPACE; case ' ': - map[x][y] = MapType.VOID; + map[x][y] = (int)MapType.VOID; default: unreachable(); } @@ -60,7 +59,7 @@ fn void load_map() height = y; side = y > width ? y / 4 : width / 4; width_spaces = width / side; - commands = str::copy(f.tgetline()); + commands = f.tgetline().copy(); } fn int region_from_pos(int[<2>] pos) diff --git a/day23.c3 b/day23.c3 index b741e54..3b21fea 100644 --- a/day23.c3 +++ b/day23.c3 @@ -10,18 +10,17 @@ const int PADDING = 100; fn void print_map(CharsArray* list) { - io::println("-----"); + io::printn("-----"); foreach (String line : list) { - io::println(line); + io::printn(line); } - io::println("-----"); + io::printn("-----"); } fn void load_map(CharsArray* list) { - File f; - f.open("crater.txt", "rb")!!; + File f = file::open("crater.txt", "rb")!!; defer (void)f.close(); isz width; char[PADDING] spacing; @@ -32,16 +31,16 @@ fn void load_map(CharsArray* list) { String line = f.tgetline(); width = line.len; - line = str::tconcat(&spacing, line); - list.append(str::copy(str::tconcat(line, &spacing))); + line = ((String)&spacing).tconcat(line); + list.append(line.tconcat((String)&spacing).copy()); }; } - String top_line = array::alloc(char, width + PADDING * 2); + String top_line = (String)malloc(char, width + PADDING * 2); top_line[..] = '.'; for (int i = 0; i < PADDING; i++) { - list.insert_at(0, str::copy(top_line)); - list.append(str::copy(top_line)); + list.insert_at(0, top_line.copy()); + list.append(top_line.copy()); } } diff --git a/day24.c3 b/day24.c3 index ee7e274..8c1f1b5 100644 --- a/day24.c3 +++ b/day24.c3 @@ -19,8 +19,7 @@ int height; int common; fn void load_map() { - File f; - f.open("blizzard.txt", "rb")!!; + File f = file::open("blizzard.txt", "rb")!!; defer (void)f.close(); @pool() { diff --git a/day25.c3 b/day25.c3 index bdae3cf..4e819a8 100644 --- a/day25.c3 +++ b/day25.c3 @@ -37,7 +37,7 @@ fn String snafu_from_long(String buffer, long l) buffer[len - i - 1] = temp[i]; } buffer[idx] = 0; - return buffer.ptr[:idx]; + return (String)buffer.ptr[:idx]; } fn long snafu_to_long(String num) @@ -53,8 +53,7 @@ fn long snafu_to_long(String num) fn void part1() { - File f; - f.open("snafu.txt", "rb")!!; + File f = file::open("snafu.txt", "rb")!!; defer (void)f.close(); long total = 0; while (!f.eof()) @@ -66,7 +65,7 @@ fn void part1() }; } char[100] buffer; - String res = snafu_from_long(&buffer, total); + String res = snafu_from_long((String)&buffer, total); io::printfn("%s", res); } diff --git a/day2_with_more_c3_features.c3 b/day2_with_more_c3_features.c3 index 2eb975b..784d32e 100644 --- a/day2_with_more_c3_features.c3 +++ b/day2_with_more_c3_features.c3 @@ -14,8 +14,8 @@ enum Result : int(int points, int offset) WIN(6, 1), } -fn Choice Choice.loses_to(Choice c) = (Choice)((c.ordinal + 1) % 3); -fn Choice Choice.defeats(Choice c) = (Choice)((c.ordinal + 2) % 3); +fn Choice Choice.loses_to(Choice c) => (Choice)((c.ordinal + 1) % 3); +fn Choice Choice.defeats(Choice c) => (Choice)((c.ordinal + 2) % 3); fn Result Choice.result_against(Choice c, Choice other) { @@ -24,7 +24,7 @@ fn Result Choice.result_against(Choice c, Choice other) return Result.WIN; } -fn Choice Result.choice_from_other(Result r, Choice other) = (Choice)((other.ordinal + r.offset) % 3); +fn Choice Result.choice_from_other(Result r, Choice other) => (Choice)((other.ordinal + r.offset) % 3); struct Select { @@ -60,8 +60,7 @@ fn Select! selectFromString(String line) fn void part1() { - File f; - f.open("solution.txt", "rb")!!; + File f = file::open("solution.txt", "rb")!!; defer (void)f.close(); int points = 0; while (!f.eof()) @@ -77,8 +76,7 @@ fn void part1() fn void part2() { - File f; - f.open("solution.txt", "rb")!!; + File f = file::open("solution.txt", "rb")!!; defer (void)f.close(); int points = 0; while (!f.eof()) diff --git a/day3.c3 b/day3.c3 index d01c6cb..92aa391 100644 --- a/day3.c3 +++ b/day3.c3 @@ -13,8 +13,7 @@ fn int evaluate(char c) fn void part1() { - File f; - f.open("rucksack.txt", "rb")!!; + File f = file::open("rucksack.txt", "rb")!!; defer (void)f.close(); int total = 0; while NEXT: (!f.eof()) @@ -48,8 +47,7 @@ fn void part1() fn void part2() { - File f; - f.open("rucksack.txt", "rb")!!; + File f = file::open("rucksack.txt", "rb")!!; defer (void)f.close(); int total = 0; while NEXT: (!f.eof()) diff --git a/day4.c3 b/day4.c3 index b9e016f..de39162 100644 --- a/day4.c3 +++ b/day4.c3 @@ -3,7 +3,7 @@ import std::io; fn int[2]! parse_range(String range) { - String[] ranges = str::tsplit(range, "-"); + String[] ranges = range.tsplit("-"); assert(ranges.len == 2); return { str::to_int(ranges[0]), str::to_int(ranges[1]) }; } @@ -20,8 +20,7 @@ fn bool range_contains_any(int[2] range1, int[2] range2) fn void part1() { - File f; - f.open("camp.txt", "rb")!!; + File f = file::open("camp.txt", "rb")!!; defer (void)f.close(); int total = 0; while NEXT: (!f.eof()) @@ -29,7 +28,7 @@ fn void part1() @pool() { String line = f.tgetline(); - String[] parts = str::tsplit(line, ","); + String[] parts = line.tsplit(","); assert(parts.len == 2); int[2] range1 = parse_range(parts[0])!!; @@ -43,8 +42,7 @@ fn void part1() fn void part2() { - File f; - f.open("camp.txt", "rb")!!; + File f = file::open("camp.txt", "rb")!!; defer (void)f.close(); int total = 0; while NEXT: (!f.eof()) @@ -52,7 +50,7 @@ fn void part2() @pool() { String line = f.tgetline(); - String[] parts = str::tsplit(line, ","); + String[] parts = line.tsplit(","); assert(parts.len == 2); int[2] range1 = parse_range(parts[0])!!; diff --git a/day5.c3 b/day5.c3 index 40ed431..8a7ede0 100644 --- a/day5.c3 +++ b/day5.c3 @@ -34,8 +34,7 @@ fn int init_piles(CharList[MAX_PILES]* piles, File* f) macro void @process_moves(; @body(int move_amount, CharList* a, CharList *b)) { - File f; - f.open("crates.txt", "rb")!!; + File f = file::open("crates.txt", "rb")!!; defer (void)f.close(); CharList[MAX_PILES] piles; @@ -45,7 +44,7 @@ macro void @process_moves(; @body(int move_amount, CharList* a, CharList *b)) @pool() { String line = f.tgetline(); - String[] command = str::split(line, " "); + String[] command = line.split(" "); assert(command.len == 6); int move_amount = str::to_int(command[1])!!; int from = str::to_int(command[3])!!; @@ -60,7 +59,7 @@ macro void @process_moves(; @body(int move_amount, CharList* a, CharList *b)) { io::printf("%c", *piles[i].last()); } - io::println(); + io::printn(); } diff --git a/day6.c3 b/day6.c3 index 0a4d968..c8ecdc7 100644 --- a/day6.c3 +++ b/day6.c3 @@ -13,8 +13,7 @@ fn bool in_len(char* first, int len) fn void find_packet_start(int check_len) { - File f; - f.open("signal.txt", "rb")!!; + File f = file::open("signal.txt", "rb")!!; defer (void)f.close(); while READ: (!f.eof()) diff --git a/day7.c3 b/day7.c3 index 2d243d8..8dd558b 100644 --- a/day7.c3 +++ b/day7.c3 @@ -45,8 +45,7 @@ fn Directory *handle_command(String command, Directory* top, Directory* current_ fn void parse_dir(Directory *top) { - File f; - f.open("dir.txt", "rb")!!; + File f = file::open("dir.txt", "rb")!!; defer (void)f.close(); Directory* current_dir; while TOP: (!f.eof()) @@ -60,12 +59,12 @@ fn void parse_dir(Directory *top) } if (line[0..2] == "dir") { - Directory *new_dir = talloc(Directory); + Directory *new_dir = tmalloc(Directory); *new_dir = { .name = line[4..], .parent_dir = current_dir }; current_dir.other_dirs.append(new_dir); continue; } - String[] split = str::tsplit(line, " "); + String[] split = line.tsplit(" "); assert(split.len == 2); current_dir.own_files_size += str::to_long(split[0])!!; } diff --git a/day8.c3 b/day8.c3 index 1796d93..8c4c0f7 100644 --- a/day8.c3 +++ b/day8.c3 @@ -5,8 +5,7 @@ import std::io; define Forest = distinct List; fn Forest* parse_forest() { - File f; - f.open("forest.txt", "rb")!!; + File f = file::open("forest.txt", "rb")!!; defer (void)f.close(); Forest* forest = malloc(Forest); forest.init(512); diff --git a/day9.c3 b/day9.c3 index 73a3368..1b95f63 100644 --- a/day9.c3 +++ b/day9.c3 @@ -64,8 +64,7 @@ macro void part(int $part) state.map[MAP_SIZE / 2][MAP_SIZE / 2] = true; int[<2>][$part == 1 ? 1 : 9] tail; state.tail = &tail; - File f; - f.open("moves.txt", "rb")!!; + File f = file::open("moves.txt", "rb")!!; defer (void)f.close(); while (!f.eof()) {