Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tests #345

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions examples/demo_io/main.bend
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# TODO: update tests to handle IO
test-skip = 1

type IO_T:
Done { magic, expr }
Call { magic, func, argm, cont }
Expand All @@ -15,15 +18,11 @@ def IO_T/bind(a, b):
case IO_T/Call:
return IO_T/Call(IO_T/MAGIC, a.func, a.argm, lambda x: IO_T/bind(a.cont(x), b))

def call(func, argm):
def call_io(func, argm):
return IO_T/Call(IO_T/MAGIC, func, argm, lambda x: IO_T/Done(IO_T/MAGIC, x))

def main:
return 42

# FIXME: tests still can't handle IO, so I commented this out
#def main:
#do IO_T:
#x <- call("PUT_TEXT", "hello\n")
#y <- call("PUT_TEXT", "world\n")
#return 42
do IO_T:
x <- call_io("PUT_TEXT", "hello\n")
y <- call_io("PUT_TEXT", "world\n")
return 42
52 changes: 48 additions & 4 deletions examples/demo_io/main.hvm
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,54 @@
@IO_T/wrap = a
& @IO_T/Done ~ (@IO_T/MAGIC a)

@call = (a (b c))
& @IO_T/Call ~ (@IO_T/MAGIC (a (b (@call__C0 c))))
@String/Cons = (a (b ((1 (a (b c))) c)))

@call__C0 = a
@String/Nil = ((0 a) a)

@call_io = (a (b c))
& @IO_T/Call ~ (@IO_T/MAGIC (a (b (@call_io__C0 c))))

@call_io__C0 = a
& @IO_T/Done ~ (@IO_T/MAGIC a)

@main = 42
@main = a
& @IO_T/bind ~ (@main__C2 (@main__C1 a))

@main__C0 = o
& @call_io ~ (h (n o))
& @String/Cons ~ (80 (g h))
& @String/Cons ~ (85 (f g))
& @String/Cons ~ (84 (e f))
& @String/Cons ~ (95 (d e))
& @String/Cons ~ (84 (c d))
& @String/Cons ~ (69 (b c))
& @String/Cons ~ (88 (a b))
& @String/Cons ~ (84 (@String/Nil a))
& @String/Cons ~ (119 (m n))
& @String/Cons ~ (111 (l m))
& @String/Cons ~ (114 (k l))
& @String/Cons ~ (108 (j k))
& @String/Cons ~ (100 (i j))
& @String/Cons ~ (10 (@String/Nil i))

@main__C1 = (* a)
& @IO_T/bind ~ (@main__C0 ((* 42) a))

@main__C2 = o
& @call_io ~ (h (n o))
& @String/Cons ~ (80 (g h))
& @String/Cons ~ (85 (f g))
& @String/Cons ~ (84 (e f))
& @String/Cons ~ (95 (d e))
& @String/Cons ~ (84 (c d))
& @String/Cons ~ (69 (b c))
& @String/Cons ~ (88 (a b))
& @String/Cons ~ (84 (@String/Nil a))
& @String/Cons ~ (104 (m n))
& @String/Cons ~ (101 (l m))
& @String/Cons ~ (108 (k l))
& @String/Cons ~ (108 (j k))
& @String/Cons ~ (111 (i j))
& @String/Cons ~ (10 (@String/Nil i))

@test-skip = 1
140 changes: 69 additions & 71 deletions examples/sort_radix/main.bend
Original file line number Diff line number Diff line change
@@ -1,82 +1,80 @@

#// data Arr = Empty | (Single x) | (Concat x0 x1)
#Empty = λempty λsingle λconcat empty
#Single = λx λempty λsingle λconcat (single x)
#Concat = λx0 λx1 λempty λsingle λconcat (concat x0 x1)
# data Arr = Empty | (Single x) | (Concat x0 x1)
Empty = λempty λsingle λconcat empty
Single = λx λempty λsingle λconcat (single x)
Concat = λx0 λx1 λempty λsingle λconcat (concat x0 x1)

#// data Map = Free | Busy | (Node x0 x1)
#Free = λfree λbusy λnode free
#Busy = λfree λbusy λnode busy
#Node = λx0 λx1 λfree λbusy λnode (node x0 x1)
# data Map = Free | Busy | (Node x0 x1)
Free = λfree λbusy λnode free
Busy = λfree λbusy λnode busy
Node = λx0 λx1 λfree λbusy λnode (node x0 x1)

#// gen : u32 -> Arr
#gen = λn switch n {
#0: λx (Single x)
#_: λx
#let x0 = (* x 2)
#let x1 = (+ x0 1)
#(Concat (gen n-1 x1) (gen n-1 x0))
#}
# gen : u32 -> Arr
gen = λn switch n {
0: λx (Single x)
_: λx
let x0 = (* x 2)
let x1 = (+ x0 1)
(Concat (gen n-1 x1) (gen n-1 x0))
}

