From dc855802cf6043b0e599f19ea1fa949acaded6d8 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Thu, 18 Nov 2021 18:14:04 -0600 Subject: [PATCH] using language features --- core/container/iter.onyx | 16 ++++++++-------- examples/18_macros.onyx | 2 +- examples/22_interfaces.onyx | 2 +- tests/aoc-2020/day10.onyx | 3 +-- tests/aoc-2020/day19.onyx | 9 ++------- tests/aoc-2020/day21.onyx | 4 +--- 6 files changed, 14 insertions(+), 22 deletions(-) diff --git a/core/container/iter.onyx b/core/container/iter.onyx index cb9b372a..8778c9cd 100644 --- a/core/container/iter.onyx +++ b/core/container/iter.onyx @@ -168,7 +168,7 @@ skip :: (it: Iterator($T), count: u32) -> Iterator(T) { skip_iterator.iterator = it; skip_iterator.to_skip = count; - next :: ($T: type_expr, si: ^SkipIterator(T)) -> (T, bool) { + next :: (si: ^SkipIterator($T)) -> (T, bool) { while !si.skipped && si.to_skip > 0 { si.to_skip -= 1; value, cont := si.iterator.next(si.iterator.data); @@ -182,7 +182,7 @@ skip :: (it: Iterator($T), count: u32) -> Iterator(T) { return si.iterator.next(si.iterator.data); } - close :: ($T: type_expr, si: ^SkipIterator(T)) { + close :: (si: ^SkipIterator($T)) { if si.iterator.close != null_proc do si.iterator.close(si.iterator.data); cfree(si); } @@ -209,14 +209,14 @@ zip :: (left_iterator: Iterator($T), right_iterator: Iterator($R)) -> Iterator(Z zipped_iterator.iterator1 = left_iterator; zipped_iterator.iterator2 = right_iterator; - next :: ($T: type_expr, $R: type_expr, zi: ^ZippedIterator(T, R)) -> (Zipped(T, R), bool) { + next :: (zi: ^ZippedIterator($T, $R)) -> (Zipped(T, R), bool) { v1, cont1 := zi.iterator1.next(zi.iterator1.data); v2, cont2 := zi.iterator2.next(zi.iterator2.data); return .{ v1, v2 }, cont1 && cont2; } - close :: ($T: type_expr, $R: type_expr, zi: ^ZippedIterator(T, R)) { + close :: (zi: ^ZippedIterator($T, $R)) { if zi.iterator1.close != null_proc do zi.iterator1.close(zi.iterator1.data); if zi.iterator2.close != null_proc do zi.iterator2.close(zi.iterator2.data); cfree(zi); @@ -230,7 +230,7 @@ zip :: (left_iterator: Iterator($T), right_iterator: Iterator($R)) -> Iterator(Z } const :: (value: $T) -> Iterator(T) { - next :: ($T: type_expr, data: rawptr) -> (T, bool) { + next :: (data: ^$T) -> (T, bool) { return *(cast(^T) data), true; } @@ -259,7 +259,7 @@ enumerate :: (it: Iterator($T), start_index: i32 = 0) -> Iterator(Enumeration_Va ec.iterator = it; ec.current_index = start_index; - next :: ($T: type_expr, use data: ^Enumeration_Context(T)) -> (Enumeration_Value(T), bool) { + next :: (use data: ^Enumeration_Context($T)) -> (Enumeration_Value(T), bool) { value, cont := iterator.next(iterator.data); if !cont do return .{ current_index, __zero_value(T) }, false; @@ -268,7 +268,7 @@ enumerate :: (it: Iterator($T), start_index: i32 = 0) -> Iterator(Enumeration_Va return .{ current_index, value }, true; } - close :: ($T: type_expr, use data: ^Enumeration_Context(T)) { + close :: (use data: ^Enumeration_Context($T)) { if iterator.close != null_proc do iterator.close(iterator.data); cfree(data); } @@ -310,7 +310,7 @@ from_array :: (arr: [] $T) -> Iterator(^T) { c.count = arr.count; c.current = 0; - next :: ($T: type_expr, use _: ^Context(T)) -> (^T, bool) { + next :: (use _: ^Context($T)) -> (^T, bool) { if current < count { defer current += 1; return ^data[current], true; diff --git a/examples/18_macros.onyx b/examples/18_macros.onyx index 383ca7d4..1461f160 100644 --- a/examples/18_macros.onyx +++ b/examples/18_macros.onyx @@ -4,7 +4,7 @@ // and then it uses the symbols from the current scope. main :: (args: [] cstr) { - // A macro in Onyx looks just like a procedure, just with the work "macro" in front of it. + // A macro in Onyx looks just like a procedure, just with the word "macro" in front of it. a_simple_macro :: macro () { println("This is a simple macro"); } diff --git a/examples/22_interfaces.onyx b/examples/22_interfaces.onyx index da8de3a9..2dedc83a 100644 --- a/examples/22_interfaces.onyx +++ b/examples/22_interfaces.onyx @@ -81,7 +81,7 @@ struct_example :: () { // This will generate an error because the dot product definition of // multiplication of two Vector2(f32) results in a f32, which cannot // be casted to a Vector2(f32). - v2 := Vector2(Vector2(f32)).{}; + // v2 := Vector2(Vector2(f32)).{}; // println(v2); } diff --git a/tests/aoc-2020/day10.onyx b/tests/aoc-2020/day10.onyx index 31f764e8..29a66ba0 100644 --- a/tests/aoc-2020/day10.onyx +++ b/tests/aoc-2020/day10.onyx @@ -39,8 +39,7 @@ main :: (args: [] cstr) { // Slight hack, but having 0 in the array makes both parts easier array.push(^nums, 0); - cmp_asc :: (a: $T, b: T) -> i32 do return ~~(a - b); - array.sort(nums, cmp_asc); + array.sort(nums, (a, b) => a - b); diffs: [3] u32; for ^d: diffs do *d = 0; diff --git a/tests/aoc-2020/day19.onyx b/tests/aoc-2020/day19.onyx index 1adaed1f..9bc9bb52 100644 --- a/tests/aoc-2020/day19.onyx +++ b/tests/aoc-2020/day19.onyx @@ -63,13 +63,8 @@ grammar_prepare :: (use g: ^Grammar) { } } - array.sort(terminate_rules, (a: Term, b: Term) -> i32 { - return (cast(i32) a.nt) - (cast(i32) b.nt); - }); - - array.sort(production_rules, (a: Prod, b: Prod) -> i32 { - return (cast(i32) a.nt0) - (cast(i32) b.nt0); - }); + array.quicksort(terminate_rules, (a, b) => (cast(i32) a.nt) - (cast(i32) b.nt)); + array.quicksort(production_rules, (a, b) => (cast(i32) a.nt0) - (cast(i32) b.nt0)); max_terminal = math.max( production_rules[production_rules.count - 1].nt0, diff --git a/tests/aoc-2020/day21.onyx b/tests/aoc-2020/day21.onyx index c1dc72a5..f4578872 100644 --- a/tests/aoc-2020/day21.onyx +++ b/tests/aoc-2020/day21.onyx @@ -162,9 +162,7 @@ main :: (args: [] cstr) { } } - array.sort(matched_ingredients, (i1: ^Ingredient, i2: ^Ingredient) -> i32 { - return 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); -- 2.25.1