Test stubs need returns now

This commit is contained in:
Reid D. 'arrdem' McKenzie 2022-05-31 23:17:32 -06:00
parent 824547821c
commit d1fab97c85
5 changed files with 21 additions and 28 deletions

View file

@ -5,14 +5,13 @@ Hopefully no "real" interpreter ever uses this code, since it's obviously replac
"""
from .isa import Module, Opcode
from .typing import ProductExpr, SumExpr
BOOTSTRAP = Module()
NOT1 = BOOTSTRAP.define_function(
";/lang/shoggoth/v0/bootstrap/not;bool;bool",
";not;bool;bool",
[
Opcode.IF(target=3),
Opcode.FALSE(),
@ -23,7 +22,7 @@ NOT1 = BOOTSTRAP.define_function(
)
OR2 = BOOTSTRAP.define_function(
";/lang/shoggoth/v0/bootstrap/or;bool,bool;bool",
";or;bool,bool;bool",
[
Opcode.IF(target=3),
Opcode.TRUE(),
@ -37,7 +36,7 @@ OR2 = BOOTSTRAP.define_function(
)
OR3 = BOOTSTRAP.define_function(
";/lang/shoggoth/v0/bootstrap/or;bool,bool,bool;bool",
";or;bool,bool,bool;bool",
[
# A B C
Opcode.CALLS(OR2), # A|B C
@ -47,7 +46,7 @@ OR3 = BOOTSTRAP.define_function(
)
AND2 = BOOTSTRAP.define_function(
";/lang/shoggoth/v0/bootstrap/and;bool,bool;bool",
";and;bool,bool;bool",
[
Opcode.IF(target=3),
Opcode.IF(target=3),
@ -60,7 +59,7 @@ AND2 = BOOTSTRAP.define_function(
)
AND3 = BOOTSTRAP.define_function(
";/lang/shoggoth/v0/bootstrap/and;bool,bool,bool;bool",
";and;bool,bool,bool;bool",
[
# A B C
Opcode.CALLS(AND2), # A&B C
@ -70,7 +69,7 @@ AND3 = BOOTSTRAP.define_function(
)
XOR2 = BOOTSTRAP.define_function(
";/lang/shoggoth/v0/bootstrap/xor;bool,bool;bool",
";xor;bool,bool;bool",
[
Opcode.DUP(nargs=2),
# !A && B
@ -93,7 +92,7 @@ XOR2 = BOOTSTRAP.define_function(
)
XOR3 = BOOTSTRAP.define_function(
";/lang/shoggoth/v0/bootstrap/xor;bool,bool,bool;bool",
";xor;bool,bool,bool;bool",
[
# A B C
Opcode.ROT(nargs=3), # C A B
@ -110,16 +109,16 @@ XOR3 = BOOTSTRAP.define_function(
)
TRUE = BOOTSTRAP.define_type(
"/lang/shoggoth/v0/true",
"true",
ProductExpr([]),
)
FALSE = BOOTSTRAP.define_type(
"/lang/shoggoth/v0/false",
"false",
ProductExpr([]),
)
BOOL = BOOTSTRAP.define_type(
"/lang/shoggoth/v0/bool",
"bool",
SumExpr([TRUE, FALSE])
)

View file

@ -98,7 +98,7 @@ class Interpreter(object):
while True:
op = mod.opcodes[stack.ip]
# print("{0}{1: <50} {2}: {3}".format(" " * stack.depth, str(stack.stack), stack.ip, op))
print("{0}{1: <50} {2}: {3}".format(" " * stack.depth, str(stack.stack), stack.ip, op))
match op:
case Opcode.TRUE():

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python3
import pytest
from ichor import *
import pytest
@pytest.fixture

View file

@ -2,8 +2,9 @@
from .fixtures import * # noqa
import pytest
from ichor import *
from ichor.isa import Opcode
import pytest
@pytest.mark.parametrize("stack,ret", [
@ -11,7 +12,7 @@ from ichor import *
[[True], [False]],
])
def test_not(vm, stack, ret):
assert vm.run([Opcode.CALLS(NOT1)], stack = stack) == ret
assert vm.run([Opcode.CALLS(NOT1), Opcode.RETURN(1)], stack = stack) == ret
@pytest.mark.parametrize("stack,ret", [
@ -21,7 +22,7 @@ def test_not(vm, stack, ret):
[[True, True], [True]],
])
def test_or(vm, stack, ret):
assert vm.run([Opcode.CALLS(OR2)], stack = stack) == ret
assert vm.run([Opcode.CALLS(OR2), Opcode.RETURN(1)], stack = stack) == ret
@pytest.mark.parametrize("stack,ret", [
@ -31,7 +32,7 @@ def test_or(vm, stack, ret):
[[True, True], [True]],
])
def test_and(vm, stack, ret):
assert vm.run([Opcode.CALLS(AND2)], stack = stack) == ret
assert vm.run([Opcode.CALLS(AND2), Opcode.RETURN(1)], stack = stack) == ret
@pytest.mark.parametrize("stack,ret", [
@ -41,7 +42,7 @@ def test_and(vm, stack, ret):
[[True, True], [False]],
])
def test_xor2(vm, stack, ret):
assert vm.run([Opcode.CALLS(XOR2)], stack = stack) == ret
assert vm.run([Opcode.CALLS(XOR2), Opcode.RETURN(1)], stack = stack) == ret
@pytest.mark.parametrize("stack,ret", [
[[False, False, False], [False]],
@ -53,7 +54,7 @@ def test_xor2(vm, stack, ret):
[[False, False, True], [True]],
])
def test_xor3(vm, stack, ret):
assert vm.run([Opcode.CALLS(XOR3)], stack = stack) == ret
assert vm.run([Opcode.CALLS(XOR3), Opcode.RETURN(1)], stack = stack) == ret
@pytest.mark.parametrize("stack,ret", [
@ -67,4 +68,4 @@ def test_funref(vm, stack, ret):
[[], [True]]
])
def test_callf(vm, stack, ret):
assert vm.run([Opcode.FALSE(), Opcode.FUNREF(NOT1), Opcode.CALLF(1)], stack = stack) == ret
assert vm.run([Opcode.FALSE(), Opcode.FUNREF(NOT1), Opcode.CALLF(1), Opcode.RETURN(1)], stack = stack) == ret

View file

@ -4,8 +4,8 @@ Tests coverign the VM interpreter
from .fixtures import * # noqa
import pytest
from ichor import *
import pytest
def test_true(vm):
@ -86,10 +86,3 @@ def test_drop_too_many(vm):
with pytest.raises(InterpreterError):
vm.run([Opcode.TRUE(), Opcode.DROP(2)])
def test_frames():
assert len(list(Stackframe().frames())) == 1
assert len(list(Stackframe(parent=Stackframe()).frames())) == 2
assert len(list(Stackframe(parent=Stackframe(parent=Stackframe())).frames())) == 3
assert len(list(Stackframe(parent=Stackframe(parent=Stackframe(parent=Stackframe()))).frames())) == 4