From c1498c98ebb025fd616a583dd78dd2e15f2cd2f1 Mon Sep 17 00:00:00 2001 From: "Reid D. 'arrdem' McKenzie" Date: Tue, 31 May 2022 19:25:18 -0600 Subject: [PATCH] Split out Ichor --- projects/shoggoth/BUILD | 2 +- .../python/{shoggoth/vm => ichor}/NOTES.md | 0 .../python/{shoggoth/vm => ichor}/__init__.py | 0 .../{shoggoth/vm => ichor}/bootstrap.py | 2 +- .../src/python/{shoggoth/vm => ichor}/impl.py | 12 ++------ .../src/python/{shoggoth/vm => ichor}/isa.py | 2 +- .../types/__init__.py => ichor/typing.py} | 29 ++++++++++++++---- .../src/python/shoggoth/types/function.py | 30 ------------------- .../src/python/shoggoth/types/keyword.py | 5 ---- .../src/python/shoggoth/types/symbol.py | 21 ------------- .../python/{shogoth/vm => ichor}/fixtures.py | 2 +- .../{shogoth/vm => ichor}/test_bootstrap.py | 2 +- .../{shogoth/vm => ichor}/test_interpreter.py | 2 +- 13 files changed, 31 insertions(+), 78 deletions(-) rename projects/shoggoth/src/python/{shoggoth/vm => ichor}/NOTES.md (100%) rename projects/shoggoth/src/python/{shoggoth/vm => ichor}/__init__.py (100%) rename projects/shoggoth/src/python/{shoggoth/vm => ichor}/bootstrap.py (97%) rename projects/shoggoth/src/python/{shoggoth/vm => ichor}/impl.py (95%) rename projects/shoggoth/src/python/{shoggoth/vm => ichor}/isa.py (99%) rename projects/shoggoth/src/python/{shoggoth/types/__init__.py => ichor/typing.py} (70%) delete mode 100644 projects/shoggoth/src/python/shoggoth/types/function.py delete mode 100644 projects/shoggoth/src/python/shoggoth/types/keyword.py delete mode 100644 projects/shoggoth/src/python/shoggoth/types/symbol.py rename projects/shoggoth/test/python/{shogoth/vm => ichor}/fixtures.py (79%) rename projects/shoggoth/test/python/{shogoth/vm => ichor}/test_bootstrap.py (98%) rename projects/shoggoth/test/python/{shogoth/vm => ichor}/test_interpreter.py (98%) diff --git a/projects/shoggoth/BUILD b/projects/shoggoth/BUILD index 0ec38de..d8fe06e 100644 --- a/projects/shoggoth/BUILD +++ b/projects/shoggoth/BUILD @@ -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"), diff --git a/projects/shoggoth/src/python/shoggoth/vm/NOTES.md b/projects/shoggoth/src/python/ichor/NOTES.md similarity index 100% rename from projects/shoggoth/src/python/shoggoth/vm/NOTES.md rename to projects/shoggoth/src/python/ichor/NOTES.md diff --git a/projects/shoggoth/src/python/shoggoth/vm/__init__.py b/projects/shoggoth/src/python/ichor/__init__.py similarity index 100% rename from projects/shoggoth/src/python/shoggoth/vm/__init__.py rename to projects/shoggoth/src/python/ichor/__init__.py diff --git a/projects/shoggoth/src/python/shoggoth/vm/bootstrap.py b/projects/shoggoth/src/python/ichor/bootstrap.py similarity index 97% rename from projects/shoggoth/src/python/shoggoth/vm/bootstrap.py rename to projects/shoggoth/src/python/ichor/bootstrap.py index 9249971..75b9467 100644 --- a/projects/shoggoth/src/python/shoggoth/vm/bootstrap.py +++ b/projects/shoggoth/src/python/ichor/bootstrap.py @@ -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() diff --git a/projects/shoggoth/src/python/shoggoth/vm/impl.py b/projects/shoggoth/src/python/ichor/impl.py similarity index 95% rename from projects/shoggoth/src/python/shoggoth/vm/impl.py rename to projects/shoggoth/src/python/ichor/impl.py index eb72a83..6e7a8a8 100644 --- a/projects/shoggoth/src/python/shoggoth/vm/impl.py +++ b/projects/shoggoth/src/python/ichor/impl.py @@ -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, ...] - """ diff --git a/projects/shoggoth/src/python/shoggoth/vm/isa.py b/projects/shoggoth/src/python/ichor/isa.py similarity index 99% rename from projects/shoggoth/src/python/shoggoth/vm/isa.py rename to projects/shoggoth/src/python/ichor/isa.py index f318fef..c2c9998 100644 --- a/projects/shoggoth/src/python/shoggoth/vm/isa.py +++ b/projects/shoggoth/src/python/ichor/isa.py @@ -3,7 +3,7 @@ from typing import NamedTuple -from shoggoth.types import FunctionRef +from .typing import FunctionRef class Opcode: diff --git a/projects/shoggoth/src/python/shoggoth/types/__init__.py b/projects/shoggoth/src/python/ichor/typing.py similarity index 70% rename from projects/shoggoth/src/python/shoggoth/types/__init__.py rename to projects/shoggoth/src/python/ichor/typing.py index 7f40a9a..c9235b7 100644 --- a/projects/shoggoth/src/python/shoggoth/types/__init__.py +++ b/projects/shoggoth/src/python/ichor/typing.py @@ -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.""" diff --git a/projects/shoggoth/src/python/shoggoth/types/function.py b/projects/shoggoth/src/python/shoggoth/types/function.py deleted file mode 100644 index 04fde96..0000000 --- a/projects/shoggoth/src/python/shoggoth/types/function.py +++ /dev/null @@ -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.""" diff --git a/projects/shoggoth/src/python/shoggoth/types/keyword.py b/projects/shoggoth/src/python/shoggoth/types/keyword.py deleted file mode 100644 index da154b2..0000000 --- a/projects/shoggoth/src/python/shoggoth/types/keyword.py +++ /dev/null @@ -1,5 +0,0 @@ -from .symbol import Symbol - - -class Keyword(Symbol): - pass diff --git a/projects/shoggoth/src/python/shoggoth/types/symbol.py b/projects/shoggoth/src/python/shoggoth/types/symbol.py deleted file mode 100644 index 13cd9e9..0000000 --- a/projects/shoggoth/src/python/shoggoth/types/symbol.py +++ /dev/null @@ -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 diff --git a/projects/shoggoth/test/python/shogoth/vm/fixtures.py b/projects/shoggoth/test/python/ichor/fixtures.py similarity index 79% rename from projects/shoggoth/test/python/shogoth/vm/fixtures.py rename to projects/shoggoth/test/python/ichor/fixtures.py index d3937d6..ea04695 100644 --- a/projects/shoggoth/test/python/shogoth/vm/fixtures.py +++ b/projects/shoggoth/test/python/ichor/fixtures.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import pytest -from shoggoth.vm import * +from ichor import * @pytest.fixture diff --git a/projects/shoggoth/test/python/shogoth/vm/test_bootstrap.py b/projects/shoggoth/test/python/ichor/test_bootstrap.py similarity index 98% rename from projects/shoggoth/test/python/shogoth/vm/test_bootstrap.py rename to projects/shoggoth/test/python/ichor/test_bootstrap.py index fb99599..75188a1 100644 --- a/projects/shoggoth/test/python/shogoth/vm/test_bootstrap.py +++ b/projects/shoggoth/test/python/ichor/test_bootstrap.py @@ -3,7 +3,7 @@ from .fixtures import * # noqa import pytest -from shoggoth.vm import * +from ichor import * @pytest.mark.parametrize("stack,ret", [ diff --git a/projects/shoggoth/test/python/shogoth/vm/test_interpreter.py b/projects/shoggoth/test/python/ichor/test_interpreter.py similarity index 98% rename from projects/shoggoth/test/python/shogoth/vm/test_interpreter.py rename to projects/shoggoth/test/python/ichor/test_interpreter.py index 3f1ee9f..2cfcd9b 100644 --- a/projects/shoggoth/test/python/shogoth/vm/test_interpreter.py +++ b/projects/shoggoth/test/python/ichor/test_interpreter.py @@ -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):