Skip to content

Commit

Permalink
use new Bend IO in test (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
enricozb authored Jun 3, 2024
2 parents 7e547e0 + 18e648a commit 166a3cb
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 55 deletions.
15 changes: 6 additions & 9 deletions examples/demo_io/main.bend
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# TODO: update tests to handle IO
test-skip = 1
# run io on tests
test-io = 1

type IO_T:
Done { magic, expr }
Expand All @@ -8,24 +8,21 @@ type IO_T:
def IO_T/MAGIC:
return (0xD0CA11, 0xFF1FF1)

def IO_T/wrap(x):
return IO_T/Done(IO_T/MAGIC, x)

def IO_T/bind(a, b):
match a:
case IO_T/Done:
return b(a.expr)
return (undefer(b))(a.expr)
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_io(func, argm):
return IO_T/Call(IO_T/MAGIC, func, argm, lambda x: IO_T/Done(IO_T/MAGIC, x))

def main:
do IO_T:
* <- call_io("WRITE", (1, "What is your name?\n"))
with IO_T:
* <- call_io("WRITE", (1, "Hi! What's your name?\n"))
name <- call_io("READ_LINE", 0)
* <- call_io("WRITE", (1, "Hello, '"))
* <- call_io("WRITE", (1, "Your name is '"))
* <- call_io("WRITE", (1, name))
* <- call_io("WRITE", (1, "'!\n"))

Expand Down
168 changes: 122 additions & 46 deletions examples/demo_io/main.hvm
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
@IO_T/Call = (a (b (c (d ((1 (a (b (c (d e))))) e)))))
@IO_T/Call = (a (b (c (d ((@IO_T/Call/tag (a (b (c (d e))))) e)))))

@IO_T/Done = (a (b ((0 (a (b c))) c)))
@IO_T/Call/tag = 1

@IO_T/Done = (a (b ((@IO_T/Done/tag (a (b c))) c)))

@IO_T/Done/tag = 0

@IO_T/MAGIC = (13683217 16719857)

@IO_T/bind = ((@IO_T/bind__C2 a) a)

@IO_T/bind__C0 = (* (a ((a b) b)))
@IO_T/bind__C0 = (* (b (a c)))
& @undefer ~ (a (b c))

@IO_T/bind__C1 = (* (* (a (b ((c d) (e g))))))
& @IO_T/Call ~ (@IO_T/MAGIC (a (b ((c f) g))))
& @IO_T/bind ~ (d (e f))

@IO_T/bind__C2 = (?((@IO_T/bind__C0 @IO_T/bind__C1) a) a)

@IO_T/wrap = a
& @IO_T/Done ~ (@IO_T/MAGIC a)
@String/Cons = (a (b ((@String/Cons/tag (a (b c))) c)))

@String/Cons = (a (b ((1 (a (b c))) c)))
@String/Cons/tag = 1

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

@String/Nil/tag = 0

@call_io = (a (b c))
& @IO_T/Call ~ (@IO_T/MAGIC (a (b (@call_io__C0 c))))
Expand All @@ -28,43 +34,113 @@
& @IO_T/Done ~ (@IO_T/MAGIC a)

@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))
& @IO_T/bind ~ (@main__C12 (@main__C11 a))

@main__C0 = (((* 42) a) a)

@main__C1 = i
& @call_io ~ (e ((1 h) i))
& @String/Cons ~ (87 (d e))
& @String/Cons ~ (82 (c d))
& @String/Cons ~ (73 (b c))
& @String/Cons ~ (84 (a b))
& @String/Cons ~ (69 (@String/Nil a))
& @String/Cons ~ (39 (g h))
& @String/Cons ~ (33 (f g))
& @String/Cons ~ (10 (@String/Nil f))

@main__C10 = (* a)
& @IO_T/bind ~ (@main__C9 (@main__C8 a))

@main__C11 = ((@main__C10 a) a)

@main__C12 = bb
& @call_io ~ (e ((1 ab) bb))
& @String/Cons ~ (87 (d e))
& @String/Cons ~ (82 (c d))
& @String/Cons ~ (73 (b c))
& @String/Cons ~ (84 (a b))
& @String/Cons ~ (69 (@String/Nil a))
& @String/Cons ~ (72 (z ab))
& @String/Cons ~ (105 (y z))
& @String/Cons ~ (33 (x y))
& @String/Cons ~ (32 (w x))
& @String/Cons ~ (87 (v w))
& @String/Cons ~ (104 (u v))
& @String/Cons ~ (97 (t u))
& @String/Cons ~ (116 (s t))
& @String/Cons ~ (39 (r s))
& @String/Cons ~ (115 (q r))
& @String/Cons ~ (32 (p q))
& @String/Cons ~ (121 (o p))
& @String/Cons ~ (111 (n o))
& @String/Cons ~ (117 (m n))
& @String/Cons ~ (114 (l m))
& @String/Cons ~ (32 (k l))
& @String/Cons ~ (110 (j k))
& @String/Cons ~ (97 (i j))
& @String/Cons ~ (109 (h i))
& @String/Cons ~ (101 (g h))
& @String/Cons ~ (63 (f g))
& @String/Cons ~ (10 (@String/Nil f))

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

@main__C3 = e
& @String/Cons ~ (87 (d e))
& @String/Cons ~ (82 (c d))
& @String/Cons ~ (73 (b c))
& @String/Cons ~ (84 (a b))
& @String/Cons ~ (69 (@String/Nil a))

@main__C4 = ((@main__C2 a) a)

@main__C5 = (a (* c))
& @IO_T/bind ~ (b (@main__C4 c))
& @call_io ~ (@main__C3 ((1 a) b))

@main__C6 = t
& @call_io ~ (e ((1 s) t))
& @String/Cons ~ (87 (d e))
& @String/Cons ~ (82 (c d))
& @String/Cons ~ (73 (b c))
& @String/Cons ~ (84 (a b))
& @String/Cons ~ (69 (@String/Nil a))
& @String/Cons ~ (89 (r s))
& @String/Cons ~ (111 (q r))
& @String/Cons ~ (117 (p q))
& @String/Cons ~ (114 (o p))
& @String/Cons ~ (32 (n o))
& @String/Cons ~ (110 (m n))
& @String/Cons ~ (97 (l m))
& @String/Cons ~ (109 (k l))
& @String/Cons ~ (101 (j k))
& @String/Cons ~ (32 (i j))
& @String/Cons ~ (105 (h i))
& @String/Cons ~ (115 (g h))
& @String/Cons ~ (32 (f g))
& @String/Cons ~ (39 (@String/Nil f))

@main__C7 = (a c)
& @IO_T/bind ~ (@main__C6 (((@main__C5 (a b)) b) c))

@main__C8 = ((@main__C7 a) a)

@main__C9 = j
& @call_io ~ (i (0 j))
& @String/Cons ~ (82 (h i))
& @String/Cons ~ (69 (g h))
& @String/Cons ~ (65 (f g))
& @String/Cons ~ (68 (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
& @String/Cons ~ (76 (c d))
& @String/Cons ~ (73 (b c))
& @String/Cons ~ (78 (a b))
& @String/Cons ~ (69 (@String/Nil a))

@test-io = 1

@undefer = (((a a) b) b)


8 changes: 8 additions & 0 deletions tests/snapshots/run__io_file@demo_io__main.hvm.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
source: tests/run.rs
expression: c_output
input_file: examples/demo_io/main.hvm
---
Hi! What's your name?
Your name is 'io from the tests'!
Result: 42

0 comments on commit 166a3cb

Please sign in to comment.