using language features
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 19 Nov 2021 00:14:04 +0000 (18:14 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 19 Nov 2021 00:14:04 +0000 (18:14 -0600)
core/container/iter.onyx
examples/18_macros.onyx
examples/22_interfaces.onyx
tests/aoc-2020/day10.onyx
tests/aoc-2020/day19.onyx
tests/aoc-2020/day21.onyx

index cb9b372a3ed3eb3f01d6368650096764d243de2e..8778c9cd8d6f55c671b8d4d4d537ae1c23c1b580 100644 (file)
@@ -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;
index 383ca7d4608c6c96f79b1e4f07dcd4a313933b28..1461f16047c71bccf12cce033650e46becc7d647 100644 (file)
@@ -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");
     }
index da8de3a9510a271f71bfae7832fd28588a9f80f3..2dedc83a8e540726d1c15e643bf164ee25d4e144 100644 (file)
@@ -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);
 }
 
index 31f764e8b0881e0d6c20d970996b816955918d92..29a66ba023aed4baccbaa1e614184ca59f808e68 100644 (file)
@@ -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;
index 1adaed1ffe09d4a9a1f0edb7d986b96f04e23f99..9bc9bb526e9575a1cee16ce47b9332139c0be25c 100644 (file)
@@ -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,
index c1dc72a5db35e1a489db6193a278b8c9834b5f72..f45788724d6060b3d165e52afd4405d3c46c51f8 100644 (file)
@@ -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);