#// sum : Arr -> u32
#sum = λa
#let a_empty = 0
#let a_single = λx x
#let a_concat = λx0 λx1 (+ (sum x0) (sum x1))
#(a a_empty a_single a_concat)
# sum : Arr -> u32
sum = λa
let a_empty = 0
let a_single = λx x
let a_concat = λx0 λx1 (+ (sum x0) (sum x1))
(a a_empty a_single a_concat)

#// sort : Arr -> Arr
#sort = λt (to_arr (to_map t) 0)
# sort : Arr -> Arr
sort = λt (to_arr (to_map t) 0)

#// to_arr : Map -> u32 -> Arr
#to_arr = λa
#let a_free = λk Empty
#let a_busy = λk (Single k)
#let a_node = λx0 λx1 λk
#let x0 = (to_arr x0 (+ (* k 2) 0))
#let x1 = (to_arr x1 (+ (* k 2) 1))
#(Concat x0 x1)
#(a a_free a_busy a_node)
# to_arr : Map -> u32 -> Arr
to_arr = λa
let a_free = λk Empty
let a_busy = λk (Single k)
let a_node = λx0 λx1 λk
let x0 = (to_arr x0 (+ (* k 2) 0))
let x1 = (to_arr x1 (+ (* k 2) 1))
(Concat x0 x1)
(a a_free a_busy a_node)

#// to_map : Arr -> Map
#to_map = λa
#let a_empty = Free
#let a_single = λx (radix 24 x 1 Busy)
#let a_concat = λx0 λx1 (merge (to_map x0) (to_map x1))
#(a a_empty a_single a_concat)
# to_map : Arr -> Map
to_map = λa
let a_empty = Free
let a_single = λx (radix 24 x 1 Busy)
let a_concat = λx0 λx1 (merge (to_map x0) (to_map x1))
(a a_empty a_single a_concat)

#// merge : Map -> Map -> Map
#merge = λa
#let a_free = λb
#let b_free = Free
#let b_busy = Busy
#let b_node = λb0 λb1 (Node b0 b1)
#(b b_free b_busy b_node)
#let a_busy = λb
#let b_free = Busy
#let b_busy = Busy
#let b_node = λb0 λb1 0
#(b b_free b_busy b_node)
#let a_node = λa0 λa1 λb
#let b_free = λa0 λa1 (Node a0 a1)
#let b_busy = λa0 λa1 0
#let b_node = λb0 λb1 λa0 λa1 (Node (merge a0 b0) (merge a1 b1))
#(b b_free b_busy b_node a0 a1)
#(a a_free a_busy a_node)
# merge : Map -> Map -> Map
merge = λa
let a_free = λb
let b_free = Free
let b_busy = Busy
let b_node = λb0 λb1 (Node b0 b1)
(b b_free b_busy b_node)
let a_busy = λb
let b_free = Busy
let b_busy = Busy
let b_node = λb0 λb1 0
(b b_free b_busy b_node)
let a_node = λa0 λa1 λb
let b_free = λa0 λa1 (Node a0 a1)
let b_busy = λa0 λa1 0
let b_node = λb0 λb1 λa0 λa1 (Node (merge a0 b0) (merge a1 b1))
(b b_free b_busy b_node a0 a1)
(a a_free a_busy a_node)

#// radix : u32 -> Map
#radix = λi λn λk λr switch i {
#0: r
#_: (radix i-1 n (* k 2) (swap (& n k) r Free))
#}
# radix : u32 -> Map
radix = λi λn λk λr switch i {
0: r
_: (radix i-1 n (* k 2) (swap (& n k) r Free))
}

#// swap : u32 -> Map -> Map -> Map
#swap = λn switch n {
#0: λx0 λx1 (Node x0 x1)
#_: λx0 λx1 (Node x1 x0)
#}
# swap : u32 -> Map -> Map -> Map
swap = λn switch n {
0: λx0 λx1 (Node x0 x1)
_: λx0 λx1 (Node x1 x0)
}

#// main : u32
#main = (sum (sort (gen 16 0)))

main = 42
# main : u32
main = (sum (sort (gen 16 0)))
94 changes: 93 additions & 1 deletion examples/sort_radix/main.hvm
Original file line number Diff line number Diff line change
@@ -1 +1,93 @@
@main = 42
@Busy = (* (a (* a)))

@Concat = (a (b (* (* ((a (b c)) c)))))

@Empty = (a (* (* a)))

@Free = (a (* (* a)))

@Node = (a (b (* (* ((a (b c)) c)))))

@Single = (a (* ((a b) (* b))))

@gen = (?((@gen__C0 @gen__C1) a) a)

@gen__C0 = a
& @Single ~ a

