Get and2/3 working

This commit is contained in:
Reid 'arrdem' McKenzie 2022-08-17 00:18:08 -06:00
parent c484691aca
commit a6b20ed7c3
2 changed files with 113 additions and 17 deletions

View file

@ -64,7 +64,7 @@ _b.write(isa.IDENTIFIERC("false"))
_b.write(isa.ARMREF())
_false_t = _b.mark_slot()
# x: Bool, x: Bool -> Bool
# x: Bool, y: Bool -> Bool
_true_l = _b.make_label()
_b.write(isa.SLOT(_x))
_b.write(isa.SLOT(_true_t))
@ -109,7 +109,7 @@ _b.write(isa.IDENTIFIERC("false"))
_b.write(isa.ARMREF())
_false_t = _b.mark_slot()
# x: Bool, x: Bool -> Bool
# x: Bool, y: Bool, z: Bool -> Bool
_true_l = _b.make_label()
_b.write(isa.SLOT(_x))
_b.write(isa.SLOT(_true_t))
@ -139,7 +139,43 @@ OR3 = BOOTSTRAP.define_function(
)
_b = FuncBuilder()
_b.write(isa.BREAK())
# Capture args
_x = _b.mark_argument()
_y = _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
_false_l = _b.make_label()
_b.write(isa.SLOT(_x))
_b.write(isa.SLOT(_false_t))
_b.write(isa.ATEST(_false_l))
_b.write(isa.SLOT(_y))
_b.write(isa.SLOT(_false_t))
_b.write(isa.ATEST(_false_l))
_b.write(isa.SLOT(_true_t))
_b.write(isa.ARM(0))
_b.write(isa.RETURN())
_b.write(_false_l)
_b.write(isa.SLOT(_false_t))
_b.write(isa.ARM(0))
_b.write(isa.RETURN())
AND2 = BOOTSTRAP.define_function(
f";and;{BOOL},{BOOL};{BOOL}",
@ -147,7 +183,49 @@ AND2 = BOOTSTRAP.define_function(
)
_b = FuncBuilder()
_b.write(isa.BREAK())
_b = FuncBuilder()
# 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
_false_l = _b.make_label()
_b.write(isa.SLOT(_x))
_b.write(isa.SLOT(_false_t))
_b.write(isa.ATEST(_false_l))
_b.write(isa.SLOT(_y))
_b.write(isa.SLOT(_false_t))
_b.write(isa.ATEST(_false_l))
_b.write(isa.SLOT(_z))
_b.write(isa.SLOT(_false_t))
_b.write(isa.ATEST(_false_l))
_b.write(isa.SLOT(_true_t))
_b.write(isa.ARM(0))
_b.write(isa.RETURN())
_b.write(_false_l)
_b.write(isa.SLOT(_false_t))
_b.write(isa.ARM(0))
_b.write(isa.RETURN())
AND3 = BOOTSTRAP.define_function(
f";and;{BOOL},{BOOL},{BOOL};{BOOL}",

View file

@ -9,6 +9,8 @@ from ichor.bootstrap import (
OR2,
OR3,
TRUE,
AND2,
AND3
)
import pytest
@ -60,19 +62,35 @@ def test_or3(vm, stack, ret):
], stack = stack) == ret
# @pytest.mark.parametrize("stack,ret", [
# [[False, False], [False]],
# [[True, False], [False]],
# [[False, True], [False]],
# [[True, True], [True]],
# ])
# def test_and(vm, stack, ret):
# assert vm.run([
# isa.IDENTIFIERC(AND2),
# isa.FUNREF(),
# isa.CALLF(2),
# isa.RETURN(1)
# ], stack = stack) == ret
@pytest.mark.parametrize("stack,ret", [
[[FALSE, FALSE], [FALSE]],
[[TRUE, FALSE], [FALSE]],
[[FALSE, TRUE], [FALSE]],
[[TRUE, TRUE], [TRUE]],
])
def test_and2(vm, stack, ret):
assert vm.run([
isa.IDENTIFIERC(AND2),
isa.FUNREF(),
isa.CALLF(2),
isa.RETURN()
], stack = stack) == ret
@pytest.mark.parametrize("stack,ret", [
[[FALSE, FALSE, FALSE], [FALSE]],
[[TRUE, FALSE, FALSE], [FALSE]],
[[FALSE, TRUE, FALSE], [FALSE]],
[[TRUE, TRUE, FALSE], [FALSE]],
[[TRUE, TRUE, TRUE], [TRUE]],
])
def test_and3(vm, stack, ret):
assert vm.run([
isa.IDENTIFIERC(AND3),
isa.FUNREF(),
isa.CALLF(3),
isa.RETURN()
], stack = stack) == ret
# @pytest.mark.parametrize("stack,ret", [