Skip to content

Commit

Permalink
Recompile tests.
Browse files Browse the repository at this point in the history
Move `main::create_host` to `util::create_host`.
  • Loading branch information
FranchuFranchu committed Feb 29, 2024
1 parent 6ec7cd2 commit 9fd3a99
Show file tree
Hide file tree
Showing 16 changed files with 134 additions and 126 deletions.
2 changes: 1 addition & 1 deletion examples/machine_u32/num_match.hvm2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pred = λx match x {
0: 0
+: x-1
1+: x-1
}

main = (pred 10)
4 changes: 2 additions & 2 deletions examples/sort/bitonic/bitonic_sort_lam.hvm2
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Node = @x0 @x1 @Leaf @Node (Node x0 x1)

swap = λn match n {
0: λx0 λx1 (Node x0 x1)
+: λx0 λx1 (Node x1 x0)
1+: λx0 λx1 (Node x1 x0)
}

warp = λa
Expand Down Expand Up @@ -42,7 +42,7 @@ sort = λa

gen = λn match n {
0: λx (Leaf x)
+: λx (Node (gen n-1 (* x 2)) (gen n-1 (+ (* x 2) 1)))
1+: λx (Node (gen n-1 (* x 2)) (gen n-1 (+ (* x 2) 1)))
}

rev = λa
Expand Down
4 changes: 2 additions & 2 deletions examples/sort/merge/merge_sort.hvm2
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ merge = λxs
let ys_nil = λx λxs (List.cons x xs)
let ys_cons = λy λys λx λxs
let t = λt (t (List.cons x) λx(x) (List.cons y))
let t = let k = (< x y); (t (match k { 0: λaλbλcλt(t c a b); +: λaλbλcλt(t a b c) }))
let t = let k = (< x y); (t (match k { 0: λaλbλcλt(t c a b); 1+: λaλbλcλt(t a b c) }))
(t λa λb λc (a (merge (b xs) (c ys))))
(ys ys_nil ys_cons x xs)
(xs xs_nil xs_cons)
Expand All @@ -23,7 +23,7 @@ sum = λxs

range = λn match n {
0: λx (Leaf x)
+: λx (Node (range n-1 (+ (* x 2) 1)) (range n-1 (* x 2)))
1+: λx (Node (range n-1 (+ (* x 2) 1)) (range n-1 (* x 2)))
}

