This commit is contained in:
Reid D. 'arrdem' McKenzie 2022-05-31 09:41:10 -06:00
parent 65091be070
commit bd3fe9bb00
15 changed files with 44 additions and 38 deletions

View file

@ -22,9 +22,9 @@ from hashlib import sha256, sha512
from pathlib import Path from pathlib import Path
import re import re
from shutil import copy2 as copyfile from shutil import copy2 as copyfile
import stat
import sys import sys
import typing as t import typing as t
import stat
from .util import * from .util import *

View file

@ -2,4 +2,3 @@
"""A syntax analyzer for Shogoth.""" """A syntax analyzer for Shogoth."""
from .impl import *

View file

@ -6,7 +6,12 @@ from abc import ABC
from dataclasses import dataclass from dataclasses import dataclass
import typing as t import typing as t
from shogoth.types import List, Vec, Keyword, Symbol from shogoth.types import (
Keyword,
List,
Symbol,
Vec,
)
@dataclass @dataclass

View file

@ -1,3 +1,2 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from .impl import *

View file

@ -3,6 +3,8 @@
"""The shogoth reader.""" """The shogoth reader."""
import sys import sys
assert sys.version_info > (3, 10, 0), "`match` support is required" assert sys.version_info > (3, 10, 0), "`match` support is required"
import re import re
@ -10,7 +12,12 @@ from typing import Any
from lark import Token, Tree from lark import Token, Tree
from shogoth.parser import parse from shogoth.parser import parse
from shogoth.types import Keyword, Symbol, List, Vec from shogoth.types import (
Keyword,
List,
Symbol,
Vec,
)
# Monkeypatching for py3.10 matching # Monkeypatching for py3.10 matching

View file

@ -1,18 +1,16 @@
"""A testing REPL.""" """A testing REPL."""
from shogoth.reader import Reader from prompt_toolkit import PromptSession
from shogoth.types import Symbol
from shogoth.analyzer import Analyzer, SPECIALS, GLOBALS, Namespace
from prompt_toolkit import (
print_formatted_text,
PromptSession,
)
from prompt_toolkit.formatted_text import (
FormattedText,
)
from prompt_toolkit.history import FileHistory from prompt_toolkit.history import FileHistory
from prompt_toolkit.styles import Style from prompt_toolkit.styles import Style
from shogoth.analyzer import (
Analyzer,
GLOBALS,
Namespace,
SPECIALS,
)
from shogoth.reader import Reader
from shogoth.types import Symbol
from yaspin import Spinner, yaspin from yaspin import Spinner, yaspin
@ -49,7 +47,7 @@ def main():
with yaspin(SPINNER): with yaspin(SPINNER):
expr = analyzer.analyze(ns, read) expr = analyzer.analyze(ns, read)
print('analyze ]', expr, type(expr)) print("analyze ]", expr, type(expr))
if __name__ == "__main__": if __name__ == "__main__":

View file

@ -1,11 +1,7 @@
"""The public interface for shogoth's baked-in types.""" """The public interface for shogoth's baked-in types."""
from .keyword import Keyword
from .symbol import Symbol
from abc import ABC
import typing as t import typing as t
from uuid import UUID, uuid4 from uuid import UUID, uuid4

View file

@ -1,5 +1,5 @@
# noqa # noqa
from .isa import * # noqa
from .bootstrap import * # noqa from .bootstrap import * # noqa
from .impl import * # noqa from .impl import * # noqa
from .isa import * # noqa

View file