@gen__C1 = ({a d} ($([*2] {e $([+1] b)}) g))
& @Concat ~ (c (f g))
&! @gen ~ (a (b c))
&! @gen ~ (d (e f))

@main = a
& @sum ~ (@main__C1 a)

@main__C0 = a
& @gen ~ (16 (0 a))

@main__C1 = a
& @sort ~ (@main__C0 a)

@merge = ((@merge__C5 (@merge__C4 (@merge__C3 a))) a)

@merge__C0 = (b (e (a (d g))))
& @Node ~ (c (f g))
&! @merge ~ (a (b c))
&! @merge ~ (d (e f))

@merge__C1 = a
& @Node ~ a

@merge__C2 = a
& @Node ~ a

@merge__C3 = (a (b ((@merge__C1 ((* (* 0)) (@merge__C0 (a (b c))))) c)))

@merge__C4 = ((@Busy (@Busy ((* (* 0)) a))) a)

@merge__C5 = ((@Free (@Busy (@merge__C2 a))) a)

@radix = (?(((* (* (a a))) @radix__C0) b) b)

@radix__C0 = (a ({b $([&] $(d e))} ({$([*2] c) d} (f h))))
& @radix ~ (a (b (c (g h))))
& @swap ~ (e (f (@Free g)))

@sort = (a c)
& @to_arr ~ (b (0 c))
& @to_map ~ (a b)

@sum = ((0 ((a a) (@sum__C0 b))) b)

@sum__C0 = (a (b d))
&! @sum ~ (a $([+] $(c d)))
&! @sum ~ (b c)

@swap = (?((@swap__C0 @swap__C1) a) a)

@swap__C0 = a
& @Node ~ a

@swap__C1 = (* (b (a c)))
& @Node ~ (a (b c))

@to_arr = (((* @Empty) (@to_arr__C1 (@to_arr__C0 a))) a)

@to_arr__C0 = (a (d ({$([*2] $([+1] e)) $([*2] $([+0] b))} g)))
& @Concat ~ (c (f g))
&! @to_arr ~ (a (b c))
&! @to_arr ~ (d (e f))

@to_arr__C1 = a
& @Single ~ a

@to_map = ((@Free (@to_map__C1 (@to_map__C0 a))) a)

@to_map__C0 = (a (c e))
& @merge ~ (b (d e))
&! @to_map ~ (a b)
&! @to_map ~ (c d)

@to_map__C1 = (a b)
& @radix ~ (24 (a (1 (@Busy b))))
17 changes: 17 additions & 0 deletions examples/tuples/tuples.hvm
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@Tup8/New = (a (b (c (d (e (f (g (h ((0 (a (b (c (d (e (f (g (h i))))))))) i)))))))))

@app = (?(((* (a a)) @app__C0) b) b)

@app__C0 = (a ({b (c d)} (c e)))
& @app ~ (a (b (d e)))

@main = b
& @app ~ (1234 (@rot (a b)))
& @Tup8/New ~ (1 (2 (3 (4 (5 (6 (7 (8 a))))))))

@rot = ((@rot__C1 a) a)

@rot__C0 = (h (a (b (c (d (e (f (g i))))))))
& @Tup8/New ~ (a (b (c (d (e (f (g (h i))))))))

@rot__C1 = (?((@rot__C0 *) a) a)
6 changes: 5 additions & 1 deletion tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use hvm::ast::Tree;
use insta::assert_snapshot;
use TSPL::Parser;
use std::{
collections::HashMap, error::Error, ffi::OsStr, io::Read, path::{Path, PathBuf}, process::{Command, Stdio}
collections::HashMap, error::Error, ffi::OsStr, fs, io::Read, path::{Path, PathBuf}, process::{Command, Stdio}
};

#[test]
Expand All @@ -25,6 +25,10 @@ fn manifest_relative(sub: &str) -> PathBuf {
}

fn test_file(path: &Path) {
if fs::read_to_string(path).unwrap().contains("@test-skip = 1") {
println!("skipping {path:?}");
return;
}
println!("testing {path:?}...");
let rust_output = execute_hvm(&["run".as_ref(), path.as_os_str()]).unwrap();
assert_snapshot!(rust_output);
Expand Down
6 changes: 0 additions & 6 deletions tests/snapshots/run__file@demo_io__main.hvm.snap

This file was deleted.

2 changes: 1 addition & 1 deletion tests/snapshots/run__file@sort_bitonic__main.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ source: tests/run.rs
expression: rust_output
input_file: examples/sort_bitonic/main.hvm
---
Result: 16744448
Result: 8386560
2 changes: 1 addition & 1 deletion tests/snapshots/run__file@sum_rec__main.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ source: tests/run.rs
expression: rust_output
input_file: examples/sum_rec/main.hvm
---
Result: 8388608
Result: 16252928
Loading
Loading