2022-04-15 06:31:58 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2022-05-31 15:41:10 +00:00
|
|
|
from .fixtures import * # noqa
|
|
|
|
|
2022-08-09 15:39:33 +00:00
|
|
|
from ichor import isa
|
|
|
|
from ichor.bootstrap import FALSE, NOT1, TRUE
|
2022-06-01 05:17:32 +00:00
|
|
|
import pytest
|
2022-04-15 06:31:58 +00:00
|
|
|
|
|
|
|
|
2022-05-31 15:41:10 +00:00
|
|
|
@pytest.mark.parametrize("stack,ret", [
|
2022-06-28 04:35:21 +00:00
|
|
|
[[TRUE], [FALSE]],
|
|
|
|
[[FALSE], [TRUE]],
|
2022-04-15 06:31:58 +00:00
|
|
|
])
|
|
|
|
def test_not(vm, stack, ret):
|
2022-06-11 06:28:24 +00:00
|
|
|
assert vm.run([
|
2022-07-16 01:33:32 +00:00
|
|
|
isa.IDENTIFIERC(NOT1),
|
|
|
|
isa.FUNREF(),
|
|
|
|
isa.CALLF(1),
|
2022-08-09 15:39:33 +00:00
|
|
|
isa.RETURN()
|
2022-06-11 06:28:24 +00:00
|
|
|
], stack = stack) == ret
|
2022-04-15 06:31:58 +00:00
|
|
|
|
|
|
|
|
2022-06-28 04:35:21 +00:00
|
|
|
# @pytest.mark.parametrize("stack,ret", [
|
|
|
|
# [[False, False], [False]],
|
|
|
|
# [[True, False], [True]],
|
|
|
|
# [[False, True], [True]],
|
|
|
|
# [[True, True], [True]],
|
|
|
|
# ])
|
|
|
|
# def test_or(vm, stack, ret):
|
|
|
|
# assert vm.run([
|
2022-07-16 01:33:32 +00:00
|
|
|
# isa.IDENTIFIERC(OR2),
|
|
|
|
# isa.FUNREF(),
|
|
|
|
# isa.CALLF(2),
|
|
|
|
# isa.RETURN(1)
|
2022-06-28 04:35:21 +00:00
|
|
|
# ], 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([
|
2022-07-16 01:33:32 +00:00
|
|
|
# isa.IDENTIFIERC(AND2),
|
|
|
|
# isa.FUNREF(),
|
|
|
|
# isa.CALLF(2),
|
|
|
|
# isa.RETURN(1)
|
2022-06-28 04:35:21 +00:00
|
|
|
# ], stack = stack) == ret
|
|
|
|
|
|
|
|
|
|
|
|
# @pytest.mark.parametrize("stack,ret", [
|
|
|
|
# [[False, False], [False]],
|
|
|
|
# [[True, False], [True]],
|
|
|
|
# [[False, True], [True]],
|
|
|
|
# [[True, True], [False]],
|
|
|
|
# ])
|
|
|
|
# def test_xor2(vm, stack, ret):
|
|
|
|
# assert vm.run([
|
2022-07-16 01:33:32 +00:00
|
|
|
# isa.IDENTIFIERC(XOR2),
|
|
|
|
# isa.FUNREF(),
|
|
|
|
# isa.CALLF(2),
|
|
|
|
# isa.RETURN(1)
|
2022-06-28 04:35:21 +00:00
|
|
|
# ], stack = stack) == ret
|
|
|
|
|
|
|
|
|
|
|
|
# @pytest.mark.parametrize("stack,ret", [
|
|
|
|
# [[False, False, False], [False]],
|
|
|
|
# [[True, False, False], [True]],
|
|
|
|
# [[False, True, False], [True]],
|
|
|
|
# [[True, True, False], [True]],
|
|
|
|
# [[True, True, True], [False]],
|
|
|
|
# [[False, True, True], [True]],
|
|
|
|
# [[False, False, True], [True]],
|
|
|
|
# ])
|
|
|
|
# def test_xor3(vm, stack, ret):
|
|
|
|
# assert vm.run([
|
2022-07-16 01:33:32 +00:00
|
|
|
# isa.IDENTIFIERC(XOR3),
|
|
|
|
# isa.FUNREF(),
|
|
|
|
# isa.CALLF(3),
|
|
|
|
# isa.RETURN(1)
|
2022-06-28 04:35:21 +00:00
|
|
|
# ], stack = stack) == ret
|
|
|
|
|
|
|
|
|
|
|
|
# @pytest.mark.parametrize("stack,ret", [
|
|
|
|
# [[], [FunctionRef.parse(NOT1)]]
|
|
|
|
# ])
|
|
|
|
# def test_funref(vm, stack, ret):
|
|
|
|
# assert vm.run([
|
2022-07-16 01:33:32 +00:00
|
|
|
# isa.IDENTIFIERC(NOT1),
|
|
|
|
# isa.FUNREF(),
|
|
|
|
# isa.RETURN(1)
|
2022-06-28 04:35:21 +00:00
|
|
|
# ], stack = stack) == ret
|
|
|
|
|
|
|
|
|
|
|
|
# @pytest.mark.parametrize("stack,ret", [
|
|
|
|
# [[False], [True]]
|
|
|
|
# ])
|
|
|
|
# def test_callf(vm, stack, ret):
|
|
|
|
# assert vm.run([
|
2022-07-16 01:33:32 +00:00
|
|
|
# isa.IDENTIFIERC(NOT1),
|
|
|
|
# isa.FUNREF(),
|
|
|
|
# isa.CALLF(1),
|
|
|
|
# isa.RETURN(1)
|
2022-06-28 04:35:21 +00:00
|
|
|
# ], stack = stack) == ret
|
|
|
|
|
|
|
|
|
|
|
|
# @pytest.mark.parametrize("stack,ret", [
|
|
|
|
# [[False, False], [False]],
|
|
|
|
# [[True, False], [True]],
|
|
|
|
# [[False, True], [True]],
|
|
|
|
# [[True, True], [False]],
|
|
|
|
# ])
|
|
|
|
# def test_callc(vm, stack, ret):
|
|
|
|
# assert vm.run([
|
2022-07-16 01:33:32 +00:00
|
|
|
# isa.IDENTIFIERC(XOR2),
|
|
|
|
# isa.FUNREF(),
|
|
|
|
# isa.CLOSUREF(1),
|
|
|
|
# isa.CALLC(1),
|
|
|
|
# isa.RETURN(1),
|
2022-06-28 04:35:21 +00:00
|
|
|
# ], stack = stack) == ret
|
|
|
|
|
|
|
|
|
|
|
|
# @pytest.mark.parametrize("stack,ret", [
|
|
|
|
# [[False, False, False], [False]],
|
|
|
|
# [[True, False, False], [True]],
|
|
|
|
# [[False, True, False], [True]],
|
|
|
|
# [[True, True, False], [True]],
|
|
|
|
# [[True, True, True], [False]],
|
|
|
|
# [[False, True, True], [True]],
|
|
|
|
# [[False, False, True], [True]],
|
|
|
|
# ])
|
|
|
|
# def test_closurec(vm, stack, ret):
|
|
|
|
# assert vm.run([
|
2022-07-16 01:33:32 +00:00
|
|
|
# isa.IDENTIFIERC(XOR3),
|
|
|
|
# isa.FUNREF(),
|
|
|
|
# isa.CLOSUREF(1),
|
|
|
|
# isa.CLOSUREC(1),
|
|
|
|
# isa.CALLC(1),
|
|
|
|
# isa.RETURN(1),
|
2022-06-28 04:35:21 +00:00
|
|
|
# ], stack = stack) == ret
|