diff --git a/projects/shoggoth/src/python/ichor/bootstrap.py b/projects/shoggoth/src/python/ichor/bootstrap.py index 37e8baf..9806a67 100644 --- a/projects/shoggoth/src/python/ichor/bootstrap.py +++ b/projects/shoggoth/src/python/ichor/bootstrap.py @@ -89,7 +89,49 @@ OR2 = BOOTSTRAP.define_function( ) _b = FuncBuilder() -_b.write(isa.BREAK()) +# Capture args +_x = _b.mark_argument() +_y = _b.mark_argument() +_z = _b.mark_argument() + +# Const +_b.write(isa.IDENTIFIERC("bool")) +_b.write(isa.TYPEREF()) +_bool_t = _b.mark_slot() + +_b.write(isa.SLOT(_bool_t)) +_b.write(isa.IDENTIFIERC("true")) +_b.write(isa.ARMREF()) +_true_t = _b.mark_slot() + +_b.write(isa.SLOT(_bool_t)) +_b.write(isa.IDENTIFIERC("false")) +_b.write(isa.ARMREF()) +_false_t = _b.mark_slot() + +# x: Bool, x: Bool -> Bool +_true_l = _b.make_label() +_b.write(isa.SLOT(_x)) +_b.write(isa.SLOT(_true_t)) +_b.write(isa.ATEST(_true_l)) + +_b.write(isa.SLOT(_y)) +_b.write(isa.SLOT(_true_t)) +_b.write(isa.ATEST(_true_l)) + +_b.write(isa.SLOT(_z)) +_b.write(isa.SLOT(_true_t)) +_b.write(isa.ATEST(_true_l)) + +_b.write(isa.SLOT(_false_t)) +_b.write(isa.ARM(0)) +_b.write(isa.RETURN()) + +_b.write(_true_l) +_b.write(isa.SLOT(_true_t)) +_b.write(isa.ARM(0)) +_b.write(isa.RETURN()) + OR3 = BOOTSTRAP.define_function( f";or;{BOOL},{BOOL},{BOOL};{BOOL}", diff --git a/projects/shoggoth/test/python/ichor/test_bootstrap.py b/projects/shoggoth/test/python/ichor/test_bootstrap.py index 2754a1c..3f7151a 100644 --- a/projects/shoggoth/test/python/ichor/test_bootstrap.py +++ b/projects/shoggoth/test/python/ichor/test_bootstrap.py @@ -7,7 +7,7 @@ from ichor.bootstrap import ( FALSE, NOT1, OR2, - OR2_INSTRS, + OR3, TRUE, ) import pytest @@ -32,10 +32,7 @@ def test_not(vm, stack, ret): [[FALSE, TRUE], [TRUE]], [[TRUE, TRUE], [TRUE]], ]) -def test_or(vm, stack, ret): - for idx, i in zip(range(512), OR2_INSTRS): - print(f"{idx:>3} {i}") - +def test_or2(vm, stack, ret): assert vm.run([ isa.IDENTIFIERC(OR2), isa.FUNREF(), @@ -43,6 +40,25 @@ def test_or(vm, stack, ret): isa.RETURN() ], stack = stack) == ret +@pytest.mark.parametrize("stack,ret", [ + [[FALSE, FALSE, FALSE], [FALSE]], + [[TRUE, FALSE, FALSE], [TRUE]], + [[FALSE, TRUE, FALSE], [TRUE]], + [[FALSE, FALSE, TRUE], [TRUE]], + + [[TRUE, TRUE, FALSE], [TRUE]], + [[TRUE, FALSE, TRUE], [TRUE]], + [[FALSE, TRUE, TRUE], [TRUE]], + [[TRUE, TRUE, TRUE], [TRUE]], +]) +def test_or3(vm, stack, ret): + assert vm.run([ + isa.IDENTIFIERC(OR3), + isa.FUNREF(), + isa.CALLF(3), + isa.RETURN() + ], stack = stack) == ret + # @pytest.mark.parametrize("stack,ret", [ # [[False, False], [False]],