sericite 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sericite/__init__.py +4 -0
- sericite/__main__.py +5 -0
- sericite/cli.py +54 -0
- sericite/compiler.py +689 -0
- sericite/engine.py +1497 -0
- sericite/errors.py +34 -0
- sericite/io.py +72 -0
- sericite/isa.py +57 -0
- sericite/vfs.py +78 -0
- sericite-0.2.0.dist-info/METADATA +129 -0
- sericite-0.2.0.dist-info/RECORD +15 -0
- sericite-0.2.0.dist-info/WHEEL +4 -0
- sericite-0.2.0.dist-info/entry_points.txt +2 -0
- sericite-0.2.0.dist-info/licenses/LICENSE +202 -0
- sericite-0.2.0.dist-info/licenses/NOTICE +4 -0
sericite/__init__.py
ADDED
sericite/__main__.py
ADDED
sericite/cli.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import sys
|
|
3
|
+
from collections.abc import Sequence
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from . import __version__
|
|
7
|
+
from .engine import SericiteEngine, SericiteError
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _read_stdin() -> str | None:
|
|
11
|
+
value = sys.stdin.readline()
|
|
12
|
+
return value if value else None
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def main(argv: Sequence[str] | None = None) -> int:
|
|
16
|
+
parser = argparse.ArgumentParser(
|
|
17
|
+
prog="sericite",
|
|
18
|
+
description="Sericite language runtime (Sericite-PY reference implementation)",
|
|
19
|
+
)
|
|
20
|
+
parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
|
|
21
|
+
parser.add_argument("source", help="Sericite source file")
|
|
22
|
+
args = parser.parse_args(argv)
|
|
23
|
+
try:
|
|
24
|
+
source = Path(args.source).read_text(encoding="utf-8")
|
|
25
|
+
except OSError as exc:
|
|
26
|
+
print(f"sericite: unable to read source: {exc.strerror or 'I/O error'}", file=sys.stderr)
|
|
27
|
+
return 1
|
|
28
|
+
|
|
29
|
+
engine = SericiteEngine()
|
|
30
|
+
try:
|
|
31
|
+
root = engine.create_root(source, input_provider=_read_stdin)
|
|
32
|
+
except SericiteError as exc:
|
|
33
|
+
print(exc, file=sys.stderr)
|
|
34
|
+
return 1
|
|
35
|
+
|
|
36
|
+
try:
|
|
37
|
+
root.run()
|
|
38
|
+
except SericiteError as exc:
|
|
39
|
+
sys.stdout.write(root.stdout())
|
|
40
|
+
print(exc, file=sys.stderr)
|
|
41
|
+
return 1
|
|
42
|
+
|
|
43
|
+
sys.stdout.write(root.stdout())
|
|
44
|
+
snapshot = root.snapshot()
|
|
45
|
+
if snapshot["state"] == "waiting_input":
|
|
46
|
+
error = SericiteError(
|
|
47
|
+
"input required",
|
|
48
|
+
kind="input_error",
|
|
49
|
+
filename="<sericite>",
|
|
50
|
+
line=snapshot["next_line"],
|
|
51
|
+
)
|
|
52
|
+
print(error, file=sys.stderr)
|
|
53
|
+
return 1
|
|
54
|
+
return 0
|