Split out Ichor

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

View file

@ -1,6 +1,6 @@
py_project(
name = "shoggoth",
main = "src/python/forerunner/repl/__main__.py",
main = "src/python/shoggoth/repl/__main__.py",
main_deps = [
py_requirement("prompt_toolkit"),
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 shoggoth.types import *
from .typing import ProductExpr, SumExpr
BOOTSTRAP = Module()

View file

@ -1,19 +1,11 @@
#!/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
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 shoggoth.types import FunctionRef
from .typing import FunctionRef
class Opcode:

View file

@ -58,11 +58,28 @@ class Closure(t.NamedTuple):
args: t.List[t.Any]
# FIXME (arrdem 2022-05-30):
# Find a better name for this
class Vec(list):
pass
class FunctionSignature(t.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 List(list):
pass
class Function(t.NamedTuple):
"""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
import pytest
from shoggoth.vm import *
from ichor import *
@pytest.fixture

View file

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

View file

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