Split out Ichor

This commit is contained in:
Reid D. 'arrdem' McKenzie 2022-05-31 19:25:18 -06:00
parent 0ffc6c6bb7
commit c1498c98eb
13 changed files with 31 additions and 78 deletions

View file

@ -1,6 +1,6 @@
py_project( py_project(
name = "shoggoth", name = "shoggoth",
main = "src/python/forerunner/repl/__main__.py", main = "src/python/shoggoth/repl/__main__.py",
main_deps = [ main_deps = [
py_requirement("prompt_toolkit"), py_requirement("prompt_toolkit"),
py_requirement("yaspin"), py_requirement("yaspin"),

View file

@ -6,7 +6,7 @@ Hopefully no "real" interpreter ever uses this code, since it's obviously replac
from .isa import Module, Opcode from .isa import Module, Opcode
from shoggoth.types import * from .typing import ProductExpr, SumExpr
BOOTSTRAP = Module() BOOTSTRAP = Module()

View file

@ -1,19 +1,11 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
"""The Shogoth VM implementation. """The Ichor VM implementation.
The whole point of shoggoth is that program executions are checkpointable and restartable. This requires that rather than The whole point of Shoggoth is that program executions are checkpointable and restartable. This requires that rather than
using a traditional recursive interpreter which is difficult to snapshot, interpretation in shoggoth occur within a using a traditional recursive interpreter which is difficult to snapshot, interpretation in shoggoth occur within a
context (a virtual machine) which DOES have an easily introspected and serialized representation. context (a virtual machine) which DOES have an easily introspected and serialized representation.
## The Shogoth VM Architecture
- NOT [bool] -> [bool]
- IF [then: addr, else: addr, cond: bool] -> []
- CALL [procedure, n, ...] -> [...]
- RETURN [n, ...]
""" """

View file

@ -3,7 +3,7 @@
from typing import NamedTuple from typing import NamedTuple
from shoggoth.types import FunctionRef from .typing import FunctionRef
class Opcode: class Opcode:

View file

@ -58,11 +58,28 @@ class Closure(t.NamedTuple):
args: t.List[t.Any] args: t.List[t.Any]
# FIXME (arrdem 2022-05-30): class FunctionSignature(t.NamedTuple):
# Find a better name for this raw: str
class Vec(list): type_params: list
pass name: str
args: list
ret: list
@staticmethod
def parse_list(l):
return [e for e in l.split(",") if e]
@classmethod
def parse(cls, raw: str):
vars, name, args, ret = raw.split(";")
return cls(
raw,
cls.parse_list(vars),
name,
cls.parse_list(args),
cls.parse_list(ret)
)
class List(list): class Function(t.NamedTuple):
pass """The type of a function; a subset of its signature."""

View file

@ -1,30 +0,0 @@
#!/usr/bin/env python3
from typing import NamedTuple
class FunctionSignature(NamedTuple):
raw: str
type_params: list
name: str
args: list
ret: list
@staticmethod
def parse_list(l):
return [e for e in l.split(",") if e]
@classmethod
def parse(cls, raw: str):
vars, name, args, ret = raw.split(";")
return cls(
raw,
cls.parse_list(vars),
name,
cls.parse_list(args),
cls.parse_list(ret)
)
class Function(NamedTuple):
"""The type of a function; a subset of its signature."""

View file

@ -1,5 +0,0 @@
from .symbol import Symbol
class Keyword(Symbol):
pass

View file

@ -1,21 +0,0 @@
import typing as t
class Symbol(t.NamedTuple):
name: str
namespace: t.Optional[str] = None
def qualify(self, ns: str):
return Symbol(self.name, ns)
def unqualified(self):
if not self.namespace:
return self
else:
return Symbol(self.name)
def __str__(self):
if self.namespace:
return f"{self.namespace}/{self.name}"
else:
return self.name

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import pytest import pytest
from shoggoth.vm import * from ichor import *
@pytest.fixture @pytest.fixture

View file

@ -3,7 +3,7 @@
from .fixtures import * # noqa from .fixtures import * # noqa
import pytest import pytest
from shoggoth.vm import * from ichor import *
@pytest.mark.parametrize("stack,ret", [ @pytest.mark.parametrize("stack,ret", [

View file

@ -5,7 +5,7 @@ Tests coverign the VM interpreter
from .fixtures import * # noqa from .fixtures import * # noqa
import pytest import pytest
from shoggoth.vm import * from ichor import *
def test_true(vm): def test_true(vm):