Calling it a night
This commit is contained in:
parent
9b6e11818e
commit
496dfb7026
3 changed files with 68 additions and 3 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
25
projects/shoggoth/test/python/ichor/test_parsers.py
Normal file
25
projects/shoggoth/test/python/ichor/test_parsers.py
Normal 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)
|
Loading…
Reference in a new issue