@ -5,8 +5,10 @@ Hopefully no "real" interpreter ever uses this code, since it's obviously replac
""" """
from .isa import Module, Opcode from .isa import Module, Opcode
from shogoth.types import * from shogoth.types import *
BOOTSTRAP = Module() BOOTSTRAP = Module()
NOT = BOOTSTRAP.define_function( NOT = BOOTSTRAP.define_function(

View file

@ -18,6 +18,8 @@ context (a virtual machine) which DOES have an easily introspected and serialize
import sys import sys
assert sys.version_info > (3, 10, 0), "`match` support is required" assert sys.version_info > (3, 10, 0), "`match` support is required"
from copy import deepcopy from copy import deepcopy

View file

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

View file

@ -3,7 +3,6 @@
import pytest import pytest
from shogoth.vm import * from shogoth.vm import *
import pytest
@pytest.fixture @pytest.fixture
def vm(): def vm():

View file

@ -1,17 +1,16 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import pytest
from shogoth.parser import parse from shogoth.parser import parse
import pytest
@pytest.mark.parametrize("example", [
@pytest.mark.parametrize('example', [
"true", "true",
"false", "false",
"nil", "nil",
"foo", "foo",
'"this is a trivial string"', '"this is a trivial string"',
r'/this is a trivial pattern/', r"/this is a trivial pattern/",
"[]", "[]",
"[[]]", "[[]]",
"[[[]]]", "[[[]]]",

View file

@ -1,12 +1,12 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from .fixtures import * # noqa
import pytest import pytest
from shogoth.vm import * from shogoth.vm import *
from .fixtures import * # noqa
@pytest.mark.parametrize("stack,ret", [
@pytest.mark.parametrize('stack,ret', [
[[True], [False]], [[True], [False]],
[[True], [False]], [[True], [False]],
]) ])
@ -14,7 +14,7 @@ def test_not(vm, stack, ret):
assert vm.run([Opcode.CALLS(NOT)], stack = stack) == ret assert vm.run([Opcode.CALLS(NOT)], stack = stack) == ret
@pytest.mark.parametrize('stack,ret', [ @pytest.mark.parametrize("stack,ret", [
[[False, False], [False]], [[False, False], [False]],
[[True, False], [True]], [[True, False], [True]],
[[False, True], [True]], [[False, True], [True]],
@ -24,7 +24,7 @@ def test_or(vm, stack, ret):
assert vm.run([Opcode.CALLS(OR)], stack = stack) == ret assert vm.run([Opcode.CALLS(OR)], stack = stack) == ret
@pytest.mark.parametrize('stack,ret', [ @pytest.mark.parametrize("stack,ret", [
[[False, False], [False]], [[False, False], [False]],
[[True, False], [False]], [[True, False], [False]],
[[False, True], [False]], [[False, True], [False]],
@ -34,7 +34,7 @@ def test_and(vm, stack, ret):
assert vm.run([Opcode.CALLS(AND)], stack = stack) == ret assert vm.run([Opcode.CALLS(AND)], stack = stack) == ret
@pytest.mark.parametrize('stack,ret', [ @pytest.mark.parametrize("stack,ret", [
[[False, False], [False]], [[False, False], [False]],
[[True, False], [True]], [[True, False], [True]],
[[False, True], [True]], [[False, True], [True]],
@ -44,14 +44,14 @@ def test_xor(vm, stack, ret):
assert vm.run([Opcode.CALLS(XOR)], stack = stack) == ret assert vm.run([Opcode.CALLS(XOR)], stack = stack) == ret
@pytest.mark.parametrize('stack,ret', [ @pytest.mark.parametrize("stack,ret", [
[[], [FunctionRef.parse(NOT)]] [[], [FunctionRef.parse(NOT)]]
]) ])
def test_funref(vm, stack, ret): def test_funref(vm, stack, ret):
assert vm.run([Opcode.FUNREF(NOT), Opcode.RETURN(1)], stack = stack) == ret assert vm.run([Opcode.FUNREF(NOT), Opcode.RETURN(1)], stack = stack) == ret
@pytest.mark.parametrize('stack,ret', [ @pytest.mark.parametrize("stack,ret", [
[[], [True]] [[], [True]]
]) ])
def test_callf(vm, stack, ret): def test_callf(vm, stack, ret):

View file

@ -2,11 +2,11 @@
Tests coverign the VM interpreter Tests coverign the VM interpreter
""" """
from .fixtures import * # noqa
import pytest import pytest
from shogoth.vm import * from shogoth.vm import *
from .fixtures import * # noqa
def test_true(vm): def test_true(vm):
assert vm.run([Opcode.TRUE(), Opcode.RETURN(1)]) == [True] assert vm.run([Opcode.TRUE(), Opcode.RETURN(1)]) == [True]