1

restructure + syntactic sugar implementation

This commit is contained in:
Christoph
2021-08-11 21:11:35 +02:00
parent 7365c41e11
commit 3a6814a850
27 changed files with 145 additions and 86 deletions

42
tests/test_primitive.py Normal file
View File

@ -0,0 +1,42 @@
import py
from simpleparser import parse
from objmodel import W_NormalObject
from interpreter import Interpreter
def test_primitive():
ast = parse("""
k = 10 $int_add(31)
""")
interpreter = Interpreter()
w_module = interpreter.make_module()
interpreter.eval(ast, w_module)
assert w_module.getvalue("k").value == 41
def test_primitive_error():
ast = parse("""
k = 10 $int_add(31, 12)
""")
interpreter = Interpreter()
w_module = interpreter.make_module()
with py.test.raises(TypeError):
interpreter.eval(ast, w_module)
def test_loop():
ast = parse("""
def f(x):
r = 0
while x:
r = r $int_add(x)
x = x $int_add(-1)
r
y = f(100)
""")
interpreter = Interpreter()
w_module = interpreter.make_module()
interpreter.eval(ast, w_module)
assert w_module.getvalue("y").value == 5050