varphi-interpreter 2.0.0__tar.gz

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.
@@ -0,0 +1,11 @@
1
+ Metadata-Version: 2.3
2
+ Name: varphi-interpreter
3
+ Version: 2.0.0
4
+ Summary: An all-in-one tool for compiling and interpreting Varphi programs.
5
+ Author: Varphi
6
+ Author-email: Varphi <support@varphi-lang.com>
7
+ Requires-Dist: typer>=0.21.0
8
+ Requires-Dist: varphi-python-dap>=1.0.1
9
+ Requires-Python: >=3.13
10
+ Description-Content-Type: text/markdown
11
+
File without changes
@@ -0,0 +1,20 @@
1
+ [project]
2
+ name = "varphi-interpreter"
3
+ version = "2.0.0"
4
+ description = "An all-in-one tool for compiling and interpreting Varphi programs."
5
+ readme = "README.md"
6
+ authors = [
7
+ { name = "Varphi", email = "support@varphi-lang.com" }
8
+ ]
9
+ requires-python = ">=3.13"
10
+ dependencies = [
11
+ "typer>=0.21.0",
12
+ "varphi-python-dap>=1.0.1",
13
+ ]
14
+
15
+ [project.scripts]
16
+ vpi = "varphi_interpreter.cli:main"
17
+
18
+ [build-system]
19
+ requires = ["uv_build>=0.9.18,<0.10.0"]
20
+ build-backend = "uv_build"
@@ -0,0 +1,104 @@
1
+ import typer
2
+ from pathlib import Path
3
+
4
+ app = typer.Typer(add_completion=False)
5
+
6
+ @app.command(
7
+ context_settings={"allow_extra_args": True, "ignore_unknown_options": True},
8
+ help="Compile and execute a Varphi program."
9
+ )
10
+ def main_command(
11
+ ctx: typer.Context,
12
+ input_file: Path = typer.Argument(
13
+ ...,
14
+ exists=True,
15
+ file_okay=True,
16
+ dir_okay=False,
17
+ readable=True,
18
+ resolve_path=True,
19
+ help="Path to the .var source file"
20
+ ),
21
+ dap: bool = typer.Option(
22
+ False,
23
+ "--dap",
24
+ help="Run in Debug Adapter Protocol mode (for IDEs)."
25
+ ),
26
+ debug: bool = typer.Option(
27
+ False,
28
+ "--debug",
29
+ help="Enable verbose step-by-step logging (Standard mode only)."
30
+ ),
31
+ check: bool = typer.Option(
32
+ False,
33
+ "--check",
34
+ help="Compile only to verify syntax (does not execute)."
35
+ ),
36
+ ):
37
+ """
38
+ The Varphi Interpreter.
39
+
40
+ Compiles Varphi source code to Python in-memory and executes it immediately.
41
+ Any extra arguments passed after the filename are forwarded to the program
42
+ (e.g., used for setting initial tape values in DAP mode).
43
+ """
44
+ import sys
45
+ from varphi_python import VarphiToPythonCompiler
46
+ from varphi_python_dap import VarphiToPythonDAPCompiler
47
+ from varphi_devkit import VarphiSyntaxError
48
+
49
+ # Select the Compiler Backend
50
+ if dap:
51
+ compiler = VarphiToPythonDAPCompiler()
52
+ compiler.set_source_path(str(input_file))
53
+ if debug:
54
+ typer.echo("Warning: --debug flag is ignored in DAP mode.", err=True)
55
+ else:
56
+ compiler = VarphiToPythonCompiler()
57
+ if debug:
58
+ compiler.toggle_debug()
59
+
60
+ # Compile Source
61
+ try:
62
+ source_code = input_file.read_text(encoding="utf-8")
63
+ compiled_python_code = compiler.compile(source_code)
64
+
65
+ if check:
66
+ typer.echo("OK")
67
+ raise typer.Exit(code=0)
68
+
69
+ except VarphiSyntaxError as e:
70
+ typer.echo(f"Compilation Error: {e}", err=True)
71
+ raise typer.Exit(code=1)
72
+
73
+ # We construct a new argv.
74
+ # argv[0] should be the script name (we fake it as the input file).
75
+ # argv[1:] should be the extra arguments passed by the user (e.g., --tapes 101).
76
+ fake_argv = [str(input_file)] + ctx.args
77
+
78
+ # Global scope for the executed code.
79
+ execution_globals = {
80
+ "__name__": "__main__",
81
+ "__file__": str(input_file),
82
+ "__builtins__": __builtins__,
83
+ }
84
+
85
+ # Execute (Interpret)
86
+ # We create a safe context where sys.argv is temporarily swapped.
87
+ original_argv = sys.argv
88
+ try:
89
+ sys.argv = fake_argv
90
+ exec(compiled_python_code, execution_globals)
91
+ except SystemExit as e:
92
+ raise typer.Exit(code=e.code)
93
+ except Exception as e:
94
+ typer.echo(f"Runtime Error: {e}", err=True)
95
+ raise typer.Exit(code=1)
96
+ finally:
97
+ # Restore sys.argv
98
+ sys.argv = original_argv
99
+
100
+ def main():
101
+ app()
102
+
103
+ if __name__ == "__main__":
104
+ main()