Update manuals and other additions

This commit is contained in:
2026-06-09 12:45:33 -05:00
parent 051b12f28d
commit 78fb8d6d7c
101 changed files with 1629 additions and 401 deletions
+14 -14
View File
@@ -10,26 +10,26 @@ from src.cpp_transpiler import transpile_to_cpp
ROOT = Path(__file__).resolve().parent.parent
EXAMPLES = ROOT / "examples"
PROTEL = ROOT / "protel"
PROTEL = ROOT / "Pc"
def _transpile_hello() -> str:
source = (EXAMPLES / "Hello.protel").read_text(encoding="utf-8")
source = (EXAMPLES / "Hello.P").read_text(encoding="utf-8")
tree = parse_protel(source)
return transpile_to_cpp(tree, source_name="Hello.protel")
return transpile_to_cpp(tree, source_name="Hello.P")
def test_cpp_hello_emits_namespace_and_main():
cpp = _transpile_hello()
assert "namespace protel_generated" in cpp
assert "namespace Hello" in cpp
assert "IS ENTRY" in (EXAMPLES / "Hello.protel").read_text(encoding="utf-8")
assert "IS ENTRY" in (EXAMPLES / "Hello.P").read_text(encoding="utf-8")
assert "void Start()" in cpp
assert 'extern "C"' in cpp
assert "void writeln(const char* msg)" in cpp
assert "<iostream>" not in cpp
assert "IS INTRINSIC" not in (EXAMPLES / "Hello.protel").read_text(encoding="utf-8")
assert "EXTERNAL" in (EXAMPLES / "Hello.protel").read_text(encoding="utf-8")
assert "IS INTRINSIC" not in (EXAMPLES / "Hello.P").read_text(encoding="utf-8")
assert "EXTERNAL" in (EXAMPLES / "Hello.P").read_text(encoding="utf-8")
assert "int main()" in cpp
assert "protel_generated::Hello::Start()" in cpp
assert "(const char[]){" in cpp
@@ -38,8 +38,8 @@ def test_cpp_hello_emits_namespace_and_main():
def test_cpp_hello_class_uses_this():
source = (EXAMPLES / "ref_oo_class_with_var.protel").read_text(encoding="utf-8")
cpp = transpile_to_cpp(parse_protel(source), source_name="ref_oo_class_with_var.protel")
source = (EXAMPLES / "ref_oo_class_with_var.P").read_text(encoding="utf-8")
cpp = transpile_to_cpp(parse_protel(source), source_name="ref_oo_class_with_var.P")
assert "class class_with_var" in cpp
assert "static int16_t class_var" in cpp
assert "class_with_var::class_method" in cpp
@@ -53,7 +53,7 @@ def test_hello_compiles_and_runs():
[
str(ROOT / ".venv/bin/python"),
str(PROTEL),
str(EXAMPLES / "Hello.protel"),
str(EXAMPLES / "Hello.P"),
"-o",
str(ROOT / "build" / "Hello"),
"--run",
@@ -67,8 +67,8 @@ def test_hello_compiles_and_runs():
def test_hello_shebang_direct_execution():
hello = EXAMPLES / "Hello.protel"
assert hello.read_text(encoding="utf-8").startswith("#!/usr/bin/env protel-run")
hello = EXAMPLES / "Hello.P"
assert hello.read_text(encoding="utf-8").startswith("#!/usr/bin/env Pc!")
mode = hello.stat().st_mode
hello.chmod(mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
env = dict(os.environ)
@@ -86,7 +86,7 @@ def test_hello_shebang_direct_execution():
def test_hello_compiles_and_runs_a_out():
result = subprocess.run(
[str(ROOT / ".venv/bin/python"), str(PROTEL), "examples/Hello.protel", "--run"],
[str(ROOT / ".venv/bin/python"), str(PROTEL), "examples/Hello.P", "--run"],
capture_output=True,
text=True,
cwd=ROOT,
@@ -99,11 +99,11 @@ def test_hello_compiles_and_runs_a_out():
def test_cpp_oo_examples_compile():
from src.compile import check_cpp_syntax
for name in ("ref_oo_class_with_var.protel", "ref_oo_class_method_invoke.protel"):
for name in ("ref_oo_class_with_var.P", "ref_oo_class_method_invoke.P"):
source = EXAMPLES / name
tree = parse_protel(source.read_text(encoding="utf-8"))
cpp = transpile_to_cpp(tree, source_name=name)
cpp_path = ROOT / "build" / f"{name.replace('.protel', '.cpp')}"
cpp_path = ROOT / "build" / f"{name.replace('.P', '.cpp')}"
cpp_path.parent.mkdir(parents=True, exist_ok=True)
cpp_path.write_text(cpp, encoding="utf-8")
check_cpp_syntax(cpp_path)