Skip to content

Commit

Permalink
prep for n-ary nodes (HigherOrderCO#84)
Browse files Browse the repository at this point in the history
Co-authored-by: FranchuFranchu <[email protected]>
  • Loading branch information
tjjfvi and FranchuFranchu authored Mar 15, 2024
1 parent 1060d20 commit 781ff0d
Show file tree
Hide file tree
Showing 63 changed files with 785 additions and 353 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ panic = "abort"
debug = "full"

[dependencies]
arrayvec = "0.7.4"
clap = { version = "4.5.1", features = ["derive"] }
nohash-hasher = { version = "0.2.0" }
stacker = "0.1.15"
Expand Down
18 changes: 15 additions & 3 deletions benches/benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,21 @@ fn interact_benchmark(c: &mut Criterion) {

let cases = [
("era-era", (Era, Era)),
("era-con", (Era, Ctr { lab: 0, lft: Era.into(), rgt: Era.into() })),
("con-con", ((Ctr { lab: 0, lft: Era.into(), rgt: Era.into() }), Ctr { lab: 0, lft: Era.into(), rgt: Era.into() })),
("con-dup", ((Ctr { lab: 0, lft: Era.into(), rgt: Era.into() }), Ctr { lab: 2, lft: Era.into(), rgt: Era.into() })),
("era-con", (Era, Ctr { lab: 0, ports: [Era.into(), Era.into()].into() })),
(
"con-con",
((Ctr { lab: 0, ports: [Era.into(), Era.into()].into() }, Ctr {
lab: 0,
ports: [Era.into(), Era.into()].into(),
})),
),
(
"con-dup",
((Ctr { lab: 0, ports: [Era.into(), Era.into()].into() }, Ctr {
lab: 2,
ports: [Era.into(), Era.into()].into(),
})),
),
];

for (name, redex) in cases {
Expand Down
3 changes: 3 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
"words": [
"anni",
"annihilations",
"arrayvec",
"backlinks",
"backoffs",
"combinators",
"condvar",
"ctrs",
"dereferencable",
"dref",
"dups",
Expand Down Expand Up @@ -47,6 +49,7 @@
"sigabrt",
"skippable",
"struct",
"succ",
"supercombinators",
"targ",
"tids",
Expand Down
4 changes: 2 additions & 2 deletions examples/church_encoding/church.hvmc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@S = ((a (b c)) ({3 (c d) a} (b d)))
@Z = (* (a a))
@add = ((a (b c)) ((d (e b)) ({11 a d} (e c))))
@add = ((a (b c)) ((d (e b)) ({9 a d} (e c))))
@c2 = ({5 (a b) (c a)} (c b))
@c3 = ({7 (a b) {9 (c a) (d c)}} (d b))
@c3 = ({7 (a b) {7 (c a) (d c)}} (d b))
@c4 = a
& @S ~ (b a)
& @S ~ (c b)
Expand Down
12 changes: 6 additions & 6 deletions examples/lambda_calculus/hoas.hvmc
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
& @App ~ (b (d f))
@C3 = a
& @Lam ~ (@C3$S0 a)
@C3$S0 = ({5 a {7 b c}} d)
@C3$S0 = ({5 a {5 b c}} d)
& @Lam ~ ((e f) d)
& @App ~ (a (g f))
& @App ~ (b (h g))
& @App ~ (c (e h))
@C4 = a
& @Lam ~ (@C4$S0 a)
@C4$S0 = ({9 a {11 b {13 c d}}} e)
@C4$S0 = ({7 a {7 b {7 c d}}} e)
& @Lam ~ ((f g) e)
& @App ~ (a (h g))
& @App ~ (b (i h))
& @App ~ (c (j i))
& @App ~ (d (f j))
@C6 = a
& @Lam ~ (@C6$S0 a)
@C6$S0 = ({15 a {17 b {19 c {21 d {23 e f}}}}} g)
@C6$S0 = ({9 a {9 b {9 c {9 d {9 e f}}}}} g)
& @Lam ~ ((h i) g)
& @App ~ (a (j i))
& @App ~ (b (k j))
Expand All @@ -41,7 +41,7 @@
& @App ~ (f (h n))
@C8 = a
& @Lam ~ (@C8$S0 a)
@C8$S0 = ({25 a {27 b {29 c {31 d {33 e {35 f g}}}}}} h)
@C8$S0 = ({11 a {11 b {11 c {11 d {11 e {11 f g}}}}}} h)
& @Lam ~ ((i j) h)
& @App ~ (a (k j))
& @App ~ (b (l k))
Expand All @@ -53,14 +53,14 @@
@CS = a
& @Lam ~ (@CS$S0 a)
@CS$S0 = (a b)
& @Lam ~ (({37 c d} e) b)
& @Lam ~ (({13 c d} e) b)
& @Lam ~ ((f g) e)
& @App ~ (c (h g))
& @App ~ (i (f h))
& @App ~ (a (d i))
@FOO = a
& @Lam ~ (@FOO$S0 a)
@FOO$S0 = ({39 a b} c)
@FOO$S0 = ({15 a b} c)
& @App ~ (a (b c))
@False = a
& @Lam ~ (@False$S0 a)
Expand Down
3 changes: 2 additions & 1 deletion examples/machine_u32/num_match.hvmc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@main = a
& @pred ~ (#10 a)
@pred = (?<(#0 (a a)) b> b)
@pred = (?<(a b) d> d)
& (a b) ~ (#0 (c c))

6 changes: 4 additions & 2 deletions examples/sort/bitonic/bitonic_sort_lam.hvmc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
@flow$S1 = (a (b ({5 c d} e)))
& @down ~ (f (d e))
& @warp ~ (a (b (c f)))
@gen = (?<(@gen$S0 @gen$S1) a> a)
@gen = (?<(a b) c> c)
& (a b) ~ (@gen$S0 @gen$S1)
@gen$S0 = (a b)
& @Leaf ~ (a b)
@gen$S1 = ({7 a b} ({9 <* #2 c> <* #2 <+ #1 d>>} e))
Expand Down Expand Up @@ -55,7 +56,8 @@
@sum$S0 = (a (b c))
& @sum ~ (a <+ d c>)
& @sum ~ (b d)
@swap = (?<(@swap$S0 @swap$S2) a> a)
@swap = (?<(a b) c> c)
& (a b) ~ (@swap$S0 @swap$S2)
@swap$S0 = (a (b c))
& @Node ~ (a (b c))
@swap$S1 = (a (b c))
Expand Down
20 changes: 11 additions & 9 deletions examples/sort/merge/merge_sort.hvmc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@Leaf = (a {8 {10 a b} {8 * b}})
@List.cons = (a (b {2 {6 a {4 b c}} {2 * c}}))
@Leaf = (a {4 {4 a b} {4 * b}})
@List.cons = (a (b {2 {2 a {2 b c}} {2 * c}}))
@List.nil = {2 * {2 a a}}
@Node = (a (b {8 * {8 {14 a {12 b c}} c}}))
@Node = (a (b {4 * {4 {4 a {4 b c}} c}}))
@main = a
& @sum ~ (b a)
& @sort ~ (c b)
Expand All @@ -12,13 +12,15 @@
@merge$S1 = (a (b (c ((c (a (b d))) d))))
@merge$S2 = (a (b (c ((a (b (c d))) d))))
@merge$S3 = (* @merge$S2)
@merge$S4 = ({3 a b} (c ({5 << a ?<(@merge$S1 @merge$S3) d>> e} (f g))))
& ((h ((i i) (j k))) k) ~ (d (((l m) ((f n) ((c o) m))) g))
& @merge ~ (n (o l))
& @List.cons ~ (b j)
& @List.cons ~ (e h)
@merge$S4 = ({3 a b} (c ({5 << a ?<(d e) f>> g} (h i))))
& (d e) ~ (@merge$S1 @merge$S3)
& ((j ((k k) (l m))) m) ~ (f (((n o) ((h p) ((c q) o))) i))
& @merge ~ (p (q n))
& @List.cons ~ (b l)
& @List.cons ~ (g j)
@merge$S5 = (a (b ((@merge$S0 (@merge$S4 (a (b c)))) c)))
@range = (?<(@range$S0 @range$S1) a> a)
@range = (?<(a b) c> c)
& (a b) ~ (@range$S0 @range$S1)
@range$S0 = (a b)
& @Leaf ~ (a b)
@range$S1 = ({7 a b} ({9 <* #2 <+ #1 c>> <* #2 d>} e))
Expand Down
12 changes: 7 additions & 5 deletions examples/sort/radix/radix_sort_lam.hvmc
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
@Single = (a (* ((a b) (* b))))
@Used = (* @Used$S0)
@Used$S0 = (a (* a))
@gen = (?<(@gen$S0 @gen$S1) a> a)
@gen = (?<(a b) c> c)
& (a b) ~ (@gen$S0 @gen$S1)
@gen$S0 = (a b)
& @Single ~ (a b)
@gen$S1 = ({51 a b} (<<< #1 {53 c <| #1 d>}> e))
@gen$S1 = ({7 a b} (<<< #1 {9 c <| #1 d>}> e))
& @Concat ~ (f (g e))
& @gen ~ (b (d g))
& @gen ~ (a (c f))
Expand All @@ -33,7 +34,7 @@
& @merge ~ (d (b g))
& @merge ~ (c (a f))
@merge$S9 = (a (b ((@merge$S5 (@merge$S7 (@merge$S8 (a (b c))))) c)))
@radix = ({3 <& #8388608 a> {5 <& #4194304 b> {7 <& #2097152 c> {9 <& #1048576 d> {11 <& #524288 e> {13 <& #262144 f> {15 <& #131072 g> {17 <& #65536 h> {19 <& #32768 i> {21 <& #16384 j> {23 <& #8192 k> {25 <& #4096 l> {27 <& #2048 m> {29 <& #1024 n> {31 <& #512 o> {33 <& #256 p> {35 <& #128 q> {37 <& #64 r> {39 <& #32 s> {41 <& #16 t> {43 <& #8 u> {45 <& #4 v> {47 <& #2 w> <& #1 x>}}}}}}}}}}}}}}}}}}}}}}} y)
@radix = ({3 <& #8388608 a> {3 <& #4194304 b> {3 <& #2097152 c> {3 <& #1048576 d> {3 <& #524288 e> {3 <& #262144 f> {3 <& #131072 g> {3 <& #65536 h> {3 <& #32768 i> {3 <& #16384 j> {3 <& #8192 k> {3 <& #4096 l> {3 <& #2048 m> {3 <& #1024 n> {3 <& #512 o> {3 <& #256 p> {3 <& #128 q> {3 <& #64 r> {3 <& #32 s> {3 <& #16 t> {3 <& #8 u> {3 <& #4 v> {3 <& #2 w> <& #1 x>}}}}}}}}}}}}}}}}}}}}}}} y)
& @swap ~ (a (z (@Free y)))
& @swap ~ (b (ab (@Free z)))
& @swap ~ (c (bb (@Free ab)))
Expand Down Expand Up @@ -72,7 +73,8 @@
@sum$S0 = (a (b c))
& @sum ~ (a <+ d c>)
& @sum ~ (b d)
@swap = (?<(@swap$S0 @swap$S2) a> a)
@swap = (?<(a b) c> c)
& (a b) ~ (@swap$S0 @swap$S2)
@swap$S0 = (a (b c))
& @Node ~ (a (b c))
@swap$S1 = (a (b c))
Expand All @@ -82,7 +84,7 @@
@to_arr$S0 = (* @Empty)
@to_arr$S1 = (a b)
& @Single ~ (a b)
@to_arr$S2 = (a (b ({49 <* #2 <+ #1 c>> <* #2 <+ #0 d>>} e)))
@to_arr$S2 = (a (b ({5 <* #2 <+ #1 c>> <* #2 <+ #0 d>>} e)))
& @Concat ~ (f (g e))
& @to_arr ~ (b (c g))
& @to_arr ~ (a (d f))
Expand Down
Loading

0 comments on commit 781ff0d

Please sign in to comment.