Calling it a night

This commit is contained in:
Reid 'arrdem' McKenzie 2022-06-14 01:19:30 -06:00
parent 9b6e11818e
commit 496dfb7026
3 changed files with 68 additions and 3 deletions

View file

@ -4,20 +4,21 @@
ichor entrypoint
"""
from . import *
from . import Opcode, Interpreter, BOOTSTRAP, XOR3
def main():
vm = Interpreter(BOOTSTRAP)
ret = vm.run(
[
Opcode.FUNREF(XOR3),
Opcode.IDENTIFIERC(XOR3),
Opcode.FUNREF(),
Opcode.CLOSUREF(1),
Opcode.CLOSUREC(1),
Opcode.CALLC(1),
Opcode.RETURN(1),
],
stackframe = [True, True, False]
stack = [True, True, False]
)
print(ret)

View file

@ -6,6 +6,7 @@
import typing as t
from ichor.isa import Opcode
from lark import Lark
class Identifier(t.NamedTuple):
@ -34,6 +35,28 @@ class FunctionSignature(t.NamedTuple):
cls.parse_list(ret)
)
GRAMMAR = r"""
fun: constraints ";" name ";" arguments ";" ret
arguments: (type ","?)*
ret: (type ","?)*
constraints: (constraint ","?)*
constraint: type
var: constraints ";" name ";" arms
arms: (arm ("," arms)?)?
arm: name "(" bindings ")"
bindings: (binding ","?)*
binding: name ":" type
type: NAME
name: NAME
NAME: /[^;,:]+/
"""
FUNC = Lark(GRAMMAR, start="fun")
class FunctionRef(t.NamedTuple):
raw: str
@ -60,6 +83,22 @@ class FunctionRef(t.NamedTuple):
class Function(t.NamedTuple):
name: str
arguments: t.List[str]
returns: t.List[str]
instructions: t.List[Opcode]
typevars: t.List[t.Any] = []
typeconstraints: t.List[t.Any] = []
metadata: dict = {}
VAR = Lark(GRAMMAR, start="var")
class Type(t.NamedTuple):
name: str
constructors: t.List[t.Tuple[str, t.List[str]]]
typevars: t.List[t.Any] = []
typeconstraints: t.List[t.Any] = []
metadata: dict = {}
class Closure(t.NamedTuple):

View file

@ -0,0 +1,25 @@
#!/usr/bin/env python3
from ichor.state import FUNC, VAR
import pytest
@pytest.mark.parametrize('sig', [
";not;bool;bool",
";and;bool,bool;bool",
";or;bool,bool,bool;bool",
])
def test_func_parses(sig):
assert FUNC.parse(sig)
@pytest.mark.parametrize('sig', [
";bool;true(),false()",
"A,B;pair;pair(a:A,b:B)",
"A,B,C;tripple;tripple(a:A,b:B,c:C)",
"A,B,C,D;quad;quad(a:A,b:B,c:C,d:D)",
"A,B,C,D,E;quint;quint(a:A,b:B,c:C,d:D,e:E)",
])
def test_var_parses(sig):
assert VAR.parse(sig)