diff --git a/projects/shoggoth/src/python/ichor/bootstrap.py b/projects/shoggoth/src/python/ichor/bootstrap.py index 7ecea4b..ce64973 100644 --- a/projects/shoggoth/src/python/ichor/bootstrap.py +++ b/projects/shoggoth/src/python/ichor/bootstrap.py @@ -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]) ) diff --git a/projects/shoggoth/src/python/ichor/impl.py b/projects/shoggoth/src/python/ichor/impl.py index ee47716..1f15b18 100644 --- a/projects/shoggoth/src/python/ichor/impl.py +++ b/projects/shoggoth/src/python/ichor/impl.py @@ -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(): diff --git a/projects/shoggoth/test/python/ichor/fixtures.py b/projects/shoggoth/test/python/ichor/fixtures.py index ea04695..0d12c13 100644 --- a/projects/shoggoth/test/python/ichor/fixtures.py +++ b/projects/shoggoth/test/python/ichor/fixtures.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 -import pytest from ichor import * +import pytest @pytest.fixture diff --git a/projects/shoggoth/test/python/ichor/test_bootstrap.py b/projects/shoggoth/test/python/ichor/test_bootstrap.py index 897e03f..b2d7a8e 100644 --- a/projects/shoggoth/test/python/ichor/test_bootstrap.py +++ b/projects/shoggoth/test/python/ichor/test_bootstrap.py @@ -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 diff --git a/projects/shoggoth/test/python/ichor/test_interpreter.py b/projects/shoggoth/test/python/ichor/test_interpreter.py index 99b2c1d..b502a0b 100644 --- a/projects/shoggoth/test/python/ichor/test_interpreter.py +++ b/projects/shoggoth/test/python/ichor/test_interpreter.py @@ -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