Skip to content

Commit

Permalink
Add a test for “eval” from the library
Browse files Browse the repository at this point in the history
  • Loading branch information
mossprescott committed Mar 25, 2024
1 parent 29d7bbc commit 9cd4b62
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions alt/scheme/test_rvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def vector(chip, **args):
def codegen(chip, **args):
return run_to_halt(chip, simulator="codegen", interpreter="assembly", **args)
def jack(chip, **args):
return run_to_halt(chip, simulator="codegen", interpreter="jack", max_cycles=100000, **args)
return run_to_halt(chip, simulator="codegen", interpreter="jack", **args)
return pytest.mark.parametrize("run", [vector, codegen, jack])(f)

@parameterize
Expand Down Expand Up @@ -217,6 +217,18 @@ def test_tty(run):
assert output == [ord('0')]


@parameterize
def test_eval(run):
with open("alt/scheme/ribbit/min.scm") as f:
lib = f.readlines()

program = "\n".join(lib + ["""(eval '(+ 1 2))"""])

inspect, output = run(program)

assert inspect.stack() == [3]
assert output == []


#
# Tests for specific primitives:
Expand Down Expand Up @@ -380,7 +392,7 @@ def go(xs):
return "(define (cons $$x $$y) (rib $$x $$y 0))\n" + go(list(exprs))


def run_to_halt(program, interpreter, max_cycles=20000, simulator="codegen"):
def run_to_halt(program, interpreter, max_cycles=200000, simulator="codegen"):
"""Compile and run a Scheme program, then return a function for inspecting the RAM, and a
list of words that were written to the TTY port.
"""
Expand Down

0 comments on commit 9cd4b62

Please sign in to comment.