micalang 0.1.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.
- mica/__init__.py +4 -0
- mica/__main__.py +5 -0
- mica/cli.py +54 -0
- mica/compiler.py +689 -0
- mica/engine.py +1497 -0
- mica/errors.py +34 -0
- mica/io.py +72 -0
- mica/isa.py +57 -0
- mica/vfs.py +78 -0
- micalang-0.1.0.dist-info/METADATA +123 -0
- micalang-0.1.0.dist-info/RECORD +15 -0
- micalang-0.1.0.dist-info/WHEEL +4 -0
- micalang-0.1.0.dist-info/entry_points.txt +2 -0
- micalang-0.1.0.dist-info/licenses/LICENSE +202 -0
- micalang-0.1.0.dist-info/licenses/NOTICE +4 -0
mica/__init__.py
ADDED
mica/__main__.py
ADDED
mica/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 MicaEngine, MicaError
|
|
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="micalang",
|
|
18
|
+
description="Mica language runtime (Mica-PY reference implementation)",
|
|
19
|
+
)
|
|
20
|
+
parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
|
|
21
|
+
parser.add_argument("source", help="Mica 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"mica: unable to read source: {exc.strerror or 'I/O error'}", file=sys.stderr)
|
|
27
|
+
return 1
|
|
28
|
+
|
|
29
|
+
engine = MicaEngine()
|
|
30
|
+
try:
|
|
31
|
+
root = engine.create_root(source, input_provider=_read_stdin)
|
|
32
|
+
except MicaError as exc:
|
|
33
|
+
print(exc, file=sys.stderr)
|
|
34
|
+
return 1
|
|
35
|
+
|
|
36
|
+
try:
|
|
37
|
+
root.run()
|
|
38
|
+
except MicaError 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 = MicaError(
|
|
47
|
+
"input required",
|
|
48
|
+
kind="input_error",
|
|
49
|
+
filename="<mica>",
|
|
50
|
+
line=snapshot["next_line"],
|
|
51
|
+
)
|
|
52
|
+
print(error, file=sys.stderr)
|
|
53
|
+
return 1
|
|
54
|
+
return 0
|