main = (sum (sort (range 2 0)))
4 changes: 2 additions & 2 deletions examples/sort/radix/radix_sort_lam.hvm2
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Node = λx0 λx1 λfree λused λnode (node x0 x1)
// gen : u32 -> Arr
gen = λn match n {
0: λx (Single x)
+: λx
1+: λx
let x0 = (<< x 1)
let x1 = (| x0 1)
(Concat (gen n-1 x0) (gen n-1 x1))
Expand Down Expand Up @@ -102,7 +102,7 @@ radix = λn
// swap : u32 -> Map -> Map -> Map
swap = λn match n {
0: λx0 λx1 (Node x0 x1)
+: λx0 λx1 (Node x1 x0)
1+: λx0 λx1 (Node x1 x0)
}

// main : u32
Expand Down
15 changes: 1 addition & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use hvmc::{
ast::{Book, Net, Tree},
host::Host,
run::{DynNet, Mode, Strict, Trg},
util::create_host,
*,
};

Expand Down Expand Up @@ -287,20 +288,6 @@ fn load_book(files: &[String], compile_opts: &CompileArgs) -> Book {
book
}

fn create_host(book: &Book) -> Arc<Mutex<Host>> {
let host = Arc::new(Mutex::new(host::Host::default()));
host.lock().unwrap().insert_def(
"HVM.log",
host::DefRef::Owned(Box::new(stdlib::LogDef::new({
let host = Arc::downgrade(&host);
move |wire| {
println!("{}", host.upgrade().unwrap().lock().unwrap().readback_tree(&wire));
}
}))),
);
host.lock().unwrap().insert_book(&book);
host
}

fn reduce_exprs(host: &Host, exprs: &[Net], opts: &RuntimeOpts) {
let heap = run::Net::<Strict>::init_heap_bytes(opts.memory as usize);
Expand Down
21 changes: 18 additions & 3 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::{
ast::{Net, Tree},
run::Rewrites,
ast::{Book, Net, Tree}, host::{DefRef, Host}, run::Rewrites
};
use std::time::Duration;
use std::{sync::{Arc, Mutex}, time::Duration};

/// Creates a variable uniquely identified by `id`.
pub(crate) fn create_var(mut id: usize) -> String {
Expand Down Expand Up @@ -249,3 +248,19 @@ fn pretty_num(n: u64) -> String {
.skip(1)
.collect()
}

/// Create a `Host` from a `Book`, including `hvm-core`'s built-in definitions
pub fn create_host(book: &Book) -> Arc<Mutex<Host>> {
let host = Arc::new(Mutex::new(Host::default()));
host.lock().unwrap().insert_def(
"HVM.log",
DefRef::Owned(Box::new(crate::stdlib::LogDef::new({
let host = Arc::downgrade(&host);
move |wire| {
println!("{}", host.upgrade().unwrap().lock().unwrap().readback_tree(&wire));
}
}))),
);
host.lock().unwrap().insert_book(&book);
host
}
154 changes: 74 additions & 80 deletions tests/programs/list_put_got.hvmc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
@GotC = (a (b ((@GotS (@GotZ (a (b c)))) c)))
@GotN = (* [@None @Nil])
@GotS = (a (b (c d)))
& @GotS$match$1 ~ (e (b d))
& @Got ~ (c (a e))
@GotS$match$1 = ([a b] (c [a d]))
& @Cons ~ (c (b d))
& (e [f g]) ~ (b d)
& @Cons ~ (e (h g))
& @Got ~ (c (a [f h]))
@GotZ = ({3 a b} (c [d e]))
& @Cons ~ (b (c e))
& @Some ~ (a d)
Expand All @@ -19,19 +18,16 @@
@Put = ((@PutN (@PutC a)) a)
@PutC = (a (b ((@PutCS (@PutCZ (a (b c)))) c)))
@PutCS = (a (b (c (d e))))
& @PutCS$match$1 ~ (f (b e))
& @Put ~ (c (a (d f)))
@PutCS$match$1 = ([a b] (c [a d]))
& @Cons ~ (c (b d))
& (f [g h]) ~ (b e)
& @Cons ~ (f (i h))
& @Put ~ (c (a (d [g i])))
@PutCZ = (a (b (c [d e])))
& @Cons ~ (c (b e))
& @Some ~ (a d)
@PutN = ((@PutNS (@PutNZ a)) a)
@PutNS = (a (b c))
& @PutNS$match$1 ~ (d c)
& @PutN ~ (a (b d))
@PutNS$match$1 = ([a b] [a c])
& @Cons ~ (@None (b c))
@PutNS = (a (b [c d]))
& @Cons ~ (@None (e d))
& @PutN ~ (a (b [c e]))
@PutNZ = (a [@None b])
& @Cons ~ (a (@Nil b))
@S0 = (* (a a))
Expand Down Expand Up @@ -596,71 +592,69 @@
@S9$S7 = ((@S9$S6 a) (* a))
@S9$S8 = ((@S9$S7 a) (* a))
@Some = (a (* ((a b) b)))
@main = ((a b) c)
& @main$match$1 ~ (b c)
& @Cons ~ (d (e a))
& @Cons ~ (f (g e))
& @Cons ~ (h (i g))
& @Cons ~ (j (k i))
& @Cons ~ (l (m k))
& @Cons ~ (n (o m))
& @Cons ~ (p (q o))
& @Cons ~ (r (s q))
& @Cons ~ (t (u s))
& @Cons ~ (v (w u))
& @Cons ~ (x (y w))
& @Cons ~ (z (ab y))
& @Cons ~ (bb (cb ab))
& @Cons ~ (db (eb cb))
& @Cons ~ (fb (gb eb))
& @Cons ~ (hb (ib gb))
& @Cons ~ (jb (kb ib))
& @Cons ~ (lb (mb kb))
& @Cons ~ (nb (ob mb))
& @Cons ~ (pb (qb ob))
& @Cons ~ (rb (sb qb))
& @Cons ~ (tb (ub sb))
& @Cons ~ (vb (wb ub))
& @Cons ~ (xb (yb wb))
& @Cons ~ (zb (ac yb))
& @Cons ~ (bc (cc ac))
& @Cons ~ (dc (ec cc))
& @Cons ~ (fc (gc ec))
& @Cons ~ (hc (ic gc))
& @Cons ~ (jc (kc ic))
& @Cons ~ (lc (mc kc))
& @Cons ~ (nc (@Nil mc))
& @Some ~ (@S31 nc)
& @Some ~ (@S30 lc)
& @Some ~ (@S29 jc)
& @Some ~ (@S28 hc)
& @Some ~ (@S27 fc)
& @Some ~ (@S26 dc)
& @Some ~ (@S25 bc)
& @Some ~ (@S24 zb)
& @Some ~ (@S23 xb)
& @Some ~ (@S22 vb)
& @Some ~ (@S21 tb)
& @Some ~ (@S20 rb)
& @Some ~ (@S19 pb)
& @Some ~ (@S18 nb)
& @Some ~ (@S17 lb)
& @Some ~ (@S16 jb)
& @Some ~ (@S15 hb)
& @Some ~ (@S14 fb)
& @Some ~ (@S13 db)
& @Some ~ (@S12 bb)
& @Some ~ (@S11 z)
& @Some ~ (@S10 x)
& @Some ~ (@S9 v)
& @Some ~ (@S8 t)
& @Some ~ (@S7 r)
& @Some ~ (@S6 p)
& @Some ~ (@S5 n)
& @Some ~ (@S4 l)
& @Some ~ (@S3 j)
& @Some ~ (@S2 h)
& @Some ~ (@S1 f)
& @Some ~ (@S0 d)
@main$match$1 = ([a *] a)
@main = ((a [b *]) b)
& @Cons ~ (c (d a))
& @Cons ~ (e (f d))
& @Cons ~ (g (h f))
& @Cons ~ (i (j h))
& @Cons ~ (k (l j))
& @Cons ~ (m (n l))
& @Cons ~ (o (p n))
& @Cons ~ (q (r p))
& @Cons ~ (s (t r))
& @Cons ~ (u (v t))
& @Cons ~ (w (x v))
& @Cons ~ (y (z x))
& @Cons ~ (ab (bb z))
& @Cons ~ (cb (db bb))
& @Cons ~ (eb (fb db))
& @Cons ~ (gb (hb fb))
& @Cons ~ (ib (jb hb))
& @Cons ~ (kb (lb jb))
& @Cons ~ (mb (nb lb))
& @Cons ~ (ob (pb nb))
& @Cons ~ (qb (rb pb))
& @Cons ~ (sb (tb rb))
& @Cons ~ (ub (vb tb))
& @Cons ~ (wb (xb vb))
& @Cons ~ (yb (zb xb))
& @Cons ~ (ac (bc zb))
& @Cons ~ (cc (dc bc))
& @Cons ~ (ec (fc dc))
& @Cons ~ (gc (hc fc))
& @Cons ~ (ic (jc hc))
& @Cons ~ (kc (lc jc))
& @Cons ~ (mc (@Nil lc))
& @Some ~ (@S31 mc)
& @Some ~ (@S30 kc)
& @Some ~ (@S29 ic)
& @Some ~ (@S28 gc)
& @Some ~ (@S27 ec)
& @Some ~ (@S26 cc)
& @Some ~ (@S25 ac)
& @Some ~ (@S24 yb)
& @Some ~ (@S23 wb)
& @Some ~ (@S22 ub)
& @Some ~ (@S21 sb)
& @Some ~ (@S20 qb)
& @Some ~ (@S19 ob)
& @Some ~ (@S18 mb)
& @Some ~ (@S17 kb)
& @Some ~ (@S16 ib)
& @Some ~ (@S15 gb)
& @Some ~ (@S14 eb)
& @Some ~ (@S13 cb)
& @Some ~ (@S12 ab)
& @Some ~ (@S11 y)
& @Some ~ (@S10 w)
& @Some ~ (@S9 u)
& @Some ~ (@S8 s)
& @Some ~ (@S7 q)
& @Some ~ (@S6 o)
& @Some ~ (@S5 m)
& @Some ~ (@S4 k)
& @Some ~ (@S3 i)
& @Some ~ (@S2 g)
& @Some ~ (@S1 e)
& @Some ~ (@S0 c)

2 changes: 1 addition & 1 deletion tests/programs/stress_tests/all_tree.hvm2
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ and = λa (a λb(b) λb(False))

gen = λn match n {
0: (Leaf True)
+: (Node (gen n-1) (gen n-1))
1+: (Node (gen n-1) (gen n-1))
}

all = λt
Expand Down
4 changes: 2 additions & 2 deletions tests/programs/stress_tests/apelacion.hvm2
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
sum = λa match a {
0: λs s
+: λs (sum a-1 (+ a-1 s))
1+: λs (sum a-1 (+ a-1 s))
}

rec = λa match a {
0: (sum 1000000 0)
+: (+ (rec a-1) (rec a-1))
1+: (+ (rec a-1) (rec a-1))
}

main = (rec 6)
4 changes: 2 additions & 2 deletions tests/programs/stress_tests/fib_rec.hvm2
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ add = λa λb (+ a b)

fib = λx match x {
0: 1
+: let p = x-1; match p {
1+: let p = x-1; match p {
0: 1
+: (+ (fib p) (fib p-1))
1+: (+ (fib p) (fib p-1))
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/programs/stress_tests/sum_rec.hvm2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ add = λa λb (+ a b)

sum = λn match n {
0: 1
+: (add (sum n-1) (sum n-1))
1+: (add (sum n-1) (sum n-1))
}

main = (sum 26)
2 changes: 1 addition & 1 deletion tests/programs/stress_tests/sum_tail.hvm2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sum = λa match a {
0: λs s
+: λs (sum a-1 (+ a-1 s))
1+: λs (sum a-1 (+ a-1 s))
}

main = (sum 10000000 0)
2 changes: 1 addition & 1 deletion tests/programs/stress_tests/sum_tree.hvm2
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ add = λa λb (+ a b)

gen = λn match n {
0: (Leaf 1)
+: (Node (gen n-1) (gen n-1))
1+: (Node (gen n-1) (gen n-1))
}

sum = λt
Expand Down
2 changes: 1 addition & 1 deletion tests/programs/stress_tests/tuple_rots.hvm2
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ rot = λx (x λa λb λc λd λe λf λg λh (MkTup8 b c d e f g h a))

app = λn match n {
0: λf λx x
+: λf λx (app n-1 f (f x))
1+: λf λx (app n-1 f (f x))
}

main = (app 2000000 rot (MkTup8 1 2 3 4 5 6 7 8))
12 changes: 12 additions & 0 deletions tests/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
source: tests/tests.rs
expression: output
input_file: tests/programs/log.hvmc
---
#2
RWTS : 7
- ANNI : 2
- COMM : 0
- ERAS : 1
- DREF : 4
- OPER : 0
Loading

0 comments on commit 9fd3a99

Please sign in to comment.