From 5b4524e4a72ab00378c632bc4b58728aadb8e120 Mon Sep 17 00:00:00 2001 From: Nicolas Abril Date: Wed, 15 May 2024 21:26:16 +0200 Subject: [PATCH] Change comments to # --- README.md | 50 +++++++++---------- docs/syntax.md | 20 ++++---- examples/bitonic_sort.bend | 2 +- examples/bubble_sort.bend | 16 +++--- examples/callcc.bend | 8 +-- examples/example.bend | 46 ++++++++--------- examples/fusing_add.bend | 4 +- examples/fusing_not.bend | 6 +-- examples/neg_fusion.bend | 24 ++++----- examples/parallel_hello_world.bend | 8 +-- examples/queue.bend | 10 ++-- examples/quick_sort.bend | 16 +++--- examples/radix_sort.bend | 16 +++--- src/fun/builtins.bend | 4 +- src/fun/parser.rs | 23 ++++++++- src/imp/parser.rs | 21 ++++++++ .../compile_file/redex_order.bend | 4 +- .../compile_file/unbound_var_scope.bend | 4 +- .../golden_tests/compile_file/unused_let.bend | 4 +- .../bad_parens_making_erased_let.bend | 6 +-- .../compile_file_o_all/example.bend | 28 +++++------ .../golden_tests/compile_file_o_all/exp.bend | 2 +- .../extracted_match_pred.bend | 2 +- .../non_exhaustive_different_types.bend | 4 +- .../num_pattern_with_var.bend | 2 +- .../recursive_combinator_inactive.bend | 2 +- .../compile_file_o_no_all/bitonic_sort.bend | 18 +++---- .../compile_file_o_no_all/redex_order.bend | 36 ++++++------- .../desugar_file/switch_with_use.bend | 2 +- .../encode_pattern_match/flatten_era_pat.bend | 2 +- .../match_adt_unscoped_in_arm.bend | 2 +- .../match_auto_linearization.bend | 4 +- .../match_num_adt_tup_parser.bend | 2 +- .../hangs/recursive_with_unscoped.bend | 2 +- .../golden_tests/parse_file/imp_program.bend | 4 +- tests/golden_tests/run_file/bend_fold.bend | 2 +- tests/golden_tests/run_file/bitonic_sort.bend | 18 +++---- .../run_file/bitonic_sort_lam.bend | 2 +- .../branch_statements_assignment.bend | 2 +- .../golden_tests/run_file/do_block_mixed.bend | 2 +- tests/golden_tests/run_file/example.bend | 46 ++++++++--------- tests/golden_tests/run_file/exp.bend | 2 +- .../run_file/extracted_match_pred.bend | 2 +- .../run_file/field_vectorization.bend | 2 +- .../run_file/fold_with_state.bend | 8 +-- .../run_file/kind_compiled_tree_sum.bend | 4 +- .../run_file/match_num_adt_tup_parser.bend | 2 +- tests/golden_tests/run_file/queue.bend | 10 ++-- .../golden_tests/run_file/radix_sort_ctr.bend | 16 +++--- .../run_file/readback_list_other_ctr.bend | 2 +- .../run_file/recursive_combinator.bend | 2 +- .../run_file/recursive_combinator_nested.bend | 2 +- tests/golden_tests/run_file/str_inc.bend | 2 +- tests/golden_tests/run_file/str_inc_eta.bend | 2 +- .../golden_tests/run_file/unused_dup_var.bend | 2 +- tests/golden_tests/run_lazy/bitonic_sort.bend | 18 +++---- .../run_lazy/bitonic_sort_lam.bend | 2 +- tests/golden_tests/run_lazy/example.bend | 46 ++++++++--------- .../run_lazy/extracted_match_pred.bend | 2 +- .../run_lazy/field_vectorization.bend | 2 +- tests/golden_tests/run_lazy/queue.bend | 10 ++-- .../golden_tests/run_lazy/radix_sort_ctr.bend | 16 +++--- tests/golden_tests/run_lazy/str_inc.bend | 2 +- tests/golden_tests/run_lazy/str_inc_eta.bend | 2 +- .../golden_tests/run_lazy/unused_dup_var.bend | 2 +- .../scott_triggers_unused/test.bend | 18 +++---- .../simplify_matches/double_unwrap_box.bend | 2 +- .../simplify_matches/double_unwrap_maybe.bend | 2 +- .../flatten_with_terminal.bend | 2 +- .../simplify_matches/linearize_match_all.bend | 12 ++--- .../simplify_matches/redundant_with_era.bend | 2 +- .../compile_file__360_no_scope.bend.snap | 5 +- .../compile_file_o_all__tagged_dup.bend.snap | 5 +- .../compile_file_o_all__tagged_lam.bend.snap | 5 +- .../compile_file_o_all__tagged_sup.bend.snap | 5 +- .../run_file__360_no_scope.bend.snap | 5 +- .../run_file__adt_match_wrong_tag.bend.snap | 5 +- .../run_file__adt_wrong_tag.bend.snap | 5 +- .../run_file__fold_with_state.bend.snap | 2 +- tests/snapshots/run_file__match_sup.bend.snap | 5 +- tests/snapshots/run_file__nat_add.bend.snap | 6 ++- .../snapshots/run_file__nat_add_num.bend.snap | 6 ++- ...ile__recursive_combinator_nested.bend.snap | 5 +- tests/snapshots/run_file__str_inc.bend.snap | 5 +- .../snapshots/run_file__str_inc_eta.bend.snap | 5 +- .../snapshots/run_file__tagged_lam.bend.snap | 5 +- 86 files changed, 405 insertions(+), 343 deletions(-) diff --git a/README.md b/README.md index d6c831f5..f26460bd 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ Bend programs consist of a series of function definitions, always starting with Functions can receive arguments both directly and using a lambda abstraction. ```py -// These two are equivalent +# These two are equivalent def add(x, y): return x + y @@ -90,22 +90,22 @@ def main: You can bundle multiple values into a single value using a tuple or a struct. ```py -// With a tuple +# With a tuple def Tuple.fst(x): - // This destructures the tuple into the two values it holds. - // '*' means that the value is discarded and not bound to any variable. + # This destructures the tuple into the two values it holds. + # '*' means that the value is discarded and not bound to any variable. (fst, *) = x return fst -// With a struct +# With a struct struct Pair(fst, snd): def Pair.fst(x): match x: Pair: return x.fst -// We can also directly access the fields of a struct. -// This requires that we tell the compiler the type of the variable where it is defined. +# We can also directly access the fields of a struct. +# This requires that we tell the compiler the type of the variable where it is defined. def Pair.fst_2(x: Pair): return x.fst ``` @@ -124,7 +124,7 @@ We can then pattern match on the enum to perform different actions depending on def Maybe.or_default(x, default): match x: Maybe/some: - // We can access the fields of the variant using 'matched.field' + # We can access the fields of the variant using 'matched.field' return x.val Maybe/none: return default @@ -135,9 +135,9 @@ This allows us to easily create and consume these recursive data structures with ```py def MyTree.sum(x): - // Sum all the values in the tree. + # Sum all the values in the tree. fold x: - // The fold is implicitly called for fields marked with '~' in their definition. + # The fold is implicitly called for fields marked with '~' in their definition. Node: return val + x.left + x.right Leaf: @@ -145,10 +145,10 @@ def MyTree.sum(x): def main: bend val = 0 while val < 0: - // 'go' calls the bend recursively with the provided values. + # 'go' calls the bend recursively with the provided values. x = Node(val=val, left=go(val + 1), right=go(val + 1)) then: - // 'then' is the base case, when the condition fails. + # 'then' is the base case, when the condition fails. x = Leaf return MyTree.sum(x) @@ -206,7 +206,7 @@ def foo(x): use result = bar(1, x) return (result, result) -// Is equivalent to +# Is equivalent to def foo(x): return (bar(1, x), bar(1, x)) ``` @@ -231,11 +231,11 @@ Bend has native numbers and operations. ```py def main: - a = 1 // A 24 bit unsigned integer. - b = +2 // A 24 bit signed integer. - c = -3 // Another signed integer, but with negative value. - d = 1.0 // A 24 bit floating point number. - e = +0.001 // Also a float. + a = 1 # A 24 bit unsigned integer. + b = +2 # A 24 bit signed integer. + c = -3 # Another signed integer, but with negative value. + d = 1.0 # A 24 bit floating point number. + e = +0.001 # Also a float. return (a * 2, b - c, d / e) ``` @@ -243,13 +243,13 @@ def main: ```py switch x = 4: - // From '0' to n, ending with the default case '_'. + # From '0' to n, ending with the default case '_'. 0: "zero" 1: "one" 2: "two" - // The default case binds the name - - // where 'arg' is the name of the argument and 'n' is the next number. - // In this case, it's 'x-3', which will have value (4 - 3) = 1 + # The default case binds the name - + # where 'arg' is the name of the argument and 'n' is the next number. + # In this case, it's 'x-3', which will have value (4 - 3) = 1 _: String.concat("other: ", (String.from_num x-3)) ``` @@ -264,14 +264,14 @@ A string is desugared to a String data type containing two constructors, `String List also becomes a type with two constructors, `List.cons` and `List.nil`. ```rs -// These two are equivalent +# These two are equivalent def StrEx: "Hello" def ids: [1, 2, 3] -// These types are builtin. +# These types are builtin. enum String: String.cons(head, tail) String.nil @@ -287,7 +287,7 @@ def ids: Characters are delimited by `'` `'` and support Unicode escape sequences. They are encoded as a U24 with the unicode codepoint as their value. ``` -// These two are equivalent +# These two are equivalent def chars: ['A', '\u{4242}', '馃寧'] diff --git a/docs/syntax.md b/docs/syntax.md index fa08cf63..41724416 100644 --- a/docs/syntax.md +++ b/docs/syntax.md @@ -119,7 +119,7 @@ return "hello" Returns the expression that follows. The last statement of each branch of a function must be a `return`. ```py -// Allowed, all branches return +# Allowed, all branches return def max(a, b): if a > b: return a @@ -128,7 +128,7 @@ def max(a, b): ``` ```py -// Not allowed, early return +# Not allowed, early return def Foo(x): if test_condition(x): return "err" @@ -139,7 +139,7 @@ def Foo(x): ``` ```py -// Not allowed, one of the branches doesn't return +# Not allowed, one of the branches doesn't return def Foo(a, b): if a < b: return a @@ -283,7 +283,7 @@ It's equivalent to pattern matching on the object, with the restriction that its open Point: p ... -// Equivalent to: +# Equivalent to: match p: Point: ... @@ -316,7 +316,7 @@ def Result/bind(res, nxt): Other statements are allowed inside the `do` block and it can both return a value at the end and bind a variable, like branching statements do. ``` -// Also ok: +# Also ok: do Result: x <- safe_div(2, 0); y = x @@ -399,9 +399,9 @@ In case named arguments are used, they must come after the positional arguments eraser = * -*(41 + 1) // applies 41 + 1 to `*` erasing the number and returns `*` +*(41 + 1) # applies 41 + 1 to `*` erasing the number and returns `*` -* = 41 + 1 // erases 41 + 1 +* = 41 + 1 # erases 41 + 1 ``` The effect of an eraser is to free memory. Erasers behave like a `null`. @@ -482,7 +482,7 @@ Only supports unicode codepoints up to `0xFFFFFF`. ### Symbol Literal ```python -// Becomes 2146 (33 << 6 + 34) +# Becomes 2146 (33 << 6 + 34) `hi` ``` @@ -811,7 +811,7 @@ ask y = (div 3 2) ask x = (rem y 0) x -// Becomes +# Becomes (Result/bind (div 3 2) 位y (Result/bind (rem y 0) 位x x)) ``` @@ -857,7 +857,7 @@ Only supports unicode codepoints up to `0xFFFFFF`. ### Symbol Literal ```python -// Becomes 2146 (33 << 6 + 34) +# Becomes 2146 (33 << 6 + 34) `hi` ``` diff --git a/examples/bitonic_sort.bend b/examples/bitonic_sort.bend index 901bab2c..8587031c 100644 --- a/examples/bitonic_sort.bend +++ b/examples/bitonic_sort.bend @@ -56,6 +56,6 @@ def sort(d, s, t): return flow(d, s, sort(d-1, 0, t.a), sort(d-1, 1, t.b)) def main: - // Sorts the numbers from 0 to 2^depth. + # Sorts the numbers from 0 to 2^depth. depth = 14 return sum(depth, sort(depth, 0, gen(depth, 0))) diff --git a/examples/bubble_sort.bend b/examples/bubble_sort.bend index 3dc0527f..bd92193b 100644 --- a/examples/bubble_sort.bend +++ b/examples/bubble_sort.bend @@ -1,18 +1,18 @@ -// Sorts a list +# Sorts a list -// sort : List -> List +# sort : List -> List (Sort []) = [] (Sort (List/Cons x xs)) = (Insert x (Sort xs)) -// Insert : U60 -> List -> List +# Insert : U60 -> List -> List (Insert v []) = (List/Cons v []) (Insert v (List/Cons x xs)) = (SwapGT (> v x) v x xs) -// SwapGT : U60 -> U60 -> U60 -> List -> List +# SwapGT : U60 -> U60 -> U60 -> List -> List (SwapGT 0 v x xs) = (List/Cons v (List/Cons x xs)) (SwapGT _ v x xs) = (List/Cons x (Insert v xs)) -// Generates a random list +# Generates a random list (Rnd 0 s) = List/Nil (Rnd n s) = let s = (^ s (* s 0b10000000000000)) @@ -20,7 +20,7 @@ let s = (^ s (* s 0b100000)) (List/Cons s (Rnd (- n 1) s)) -// Sums a list +# Sums a list (Sum []) = 0 (Sum (List/Cons x xs)) = (+ x (Sum xs)) @@ -28,5 +28,5 @@ let n = 10 (Sum (Sort (Rnd 0x100 n))) -// Use an argument from cli -// (Main n) = (Sum (Sort (Rnd 0x100 n))) +# Use an argument from cli +# (Main n) = (Sum (Sort (Rnd 0x100 n))) diff --git a/examples/callcc.bend b/examples/callcc.bend index 28daa4fa..de3d7b21 100644 --- a/examples/callcc.bend +++ b/examples/callcc.bend @@ -1,15 +1,15 @@ -// This program is an example that shows how scopeless lambdas can be used. +# This program is an example that shows how scopeless lambdas can be used. Seq a b = a -// Create a program capable of using `callcc` +# Create a program capable of using `callcc` CC.lang = 位program let callcc = 位callback (位$garbage($hole) (callback 位$hole(0))); let result = (program callcc); - let garbage = $garbage; // Discard `$garbage`, which is the value returned by `callback` + let garbage = $garbage; # Discard `$garbage`, which is the value returned by `callback` (Seq result garbage) main = (CC.lang 位callcc - // This code calls `callcc`, then calls `k` to fill the hole with `42`. This means that the call to callcc returns `42`, and the program returns `52` + # This code calls `callcc`, then calls `k` to fill the hole with `42`. This means that the call to callcc returns `42`, and the program returns `52` (+ 10 (callcc 位k(+ (k 42) 1729))) ) diff --git a/examples/example.bend b/examples/example.bend index 77c8fa12..b4729896 100644 --- a/examples/example.bend +++ b/examples/example.bend @@ -1,36 +1,36 @@ -// Write definitions like this +# Write definitions like this (Def1) = ((位a a) (位b b)) -// You can call a definition by just referencing its name -// It will be substituted in place of the reference +# You can call a definition by just referencing its name +# It will be substituted in place of the reference (Def2) = ((位a a) Def1) -// Definitions and variables can have names in upper and lower case and contain numbers -// Names defined in a more inner position shadow names in an outer position +# Definitions and variables can have names in upper and lower case and contain numbers +# Names defined in a more inner position shadow names in an outer position (def3) = ((位Def1 Def1) (位x 位x x)) -// The language is affine, but if you use a variable more than once the compiler inserts duplications for you -// Of course you can always do them manually +# The language is affine, but if you use a variable more than once the compiler inserts duplications for you +# Of course you can always do them manually (def4) = 位z let {z1 z2} = z; (z1 ((位x (x x x x x)) z2)) -// You can use machine numbers and some native numeric operations -// Numeric operations can only reduce numbers, doing (+ (位x x) 1) will not do anything +# You can use machine numbers and some native numeric operations +# Numeric operations can only reduce numbers, doing (+ (位x x) 1) will not do anything (nums) = 位x1 位x2 (* (+ x1 1) (/ (- x2 2) 1)) -// You can use numbers on the native match expression -// The `+` arm binds the `scrutinee`-1 variable to the the value of the number -1 +# You can use numbers on the native match expression +# The `+` arm binds the `scrutinee`-1 variable to the the value of the number -1 (Num.pred) = 位n switch n { 0: 0 _: n-1 } -// Write new data types like this +# Write new data types like this data Option = (Some val) | None data Bool = True | False -// You can have pattern matching on definitions -// Use `*` to ignore a pattern +# You can have pattern matching on definitions +# Use `*` to ignore a pattern (Option.unwrap_or (Option/Some val) *) = val (Option.unwrap_or Option/None or) = or @@ -38,39 +38,39 @@ data Bool = True | False (Bool.or * Bool/True) = Bool/True (Bool.or * *) = Bool/False -// Or using a match expression +# Or using a match expression (Bool.not) = 位bool match bool { Bool/True: Bool/False Bool/False: Bool/True } -// Data types can store values +# Data types can store values data Boxed = (Box val) -// Types with only one constructor can be destructured using `let` or a single matching definition +# Types with only one constructor can be destructured using `let` or a single matching definition (Box.map (Boxed/Box val) f) = (Boxed/Box (f val)) (Box.unbox) = 位box match box { Boxed/Box: box.val } -// Use tuples to store two values together without needing to create a new data type +# Use tuples to store two values together without needing to create a new data type (Tuple.new fst snd) = let pair = (fst, snd) pair -// Then you can destructure it inside the definition or using `let` +# Then you can destructure it inside the definition or using `let` (Tuple.fst (fst, snd)) = fst (Tuple.snd) = 位pair let (fst, snd) = pair snd -// All files must have a main definition to be run. -// You can execute a program in HVM with "cargo run -- run " -// Other options are "check" (the default mode) to just see if the file is well formed -// and "compile" to output hvm-core code. +# All files must have a main definition to be run. +# You can execute a program in HVM with "cargo run -- run " +# Other options are "check" (the default mode) to just see if the file is well formed +# and "compile" to output hvm-core code. (main) = let tup = (Tuple.new Option/None (Num.pred 5)) diff --git a/examples/fusing_add.bend b/examples/fusing_add.bend index 3e9a5147..3c79cfb7 100644 --- a/examples/fusing_add.bend +++ b/examples/fusing_add.bend @@ -1,7 +1,7 @@ zero = 位s 位z z -succ = 位pred 位s 位z (s pred) // Creates a Scott number out of its predecessor +succ = 位pred 位s 位z (s pred) # Creates a Scott number out of its predecessor -two = (succ (succ zero)) // 位s 位z (s 位s 位z (s 位s 位z z)) +two = (succ (succ zero)) # 位s 位z (s 位s 位z (s 位s 位z z)) fusing_add = 位a let case_succ = 位a_pred 位b (succ (fusing_add a_pred b)) diff --git a/examples/fusing_not.bend b/examples/fusing_not.bend index 9c1bcfe3..201d604e 100644 --- a/examples/fusing_not.bend +++ b/examples/fusing_not.bend @@ -2,11 +2,11 @@ true = 位t 位f t false = 位t 位f f not = 位boolean (boolean false true) fusing_not = 位boolean 位t 位f (boolean f t) -// Creates a Church numeral out of a native number +# Creates a Church numeral out of a native number to_church n = switch n { 0: 位f 位x x _: 位f 位x (f (to_church n-1 f x)) } main = - // Self-composes `not` 2^24 times and prints the result. - ((to_church 0xFFFFFF) fusing_not) // try replacing this by not. Will it still work? + # Self-composes `not` 2^24 times and prints the result. + ((to_church 0xFFFFFF) fusing_not) # try replacing this by not. Will it still work? diff --git a/examples/neg_fusion.bend b/examples/neg_fusion.bend index b7cdf538..12ab997c 100644 --- a/examples/neg_fusion.bend +++ b/examples/neg_fusion.bend @@ -1,24 +1,24 @@ -// size = 1 << 8 +# size = 1 << 8 Mul = 位n 位m 位s (n (m s)) -// Church nat +# Church nat C2 = 位f 位x (f (f x)) -// Church powers of two -P2 = (Mul C2 C2) // 4 -P3 = (Mul C2 P2) // 8 -P4 = (Mul C2 P3) // 16 -P5 = (Mul C2 P4) // 32 -P6 = (Mul C2 P5) // 64 -P7 = (Mul C2 P6) // 128 -P8 = (Mul C2 P7) // 256 +# Church powers of two +P2 = (Mul C2 C2) # 4 +P3 = (Mul C2 P2) # 8 +P4 = (Mul C2 P3) # 16 +P5 = (Mul C2 P4) # 32 +P6 = (Mul C2 P5) # 64 +P7 = (Mul C2 P6) # 128 +P8 = (Mul C2 P7) # 256 -// Booleans +# Booleans True = 位t 位f t False = 位t 位f f Not = 位b ((b False) True) Neg = 位b 位t 位f (b f t) -// Negates 'true' 256 times: 'neg' is faster than 'not' because it fuses +# Negates 'true' 256 times: 'neg' is faster than 'not' because it fuses Main = (P8 Neg True) diff --git a/examples/parallel_hello_world.bend b/examples/parallel_hello_world.bend index b89569c4..60bf6307 100644 --- a/examples/parallel_hello_world.bend +++ b/examples/parallel_hello_world.bend @@ -1,9 +1,9 @@ -// a binary tree +# a binary tree type MyTree: Node { val, ~left, ~right } Leaf { val } -// sums all values in a tree +# sums all values in a tree def sum(tree): fold tree: case MyTree/Node: @@ -11,7 +11,7 @@ def sum(tree): case MyTree/Leaf: return tree.val -// generates a binary tree of given depth +# generates a binary tree of given depth def gen(depth): bend val = 0: when val < depth: @@ -20,6 +20,6 @@ def gen(depth): tree = MyTree/Leaf { val: val } return tree -// returns the sum of 0..2^16 +# returns the sum of 0..2^16 def main: return sum(gen(16)) diff --git a/examples/queue.bend b/examples/queue.bend index 339e5388..b42838a3 100644 --- a/examples/queue.bend +++ b/examples/queue.bend @@ -1,15 +1,15 @@ -// A cool trick involving HVM's scopeless lambdas is linear qs: +# A cool trick involving HVM's scopeless lambdas is linear qs: -// Qnew : Queue a +# Qnew : Queue a Qnew = 位x x -// Qadd : a -> Queue a -> Queue a +# Qadd : a -> Queue a -> Queue a Qadd = 位x 位q 位k (q 位c (c x k)) -// Qrem : Queue a -> Pair a (Queue a) +# Qrem : Queue a -> Pair a (Queue a) Qrem = 位q (q $k 位x 位xs 位p(p x 位$k xs)) -// Output: [1, 2, 3] +# Output: [1, 2, 3] main = let q = Qnew let q = (Qadd 1 q) diff --git a/examples/quick_sort.bend b/examples/quick_sort.bend index 3009c802..150cf2c3 100644 --- a/examples/quick_sort.bend +++ b/examples/quick_sort.bend @@ -1,6 +1,6 @@ data Tree = Leaf | (Node l m r) -// Parallel QuickSort +# Parallel QuickSort (Sort List/Nil) = Tree/Leaf (Sort (List/Cons x xs)) = ((Part x xs) 位min 位max @@ -8,15 +8,15 @@ data Tree = Leaf | (Node l m r) let rgt = (Sort max) (Tree/Node lft x rgt)) - // Partitions a list in two halves, less-than-p and greater-than-p + # Partitions a list in two halves, less-than-p and greater-than-p (Part p List/Nil) = 位t (t List/Nil List/Nil) (Part p (List/Cons x xs)) = (Push (> x p) x (Part p xs)) - // Pushes a value to the first or second list of a pair + # Pushes a value to the first or second list of a pair (Push 0 x pair) = (pair 位min 位max 位p (p (List/Cons x min) max)) (Push _ x pair) = (pair 位min 位max 位p (p min (List/Cons x max))) -// Generates a random list +# Generates a random list (Rnd 0 s) = List/Nil (Rnd n s) = let s = (^ s (* s 0b10000000000000)) @@ -24,13 +24,13 @@ data Tree = Leaf | (Node l m r) let s = (^ s (* s 0b100000)) (List/Cons s (Rnd (- n 1) s)) -// Sums all elements in a concatenation tree +# Sums all elements in a concatenation tree (Sum Tree/Leaf) = 0 (Sum (Tree/Node l m r)) = (+ m (+ (Sum l) (Sum r))) -// Sorts and sums n random numbers +# Sorts and sums n random numbers (Main) = (Sum (Sort (Rnd 0x100 1))) -// Use an argument from cli -// (Main n) = (Sum (Sort (Rnd (<< 1 n) 1))) +# Use an argument from cli +# (Main n) = (Sum (Sort (Rnd (<< 1 n) 1))) diff --git a/examples/radix_sort.bend b/examples/radix_sort.bend index b9beef61..4630a0c1 100644 --- a/examples/radix_sort.bend +++ b/examples/radix_sort.bend @@ -6,15 +6,15 @@ data Arr = Null | (Leaf x) | (Node a b) _: (Map_/Both b a) } -// Sort : Arr -> Arr +# Sort : Arr -> Arr (Sort t) = (ToArr 0 (ToMap t)) -// ToMap : Arr -> Map +# ToMap : Arr -> Map (ToMap Arr/Null) = Map_/Free (ToMap (Arr/Leaf a)) = (Radix a) (ToMap (Arr/Node a b)) = (Merge (ToMap a) (ToMap b)) -// ToArr : U60 -> Map -> Arr +# ToArr : U60 -> Map -> Arr (ToArr x Map_/Free) = Arr/Null (ToArr x Map_/Used) = (Arr/Leaf x) (ToArr x (Map_/Both a b)) = @@ -22,7 +22,7 @@ data Arr = Null | (Leaf x) | (Node a b) let b = (ToArr (+ (* x 2) 1) b) (Arr/Node a b) -// Merge : Map -> Map -> Map +# Merge : Map -> Map -> Map (Merge Map_/Free Map_/Free) = Map_/Free (Merge Map_/Free Map_/Used) = Map_/Used (Merge Map_/Used Map_/Free) = Map_/Used @@ -33,7 +33,7 @@ data Arr = Null | (Leaf x) | (Node a b) (Merge (Map_/Both a b) Map_/Used) = * (Merge Map_/Used (Map_/Both a b)) = * -// Radix : U60 -> Map +# Radix : U60 -> Map (Radix n) = let r = Map_/Used let r = (Swap (& n 1) r Map_/Free) @@ -75,17 +75,17 @@ data Arr = Null | (Leaf x) | (Node a b) r -// Reverse : Arr -> Arr +# Reverse : Arr -> Arr (Reverse Arr/Null) = Arr/Null (Reverse (Arr/Leaf a)) = (Arr/Leaf a) (Reverse (Arr/Node a b)) = (Arr/Node (Reverse b) (Reverse a)) -// Sum : Arr -> U60 +# Sum : Arr -> U60 (Sum Arr/Null) = 0 (Sum (Arr/Leaf x)) = x (Sum (Arr/Node a b)) = (+ (Sum a) (Sum b)) -// Gen : U60 -> Arr +# Gen : U60 -> Arr (Gen n) = (Gen.go n 0) (Gen.go n x) = switch n { 0: (Arr/Leaf x) diff --git a/src/fun/builtins.bend b/src/fun/builtins.bend index 133b1738..0e09cb01 100644 --- a/src/fun/builtins.bend +++ b/src/fun/builtins.bend @@ -3,7 +3,7 @@ data List = (Cons head ~tail) | (Nil) data Result = (Ok val) | (Err val) data Nat = (Succ ~pred) | (Zero) -// MAP Impl +# MAP Impl data Map = (Node value ~left ~right) | (Leaf) @@ -46,7 +46,7 @@ Map/set map key value = } } -// IO Impl +# IO Impl STRING_NIL_TAG = 0 STRING_CONS_TAG = 1 diff --git a/src/fun/parser.rs b/src/fun/parser.rs index 665f9203..7454e89c 100644 --- a/src/fun/parser.rs +++ b/src/fun/parser.rs @@ -682,6 +682,27 @@ impl<'a> Parser<'a> for TermParser<'a> { self.expected(format!("'{text}'").as_str()) } } + + fn skip_trivia(&mut self) { + while let Some(c) = self.peek_one() { + if c.is_ascii_whitespace() { + self.advance_one(); + continue; + } + if c == '#' { + while let Some(c) = self.peek_one() { + if c != '\n' { + self.advance_one(); + } else { + break; + } + } + self.advance_one(); // Skip the newline character as well + continue; + } + break; + } + } } pub fn is_name_char(c: char) -> bool { @@ -826,7 +847,7 @@ pub trait ParserCommons<'a>: Parser<'a> { char_count += 1; continue; } - if c == '/' && self.input().get(*self.index() ..).unwrap_or_default().starts_with("//") { + if c == '#' { while let Some(c) = self.peek_one() { if c != '\n' { self.advance_one(); diff --git a/src/imp/parser.rs b/src/imp/parser.rs index b131ff65..b8febc24 100644 --- a/src/imp/parser.rs +++ b/src/imp/parser.rs @@ -58,6 +58,27 @@ impl<'a> Parser<'a> for PyParser<'a> { self.expected(format!("'{text}'").as_str()) } } + + fn skip_trivia(&mut self) { + while let Some(c) = self.peek_one() { + if c.is_ascii_whitespace() { + self.advance_one(); + continue; + } + if c == '#' { + while let Some(c) = self.peek_one() { + if c != '\n' { + self.advance_one(); + } else { + break; + } + } + self.advance_one(); // Skip the newline character as well + continue; + } + break; + } + } } impl<'a> PyParser<'a> { diff --git a/tests/golden_tests/compile_file/redex_order.bend b/tests/golden_tests/compile_file/redex_order.bend index d2c86442..ce39765d 100644 --- a/tests/golden_tests/compile_file/redex_order.bend +++ b/tests/golden_tests/compile_file/redex_order.bend @@ -1,5 +1,5 @@ -// We want the nested calls in foo to be compiled as redexes written in outer to inner order -// So they should compile to: @foo = root_tree & a ~ ... & b ~ ... & c ~ ... +# We want the nested calls in foo to be compiled as redexes written in outer to inner order +# So they should compile to: @foo = root_tree & a ~ ... & b ~ ... & c ~ ... foo = @x (a (b (c x))) foo2 = (a (b (c 0))) diff --git a/tests/golden_tests/compile_file/unbound_var_scope.bend b/tests/golden_tests/compile_file/unbound_var_scope.bend index b29a16ae..25842e8d 100644 --- a/tests/golden_tests/compile_file/unbound_var_scope.bend +++ b/tests/golden_tests/compile_file/unbound_var_scope.bend @@ -1,3 +1,3 @@ -// Fully parenthesized, this is (位a ((位b b) b)). -// Since applications must have (), the second 'b' is not in scope +# Fully parenthesized, this is (位a ((位b b) b)). +# Since applications must have (), the second 'b' is not in scope main = 位a (位b b b) diff --git a/tests/golden_tests/compile_file/unused_let.bend b/tests/golden_tests/compile_file/unused_let.bend index 8f08baf2..6233a065 100644 --- a/tests/golden_tests/compile_file/unused_let.bend +++ b/tests/golden_tests/compile_file/unused_let.bend @@ -1,3 +1,3 @@ -// theoretically, this let could be elided and no dups would need to be emitted -// but this isn't legal in all cases, and it's unclear what heuristics could work here +# theoretically, this let could be elided and no dups would need to be emitted +# but this isn't legal in all cases, and it's unclear what heuristics could work here main = @x let * = (+ x x); x diff --git a/tests/golden_tests/compile_file_o_all/bad_parens_making_erased_let.bend b/tests/golden_tests/compile_file_o_all/bad_parens_making_erased_let.bend index 075693b9..799e0a87 100644 --- a/tests/golden_tests/compile_file_o_all/bad_parens_making_erased_let.bend +++ b/tests/golden_tests/compile_file_o_all/bad_parens_making_erased_let.bend @@ -4,7 +4,7 @@ X = 位x x let two = (位f1位x1 (f1 位f2位x2 (f2 位f0位x0 x0))); let qua = (位s1位z1 (s1 位s2位z2 (s2 位s3位z3 (s3 位s4位z4 (s4 位s0位z0 z0))))); X X (X two qua) - // Because there is no parens around the return term, the lets are only in scope for the first X - // This test is to make sure that the affine checking and duping infering marks them as erased as we expect. - // We expect an unbound variable error on two and qua. + # Because there is no parens around the return term, the lets are only in scope for the first X + # This test is to make sure that the affine checking and duping infering marks them as erased as we expect. + # We expect an unbound variable error on two and qua. ) diff --git a/tests/golden_tests/compile_file_o_all/example.bend b/tests/golden_tests/compile_file_o_all/example.bend index 7d1b9e18..bb169f5b 100644 --- a/tests/golden_tests/compile_file_o_all/example.bend +++ b/tests/golden_tests/compile_file_o_all/example.bend @@ -1,25 +1,25 @@ -// Write definitions like this +# Write definitions like this (Def1) = (位a a 位b b) -// You can call a definition by just referencing its name -// It will be substituted in place of the reference +# You can call a definition by just referencing its name +# It will be substituted in place of the reference (Def2) = (位a a Def1) -// Definitions and variables can have names in upper and lower case and contain numbers -// Names defined in a more inner position shadow names in an outer position +# Definitions and variables can have names in upper and lower case and contain numbers +# Names defined in a more inner position shadow names in an outer position (def3) = (位Def1 Def1 位x 位x x) -// The language is affine, but if you use a variable more than once the compiler inserts duplications for you -// Of course you can always do them manually +# The language is affine, but if you use a variable more than once the compiler inserts duplications for you +# Of course you can always do them manually (def4) = 位z let {z1 z2} = z; (z1 (位x (x x x x x) z2)) -// You can use machine numbers and some native numeric operations -// Numeric operations can only reduce numbers, doing (+ (位x x) 1) will not do anything +# You can use machine numbers and some native numeric operations +# Numeric operations can only reduce numbers, doing (+ (位x x) 1) will not do anything (nums) = 位x1 位x2 (* (+ x1 1) (/ (- x2 2) 1)) -// All files must have a main definition to be run. -// You can execute a program in HVM with "cargo run -- --run " -// Other options are "--check" (the default mode) to just see if the file is well formed -// and "--compile" to output hvm-core code. -// (main) = (Def2 1) +# All files must have a main definition to be run. +# You can execute a program in HVM with "cargo run -- --run " +# Other options are "--check" (the default mode) to just see if the file is well formed +# and "--compile" to output hvm-core code. +# (main) = (Def2 1) (main) = (Def2 1) diff --git a/tests/golden_tests/compile_file_o_all/exp.bend b/tests/golden_tests/compile_file_o_all/exp.bend index a230d4c6..2a0b10e0 100644 --- a/tests/golden_tests/compile_file_o_all/exp.bend +++ b/tests/golden_tests/compile_file_o_all/exp.bend @@ -1,2 +1,2 @@ -// currently broken without lazy_mode +# currently broken without lazy_mode main = ((位f位x (f (f x))) (位f位x (f (f x)))) diff --git a/tests/golden_tests/compile_file_o_all/extracted_match_pred.bend b/tests/golden_tests/compile_file_o_all/extracted_match_pred.bend index a5d6d08a..bc08d516 100644 --- a/tests/golden_tests/compile_file_o_all/extracted_match_pred.bend +++ b/tests/golden_tests/compile_file_o_all/extracted_match_pred.bend @@ -1,4 +1,4 @@ -// We expect the inferred '位n-1' from the match to be extracted which allows this recursive func +# We expect the inferred '位n-1' from the match to be extracted which allows this recursive func val = 位n (switch n { 0: valZ; _: (valS n-1) }) valZ = 0 valS = 位p (val p) diff --git a/tests/golden_tests/compile_file_o_all/non_exhaustive_different_types.bend b/tests/golden_tests/compile_file_o_all/non_exhaustive_different_types.bend index acabc49e..8098ce0a 100644 --- a/tests/golden_tests/compile_file_o_all/non_exhaustive_different_types.bend +++ b/tests/golden_tests/compile_file_o_all/non_exhaustive_different_types.bend @@ -1,5 +1,5 @@ -// There was a bug where it would say "Non-exhaustive pattern (foo f1 f2 f3 f3)", -// repeating the missing constructor for the next args. +# There was a bug where it would say "Non-exhaustive pattern (foo f1 f2 f3 f3)", +# repeating the missing constructor for the next args. data b1 = f1 | t1 data b2 = f2 | t2 diff --git a/tests/golden_tests/compile_file_o_all/num_pattern_with_var.bend b/tests/golden_tests/compile_file_o_all/num_pattern_with_var.bend index 5f7675a2..9b271a70 100644 --- a/tests/golden_tests/compile_file_o_all/num_pattern_with_var.bend +++ b/tests/golden_tests/compile_file_o_all/num_pattern_with_var.bend @@ -1,4 +1,4 @@ -// We had a bug where this gave the incorrect error: "Expected a number but found 'a' at definition 'Foo'." +# We had a bug where this gave the incorrect error: "Expected a number but found 'a' at definition 'Foo'." data bool = false | true (Foo bool/false a) = 0 diff --git a/tests/golden_tests/compile_file_o_all/recursive_combinator_inactive.bend b/tests/golden_tests/compile_file_o_all/recursive_combinator_inactive.bend index 726d159b..0ceaf416 100644 --- a/tests/golden_tests/compile_file_o_all/recursive_combinator_inactive.bend +++ b/tests/golden_tests/compile_file_o_all/recursive_combinator_inactive.bend @@ -1,4 +1,4 @@ -// `Foo` inside the term `{Foo Foo}` is not in a active position, tests that it is not unnecessarily extracted +# `Foo` inside the term `{Foo Foo}` is not in a active position, tests that it is not unnecessarily extracted Foo = @a switch a { 0: {Foo Foo}; _: @* a-1 } main = (Foo 0) diff --git a/tests/golden_tests/compile_file_o_no_all/bitonic_sort.bend b/tests/golden_tests/compile_file_o_no_all/bitonic_sort.bend index dfb4c809..00f387be 100644 --- a/tests/golden_tests/compile_file_o_no_all/bitonic_sort.bend +++ b/tests/golden_tests/compile_file_o_no_all/bitonic_sort.bend @@ -1,44 +1,44 @@ data Tree = (Leaf a) | (Both a b) data Error = Err -// Atomic Swapper +# Atomic Swapper (Swap n a b) = switch n { 0: (Tree/Both a b) _: (Tree/Both b a) } -// Swaps distant values in parallel; corresponds to a Red Box +# Swaps distant values in parallel; corresponds to a Red Box (Warp s (Tree/Leaf a) (Tree/Leaf b)) = (Swap (^ (> a b) s) (Tree/Leaf a) (Tree/Leaf b)) (Warp s (Tree/Both a b) (Tree/Both c d)) = (Join (Warp s a c) (Warp s b d)) (Warp s a b) = Error/Err -// Rebuilds the warped tree in the original order +# Rebuilds the warped tree in the original order (Join (Tree/Both a b) (Tree/Both c d)) = (Tree/Both (Tree/Both a c) (Tree/Both b d)) (Join a b) = Error/Err -// Recursively warps each sub-tree; corresponds to a Blue/Green Box +# Recursively warps each sub-tree; corresponds to a Blue/Green Box (Flow s (Tree/Leaf a)) = (Tree/Leaf a) (Flow s (Tree/Both a b)) = (Down s (Warp s a b)) -// Propagates Flow downwards +# Propagates Flow downwards (Down s (Tree/Leaf a)) = (Tree/Leaf a) (Down s (Tree/Both a b)) = (Tree/Both (Flow s a) (Flow s b)) -// Bitonic Sort +# Bitonic Sort (Sort s (Tree/Leaf a)) = (Tree/Leaf a) (Sort s (Tree/Both a b)) = (Flow s (Tree/Both (Sort 0 a) (Sort 1 b))) -// Generates a tree of depth `n` +# Generates a tree of depth `n` (Gen n x) = switch n { 0: (Tree/Leaf x) _: (Tree/Both (Gen n-1 (* x 2)) (Gen n-1 (+ (* x 2) 1))) } -// Reverses a tree +# Reverses a tree (Rev (Tree/Leaf x)) = (Tree/Leaf x) (Rev (Tree/Both a b)) = (Tree/Both (Rev b) (Rev a)) -// Sums a tree +# Sums a tree (Sum (Tree/Leaf x)) = x (Sum (Tree/Both a b)) = (+ (Sum a) (Sum b)) diff --git a/tests/golden_tests/compile_file_o_no_all/redex_order.bend b/tests/golden_tests/compile_file_o_no_all/redex_order.bend index 40fab267..5ccef535 100644 --- a/tests/golden_tests/compile_file_o_no_all/redex_order.bend +++ b/tests/golden_tests/compile_file_o_no_all/redex_order.bend @@ -1,25 +1,25 @@ -// We want the nested calls in foo to be compiled as redexes written in outer to inner order -// So they should compile to: @foo = root_tree & a ~ ... & b ~ ... & c ~ ... +# We want the nested calls in foo to be compiled as redexes written in outer to inner order +# So they should compile to: @foo = root_tree & a ~ ... & b ~ ... & c ~ ... foo = @x (a (b (c x))) foo2 = (a (b (c 0))) bar = (a (b (c 0) (c (d 1))) (b (c (d 2)) (c 3))) -//bar = ( -// ( -// a -// ( -// (b (c 0)) -// (c (d 1)) -// ) -// ) -// ( -// ( -// b -// (c (d 2)) -// ) -// (c 3) -// ) -//) +#bar = ( +# ( +# a +# ( +# (b (c 0)) +# (c (d 1)) +# ) +# ) +# ( +# ( +# b +# (c (d 2)) +# ) +# (c 3) +# ) +#) a = @x x b = @x x diff --git a/tests/golden_tests/desugar_file/switch_with_use.bend b/tests/golden_tests/desugar_file/switch_with_use.bend index 4e9068d6..2f2f62b3 100644 --- a/tests/golden_tests/desugar_file/switch_with_use.bend +++ b/tests/golden_tests/desugar_file/switch_with_use.bend @@ -1,4 +1,4 @@ -// Test manual linearization of a use term +# Test manual linearization of a use term main = @x @y use z = (x y); @a @b @c switch a with z { 0: z diff --git a/tests/golden_tests/encode_pattern_match/flatten_era_pat.bend b/tests/golden_tests/encode_pattern_match/flatten_era_pat.bend index 9dc0617f..fcfe0e5a 100644 --- a/tests/golden_tests/encode_pattern_match/flatten_era_pat.bend +++ b/tests/golden_tests/encode_pattern_match/flatten_era_pat.bend @@ -1,4 +1,4 @@ -// To check that flattening works with Era patterns. +# To check that flattening works with Era patterns. (Fn1 (*,(a,*)) *) = a (Fn2 (*,(*,(a,*)))) = a diff --git a/tests/golden_tests/encode_pattern_match/match_adt_unscoped_in_arm.bend b/tests/golden_tests/encode_pattern_match/match_adt_unscoped_in_arm.bend index 048c14da..ed19165d 100644 --- a/tests/golden_tests/encode_pattern_match/match_adt_unscoped_in_arm.bend +++ b/tests/golden_tests/encode_pattern_match/match_adt_unscoped_in_arm.bend @@ -1,4 +1,4 @@ -// Test that we don't mess up with that unscoped lambda/var +# Test that we don't mess up with that unscoped lambda/var data bool = T | F main = @x match x { diff --git a/tests/golden_tests/encode_pattern_match/match_auto_linearization.bend b/tests/golden_tests/encode_pattern_match/match_auto_linearization.bend index 8d6c81a7..d348c19f 100644 --- a/tests/golden_tests/encode_pattern_match/match_auto_linearization.bend +++ b/tests/golden_tests/encode_pattern_match/match_auto_linearization.bend @@ -1,5 +1,5 @@ -// Given a match/switch term preceded by a sequence of terms with binds (lambda, let, use, etc), -// by default we linearize all bindings up to the first one that appears in the match "header". +# Given a match/switch term preceded by a sequence of terms with binds (lambda, let, use, etc), +# by default we linearize all bindings up to the first one that appears in the match "header". switch_linearization = @a diff --git a/tests/golden_tests/encode_pattern_match/match_num_adt_tup_parser.bend b/tests/golden_tests/encode_pattern_match/match_num_adt_tup_parser.bend index a00067fc..32f52867 100644 --- a/tests/golden_tests/encode_pattern_match/match_num_adt_tup_parser.bend +++ b/tests/golden_tests/encode_pattern_match/match_num_adt_tup_parser.bend @@ -1,4 +1,4 @@ -// Testing various forms of pattern matching +# Testing various forms of pattern matching data Result_ = (Ok val) | (Err err) Parse state (String/Cons '(' xs) = (Result_/Ok ('(', xs, state)) diff --git a/tests/golden_tests/hangs/recursive_with_unscoped.bend b/tests/golden_tests/hangs/recursive_with_unscoped.bend index 942df8dc..2bba2ee1 100644 --- a/tests/golden_tests/hangs/recursive_with_unscoped.bend +++ b/tests/golden_tests/hangs/recursive_with_unscoped.bend @@ -1,4 +1,4 @@ -// Impossible to extract/linearize so that it does not hang when running +# Impossible to extract/linearize so that it does not hang when running Foo = @x (x ({Foo @$unscoped *} *) $unscoped) main = (Foo *) diff --git a/tests/golden_tests/parse_file/imp_program.bend b/tests/golden_tests/parse_file/imp_program.bend index af01ad49..5c85c01f 100644 --- a/tests/golden_tests/parse_file/imp_program.bend +++ b/tests/golden_tests/parse_file/imp_program.bend @@ -22,8 +22,8 @@ def inc(n): n += 1; return n; -//def inc_list(list): -// return [x+1 for x in list]; +#def inc_list(list): +# return [x+1 for x in list]; def lam(): return lambda x, y: x; diff --git a/tests/golden_tests/run_file/bend_fold.bend b/tests/golden_tests/run_file/bend_fold.bend index 3e25872d..63d840f5 100644 --- a/tests/golden_tests/run_file/bend_fold.bend +++ b/tests/golden_tests/run_file/bend_fold.bend @@ -1,4 +1,4 @@ -// should return (a+b+c) * 2^depth +# should return (a+b+c) * 2^depth data Tree = (node ~lft ~rgt) | (leaf val) main = diff --git a/tests/golden_tests/run_file/bitonic_sort.bend b/tests/golden_tests/run_file/bitonic_sort.bend index dfb4c809..00f387be 100644 --- a/tests/golden_tests/run_file/bitonic_sort.bend +++ b/tests/golden_tests/run_file/bitonic_sort.bend @@ -1,44 +1,44 @@ data Tree = (Leaf a) | (Both a b) data Error = Err -// Atomic Swapper +# Atomic Swapper (Swap n a b) = switch n { 0: (Tree/Both a b) _: (Tree/Both b a) } -// Swaps distant values in parallel; corresponds to a Red Box +# Swaps distant values in parallel; corresponds to a Red Box (Warp s (Tree/Leaf a) (Tree/Leaf b)) = (Swap (^ (> a b) s) (Tree/Leaf a) (Tree/Leaf b)) (Warp s (Tree/Both a b) (Tree/Both c d)) = (Join (Warp s a c) (Warp s b d)) (Warp s a b) = Error/Err -// Rebuilds the warped tree in the original order +# Rebuilds the warped tree in the original order (Join (Tree/Both a b) (Tree/Both c d)) = (Tree/Both (Tree/Both a c) (Tree/Both b d)) (Join a b) = Error/Err -// Recursively warps each sub-tree; corresponds to a Blue/Green Box +# Recursively warps each sub-tree; corresponds to a Blue/Green Box (Flow s (Tree/Leaf a)) = (Tree/Leaf a) (Flow s (Tree/Both a b)) = (Down s (Warp s a b)) -// Propagates Flow downwards +# Propagates Flow downwards (Down s (Tree/Leaf a)) = (Tree/Leaf a) (Down s (Tree/Both a b)) = (Tree/Both (Flow s a) (Flow s b)) -// Bitonic Sort +# Bitonic Sort (Sort s (Tree/Leaf a)) = (Tree/Leaf a) (Sort s (Tree/Both a b)) = (Flow s (Tree/Both (Sort 0 a) (Sort 1 b))) -// Generates a tree of depth `n` +# Generates a tree of depth `n` (Gen n x) = switch n { 0: (Tree/Leaf x) _: (Tree/Both (Gen n-1 (* x 2)) (Gen n-1 (+ (* x 2) 1))) } -// Reverses a tree +# Reverses a tree (Rev (Tree/Leaf x)) = (Tree/Leaf x) (Rev (Tree/Both a b)) = (Tree/Both (Rev b) (Rev a)) -// Sums a tree +# Sums a tree (Sum (Tree/Leaf x)) = x (Sum (Tree/Both a b)) = (+ (Sum a) (Sum b)) diff --git a/tests/golden_tests/run_file/bitonic_sort_lam.bend b/tests/golden_tests/run_file/bitonic_sort_lam.bend index 73df0da9..d69c4061 100644 --- a/tests/golden_tests/run_file/bitonic_sort_lam.bend +++ b/tests/golden_tests/run_file/bitonic_sort_lam.bend @@ -1,4 +1,4 @@ -// data Tree = (Leaf x) | (Node x0 x1) +# data Tree = (Leaf x) | (Node x0 x1) Leaf = 位x 位l 位n (l x) Node = 位x0 位x1 位l 位n (n x0 x1) diff --git a/tests/golden_tests/run_file/branch_statements_assignment.bend b/tests/golden_tests/run_file/branch_statements_assignment.bend index 94b9de11..a7cb8f30 100644 --- a/tests/golden_tests/run_file/branch_statements_assignment.bend +++ b/tests/golden_tests/run_file/branch_statements_assignment.bend @@ -1,4 +1,4 @@ -// Test that branching statements can end with an assignment +# Test that branching statements can end with an assignment type Tree: node { val, ~lft, ~rgt } leaf diff --git a/tests/golden_tests/run_file/do_block_mixed.bend b/tests/golden_tests/run_file/do_block_mixed.bend index 9f88d21a..2d02dd0c 100644 --- a/tests/golden_tests/run_file/do_block_mixed.bend +++ b/tests/golden_tests/run_file/do_block_mixed.bend @@ -1,4 +1,4 @@ -// Mixed contents in a `do` block should still work. +# Mixed contents in a `do` block should still work. Result/bind r nxt = match r { Result/Ok: (nxt r.val) diff --git a/tests/golden_tests/run_file/example.bend b/tests/golden_tests/run_file/example.bend index 77c8fa12..b4729896 100644 --- a/tests/golden_tests/run_file/example.bend +++ b/tests/golden_tests/run_file/example.bend @@ -1,36 +1,36 @@ -// Write definitions like this +# Write definitions like this (Def1) = ((位a a) (位b b)) -// You can call a definition by just referencing its name -// It will be substituted in place of the reference +# You can call a definition by just referencing its name +# It will be substituted in place of the reference (Def2) = ((位a a) Def1) -// Definitions and variables can have names in upper and lower case and contain numbers -// Names defined in a more inner position shadow names in an outer position +# Definitions and variables can have names in upper and lower case and contain numbers +# Names defined in a more inner position shadow names in an outer position (def3) = ((位Def1 Def1) (位x 位x x)) -// The language is affine, but if you use a variable more than once the compiler inserts duplications for you -// Of course you can always do them manually +# The language is affine, but if you use a variable more than once the compiler inserts duplications for you +# Of course you can always do them manually (def4) = 位z let {z1 z2} = z; (z1 ((位x (x x x x x)) z2)) -// You can use machine numbers and some native numeric operations -// Numeric operations can only reduce numbers, doing (+ (位x x) 1) will not do anything +# You can use machine numbers and some native numeric operations +# Numeric operations can only reduce numbers, doing (+ (位x x) 1) will not do anything (nums) = 位x1 位x2 (* (+ x1 1) (/ (- x2 2) 1)) -// You can use numbers on the native match expression -// The `+` arm binds the `scrutinee`-1 variable to the the value of the number -1 +# You can use numbers on the native match expression +# The `+` arm binds the `scrutinee`-1 variable to the the value of the number -1 (Num.pred) = 位n switch n { 0: 0 _: n-1 } -// Write new data types like this +# Write new data types like this data Option = (Some val) | None data Bool = True | False -// You can have pattern matching on definitions -// Use `*` to ignore a pattern +# You can have pattern matching on definitions +# Use `*` to ignore a pattern (Option.unwrap_or (Option/Some val) *) = val (Option.unwrap_or Option/None or) = or @@ -38,39 +38,39 @@ data Bool = True | False (Bool.or * Bool/True) = Bool/True (Bool.or * *) = Bool/False -// Or using a match expression +# Or using a match expression (Bool.not) = 位bool match bool { Bool/True: Bool/False Bool/False: Bool/True } -// Data types can store values +# Data types can store values data Boxed = (Box val) -// Types with only one constructor can be destructured using `let` or a single matching definition +# Types with only one constructor can be destructured using `let` or a single matching definition (Box.map (Boxed/Box val) f) = (Boxed/Box (f val)) (Box.unbox) = 位box match box { Boxed/Box: box.val } -// Use tuples to store two values together without needing to create a new data type +# Use tuples to store two values together without needing to create a new data type (Tuple.new fst snd) = let pair = (fst, snd) pair -// Then you can destructure it inside the definition or using `let` +# Then you can destructure it inside the definition or using `let` (Tuple.fst (fst, snd)) = fst (Tuple.snd) = 位pair let (fst, snd) = pair snd -// All files must have a main definition to be run. -// You can execute a program in HVM with "cargo run -- run " -// Other options are "check" (the default mode) to just see if the file is well formed -// and "compile" to output hvm-core code. +# All files must have a main definition to be run. +# You can execute a program in HVM with "cargo run -- run " +# Other options are "check" (the default mode) to just see if the file is well formed +# and "compile" to output hvm-core code. (main) = let tup = (Tuple.new Option/None (Num.pred 5)) diff --git a/tests/golden_tests/run_file/exp.bend b/tests/golden_tests/run_file/exp.bend index 70581734..67117357 100644 --- a/tests/golden_tests/run_file/exp.bend +++ b/tests/golden_tests/run_file/exp.bend @@ -1,2 +1,2 @@ -// Requires different labels in the two duplications of f +# Requires different labels in the two duplications of f main = ((位f位x (f (f x))) (位f位x (f (f x)))) diff --git a/tests/golden_tests/run_file/extracted_match_pred.bend b/tests/golden_tests/run_file/extracted_match_pred.bend index cc3d8b93..11b36618 100644 --- a/tests/golden_tests/run_file/extracted_match_pred.bend +++ b/tests/golden_tests/run_file/extracted_match_pred.bend @@ -1,4 +1,4 @@ -// We expect the lambda 'p' from the match to be extracted which allows this recursive func +# We expect the lambda 'p' from the match to be extracted which allows this recursive func val = 位n (switch n { 0: valZ; _: (valS n-1) }) valZ = 0 valS = 位p (val p) diff --git a/tests/golden_tests/run_file/field_vectorization.bend b/tests/golden_tests/run_file/field_vectorization.bend index 947a4304..e75bb9d4 100644 --- a/tests/golden_tests/run_file/field_vectorization.bend +++ b/tests/golden_tests/run_file/field_vectorization.bend @@ -1,4 +1,4 @@ -// Vectorizes if the adts are encoded with tagged scott encoding +# Vectorizes if the adts are encoded with tagged scott encoding data Box = (New a) data Bool = T | F data List_ = (Cons x xs) | Nil diff --git a/tests/golden_tests/run_file/fold_with_state.bend b/tests/golden_tests/run_file/fold_with_state.bend index 12670958..ee8b980e 100644 --- a/tests/golden_tests/run_file/fold_with_state.bend +++ b/tests/golden_tests/run_file/fold_with_state.bend @@ -1,7 +1,7 @@ def main: y = 1 fold x = [0 0 0] with y: - case List/cons: - return List/cons(x.head + y x.tail(y + 1)) - case List/nil: - return List/nil + case List/Cons: + return List/Cons(x.head + y x.tail(y + 1)) + case List/Nil: + return List/Nil diff --git a/tests/golden_tests/run_file/kind_compiled_tree_sum.bend b/tests/golden_tests/run_file/kind_compiled_tree_sum.bend index fe39036a..b10bf3d0 100644 --- a/tests/golden_tests/run_file/kind_compiled_tree_sum.bend +++ b/tests/golden_tests/run_file/kind_compiled_tree_sum.bend @@ -1,5 +1,5 @@ -//WARNING: unsolved metas. -//WARNING: unsolved metas. +#WARNING: unsolved metas. +#WARNING: unsolved metas. _Char = 0 _List = 位_T 0 _List.cons = 位_head 位_tail 位_P 位_cons 位_nil ((_cons _head) _tail) diff --git a/tests/golden_tests/run_file/match_num_adt_tup_parser.bend b/tests/golden_tests/run_file/match_num_adt_tup_parser.bend index 74f96891..6656cf9d 100644 --- a/tests/golden_tests/run_file/match_num_adt_tup_parser.bend +++ b/tests/golden_tests/run_file/match_num_adt_tup_parser.bend @@ -1,4 +1,4 @@ -// Testing various forms of pattern matching +# Testing various forms of pattern matching data Result_ = (Ok val) | (Err err) Parse state (String/Cons '{' xs) = (Result_/Ok ('{', xs, state)) diff --git a/tests/golden_tests/run_file/queue.bend b/tests/golden_tests/run_file/queue.bend index b8241156..69dda5c3 100644 --- a/tests/golden_tests/run_file/queue.bend +++ b/tests/golden_tests/run_file/queue.bend @@ -1,18 +1,18 @@ -// A cool trick involving HVM's scopeless lambdas is linear qs: +# A cool trick involving HVM's scopeless lambdas is linear qs: -// Qnew : Queue a +# Qnew : Queue a Qnew = 位x x -// Qadd : a -> Queue a -> Queue a +# Qadd : a -> Queue a -> Queue a Qadd = 位x 位q 位k (q 位c (c x k)) -// Qrem : Queue a -> Pair a (Queue a) +# Qrem : Queue a -> Pair a (Queue a) Qrem = 位q (q $k 位x 位xs 位p(p x 位$k xs)) Nil = 位c 位n n Cons = 位h 位t 位c 位n (c h t) -// Output: [1, 2, 3] +# Output: [1, 2, 3] main = let q = Qnew let q = ((Qadd) 1 q) diff --git a/tests/golden_tests/run_file/radix_sort_ctr.bend b/tests/golden_tests/run_file/radix_sort_ctr.bend index b9beef61..4630a0c1 100644 --- a/tests/golden_tests/run_file/radix_sort_ctr.bend +++ b/tests/golden_tests/run_file/radix_sort_ctr.bend @@ -6,15 +6,15 @@ data Arr = Null | (Leaf x) | (Node a b) _: (Map_/Both b a) } -// Sort : Arr -> Arr +# Sort : Arr -> Arr (Sort t) = (ToArr 0 (ToMap t)) -// ToMap : Arr -> Map +# ToMap : Arr -> Map (ToMap Arr/Null) = Map_/Free (ToMap (Arr/Leaf a)) = (Radix a) (ToMap (Arr/Node a b)) = (Merge (ToMap a) (ToMap b)) -// ToArr : U60 -> Map -> Arr +# ToArr : U60 -> Map -> Arr (ToArr x Map_/Free) = Arr/Null (ToArr x Map_/Used) = (Arr/Leaf x) (ToArr x (Map_/Both a b)) = @@ -22,7 +22,7 @@ data Arr = Null | (Leaf x) | (Node a b) let b = (ToArr (+ (* x 2) 1) b) (Arr/Node a b) -// Merge : Map -> Map -> Map +# Merge : Map -> Map -> Map (Merge Map_/Free Map_/Free) = Map_/Free (Merge Map_/Free Map_/Used) = Map_/Used (Merge Map_/Used Map_/Free) = Map_/Used @@ -33,7 +33,7 @@ data Arr = Null | (Leaf x) | (Node a b) (Merge (Map_/Both a b) Map_/Used) = * (Merge Map_/Used (Map_/Both a b)) = * -// Radix : U60 -> Map +# Radix : U60 -> Map (Radix n) = let r = Map_/Used let r = (Swap (& n 1) r Map_/Free) @@ -75,17 +75,17 @@ data Arr = Null | (Leaf x) | (Node a b) r -// Reverse : Arr -> Arr +# Reverse : Arr -> Arr (Reverse Arr/Null) = Arr/Null (Reverse (Arr/Leaf a)) = (Arr/Leaf a) (Reverse (Arr/Node a b)) = (Arr/Node (Reverse b) (Reverse a)) -// Sum : Arr -> U60 +# Sum : Arr -> U60 (Sum Arr/Null) = 0 (Sum (Arr/Leaf x)) = x (Sum (Arr/Node a b)) = (+ (Sum a) (Sum b)) -// Gen : U60 -> Arr +# Gen : U60 -> Arr (Gen n) = (Gen.go n 0) (Gen.go n x) = switch n { 0: (Arr/Leaf x) diff --git a/tests/golden_tests/run_file/readback_list_other_ctr.bend b/tests/golden_tests/run_file/readback_list_other_ctr.bend index 92b5d279..84d0a700 100644 --- a/tests/golden_tests/run_file/readback_list_other_ctr.bend +++ b/tests/golden_tests/run_file/readback_list_other_ctr.bend @@ -1,4 +1,4 @@ -// Check that the ctr in the middle are interpreted correctly +# Check that the ctr in the middle are interpreted correctly data tup = (pair a b) main = (List/Cons diff --git a/tests/golden_tests/run_file/recursive_combinator.bend b/tests/golden_tests/run_file/recursive_combinator.bend index f087e769..b0968021 100644 --- a/tests/golden_tests/run_file/recursive_combinator.bend +++ b/tests/golden_tests/run_file/recursive_combinator.bend @@ -1,4 +1,4 @@ -// Tests that `(Foo 0)` is correctly extracted as a combinator, otherwise the file would hang when running +# Tests that `(Foo 0)` is correctly extracted as a combinator, otherwise the file would hang when running Foo = @x (x (Foo 0) @y (Foo y)) main = (Foo 0) diff --git a/tests/golden_tests/run_file/recursive_combinator_nested.bend b/tests/golden_tests/run_file/recursive_combinator_nested.bend index b70dcf51..9bf0a25b 100644 --- a/tests/golden_tests/run_file/recursive_combinator_nested.bend +++ b/tests/golden_tests/run_file/recursive_combinator_nested.bend @@ -1,4 +1,4 @@ -// Tests that `({Foo @* a} 9)` is correctly extracted as a combinator, otherwise the file would hang when running +# Tests that `({Foo @* a} 9)` is correctly extracted as a combinator, otherwise the file would hang when running Foo = @a switch a { 0: (#a {Foo @* a} 9); _: a-1 diff --git a/tests/golden_tests/run_file/str_inc.bend b/tests/golden_tests/run_file/str_inc.bend index 8b3a324f..065aa39a 100644 --- a/tests/golden_tests/run_file/str_inc.bend +++ b/tests/golden_tests/run_file/str_inc.bend @@ -3,7 +3,7 @@ (StrGo 0 str) = str (StrGo x (head, tail)) = ((+ 1 head), (StrGo (- x 1) tail)) -// Old str encoding +# Old str encoding Hello = (11, #str 位x (104, (101, (108, (108, (111, (32, (119, (111, (114, (108, (100, x)))))))))))) main = (StrInc Hello) diff --git a/tests/golden_tests/run_file/str_inc_eta.bend b/tests/golden_tests/run_file/str_inc_eta.bend index 31b4fb58..738b9a6c 100644 --- a/tests/golden_tests/run_file/str_inc_eta.bend +++ b/tests/golden_tests/run_file/str_inc_eta.bend @@ -3,7 +3,7 @@ (StrGo 0 (head, tail)) = (head, tail) (StrGo x (head, tail)) = ((+ 1 head), (StrGo (- x 1) tail)) -// Old str encoding +# Old str encoding Hello = (11, #str 位x (104, (101, (108, (108, (111, (32, (119, (111, (114, (108, (100, x)))))))))))) main = (StrInc Hello) diff --git a/tests/golden_tests/run_file/unused_dup_var.bend b/tests/golden_tests/run_file/unused_dup_var.bend index 00b96839..95592be5 100644 --- a/tests/golden_tests/run_file/unused_dup_var.bend +++ b/tests/golden_tests/run_file/unused_dup_var.bend @@ -1,6 +1,6 @@ X = 位x x -// This leaves (b1 X) with an ERA in the return, but the DUP is kept with an unused var +# This leaves (b1 X) with an ERA in the return, but the DUP is kept with an unused var main = ( (位a 位b let {b1 b2} = b; (a (b1 X) (b2 X))) (位a 位b b) diff --git a/tests/golden_tests/run_lazy/bitonic_sort.bend b/tests/golden_tests/run_lazy/bitonic_sort.bend index dfb4c809..00f387be 100644 --- a/tests/golden_tests/run_lazy/bitonic_sort.bend +++ b/tests/golden_tests/run_lazy/bitonic_sort.bend @@ -1,44 +1,44 @@ data Tree = (Leaf a) | (Both a b) data Error = Err -// Atomic Swapper +# Atomic Swapper (Swap n a b) = switch n { 0: (Tree/Both a b) _: (Tree/Both b a) } -// Swaps distant values in parallel; corresponds to a Red Box +# Swaps distant values in parallel; corresponds to a Red Box (Warp s (Tree/Leaf a) (Tree/Leaf b)) = (Swap (^ (> a b) s) (Tree/Leaf a) (Tree/Leaf b)) (Warp s (Tree/Both a b) (Tree/Both c d)) = (Join (Warp s a c) (Warp s b d)) (Warp s a b) = Error/Err -// Rebuilds the warped tree in the original order +# Rebuilds the warped tree in the original order (Join (Tree/Both a b) (Tree/Both c d)) = (Tree/Both (Tree/Both a c) (Tree/Both b d)) (Join a b) = Error/Err -// Recursively warps each sub-tree; corresponds to a Blue/Green Box +# Recursively warps each sub-tree; corresponds to a Blue/Green Box (Flow s (Tree/Leaf a)) = (Tree/Leaf a) (Flow s (Tree/Both a b)) = (Down s (Warp s a b)) -// Propagates Flow downwards +# Propagates Flow downwards (Down s (Tree/Leaf a)) = (Tree/Leaf a) (Down s (Tree/Both a b)) = (Tree/Both (Flow s a) (Flow s b)) -// Bitonic Sort +# Bitonic Sort (Sort s (Tree/Leaf a)) = (Tree/Leaf a) (Sort s (Tree/Both a b)) = (Flow s (Tree/Both (Sort 0 a) (Sort 1 b))) -// Generates a tree of depth `n` +# Generates a tree of depth `n` (Gen n x) = switch n { 0: (Tree/Leaf x) _: (Tree/Both (Gen n-1 (* x 2)) (Gen n-1 (+ (* x 2) 1))) } -// Reverses a tree +# Reverses a tree (Rev (Tree/Leaf x)) = (Tree/Leaf x) (Rev (Tree/Both a b)) = (Tree/Both (Rev b) (Rev a)) -// Sums a tree +# Sums a tree (Sum (Tree/Leaf x)) = x (Sum (Tree/Both a b)) = (+ (Sum a) (Sum b)) diff --git a/tests/golden_tests/run_lazy/bitonic_sort_lam.bend b/tests/golden_tests/run_lazy/bitonic_sort_lam.bend index 6b60b410..b426026c 100644 --- a/tests/golden_tests/run_lazy/bitonic_sort_lam.bend +++ b/tests/golden_tests/run_lazy/bitonic_sort_lam.bend @@ -1,4 +1,4 @@ -// data Tree = (Leaf x) | (Node x0 x1) +# data Tree = (Leaf x) | (Node x0 x1) Leaf = 位x #Tree 位l #Tree 位n (l x) Node = 位x0 位x1 #Tree 位l #Tree 位n (n x0 x1) diff --git a/tests/golden_tests/run_lazy/example.bend b/tests/golden_tests/run_lazy/example.bend index 5e515509..5592e9de 100644 --- a/tests/golden_tests/run_lazy/example.bend +++ b/tests/golden_tests/run_lazy/example.bend @@ -1,36 +1,36 @@ -// Write definitions like this +# Write definitions like this (Def1) = ((位a a) (位b b)) -// You can call a definition by just referencing its name -// It will be substituted in place of the reference +# You can call a definition by just referencing its name +# It will be substituted in place of the reference (Def2) = ((位a a) Def1) -// Definitions and variables can have names in upper and lower case and contain numbers -// Names defined in a more inner position shadow names in an outer position +# Definitions and variables can have names in upper and lower case and contain numbers +# Names defined in a more inner position shadow names in an outer position (def3) = ((位Def1 Def1) (位x 位x x)) -// The language is affine, but if you use a variable more than once the compiler inserts duplications for you -// Of course you can always do them manually +# The language is affine, but if you use a variable more than once the compiler inserts duplications for you +# Of course you can always do them manually (def4) = 位z let {z1 z2} = z; (z1 ((位x (x x x x x)) z2)) -// You can use machine numbers and some native numeric operations -// Numeric operations can only reduce numbers, doing (+ (位x x) 1) will not do anything +# You can use machine numbers and some native numeric operations +# Numeric operations can only reduce numbers, doing (+ (位x x) 1) will not do anything (nums) = 位x1 位x2 (* (+ x1 1) (/ (- x2 2) 1)) -// You can use numbers on the native match expression -// The `+` arm binds the `scrutinee`-1 variable to the the value of the number -1 +# You can use numbers on the native match expression +# The `+` arm binds the `scrutinee`-1 variable to the the value of the number -1 (Num.pred) = 位n switch n { 0: 0 _: n-1 } -// Write new data types like this +# Write new data types like this data Option = (Some val) | None data Bool = True | False -// You can have pattern matching on definitions -// Use `*` to ignore a pattern +# You can have pattern matching on definitions +# Use `*` to ignore a pattern (Option.unwrap_or (Option/Some val) *) = val (Option.unwrap_or Option/None or) = or @@ -38,39 +38,39 @@ data Bool = True | False (Bool.or * Bool/True) = Bool/True (Bool.or * *) = Bool/False -// Or using a match expression +# Or using a match expression (Bool.not) = 位bool match bool { Bool/True: Bool/False Bool/False: Bool/True } -// Data types can store values +# Data types can store values data Boxed = (Box val) -// Types with only one constructor can be destructured using `let` or a single matching definition +# Types with only one constructor can be destructured using `let` or a single matching definition (Box.map (Boxed/Box val) f) = (Boxed/Box (f val)) (Box.unbox) = 位box match box { Boxed/Box: box.val } -// Use tuples to store two values together without needing to create a new data type +# Use tuples to store two values together without needing to create a new data type (Tuple.new fst snd) = let pair = (fst, snd) pair -// Then you can destructure it inside the definition or using `let` +# Then you can destructure it inside the definition or using `let` (Tuple.fst (fst, snd)) = fst (Tuple.snd) = 位pair let (fst, snd) = pair snd -// All files must have a main definition to be run. -// You can execute a program in HVM with "cargo run -- run " -// Other options are "check" (the default mode) to just see if the file is well formed -// and "compile" to output hvm-core code. +# All files must have a main definition to be run. +# You can execute a program in HVM with "cargo run -- run " +# Other options are "check" (the default mode) to just see if the file is well formed +# and "compile" to output hvm-core code. (main) = let tup = (Tuple.new None (Num.pred 5)) diff --git a/tests/golden_tests/run_lazy/extracted_match_pred.bend b/tests/golden_tests/run_lazy/extracted_match_pred.bend index cc3d8b93..11b36618 100644 --- a/tests/golden_tests/run_lazy/extracted_match_pred.bend +++ b/tests/golden_tests/run_lazy/extracted_match_pred.bend @@ -1,4 +1,4 @@ -// We expect the lambda 'p' from the match to be extracted which allows this recursive func +# We expect the lambda 'p' from the match to be extracted which allows this recursive func val = 位n (switch n { 0: valZ; _: (valS n-1) }) valZ = 0 valS = 位p (val p) diff --git a/tests/golden_tests/run_lazy/field_vectorization.bend b/tests/golden_tests/run_lazy/field_vectorization.bend index 947a4304..e75bb9d4 100644 --- a/tests/golden_tests/run_lazy/field_vectorization.bend +++ b/tests/golden_tests/run_lazy/field_vectorization.bend @@ -1,4 +1,4 @@ -// Vectorizes if the adts are encoded with tagged scott encoding +# Vectorizes if the adts are encoded with tagged scott encoding data Box = (New a) data Bool = T | F data List_ = (Cons x xs) | Nil diff --git a/tests/golden_tests/run_lazy/queue.bend b/tests/golden_tests/run_lazy/queue.bend index b8241156..69dda5c3 100644 --- a/tests/golden_tests/run_lazy/queue.bend +++ b/tests/golden_tests/run_lazy/queue.bend @@ -1,18 +1,18 @@ -// A cool trick involving HVM's scopeless lambdas is linear qs: +# A cool trick involving HVM's scopeless lambdas is linear qs: -// Qnew : Queue a +# Qnew : Queue a Qnew = 位x x -// Qadd : a -> Queue a -> Queue a +# Qadd : a -> Queue a -> Queue a Qadd = 位x 位q 位k (q 位c (c x k)) -// Qrem : Queue a -> Pair a (Queue a) +# Qrem : Queue a -> Pair a (Queue a) Qrem = 位q (q $k 位x 位xs 位p(p x 位$k xs)) Nil = 位c 位n n Cons = 位h 位t 位c 位n (c h t) -// Output: [1, 2, 3] +# Output: [1, 2, 3] main = let q = Qnew let q = ((Qadd) 1 q) diff --git a/tests/golden_tests/run_lazy/radix_sort_ctr.bend b/tests/golden_tests/run_lazy/radix_sort_ctr.bend index b9beef61..4630a0c1 100644 --- a/tests/golden_tests/run_lazy/radix_sort_ctr.bend +++ b/tests/golden_tests/run_lazy/radix_sort_ctr.bend @@ -6,15 +6,15 @@ data Arr = Null | (Leaf x) | (Node a b) _: (Map_/Both b a) } -// Sort : Arr -> Arr +# Sort : Arr -> Arr (Sort t) = (ToArr 0 (ToMap t)) -// ToMap : Arr -> Map +# ToMap : Arr -> Map (ToMap Arr/Null) = Map_/Free (ToMap (Arr/Leaf a)) = (Radix a) (ToMap (Arr/Node a b)) = (Merge (ToMap a) (ToMap b)) -// ToArr : U60 -> Map -> Arr +# ToArr : U60 -> Map -> Arr (ToArr x Map_/Free) = Arr/Null (ToArr x Map_/Used) = (Arr/Leaf x) (ToArr x (Map_/Both a b)) = @@ -22,7 +22,7 @@ data Arr = Null | (Leaf x) | (Node a b) let b = (ToArr (+ (* x 2) 1) b) (Arr/Node a b) -// Merge : Map -> Map -> Map +# Merge : Map -> Map -> Map (Merge Map_/Free Map_/Free) = Map_/Free (Merge Map_/Free Map_/Used) = Map_/Used (Merge Map_/Used Map_/Free) = Map_/Used @@ -33,7 +33,7 @@ data Arr = Null | (Leaf x) | (Node a b) (Merge (Map_/Both a b) Map_/Used) = * (Merge Map_/Used (Map_/Both a b)) = * -// Radix : U60 -> Map +# Radix : U60 -> Map (Radix n) = let r = Map_/Used let r = (Swap (& n 1) r Map_/Free) @@ -75,17 +75,17 @@ data Arr = Null | (Leaf x) | (Node a b) r -// Reverse : Arr -> Arr +# Reverse : Arr -> Arr (Reverse Arr/Null) = Arr/Null (Reverse (Arr/Leaf a)) = (Arr/Leaf a) (Reverse (Arr/Node a b)) = (Arr/Node (Reverse b) (Reverse a)) -// Sum : Arr -> U60 +# Sum : Arr -> U60 (Sum Arr/Null) = 0 (Sum (Arr/Leaf x)) = x (Sum (Arr/Node a b)) = (+ (Sum a) (Sum b)) -// Gen : U60 -> Arr +# Gen : U60 -> Arr (Gen n) = (Gen.go n 0) (Gen.go n x) = switch n { 0: (Arr/Leaf x) diff --git a/tests/golden_tests/run_lazy/str_inc.bend b/tests/golden_tests/run_lazy/str_inc.bend index 8b3a324f..065aa39a 100644 --- a/tests/golden_tests/run_lazy/str_inc.bend +++ b/tests/golden_tests/run_lazy/str_inc.bend @@ -3,7 +3,7 @@ (StrGo 0 str) = str (StrGo x (head, tail)) = ((+ 1 head), (StrGo (- x 1) tail)) -// Old str encoding +# Old str encoding Hello = (11, #str 位x (104, (101, (108, (108, (111, (32, (119, (111, (114, (108, (100, x)))))))))))) main = (StrInc Hello) diff --git a/tests/golden_tests/run_lazy/str_inc_eta.bend b/tests/golden_tests/run_lazy/str_inc_eta.bend index deadade9..46d1bec8 100644 --- a/tests/golden_tests/run_lazy/str_inc_eta.bend +++ b/tests/golden_tests/run_lazy/str_inc_eta.bend @@ -3,7 +3,7 @@ (StrGo 0 (head, tail)) = (head, tail) (StrGo x (head, tail)) = ((+ 1 head), (StrGo (- x 1) tail)) -// Old str encoding +# Old str encoding Hello = (11, #str 位x (104, (101, (108, (108, (111, (32, (119, (111, (114, (108, (100, x)))))))))))) main = (StrInc Hello) diff --git a/tests/golden_tests/run_lazy/unused_dup_var.bend b/tests/golden_tests/run_lazy/unused_dup_var.bend index 00b96839..95592be5 100644 --- a/tests/golden_tests/run_lazy/unused_dup_var.bend +++ b/tests/golden_tests/run_lazy/unused_dup_var.bend @@ -1,6 +1,6 @@ X = 位x x -// This leaves (b1 X) with an ERA in the return, but the DUP is kept with an unused var +# This leaves (b1 X) with an ERA in the return, but the DUP is kept with an unused var main = ( (位a 位b let {b1 b2} = b; (a (b1 X) (b2 X))) (位a 位b b) diff --git a/tests/golden_tests/scott_triggers_unused/test.bend b/tests/golden_tests/scott_triggers_unused/test.bend index 5edb5c88..cc7a5239 100644 --- a/tests/golden_tests/scott_triggers_unused/test.bend +++ b/tests/golden_tests/scott_triggers_unused/test.bend @@ -1,12 +1,12 @@ -// The test below should not trigger this warning: -// -// In definition 'f': -// Definition is unused. -// In definition 't': -// Definition is unused. -// -// This was happening because the prune algorithm was just collecting constructors -// by searching for tags. +# The test below should not trigger this warning: +# +# In definition 'f': +# Definition is unused. +# In definition 't': +# Definition is unused. +# +# This was happening because the prune algorithm was just collecting constructors +# by searching for tags. data bool = t | f diff --git a/tests/golden_tests/simplify_matches/double_unwrap_box.bend b/tests/golden_tests/simplify_matches/double_unwrap_box.bend index 0f622c55..6ba29f5d 100644 --- a/tests/golden_tests/simplify_matches/double_unwrap_box.bend +++ b/tests/golden_tests/simplify_matches/double_unwrap_box.bend @@ -1,4 +1,4 @@ -// Should notice that the second rule is redundant, not create flattened rule for it and not forward the second argument. +# Should notice that the second rule is redundant, not create flattened rule for it and not forward the second argument. data Boxed = (Box x) (DoubleUnbox (Boxed/Box (Boxed/Box x)) *) = x diff --git a/tests/golden_tests/simplify_matches/double_unwrap_maybe.bend b/tests/golden_tests/simplify_matches/double_unwrap_maybe.bend index aee0ea38..d384e338 100644 --- a/tests/golden_tests/simplify_matches/double_unwrap_maybe.bend +++ b/tests/golden_tests/simplify_matches/double_unwrap_maybe.bend @@ -1,4 +1,4 @@ -// We want to make sure that the default value is not mistakenly erased in the first level of flattening. +# We want to make sure that the default value is not mistakenly erased in the first level of flattening. data Maybe = (Some x) | None (DoubleUnwrap (Maybe/Some (Maybe/Some x)) *) = x diff --git a/tests/golden_tests/simplify_matches/flatten_with_terminal.bend b/tests/golden_tests/simplify_matches/flatten_with_terminal.bend index a70d1989..6e78994f 100644 --- a/tests/golden_tests/simplify_matches/flatten_with_terminal.bend +++ b/tests/golden_tests/simplify_matches/flatten_with_terminal.bend @@ -1,4 +1,4 @@ -// The flattened rule should only have 1 arg, for matching 'B' +# The flattened rule should only have 1 arg, for matching 'B' data A_t = (A b) data B_t = B diff --git a/tests/golden_tests/simplify_matches/linearize_match_all.bend b/tests/golden_tests/simplify_matches/linearize_match_all.bend index 57fc0a7d..ab9e3dcc 100644 --- a/tests/golden_tests/simplify_matches/linearize_match_all.bend +++ b/tests/golden_tests/simplify_matches/linearize_match_all.bend @@ -1,31 +1,31 @@ -// Testing linearization in different situations +# Testing linearization in different situations data ConsList = (Cons h t) | Nil -// Auto linearized on strict mode +# Auto linearized on strict mode A = @a @b @c switch a { 0: (b c) _: (a-1 b c) } -// Manually linearized +# Manually linearized B = @a @b @c switch c with a b { 0: (a b) _: (a b c-1) } -// Not linearized +# Not linearized C = @a @b @c switch c { 0: (a b) _: (a b c-1) } -// Auto linearized, one arg not used +# Auto linearized, one arg not used D = @a @b @c switch a { 0: c _: (a-1 c) } -// Pattern matching defs linearize all arguments +# Pattern matching defs linearize all arguments E (ConsList/Cons a b) (ConsList/Cons c d) = (a b c d) E a b = (a b) diff --git a/tests/golden_tests/simplify_matches/redundant_with_era.bend b/tests/golden_tests/simplify_matches/redundant_with_era.bend index 0926e1e7..1f9aa38d 100644 --- a/tests/golden_tests/simplify_matches/redundant_with_era.bend +++ b/tests/golden_tests/simplify_matches/redundant_with_era.bend @@ -1,4 +1,4 @@ -// Should not create flattened rules for the 2 bottom rules and should properly erase the first arg. +# Should not create flattened rules for the 2 bottom rules and should properly erase the first arg. (Fn2 * (*, (*, a))) = a (Fn2 0 *) = 0 (Fn2 a *) = (- a 1) diff --git a/tests/snapshots/compile_file__360_no_scope.bend.snap b/tests/snapshots/compile_file__360_no_scope.bend.snap index 6c79cadf..905f60e6 100644 --- a/tests/snapshots/compile_file__360_no_scope.bend.snap +++ b/tests/snapshots/compile_file__360_no_scope.bend.snap @@ -4,5 +4,6 @@ input_file: tests/golden_tests/compile_file/360_no_scope.bend --- Errors: In tests/golden_tests/compile_file/360_no_scope.bend : -Tagged terms not supported for hvm32. - 4 | let #x{#y($e, $f) #y($g, $h)} = #y(#x{$d $f}, #x{$e, $g}) +- expected: '=' +- detected: end of input + 6 |   diff --git a/tests/snapshots/compile_file_o_all__tagged_dup.bend.snap b/tests/snapshots/compile_file_o_all__tagged_dup.bend.snap index 6423b4d1..a2ba6e42 100644 --- a/tests/snapshots/compile_file_o_all__tagged_dup.bend.snap +++ b/tests/snapshots/compile_file_o_all__tagged_dup.bend.snap @@ -4,5 +4,6 @@ input_file: tests/golden_tests/compile_file_o_all/tagged_dup.bend --- Errors: In tests/golden_tests/compile_file_o_all/tagged_dup.bend : -Tagged terms not supported for hvm32. - 2 | let #i {a b} = @x x; +- expected: '=' +- detected: + 4 | let #i {e f} = @x x; diff --git a/tests/snapshots/compile_file_o_all__tagged_lam.bend.snap b/tests/snapshots/compile_file_o_all__tagged_lam.bend.snap index 95bb52c0..d76c7274 100644 --- a/tests/snapshots/compile_file_o_all__tagged_lam.bend.snap +++ b/tests/snapshots/compile_file_o_all__tagged_lam.bend.snap @@ -4,5 +4,6 @@ input_file: tests/golden_tests/compile_file_o_all/tagged_lam.bend --- Errors: In tests/golden_tests/compile_file_o_all/tagged_lam.bend : -Tagged terms not supported for hvm32. - 1 | main = #foo ((#foo @x (+ x 1), #foo @x (* x x)) 2) +- expected: term +- detected: end of input + 2 |   diff --git a/tests/snapshots/compile_file_o_all__tagged_sup.bend.snap b/tests/snapshots/compile_file_o_all__tagged_sup.bend.snap index f9f9db45..d6a53503 100644 --- a/tests/snapshots/compile_file_o_all__tagged_sup.bend.snap +++ b/tests/snapshots/compile_file_o_all__tagged_sup.bend.snap @@ -4,5 +4,6 @@ input_file: tests/golden_tests/compile_file_o_all/tagged_sup.bend --- Errors: In tests/golden_tests/compile_file_o_all/tagged_sup.bend : -Tagged terms not supported for hvm32. - 1 | a = #i {位x x 位x x} +- expected: top-level definition +- detected: + 2 | b = #i {位x x 位x x} diff --git a/tests/snapshots/run_file__360_no_scope.bend.snap b/tests/snapshots/run_file__360_no_scope.bend.snap index 88bdf320..377c47ce 100644 --- a/tests/snapshots/run_file__360_no_scope.bend.snap +++ b/tests/snapshots/run_file__360_no_scope.bend.snap @@ -4,5 +4,6 @@ input_file: tests/golden_tests/run_file/360_no_scope.bend --- Errors: In tests/golden_tests/run_file/360_no_scope.bend : -Tagged terms not supported for hvm32. - 4 | let #x{#y($e, $f) #y($g, $h)} = #y(#x{$d $f}, #x{$e, $g}) +- expected: '=' +- detected: end of input + 6 |   diff --git a/tests/snapshots/run_file__adt_match_wrong_tag.bend.snap b/tests/snapshots/run_file__adt_match_wrong_tag.bend.snap index b4a01ef9..3de3d1f9 100644 --- a/tests/snapshots/run_file__adt_match_wrong_tag.bend.snap +++ b/tests/snapshots/run_file__adt_match_wrong_tag.bend.snap @@ -4,5 +4,6 @@ input_file: tests/golden_tests/run_file/adt_match_wrong_tag.bend --- Errors: In tests/golden_tests/run_file/adt_match_wrong_tag.bend : -Tagged terms not supported for hvm32. - 3 | main = 位a #Option (a #wrong_tag 位b b *) +- expected: term +- detected: end of input + 4 |   diff --git a/tests/snapshots/run_file__adt_wrong_tag.bend.snap b/tests/snapshots/run_file__adt_wrong_tag.bend.snap index a7374208..6de0184e 100644 --- a/tests/snapshots/run_file__adt_wrong_tag.bend.snap +++ b/tests/snapshots/run_file__adt_wrong_tag.bend.snap @@ -4,5 +4,6 @@ input_file: tests/golden_tests/run_file/adt_wrong_tag.bend --- Errors: In tests/golden_tests/run_file/adt_wrong_tag.bend : -Tagged terms not supported for hvm32. - 3 | main = (@a #Option (a #wrong_tag @x x *))  +- expected: term +- detected: end of input + 4 |   diff --git a/tests/snapshots/run_file__fold_with_state.bend.snap b/tests/snapshots/run_file__fold_with_state.bend.snap index f720ca24..0d1c0e51 100644 --- a/tests/snapshots/run_file__fold_with_state.bend.snap +++ b/tests/snapshots/run_file__fold_with_state.bend.snap @@ -2,4 +2,4 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/run_file/fold_with_state.bend --- -位a 位* (a 1 位b 位* (b 2 位c 位* (c 3 List/nil))) +位a 位* (a 1 位b 位* (b 2 位c 位* (c 3 List/Nil))) diff --git a/tests/snapshots/run_file__match_sup.bend.snap b/tests/snapshots/run_file__match_sup.bend.snap index 0ffa334a..99a099b1 100644 --- a/tests/snapshots/run_file__match_sup.bend.snap +++ b/tests/snapshots/run_file__match_sup.bend.snap @@ -4,5 +4,6 @@ input_file: tests/golden_tests/run_file/match_sup.bend --- Errors: In tests/golden_tests/run_file/match_sup.bend : -Tagged terms not supported for hvm32. - 2 | let k = #a{0 1}; +- expected: term +- detected: end of input + 7 |   diff --git a/tests/snapshots/run_file__nat_add.bend.snap b/tests/snapshots/run_file__nat_add.bend.snap index 9194d9e3..31b36eaa 100644 --- a/tests/snapshots/run_file__nat_add.bend.snap +++ b/tests/snapshots/run_file__nat_add.bend.snap @@ -2,4 +2,8 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/run_file/nat_add.bend --- -位a 位* (a 位b 位* (b 位c 位* (c 位d 位* (d 位e 位* (e 位f 位* (f 位g 位* (g 位h 位* (h 位i 位* (i 位j 位* (j 位k 位* (k 位l 位* (l 位m 位* (m 位n 位* (n 位o 位* (o 位p 位* (p 位q 位* (q 位r 位* (r 位s 位* (s 位t 位* (t 位u 位* (u 位v 位* (v 位w 位* (w 位x 位* (x 位y 位* (y (Nat/Succ (Nat/Succ (Nat/Succ (Nat/Succ (Nat/Succ (Nat/Succ (Nat/Succ (Nat/Succ (Nat/Succ Nat/Zero)))))))))))))))))))))))))))))))))) +Errors: +In tests/golden_tests/run_file/nat_add.bend : +- expected: term +- detected: end of input + 5 |   diff --git a/tests/snapshots/run_file__nat_add_num.bend.snap b/tests/snapshots/run_file__nat_add_num.bend.snap index a71df1ad..343188ce 100644 --- a/tests/snapshots/run_file__nat_add_num.bend.snap +++ b/tests/snapshots/run_file__nat_add_num.bend.snap @@ -2,4 +2,8 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/run_file/nat_add_num.bend --- -位a 位* (a 位b 位* (b 位c 位* (c 位d 位* (d 0)))) +Errors: +In tests/golden_tests/run_file/nat_add_num.bend : +- expected: term +- detected: end of input + 5 |   diff --git a/tests/snapshots/run_file__recursive_combinator_nested.bend.snap b/tests/snapshots/run_file__recursive_combinator_nested.bend.snap index 4253c6e0..e45fa3c3 100644 --- a/tests/snapshots/run_file__recursive_combinator_nested.bend.snap +++ b/tests/snapshots/run_file__recursive_combinator_nested.bend.snap @@ -4,5 +4,6 @@ input_file: tests/golden_tests/run_file/recursive_combinator_nested.bend --- Errors: In tests/golden_tests/run_file/recursive_combinator_nested.bend : -Tagged terms not supported for hvm32. - 3 | 0: (#a {Foo @* a} 9); +- expected: term +- detected: + 4 | _: a-1 diff --git a/tests/snapshots/run_file__str_inc.bend.snap b/tests/snapshots/run_file__str_inc.bend.snap index 2387bd7d..26573875 100644 --- a/tests/snapshots/run_file__str_inc.bend.snap +++ b/tests/snapshots/run_file__str_inc.bend.snap @@ -4,5 +4,6 @@ input_file: tests/golden_tests/run_file/str_inc.bend --- Errors: In tests/golden_tests/run_file/str_inc.bend : -Tagged terms not supported for hvm32. - 1 | (StrInc (len, buf)) = (len, #str 位x (StrGo len #str (buf x))) +- expected: ')' +- detected: + 3 | (StrGo 0 str) = str diff --git a/tests/snapshots/run_file__str_inc_eta.bend.snap b/tests/snapshots/run_file__str_inc_eta.bend.snap index 49948fd2..89c3b993 100644 --- a/tests/snapshots/run_file__str_inc_eta.bend.snap +++ b/tests/snapshots/run_file__str_inc_eta.bend.snap @@ -4,5 +4,6 @@ input_file: tests/golden_tests/run_file/str_inc_eta.bend --- Errors: In tests/golden_tests/run_file/str_inc_eta.bend : -Tagged terms not supported for hvm32. - 1 | (StrInc (len, buf)) = (len, #str 位x (StrGo len #str (buf x))) +- expected: ')' +- detected: + 3 | (StrGo 0 (head, tail)) = (head, tail) diff --git a/tests/snapshots/run_file__tagged_lam.bend.snap b/tests/snapshots/run_file__tagged_lam.bend.snap index bff14191..1f1db320 100644 --- a/tests/snapshots/run_file__tagged_lam.bend.snap +++ b/tests/snapshots/run_file__tagged_lam.bend.snap @@ -4,5 +4,6 @@ input_file: tests/golden_tests/run_file/tagged_lam.bend --- Errors: In tests/golden_tests/run_file/tagged_lam.bend : -Tagged terms not supported for hvm32. - 1 | main = #foo ((#foo @x (+ x 1), #foo @x (* x x)) 2) +- expected: term +- detected: end of input + 2 |