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
+6 -4
View File
@@ -36,7 +36,7 @@ You are an expert PROTEL language engineer and compiler developer assisting Vinc
- Keywords should be in UPPERCASE (and BOLD where appropriate). - Keywords should be in UPPERCASE (and BOLD where appropriate).
- Comprehensive error handling and diagnostics. - Comprehensive error handling and diagnostics.
- Unit tests for parser rules, transpilation edge cases, and legacy compatibility. - Unit tests for parser rules, transpilation edge cases, and legacy compatibility.
- PROTEL example files should use the .protel extension (legacy Nortel sources may use .P or PLS edition suffixes .AA01 through .ZZ99). - PROTEL example files should use the **.P** extension by default (historical Nortel/BNR suffix). The compiler does not require any particular extension — `.protel`, `.pt`, `.ptl`, PLS edition suffixes `.AA01` through `.ZZ99`, or any other name are accepted.
- Indentation should be structured like Pascal. - Indentation should be structured like Pascal.
- There should be no spaces between PROC and the first parenthesis - PROC( - There should be no spaces between PROC and the first parenthesis - PROC(
- There should be no spaces between TABLE and the first brace - TABLE[ - There should be no spaces between TABLE and the first brace - TABLE[
@@ -59,10 +59,12 @@ You are an expert PROTEL language engineer and compiler developer assisting Vinc
## Build & Test Commands ## Build & Test Commands
- Build: `make` or `cmake --build build/` - Build: `make` or `cmake --build build/`
- Local install: `make install` (checkout tree, `./man/man1/` manual pages)
- System install: `sudo make install-system` (default `SYSPREFIX=/usr/local/protel`, symlinks in `/usr/local/bin`, man pages in `/usr/local/share/man/man1/`)
- Test: Run full test suite (parser + transpiler validation) - Test: Run full test suite (parser + transpiler validation)
- Classical mode: `./protel --classical example.ptl` - Classical mode: `./Pc --classical example.ptl`
- Modern mode: `./protel example.ptl` - Modern mode: `./Pc example.ptl`
- Runnable sources: first line `#!/usr/bin/env protel-run`, `chmod +x`, project dir on `PATH` (`$PWD` or `$HOME/PROTEL`, not quoted `~/PROTEL`); preprocessor strips `#!` before parse (§7.0.5) - Runnable sources: first line `#!/usr/bin/env Pc!` (shebang helper **Pc!**, pronounced "P-C-Bang"), `chmod +x`, project dir on `PATH` (`$PWD` or `$HOME/PROTEL`, not quoted `~/PROTEL`); preprocessor strips `#!` before parse (§7.0.5)
- Generate a test suite of PROTEL code covering all features and examples code in PROTEL Introductory Manual 2026.pdf and PROTEL Reference Manual 2026.pdf. Label test code so it can be correlated to sections of the Introductory Manual and Reference Manual. - Generate a test suite of PROTEL code covering all features and examples code in PROTEL Introductory Manual 2026.pdf and PROTEL Reference Manual 2026.pdf. Label test code so it can be correlated to sections of the Introductory Manual and Reference Manual.
- Compiler and tool invocation should follow example in "PROTEL 2026 Development Tools" from the Introductory or Reference Manual. - Compiler and tool invocation should follow example in "PROTEL 2026 Development Tools" from the Introductory or Reference Manual.
+70 -16
View File
@@ -1,7 +1,17 @@
PYTHON ?= .venv/bin/python PYTHON ?= .venv/bin/python
PIP ?= .venv/bin/pip PIP ?= .venv/bin/pip
.PHONY: all venv install test examples hello beautify interop-swift interop-rust interop-python interop-java clean # System-wide install layout (FHS-oriented).
SYSPREFIX ?= /usr/local/protel
SYSBINDIR ?= /usr/local/bin
SYSMANPREFIX ?= /usr/local/share/man
DESTDIR ?=
# Local developer install (repository checkout).
LOCAL_MANPREFIX ?= $(CURDIR)/man
.PHONY: all venv install install-man install-system install-man-system uninstall-system \
test examples hello hello-pls beautify interop-swift interop-rust interop-python interop-java clean
all: venv test all: venv test
@@ -10,37 +20,81 @@ venv:
$(PIP) install -q -r requirements.txt $(PIP) install -q -r requirements.txt
$(PIP) install -q -r requirements-dev.txt $(PIP) install -q -r requirements-dev.txt
install: venv # --- Local (checkout) install -------------------------------------------------
chmod +x protel protel-run Pb examples/Hello.protel
@echo "PROTEL 2026 tools installed." install: venv install-man
@echo " Compile/run: ./protel examples/Hello.protel --run" chmod +x Pc Pc! Pb examples/Hello.P
@echo " Direct run: export PATH=\"$$(pwd):$$PATH\" && ./examples/Hello.protel" @echo "PROTEL 2026 tools installed (local checkout)."
@echo " Compile/run: ./Pc examples/Hello.P --run"
@echo " Direct run: export PATH=\"$$(pwd):$$PATH\" && ./examples/Hello.P"
@echo " (use \$$PWD or \$$HOME/PROTEL in PATH — quoted ~/PROTEL does not expand)" @echo " (use \$$PWD or \$$HOME/PROTEL in PATH — quoted ~/PROTEL does not expand)"
@echo " Manual pages: export MANPATH=\"$(LOCAL_MANPREFIX):$$MANPATH\" && man Pc"
@echo " System-wide: sudo make install-system"
install-man:
mkdir -p $(LOCAL_MANPREFIX)/man1
install -m 644 man/Pc.1 man/Pb.1 $(LOCAL_MANPREFIX)/man1/
@echo "Installed man pages to $(LOCAL_MANPREFIX)/man1 (Pc.1, Pb.1)"
# --- System-wide install (/usr/local/protel) ----------------------------------
install-system: install-man-system
@echo "Installing PROTEL 2026 to $(DESTDIR)$(SYSPREFIX) ..."
mkdir -p $(DESTDIR)$(SYSPREFIX)
install -m 755 Pc Pc! Pb $(DESTDIR)$(SYSPREFIX)/
install -m 644 requirements.txt $(DESTDIR)$(SYSPREFIX)/
cp -R src $(DESTDIR)$(SYSPREFIX)/
cp -R examples $(DESTDIR)$(SYSPREFIX)/
cp -R emacs $(DESTDIR)$(SYSPREFIX)/
chmod +x $(DESTDIR)$(SYSPREFIX)/examples/Hello.P
python3 -m venv $(DESTDIR)$(SYSPREFIX)/.venv
$(DESTDIR)$(SYSPREFIX)/.venv/bin/pip install -q \
-r $(DESTDIR)$(SYSPREFIX)/requirements.txt
mkdir -p $(DESTDIR)$(SYSBINDIR)
ln -sf $(SYSPREFIX)/Pc $(DESTDIR)$(SYSBINDIR)/Pc
ln -sf $(SYSPREFIX)/Pb $(DESTDIR)$(SYSBINDIR)/Pb
ln -sf $(SYSPREFIX)/Pc! $(DESTDIR)$(SYSBINDIR)/Pc!
@echo "PROTEL 2026 installed system-wide."
@echo " Toolkit root: $(SYSPREFIX)"
@echo " Commands: $(SYSBINDIR)/{Pc,Pb,Pc!}"
@echo " Manual pages: $(SYSMANPREFIX)/man1/{Pc,Pb}.1"
@echo " Try: Pc $(SYSPREFIX)/examples/Hello.P --run"
@echo " man Pc"
install-man-system:
mkdir -p $(DESTDIR)$(SYSMANPREFIX)/man1
install -m 644 man/Pc.1 man/Pb.1 $(DESTDIR)$(SYSMANPREFIX)/man1/
@echo "Installed man pages to $(DESTDIR)$(SYSMANPREFIX)/man1 (Pc.1, Pb.1)"
uninstall-system:
rm -f $(DESTDIR)$(SYSBINDIR)/Pc $(DESTDIR)$(SYSBINDIR)/Pb $(DESTDIR)$(SYSBINDIR)/Pc!
rm -f $(DESTDIR)$(SYSMANPREFIX)/man1/Pc.1 $(DESTDIR)$(SYSMANPREFIX)/man1/Pb.1
rm -rf $(DESTDIR)$(SYSPREFIX)
@echo "Removed PROTEL 2026 from $(SYSPREFIX), $(SYSBINDIR), and $(SYSMANPREFIX)/man1"
# --- Development targets ------------------------------------------------------
test: venv test: venv
$(PYTHON) -m pytest tests/ -v $(PYTHON) -m pytest tests/ -v
examples: venv examples: venv
@for f in examples/*.protel; do \ @for f in examples/*.P; do \
echo "=== $$f ==="; \ echo "=== $$f ==="; \
$(PYTHON) protel "$$f" --emit-c -o "build/$$(basename $$f .protel).c"; \ $(PYTHON) Pc "$$f" --emit-c -o "build/$$(basename $$f .P).c"; \
done done
hello: venv hello: venv
chmod +x examples/Hello.protel chmod +x examples/Hello.P
$(PYTHON) protel examples/Hello.protel -o build/Hello --run $(PYTHON) Pc examples/Hello.P -o build/Hello --run
hello-p: venv
$(PYTHON) protel examples/Hello.P -o build/Hello.P --run
hello-pls: venv hello-pls: venv
$(PYTHON) protel examples/Hello.aa01 -o build/Hello.aa01 --run $(PYTHON) Pc examples/Hello.aa01 -o build/Hello.aa01 --run
vdi: venv vdi: venv
$(PYTHON) protel vdi.aa01 -c -o build/vdi.aa01.o $(PYTHON) Pc vdi.aa01 -c -o build/vdi.aa01.o
beautify: venv beautify: venv
$(PYTHON) Pb examples/Hello.protel build/Hello.pretty.protel $(PYTHON) Pb examples/Hello.P build/Hello.pretty.P
interop-swift: venv interop-swift: venv
chmod +x examples/interop/build_interop.sh chmod +x examples/interop/build_interop.sh
+6 -6
View File
@@ -9,7 +9,7 @@ Reads PROTEL source from a file or standard input (supports redirection, pipes,
and explicit filename arguments for both input and output). and explicit filename arguments for both input and output).
A first-line UNIX shebang (``#!...``) is preserved unchanged for runnable A first-line UNIX shebang (``#!...``) is preserved unchanged for runnable
``.protel`` programs (see Introductory Manual section 7.0.5). ``.P`` programs (see Introductory Manual section 7.0.5).
Performs lexical analysis: Performs lexical analysis:
- Recognizes comments starting with % (to end of line). Keywords inside comments are ignored. - Recognizes comments starting with % (to end of line). Keywords inside comments are ignored.
@@ -31,12 +31,12 @@ Keyword list is derived directly from the Reference Manual (Appendix A) and
Introductory Manual + the original oflpr/oflpi sources. Introductory Manual + the original oflpr/oflpi sources.
Usage examples: Usage examples:
cat myprog.protel | Pb cat myprog.P | Pb
Pb --bold < myprog.protel > pretty.protel Pb --bold < myprog.P > pretty.P
./Pb --bold < example.txt ./Pb --bold < example.txt
Pb myprog.protel > pretty.protel Pb myprog.P > pretty.P
Pb myprog.protel pretty.protel Pb myprog.P pretty.P
Pb < myprog.protel | less Pb < myprog.P | less
Shebang makes it directly executable after chmod +x Pb Shebang makes it directly executable after chmod +x Pb
""" """
+25 -22
View File
@@ -1,5 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
"""PROTEL 2026 compiler driver (Introductory Manual 7.1).""" """Pc — PROTEL 2026 compiler (Introductory Manual 7.1)."""
from __future__ import annotations from __future__ import annotations
@@ -52,7 +52,7 @@ def _ensure_runtime() -> None:
_bootstrap_venv() _bootstrap_venv()
except Exception as exc: except Exception as exc:
print( print(
f"protel: failed to install dependencies in .venv: {exc}", f"Pc: failed to install dependencies in .venv: {exc}",
file=sys.stderr, file=sys.stderr,
) )
raise SystemExit(1) from exc raise SystemExit(1) from exc
@@ -60,8 +60,8 @@ def _ensure_runtime() -> None:
import lark # noqa: F401 import lark # noqa: F401
except ImportError as exc: except ImportError as exc:
print( print(
"protel: lark is still missing after setup; " "Pc: lark is still missing after setup; "
"run 'make install'", "run 'make install' or 'make install-system'",
file=sys.stderr, file=sys.stderr,
) )
raise SystemExit(1) from exc raise SystemExit(1) from exc
@@ -70,9 +70,9 @@ def _ensure_runtime() -> None:
try: try:
_bootstrap_venv() _bootstrap_venv()
except Exception as exc: except Exception as exc:
print(f"protel: failed to set up Python environment: {exc}", file=sys.stderr) print(f"Pc: failed to set up Python environment: {exc}", file=sys.stderr)
print( print(
"protel: run 'make install' or " "Pc: run 'make install' or 'sudo make install-system', or "
"'python3 -m venv .venv && .venv/bin/pip install -r requirements.txt'", "'python3 -m venv .venv && .venv/bin/pip install -r requirements.txt'",
file=sys.stderr, file=sys.stderr,
) )
@@ -96,7 +96,7 @@ from src.extensions import format_suffix_list, is_pls_suffix, is_protel_source
def _validate_input(path: Path) -> None: def _validate_input(path: Path) -> None:
if not is_protel_source(path): if not is_protel_source(path):
print( print(
f"protel: warning: '{path}' does not use a PROTEL extension " f"Pc: warning: '{path}' does not use a PROTEL extension "
f"({format_suffix_list()})", f"({format_suffix_list()})",
file=sys.stderr, file=sys.stderr,
) )
@@ -113,7 +113,7 @@ def _promote_shebang_input(
argv: list[str], program_args: list[str] argv: list[str], program_args: list[str]
) -> tuple[list[str], list[str]]: ) -> tuple[list[str], list[str]]:
""" """
Shebang form: protel --run -- script.protel [program args]. Shebang form: Pc --run -- script.P [program args].
The kernel places the script path after ``--``; promote it to the input The kernel places the script path after ``--``; promote it to the input
positional expected by the driver. positional expected by the driver.
@@ -138,7 +138,7 @@ def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="PROTEL 2026 compiler (GCC/clang++ backend)", description="PROTEL 2026 compiler (GCC/clang++ backend)",
epilog=( epilog=(
"Invoke: protel [-o outfile] sourcefile(s) [--classical]\n" "Invoke: Pc [-o outfile] sourcefile(s) [--classical]\n"
"GCC options -g and -c are passed through when compiling." "GCC options -g and -c are passed through when compiling."
), ),
formatter_class=argparse.RawDescriptionHelpFormatter, formatter_class=argparse.RawDescriptionHelpFormatter,
@@ -146,7 +146,10 @@ def main(argv: list[str] | None = None) -> int:
parser.add_argument( parser.add_argument(
"input", "input",
nargs="+", nargs="+",
help="PROTEL source file(s) (.protel, .pt, .ptl, .P, .AA01..ZZ99)", help=(
"PROTEL source file(s) — .P is the usual suffix; also .protel, .pt, "
".ptl, .AA01..ZZ99 (extension does not affect compilation)"
),
) )
parser.add_argument( parser.add_argument(
"-o", "-o",
@@ -193,12 +196,12 @@ def main(argv: list[str] | None = None) -> int:
action="store_true", action="store_true",
help="Keep generated C/C++ source after compiling", help="Keep generated C/C++ source after compiling",
) )
parser.add_argument("--version", action="version", version="protel 0.3.0") parser.add_argument("--version", action="version", version="Pc 0.3.0")
args = parser.parse_args(argv) args = parser.parse_args(argv)
if len(args.input) > 1: if len(args.input) > 1:
print("protel: warning: only the first source file is compiled", file=sys.stderr) print("Pc: warning: only the first source file is compiled", file=sys.stderr)
input_path = Path(args.input[0]).resolve() input_path = Path(args.input[0]).resolve()
_validate_input(input_path) _validate_input(input_path)
@@ -207,13 +210,13 @@ def main(argv: list[str] | None = None) -> int:
try: try:
source = input_path.read_text(encoding="utf-8", errors="replace") source = input_path.read_text(encoding="utf-8", errors="replace")
except OSError as exc: except OSError as exc:
print(f"protel: cannot read '{input_path}': {exc}", file=sys.stderr) print(f"Pc: cannot read '{input_path}': {exc}", file=sys.stderr)
return 1 return 1
try: try:
tree = parse_protel(source, classical=classical) tree = parse_protel(source, classical=classical)
except Exception as exc: except Exception as exc:
print(f"protel: parse error in '{input_path}': {exc}", file=sys.stderr) print(f"Pc: parse error in '{input_path}': {exc}", file=sys.stderr)
return 1 return 1
if args.parse_only: if args.parse_only:
@@ -242,15 +245,15 @@ def main(argv: list[str] | None = None) -> int:
) )
default_ext = ".cpp" default_ext = ".cpp"
except TypeCheckError as exc: except TypeCheckError as exc:
print(f"protel: type error in '{input_path}': {exc}", file=sys.stderr) print(f"Pc: type error in '{input_path}': {exc}", file=sys.stderr)
return 1 return 1
except Exception as exc: except Exception as exc:
print(f"protel: transpile error in '{input_path}': {exc}", file=sys.stderr) print(f"Pc: transpile error in '{input_path}': {exc}", file=sys.stderr)
return 1 return 1
if compile_requested: if compile_requested:
if args.emit_c: if args.emit_c:
print("protel: compile mode requires C++ output (omit --emit-c)", file=sys.stderr) print("Pc: compile mode requires C++ output (omit --emit-c)", file=sys.stderr)
return 1 return 1
build_dir = _ROOT / "build" build_dir = _ROOT / "build"
@@ -271,21 +274,21 @@ def main(argv: list[str] | None = None) -> int:
debug=args.g, debug=args.g,
) )
except RuntimeError as exc: except RuntimeError as exc:
print(f"protel: compile error: {exc}", file=sys.stderr) print(f"Pc: compile error: {exc}", file=sys.stderr)
return 1 return 1
if not args.keep: if not args.keep:
try: try:
gen_path.unlink() gen_path.unlink()
except OSError: except OSError:
pass pass
print(f"protel: wrote {obj_path}", file=sys.stderr) print(f"Pc: wrote {obj_path}", file=sys.stderr)
return 0 return 0
exe_path = Path(args.output) if args.output else Path("a.out") exe_path = Path(args.output) if args.output else Path("a.out")
try: try:
compile_cpp(gen_path, exe_path, debug=args.g) compile_cpp(gen_path, exe_path, debug=args.g)
except RuntimeError as exc: except RuntimeError as exc:
print(f"protel: compile error: {exc}", file=sys.stderr) print(f"Pc: compile error: {exc}", file=sys.stderr)
return 1 return 1
if not args.keep: if not args.keep:
@@ -302,14 +305,14 @@ def main(argv: list[str] | None = None) -> int:
sys.stderr.write(stderr) sys.stderr.write(stderr)
return code_rc return code_rc
print(f"protel: wrote {exe_path}", file=sys.stderr) print(f"Pc: wrote {exe_path}", file=sys.stderr)
return 0 return 0
if args.output: if args.output:
try: try:
Path(args.output).write_text(code, encoding="utf-8") Path(args.output).write_text(code, encoding="utf-8")
except OSError as exc: except OSError as exc:
print(f"protel: cannot write '{args.output}': {exc}", file=sys.stderr) print(f"Pc: cannot write '{args.output}': {exc}", file=sys.stderr)
return 1 return 1
else: else:
sys.stdout.write(code) sys.stdout.write(code)
Executable
+40
View File
@@ -0,0 +1,40 @@
#!/usr/bin/env python3
"""Run a PROTEL source file invoked via shebang (Introductory Manual §7.0.5).
Pc! — pronounced "P c Bang" — is the shebang helper and command-line shortcut
for running .P programs. The kernel executes: Pc! /path/to/script.P [args]
"""
from __future__ import annotations
import os
import sys
from pathlib import Path
_ROOT = Path(__file__).resolve().parent
_PC = _ROOT / "Pc"
def main() -> int:
if len(sys.argv) < 2:
print(
"Pc!: missing PROTEL source path "
"(use #!/usr/bin/env Pc! in a .P file)",
file=sys.stderr,
)
return 2
source = Path(sys.argv[1]).resolve()
program_args = sys.argv[2:]
if not _PC.is_file():
print(f"Pc!: cannot find Pc driver at '{_PC}'", file=sys.stderr)
return 1
argv = [str(_PC), str(source), "--run", "--", *program_args]
os.execv(str(_PC), argv)
return 1
if __name__ == "__main__":
raise SystemExit(main())
+4 -4
View File
@@ -48,14 +48,14 @@ int main(int argc, char** argv) {
When the ENTRY body does not **RETURNS integer**, the wrapper calls the procedure and returns `0`. When the ENTRY body does not **RETURNS integer**, the wrapper calls the procedure and returns `0`.
### Example: `examples/intro_5_5_2_args_exit.protel` ### Example: `examples/intro_5_5_2_args_exit.P`
This module prints each command-line argument (including the program name) and **RETURN**s `argc` as the exit status. This module prints each command-line argument (including the program name) and **RETURN**s `argc` as the exit status.
Build and run: Build and run:
```bash ```bash
./protel examples/intro_5_5_2_args_exit.protel -o build/ArgsExit --run -- one two ./Pc examples/intro_5_5_2_args_exit.P -o build/ArgsExit --run -- one two
echo $? echo $?
``` ```
@@ -77,6 +77,6 @@ Command-line demonstration uses **EXTERNAL** C linkage to the minimal POSIX runt
### See also ### See also
- §7.0 — **PROTEL 2026 Development Tools** (`protel` driver, `--run`) - §7.0 — **PROTEL 2026 Development Tools** (`Pc` compiler, `--run`)
- §7.0.5 — **Runnable `.protel` files (shebang)** — direct execution with `#!/usr/bin/env protel-run` - §7.0.5 — **Runnable `.P` files (shebang)** — direct execution with `#!/usr/bin/env Pc!`
- Reference Manual §13 — **EXPORT** / **EXTERNAL** (ENTRY vs library procedures) - Reference Manual §13 — **EXPORT** / **EXTERNAL** (ENTRY vs library procedures)
+91 -31
View File
@@ -10,9 +10,55 @@ The PROTEL 2026 toolchain ships with a small set of command-line and editor tool
| Tool | Section | Summary | | Tool | Section | Summary |
|------|---------|---------| |------|---------|---------|
| **`protel`** | §7.1 | Parser, transpiler, and compiler driver | | **`Pc`** | §7.1 | **PROTEL compiler** — parser, transpiler, and GCC/clang++ driver |
| **`Pc!`** | §7.0.5 | **Shebang runner** — pronounced *"P c Bang"*; runs `.P` files from `#!` lines or the shell |
| **`Pb`** | §7.0.1 | Source beautifier (keyword uppercasing) | | **`Pb`** | §7.0.1 | Source beautifier (keyword uppercasing) |
| **`protel-mode`** | §7.2 | GNU Emacs major mode for `.protel`, `.pt`, `.ptl`, legacy `.P`, and PLS `.AA01`–`.ZZ99` files | | **`protel-mode`** | §7.2 | GNU Emacs major mode for `.P`, `.protel`, `.pt`, `.ptl`, and PLS `.AA01`–`.ZZ99` files |
---
## 7.0.0 Source file extensions
**`.P`** is the default suffix for PROTEL 2026 sources (historical Nortel/BNR convention). The **`Pc`** compiler and parser **do not require** any particular extension — you may name a module `myprog.P`, `myprog.protel`, `myprog.pt`, or even `myprog.txt` if you wish.
Recognized suffixes (`.P`, `.protel`, `.pt`, `.ptl`, and PLS `.AA01`–`.ZZ99`) enable Emacs **`protel-mode`** auto-detection and suppress the optional extension warning from **`Pc`**. Unrecognized suffixes still compile when the file contains valid PROTEL source.
---
## 7.0.0.1 System-wide installation
For a host-wide install (macOS or UNIX/Linux), use **`make install-system`**. The default layout is:
| Path | Contents |
|------|----------|
| **`/usr/local/protel/`** | Toolkit root — `Pc`, `Pc!`, `Pb`, `src/`, `examples/`, `emacs/`, `.venv/` |
| **`/usr/local/bin/`** | Symlinks to `Pc`, `Pb`, and `Pc!` in the toolkit root |
| **`/usr/local/share/man/man1/`** | Manual pages `Pc.1` and `Pb.1` |
```bash
sudo make install-system
Pc /usr/local/protel/examples/Hello.P --run
man Pc
```
`/usr/local/bin` is normally already on **`PATH`**, so shebang lines (`#!/usr/bin/env Pc!`) work without extra setup once **`Pc!`** is on the path.
Override locations for packaging or non-default prefixes:
```bash
sudo make install-system SYSPREFIX=/opt/protel SYSBINDIR=/opt/bin
sudo make install-system DESTDIR=/tmp/stage SYSPREFIX=/usr/local/protel
```
Remove a system install:
```bash
sudo make uninstall-system
```
### Local (checkout) installation
From a source tree, **`make install`** prepares the repository for development: marks tools executable, creates a local **`.venv`**, and installs manual pages under **`./man/man1/`** (set **`MANPATH=$PWD/man:$MANPATH`** to read them).
--- ---
@@ -21,11 +67,11 @@ The PROTEL 2026 toolchain ships with a small set of command-line and editor tool
`Pb` uppercases PROTEL reserved keywords for readable, manual-style source. It is a filter-style tool: `Pb` uppercases PROTEL reserved keywords for readable, manual-style source. It is a filter-style tool:
```bash ```bash
Pb examples/Hello.protel build/Hello.pretty.protel Pb examples/Hello.P build/Hello.pretty.P
Pb --bold < myprog.protel > myprog.pretty.protel Pb --bold < myprog.P > myprog.pretty.P
``` ```
Install with `make install` (marks `Pb` executable). See `Pb --help` for options. Install with `make install` (checkout) or `sudo make install-system` (host-wide). See `Pb --help` and `man Pb`.
In Emacs, run Pb on the current buffer with **`C-c C-f`** (`M-x protel-beautify`) — see Introductory Manual §7.2. In Emacs, run Pb on the current buffer with **`C-c C-f`** (`M-x protel-beautify`) — see Introductory Manual §7.2.
@@ -33,10 +79,10 @@ In Emacs, run Pb on the current buffer with **`C-c C-f`** (`M-x protel-beautify`
## 7.0.2 PLS edition modules (`.AA01` … `.ZZ99`) ## 7.0.2 PLS edition modules (`.AA01` … `.ZZ99`)
Historical DMS/PLS modules use edition suffixes such as `vdi.aa01`. The `protel` driver **automatically enables classical preprocessing** for these names (keyword normalization, `$LI` / `$EJECT` linker directives stripped before parse). Historical DMS/PLS modules use edition suffixes such as `vdi.aa01`. The `Pc` compiler **automatically enables classical preprocessing** for these names (keyword normalization, `$LI` / `$EJECT` linker directives stripped before parse).
```bash ```bash
protel vdi.aa01 -c -o build/vdi.aa01.o Pc vdi.aa01 -c -o build/vdi.aa01.o
make vdi make vdi
``` ```
@@ -47,75 +93,89 @@ make vdi
The transpiler performs **strong typing** checks (Reference Manual §11.3). Invalid assignments — such as storing an **integer** into **char** or a **PACK** byte — are rejected before code generation. See `docs/reference-error-messages.md` and `examples/errors/`. The transpiler performs **strong typing** checks (Reference Manual §11.3). Invalid assignments — such as storing an **integer** into **char** or a **PACK** byte — are rejected before code generation. See `docs/reference-error-messages.md` and `examples/errors/`.
```bash ```bash
./protel examples/errors/err_assign_integer_to_char.protel ./Pc examples/errors/err_assign_integer_to_char.P
./protel examples/errors/ok_assign_char_literal.protel -o build/ok_char ./Pc examples/errors/ok_assign_char_literal.P -o build/ok_char
``` ```
--- ---
## 7.0.4 UNIX command line and exit status ## 7.0.4 UNIX command line and exit status
Standalone programs may read **`argc`** and **`argv`** in the **IS ENTRY** procedure and **RETURN** an integer exit status to the shell. See Introductory Manual §5.5.2 (`docs/intro-5-5-2-entry-args-exit.md`) and `examples/intro_5_5_2_args_exit.protel`. Standalone programs may read **`argc`** and **`argv`** in the **IS ENTRY** procedure and **RETURN** an integer exit status to the shell. See Introductory Manual §5.5.2 (`docs/intro-5-5-2-entry-args-exit.md`) and `examples/intro_5_5_2_args_exit.P`.
```bash ```bash
./protel examples/intro_5_5_2_args_exit.protel -o build/ArgsExit --run -- one two ./Pc examples/intro_5_5_2_args_exit.P -o build/ArgsExit --run -- one two
echo $? echo $?
``` ```
--- ---
## 7.0.5 Runnable `.protel` files (shebang) ## 7.0.5 Runnable `.P` files (shebang)
A PROTEL source file may be executed directly from the shell when: A PROTEL source file may be executed directly from the shell when:
1. **Line 1** is a UNIX shebang (`#!...`) naming **`protel-run`** (or `protel --run` via `env -S`). 1. **Line 1** is a UNIX shebang (`#!...`) naming **`Pc!`** (or `Pc --run` via `env -S`).
2. The file is **executable** (`chmod +x`). 2. The file is **executable** (`chmod +x`).
3. The PROTEL project directory is on your **`PATH`** so `protel-run` (or `protel`) is found. 3. **`Pc!`** (or `Pc`) is on your **`PATH`** — automatic after **`make install-system`** (`/usr/local/bin`); for a checkout, add the project directory to **`PATH`**.
The shebang is **not** PROTEL syntax. The preprocessor removes it before parse; **`Pb`** preserves it unchanged when beautifying. The shebang is **not** PROTEL syntax. The preprocessor removes it before parse; **`Pb`** preserves it unchanged when beautifying.
`examples/Hello.protel` demonstrates the usual form: `examples/Hello.P` demonstrates the usual form:
```protel ```protel
#!/usr/bin/env protel-run #!/usr/bin/env Pc!
% Hello World — run with: ./Hello.protel % Hello World — run with: ./Hello.P
SECTION Hello; SECTION Hello;
... ...
``` ```
**`protel-run`** is a small helper in the project root. The kernel runs `protel-run /path/to/script.protel [args]`; the helper invokes `protel script.protel --run -- [args]`. **`Pc!`** (pronounced *"P c Bang"*) is a small helper in the project root. The exclamation mark echoes the **`#!`** *shebang* convention and doubles as a memorable command-line shortcut for running PROTEL programs. The kernel runs `Pc! /path/to/script.P [args]`; the helper invokes `Pc script.P --run -- [args]`.
You can also invoke **`Pc!`** directly from the shell (with the project directory on **`PATH`**):
```bash
Pc! examples/Hello.P
Pc! examples/intro_5_5_2_args_exit.P one two
```
### Setup ### Setup
From the PROTEL project directory: **System-wide** (after `sudo make install-system`):
```bash
Pc! /usr/local/protel/examples/Hello.P
/usr/local/protel/examples/Hello.P # if executable
```
**From a source checkout**:
```bash ```bash
make install make install
export PATH="$PWD:$PATH" export PATH="$PWD:$PATH"
./examples/Hello.protel ./examples/Hello.P
``` ```
From any directory (replace with your checkout path): From any directory (replace with your checkout path):
```bash ```bash
export PATH="$HOME/PROTEL:$PATH" export PATH="$HOME/PROTEL:$PATH"
~/PROTEL/examples/Hello.protel ~/PROTEL/examples/Hello.P
``` ```
`make install` marks `protel`, `protel-run`, `Pb`, and `examples/Hello.protel` executable. `make install` marks `Pc`, `Pc!`, `Pb`, and `examples/Hello.P` executable in the tree. `make install-system` installs the same tools under **`/usr/local/protel`** with symlinks in **`/usr/local/bin`**.
**PATH pitfall:** `export PATH="~/PROTEL:$PATH"` does **not** work — the shell does not expand `~` inside double quotes, so `env` cannot find `protel-run`. Use **`$PWD`**, **`$HOME/PROTEL`**, or an absolute path instead. **PATH pitfall:** `export PATH="~/PROTEL:$PATH"` does **not** work — the shell does not expand `~` inside double quotes, so `env` cannot find **`Pc!`**. Use **`$PWD`**, **`$HOME/PROTEL`**, or an absolute path instead.
### ENTRY programs with arguments ### ENTRY programs with arguments
Add the same shebang to programs such as `examples/intro_5_5_2_args_exit.protel`, then: Add the same shebang to programs such as `examples/intro_5_5_2_args_exit.P`, then:
```bash ```bash
chmod +x examples/intro_5_5_2_args_exit.protel chmod +x examples/intro_5_5_2_args_exit.P
./examples/intro_5_5_2_args_exit.protel one two ./examples/intro_5_5_2_args_exit.P one two
``` ```
The kernel invokes `protel --run -- script.protel one two`. The driver promotes the script path from after **`--`** to the input positional, then forwards **`one`** and **`two`** to the ENTRY procedure. The kernel invokes `Pc --run -- script.P one two`. The driver promotes the script path from after **`--`** to the input positional, then forwards **`one`** and **`two`** to the ENTRY procedure.
### Notes ### Notes
@@ -125,8 +185,8 @@ The kernel invokes `protel --run -- script.protel one two`. The driver promotes
| **`Pb`** | Copies line 1 unchanged when it begins with `#!` | | **`Pb`** | Copies line 1 unchanged when it begins with `#!` |
| **`protel-mode`** | Displays the shebang line with `protel-comment-face` (§7.2) | | **`protel-mode`** | Displays the shebang line with `protel-comment-face` (§7.2) |
| **Parser** | `strip_shebang()` in `src/preprocess.py` runs before keyword normalization | | **Parser** | `strip_shebang()` in `src/preprocess.py` runs before keyword normalization |
| **Output binary** | Default `a.out` in the current working directory (same as `protel … --run`) | | **Output binary** | Default `a.out` in the current working directory (same as `Pc … --run`) |
| `env: protel: No such file or directory` | **`PATH` wrong** — avoid quoted `~/PROTEL`; use `export PATH="$PWD:$PATH"` from the repo or `export PATH="$HOME/PROTEL:$PATH"` | | `env: Pc!: No such file or directory` | **`PATH` wrong** — avoid quoted `~/PROTEL`; use `export PATH="$PWD:$PATH"` from the repo or `export PATH="$HOME/PROTEL:$PATH"` |
--- ---
@@ -134,6 +194,6 @@ The kernel invokes `protel --run -- script.protel one two`. The driver promotes
- §11.3 — **Type errors** (`docs/reference-error-messages.md`) - §11.3 — **Type errors** (`docs/reference-error-messages.md`)
- §5.5.2 — **UNIX argc/argv and shell exit status** - §5.5.2 — **UNIX argc/argv and shell exit status**
- §7.0.5 — **Runnable `.protel` files (shebang)** - §7.0.5 — **Runnable `.P` files (shebang)**
- §7.2 — **EMACS PROTEL mode** (`.emacs` setup; automatic `.protel`, `.P`, and PLS suffix detection) - §7.2 — **EMACS PROTEL mode** (`.emacs` setup; automatic `.P`, `.protel`, and PLS suffix detection)
- §7.3 — Foreign language interoperability - §7.3 — Foreign language interoperability
+8 -8
View File
@@ -33,7 +33,7 @@ Edit the copy once and set your checkout path (required when the file is not ins
(setq protel-user-root "/path/to/PROTEL") (setq protel-user-root "/path/to/PROTEL")
``` ```
The project `.emacs` also searches, in order: `PROTEL_ROOT` environment variable, the directory containing this init file (if it still lives inside PROTEL), the `protel` executable on your `PATH`, then `~/PROTEL`. The project `.emacs` also searches, in order: `PROTEL_ROOT` environment variable, the directory containing this init file (if it still lives inside PROTEL), the `Pc` executable on your `PATH` (including `/usr/local/bin` after `make install-system`), then `~/PROTEL` and `/usr/local/protel`.
**Option B — load from the project directory** **Option B — load from the project directory**
@@ -48,10 +48,10 @@ After Emacs loads this block, `protel-mode` is available and **file-name detecti
| Extension | Mode started | | Extension | Mode started |
|-----------|--------------| |-----------|--------------|
| `.P` | `protel-mode` (default PROTEL 2026 suffix; historical Nortel/BNR) |
| `.protel` | `protel-mode` | | `.protel` | `protel-mode` |
| `.pt` | `protel-mode` | | `.pt` | `protel-mode` |
| `.ptl` | `protel-mode` | | `.ptl` | `protel-mode` |
| `.P` | `protel-mode` (legacy Nortel/BNR suffix; case-sensitive match) |
| `.AA01` … `.ZZ99` | `protel-mode` (PLS edition suffix: two letters + two digits) | | `.AA01` … `.ZZ99` | `protel-mode` (PLS edition suffix: two letters + two digits) |
The PLS pattern matches any extension of the form **`.LLNN`** where `L` is a letter (`A`–`Z` or `a`–`z`) and `N` is a decimal digit. Examples: `vdi.aa01`, `module.AB18`, `Hello.aa01`. The PLS pattern matches any extension of the form **`.LLNN`** where `L` is a letter (`A`–`Z` or `a`–`z`) and `N` is a decimal digit. Examples: `vdi.aa01`, `module.AB18`, `Hello.aa01`.
@@ -79,7 +79,7 @@ Then in `.emacs`:
## 7.2.2 Verifying automatic detection ## 7.2.2 Verifying automatic detection
1. Restart Emacs (or evaluate the `.emacs` block with `M-x eval-buffer`). 1. Restart Emacs (or evaluate the `.emacs` block with `M-x eval-buffer`).
2. Open a PROTEL source file, for example `examples/Hello.protel`, legacy `examples/Hello.P`, or PLS `examples/Hello.aa01`. 2. Open a PROTEL source file, for example `examples/Hello.P` or PLS `examples/Hello.aa01`.
3. Confirm the mode line shows **`PROTEL`** (not `Fundamental`). 3. Confirm the mode line shows **`PROTEL`** (not `Fundamental`).
4. Alternatively, run `M-x describe-mode` — it should report `protel-mode`. 4. Alternatively, run `M-x describe-mode` — it should report `protel-mode`.
@@ -191,13 +191,13 @@ Example:
From the PROTEL project directory: From the PROTEL project directory:
```bash ```bash
emacs -nw -l .emacs examples/Hello.protel emacs -nw -l .emacs examples/Hello.P
``` ```
On Linux with a separate nox build: On Linux with a separate nox build:
```bash ```bash
emacs-nox -l /path/to/PROTEL/.emacs /path/to/PROTEL/examples/Hello.protel emacs-nox -l /path/to/PROTEL/.emacs /path/to/PROTEL/examples/Hello.P
``` ```
Ensure **Font Lock** is on (`M-x font-lock-mode` or `(global-font-lock-mode 1)` in `.emacs`, already set in the project file). If keywords are not bold, verify your terminal profile allows bold text (Terminal.app: Settings → Profiles → Text → “Use bold fonts”). Ensure **Font Lock** is on (`M-x font-lock-mode` or `(global-font-lock-mode 1)` in `.emacs`, already set in the project file). If keywords are not bold, verify your terminal profile allows bold text (Terminal.app: Settings → Profiles → Text → “Use bold fonts”).
@@ -215,7 +215,7 @@ Ensure **Font Lock** is on (`M-x font-lock-mode` or `(global-font-lock-mode 1)`
| Tool | Manual section | Purpose | | Tool | Manual section | Purpose |
|------|----------------|---------| |------|----------------|---------|
| `protel` | §7.1 | Transpile and compile PROTEL sources | | `Pc` | §7.1 | Transpile and compile PROTEL sources |
| `Pb` | §7.0 | Beautify / uppercase keywords | | `Pb` | §7.0 | Beautify / uppercase keywords |
| `protel-mode` | §7.2 (this section) | Emacs editing support | | `protel-mode` | §7.2 (this section) | Emacs editing support |
@@ -228,9 +228,9 @@ For foreign-language linking from PROTEL, see §7.3.
| Symptom | Likely cause | Remedy | | Symptom | Likely cause | Remedy |
|---------|--------------|--------| |---------|--------------|--------|
| `Cannot open load file: protel-mode` | `load-path` does not include `emacs/` | In `~/.emacs`, set `(setq protel-user-root "/path/to/PROTEL")` | | `Cannot open load file: protel-mode` | `load-path` does not include `emacs/` | In `~/.emacs`, set `(setq protel-user-root "/path/to/PROTEL")` |
| `PROTEL mode not loaded` warning at startup | Copied `~/.emacs` without checkout path | Set `protel-user-root` in `~/.emacs`, or add PROTEL `protel` to `PATH` | | `PROTEL mode not loaded` warning at startup | Copied `~/.emacs` without checkout path | Set `protel-user-root` in `~/.emacs`, or add PROTEL `Pc` to `PATH` |
| `Cannot find Pb` on beautify | Pb not on PATH | Set `protel-root` or `protel-beautify-command` after mode loads | | `Cannot find Pb` on beautify | Pb not on PATH | Set `protel-root` or `protel-beautify-command` after mode loads |
| Buffer stays in `Fundamental` mode | `protel-mode` not loaded, or wrong extension | Add `(require 'protel-mode)`; use `.protel`, `.P`, `.AA01`-style PLS suffix, or `M-x protel-mode` | | Buffer stays in `Fundamental` mode | `protel-mode` not loaded, or wrong extension | Add `(require 'protel-mode)`; use `.P`, `.protel`, `.AA01`-style PLS suffix, or `M-x protel-mode` |
| No keyword highlighting | Font-lock not enabled | `M-x font-lock-mode` (normally on by default) | | No keyword highlighting | Font-lock not enabled | `M-x font-lock-mode` (normally on by default) |
| `Cannot open load file: cc-mode` | Incomplete Emacs install | Use a full GNU Emacs build, not a minimal editor | | `Cannot open load file: cc-mode` | Incomplete Emacs install | Use a full GNU Emacs build, not a minimal editor |
| No bold in Terminal | Terminal profile disables bold | Enable bold fonts in Terminal.app / iTerm; `protel-keyword-face` uses `:weight bold` | | No bold in Terminal | Terminal profile disables bold | Enable bold fonts in Terminal.app / iTerm; `protel-keyword-face` uses `:weight bold` |
+14 -14
View File
@@ -101,7 +101,7 @@ DCL Start PROC() IS
### Step 4 — Build and link ### Step 4 — Build and link
```bash ```bash
protel myprog.protel --keep -o build/myprog.cpp Pc myprog.P --keep -o build/myprog.cpp
clang++ -std=c++20 -c build/myprog.cpp -o build/myprog.o clang++ -std=c++20 -c build/myprog.cpp -o build/myprog.o
rustc --crate-type staticlib rust_greet.rs -o build/librust_greet.a rustc --crate-type staticlib rust_greet.rs -o build/librust_greet.a
clang++ build/myprog.o build/librust_greet.a src/runtime/protel_io.c -o myprog clang++ build/myprog.o build/librust_greet.a src/runtime/protel_io.c -o myprog
@@ -185,7 +185,7 @@ Compile the EXPORT module and a thin **JNI** bridge into `libjavacallsprotel.dyl
### Step 4 — Link ### Step 4 — Link
```bash ```bash
protel protel_for_rust.protel --keep -o build/protel_for_rust.cpp Pc protel_for_rust.P --keep -o build/protel_for_rust.cpp
clang++ -std=c++20 -c build/protel_for_rust.cpp -o build/protel_for_rust.o clang++ -std=c++20 -c build/protel_for_rust.cpp -o build/protel_for_rust.o
rustc rust_calls_protel.rs build/protel_for_rust.o -o rust_calls_protel rustc rust_calls_protel.rs build/protel_for_rust.o -o rust_calls_protel
``` ```
@@ -193,7 +193,7 @@ rustc rust_calls_protel.rs build/protel_for_rust.o -o rust_calls_protel
**Python** (shared library + ctypes): **Python** (shared library + ctypes):
```bash ```bash
protel protel_for_python.protel --keep -o build/protel_for_python.cpp Pc protel_for_python.P --keep -o build/protel_for_python.cpp
clang++ -std=c++20 -fPIC -c build/protel_for_python.cpp -o build/protel_for_python.o clang++ -std=c++20 -fPIC -c build/protel_for_python.cpp -o build/protel_for_python.o
clang++ -shared -o build/libprotel_for_python.so build/protel_for_python.o clang++ -shared -o build/libprotel_for_python.so build/protel_for_python.o
python3 examples/interop/python_calls_protel.py python3 examples/interop/python_calls_protel.py
@@ -202,7 +202,7 @@ python3 examples/interop/python_calls_protel.py
**Java** (shared library + JNI): **Java** (shared library + JNI):
```bash ```bash
protel protel_for_java.protel --keep -o build/protel_for_java.cpp Pc protel_for_java.P --keep -o build/protel_for_java.cpp
clang++ -std=c++20 -fPIC -c build/protel_for_java.cpp -o build/protel_for_java.o clang++ -std=c++20 -fPIC -c build/protel_for_java.cpp -o build/protel_for_java.o
clang -fPIC -c java_calls_protel.c -o build/java_calls_protel.o -I$JAVA_HOME/include clang -fPIC -c java_calls_protel.c -o build/java_calls_protel.o -I$JAVA_HOME/include
clang++ -shared -o build/libjavacallsprotel.so build/protel_for_java.o build/java_calls_protel.o clang++ -shared -o build/libjavacallsprotel.so build/protel_for_java.o build/java_calls_protel.o
@@ -215,7 +215,7 @@ java -Djava.library.path=build/interop -cp build/interop JavaCallsProtel
### PROTEL calls Rust ### PROTEL calls Rust
File: `examples/interop/protel_calls_rust.protel` File: `examples/interop/protel_calls_rust.P`
``` ```
SECTION protel_calls_rust; SECTION protel_calls_rust;
@@ -237,7 +237,7 @@ DCL Start PROC() IS
### PROTEL calls Python ### PROTEL calls Python
File: `examples/interop/protel_calls_python.protel` File: `examples/interop/protel_calls_python.P`
``` ```
SECTION protel_calls_python; SECTION protel_calls_python;
@@ -259,7 +259,7 @@ DCL Start PROC() IS
### Rust calls PROTEL ### Rust calls PROTEL
File: `examples/interop/protel_for_rust.protel` (same EXPORT library as Swift example) File: `examples/interop/protel_for_rust.P` (same EXPORT library as Swift example)
``` ```
INTERFACE protel_math; INTERFACE protel_math;
@@ -276,7 +276,7 @@ DCL protel_add PROC(a integer, b integer) RETURNS integer IS
### PROTEL calls Java ### PROTEL calls Java
File: `examples/interop/protel_calls_java.protel` File: `examples/interop/protel_calls_java.P`
``` ```
SECTION protel_calls_java; SECTION protel_calls_java;
@@ -298,11 +298,11 @@ DCL Start PROC() IS
### Python calls PROTEL ### Python calls PROTEL
File: `examples/interop/python_calls_protel.py` loads `protel_for_python.protel` as a shared library via **ctypes**. File: `examples/interop/python_calls_protel.py` loads `protel_for_python.P` as a shared library via **ctypes**.
### Java calls PROTEL ### Java calls PROTEL
File: `examples/interop/JavaCallsProtel.java` loads `protel_for_java.protel` via **JNI** (`java_calls_protel.c` bridge). File: `examples/interop/JavaCallsProtel.java` loads `protel_for_java.P` via **JNI** (`java_calls_protel.c` bridge).
--- ---
@@ -320,14 +320,14 @@ A single module may have **one ENTRY** and **many EXPORT** procedures.
| Task | PROTEL | Build driver | | Task | PROTEL | Build driver |
|------|--------|--------------| |------|--------|--------------|
| Hello World (PROTEL only) | `protel Hello.protel --run` | `protel` + `clang++` | | Hello World (PROTEL only) | `Pc Hello.P --run` | `Pc` + `clang++` |
| Hello World (direct shebang) | `./examples/Hello.protel` | §7.0.5 — `export PATH="$PWD:$PATH"`, file executable | | Hello World (direct shebang) | `./examples/Hello.P` | §7.0.5 — `export PATH="$PWD:$PATH"`, file executable |
| PROTEL + Swift | `make interop-swift` | `examples/interop/build_interop.sh` | | PROTEL + Swift | `make interop-swift` | `examples/interop/build_interop.sh` |
| PROTEL + Rust | `make interop-rust` | `examples/interop/build_interop_rust.sh` | | PROTEL + Rust | `make interop-rust` | `examples/interop/build_interop_rust.sh` |
| PROTEL + Python | `make interop-python` | `examples/interop/build_interop_python.sh` | | PROTEL + Python | `make interop-python` | `examples/interop/build_interop_python.sh` |
| PROTEL + Java | `make interop-java` | `examples/interop/build_interop_java.sh` | | PROTEL + Java | `make interop-java` | `examples/interop/build_interop_java.sh` |
| Edit `.protel` / `.P` / PLS `.AA01` in Emacs | Add `emacs/` to `load-path`, `(require 'protel-mode)` | See §7.2 | | Edit `.P` / `.P` / PLS `.AA01` in Emacs | Add `emacs/` to `load-path`, `(require 'protel-mode)` | See §7.2 |
| Beautify source | `Pb file.protel` | `Pb` | | Beautify source | `Pb file.P` | `Pb` |
--- ---
+1 -1
View File
@@ -145,7 +145,7 @@ extern "C" {
## Linking ## Linking
1. Transpile PROTEL to `.cpp` with the PROTEL 2026 compiler (`protel`). 1. Transpile PROTEL to `.cpp` with the PROTEL 2026 compiler (`Pc`).
2. Compile generated C++ with `g++` or `clang++` (`-std=c++20`). 2. Compile generated C++ with `g++` or `clang++` (`-std=c++20`).
+20 -20
View File
@@ -6,17 +6,17 @@
## Overview ## Overview
The `protel` driver reports errors in three phases: **parse**, **type check**, and **compile**. Error examples live under `examples/errors/`. The **`Pc`** driver reports errors in three phases: **parse**, **type check**, and **compile**. Error examples live under `examples/errors/`.
```bash ```bash
./protel examples/errors/err_assign_integer_to_char.protel ./Pc examples/errors/err_assign_integer_to_char.P
``` ```
--- ---
## 1. Parse errors ## 1. Parse errors
**Prefix:** `protel: parse error in '<file>':` **Prefix:** `Pc: parse error in '<file>':`
The Lark parser rejects invalid syntax before transpilation. The Lark parser rejects invalid syntax before transpilation.
@@ -41,23 +41,23 @@ DCL demo PROC() IS
## 2. Type errors (strong typing) ## 2. Type errors (strong typing)
**Prefix:** `protel: type error in '<file>':` **Prefix:** `Pc: type error in '<file>':`
PROTEL 2026 enforces Reference Manual §11.3 compatibility at transpile time. Wide **integer** values cannot be stored in **char**, **PACK** byte fields, or **BOOL** without an explicit **CAST**. PROTEL 2026 enforces Reference Manual §11.3 compatibility at transpile time. Wide **integer** values cannot be stored in **char**, **PACK** byte fields, or **BOOL** without an explicit **CAST**.
| Message | Meaning | Example file | | Message | Meaning | Example file |
|---------|---------|--------------| |---------|---------|--------------|
| `cannot assign integer to char in …` | A variable or expression typed **integer** is assigned to **char {0 TO 255}** | `examples/errors/err_assign_integer_to_char.protel` | | `cannot assign integer to char in …` | A variable or expression typed **integer** is assigned to **char {0 TO 255}** | `examples/errors/err_assign_integer_to_char.P` |
| `cannot assign wide integer to packed byte-sized type {…} PACK(n) in …` | **integer** assigned to a **PACK** subrange | `examples/errors/err_assign_integer_to_packed_byte.protel` | | `cannot assign wide integer to packed byte-sized type {…} PACK(n) in …` | **integer** assigned to a **PACK** subrange | `examples/errors/err_assign_integer_to_packed_byte.P` |
| `cannot assign integer to BOOL in …` | Numeric value assigned to **BOOL** | `examples/errors/err_assign_integer_to_bool.protel` | | `cannot assign integer to BOOL in …` | Numeric value assigned to **BOOL** | `examples/errors/err_assign_integer_to_bool.P` |
| `value L..H is out of range for {A TO B} in …` | Numeric literal exceeds destination subrange | `examples/errors/err_constant_out_of_range.protel` | | `value L..H is out of range for {A TO B} in …` | Numeric literal exceeds destination subrange | `examples/errors/err_constant_out_of_range.P` |
| `cannot assign PTR TO T1 to PTR TO T2 in …` | Pointer pointee types differ | `examples/errors/err_assign_incompatible_pointer.protel` | | `cannot assign PTR TO T1 to PTR TO T2 in …` | Pointer pointee types differ | `examples/errors/err_assign_incompatible_pointer.P` |
| `RETURN type T1 is not compatible with RETURNS T2 in procedure 'P'` | **RETURN** expression does not match **RETURNS** type | `examples/errors/err_return_type_mismatch.protel` | | `RETURN type T1 is not compatible with RETURNS T2 in procedure 'P'` | **RETURN** expression does not match **RETURNS** type | `examples/errors/err_return_type_mismatch.P` |
| `procedure 'P' cannot RETURN a value` | **RETURN** with value in a `PROC()` without **RETURNS** | — | | `procedure 'P' cannot RETURN a value` | **RETURN** with value in a `PROC()` without **RETURNS** | — |
| `procedure 'P' must RETURN T` | Missing **RETURN** in a **RETURNS** procedure | — | | `procedure 'P' must RETURN T` | Missing **RETURN** in a **RETURNS** procedure | — |
| `unknown identifier 'x' in …` | Assignment to an undeclared name | — | | `unknown identifier 'x' in …` | Assignment to an undeclared name | — |
**Valid contrast:** `examples/errors/ok_assign_char_literal.protel` assigns literal `65` to **char** (within `{0 TO 255}`). **Valid contrast:** `examples/errors/ok_assign_char_literal.P` assigns literal `65` to **char** (within `{0 TO 255}`).
### Strong typing rules (summary) ### Strong typing rules (summary)
@@ -71,7 +71,7 @@ PROTEL 2026 enforces Reference Manual §11.3 compatibility at transpile time. Wi
## 3. Transpile errors ## 3. Transpile errors
**Prefix:** `protel: transpile error in '<file>':` **Prefix:** `Pc: transpile error in '<file>':`
Structural or linkage problems in the transpiler (not type compatibility). Structural or linkage problems in the transpiler (not type compatibility).
@@ -90,22 +90,22 @@ Structural or linkage problems in the transpiler (not type compatibility).
| Message | Cause | | Message | Cause |
|---------|-------| |---------|-------|
| `protel: cannot read '<file>': …` | Missing or unreadable source path | | `Pc: cannot read '<file>': …` | Missing or unreadable source path |
| `protel: cannot write '<file>': …` | Output path not writable | | `Pc: cannot write '<file>': …` | Output path not writable |
| `protel: '<file>' is not a PROTEL source file` | Unrecognized extension | | `Pc: '<file>' is not a PROTEL source file` | Unrecognized extension |
| `protel: warning: only the first source file is compiled` | Multiple inputs on command line | | `Pc: warning: only the first source file is compiled` | Multiple inputs on command line |
--- ---
## 5. Compile and link errors ## 5. Compile and link errors
**Prefix:** `protel: compile error:` **Prefix:** `Pc: compile error:`
Emitted when GCC/clang++ rejects generated C++. Often caused by invalid generated code or missing runtime symbols. Emitted when GCC/clang++ rejects generated C++. Often caused by invalid generated code or missing runtime symbols.
| Underlying message | Typical fix | | Underlying message | Typical fix |
|--------------------|-------------| |--------------------|-------------|
| `undefined reference to 'writeln'` | Link without `protel_io.c` (use default `protel` compile, not raw `g++` on `.cpp` alone) | | `undefined reference to 'writeln'` | Link without `protel_io.c` (use default `Pc` compile, not raw `g++` on `.cpp` alone) |
| `functions that differ only in their return type` | Duplicate ENTRY/forward signatures (report as transpile bug) | | `functions that differ only in their return type` | Duplicate ENTRY/forward signatures (report as transpile bug) |
| `no C++ compiler found` | Install `g++`, `clang++`, or `c++` on `PATH` | | `no C++ compiler found` | Install `g++`, `clang++`, or `c++` on `PATH` |
@@ -115,7 +115,7 @@ Emitted when GCC/clang++ rejects generated C++. Often caused by invalid generate
| Message | Cause | | Message | Cause |
|---------|-------| |---------|-------|
| `protel: warning: call to P uses a PROTEL string without an explicit NUL (0) suffix` | **EXTERNAL** call with string missing `, 0` in char tuple | | `Pc: warning: call to P uses a PROTEL string without an explicit NUL (0) suffix` | **EXTERNAL** call with string missing `, 0` in char tuple |
--- ---
@@ -123,4 +123,4 @@ Emitted when GCC/clang++ rejects generated C++. Often caused by invalid generate
- Reference Manual §11.0–§11.3 — type compatibility - Reference Manual §11.0–§11.3 — type compatibility
- `examples/errors/` — intentional error and OK contrast programs - `examples/errors/` — intentional error and OK contrast programs
- Introductory Manual §7.0 — `protel` driver usage - Introductory Manual §7.0 — **`Pc`** driver usage
+2 -2
View File
@@ -24,7 +24,7 @@
:group 'protel) :group 'protel)
(defcustom protel-root nil (defcustom protel-root nil
"PROTEL 2026 checkout directory (contains Pb and emacs/protel-mode.el). "PROTEL 2026 checkout directory (contains Pc, Pb, and emacs/protel-mode.el).
Used to find Pb when it is not on PATH. Usually set from ~/.emacs." Used to find Pb when it is not on PATH. Usually set from ~/.emacs."
:type 'directory :type 'directory
:group 'protel) :group 'protel)
@@ -109,7 +109,7 @@ When nil, `protel--locate-pb' searches PATH and PROTEL-ROOT."
(when protel-root (when protel-root
(let ((pb (expand-file-name "Pb" protel-root))) (let ((pb (expand-file-name "Pb" protel-root)))
(when (file-exists-p pb) pb))) (when (file-exists-p pb) pb)))
(when-let ((protel-bin (protel--executable-find "protel"))) (when-let ((protel-bin (protel--executable-find "Pc")))
(let ((pb (expand-file-name "Pb" (file-name-directory protel-bin)))) (let ((pb (expand-file-name "Pb" (file-name-directory protel-bin))))
(when (file-exists-p pb) pb))))) (when (file-exists-p pb) pb)))))
-18
View File
@@ -1,18 +0,0 @@
#!/usr/bin/env protel-run
% Hello World - PROTEL 2026 (Introductory Manual 5.5.2 / 7.0)
% Run from repo root: export PATH="$PWD:$PATH" && ./examples/Hello.protel
% EXTERNAL C I/O via minimal runtime; no INTRINSIC, no iostream.
% PROTEL strings are char tuples; append 0 explicitly for C calls.
SECTION Hello;
TYPE char {0 TO 255};
DCL writeln PROC(msg PTR TO char) EXTERNAL;
DCL Start PROC() IS ENTRY;
DCL Start PROC() IS
BLOCK
writeln({'Hello, World!', 0});
ENDBLOCK;
Regular → Executable
+4 -2
View File
@@ -1,6 +1,8 @@
% Hello World - legacy .P extension (Introductory Manual 5.5.2 / 7.0 / 7.2) #!/usr/bin/env Pc!
% Same program as Hello.protel; .P is the historical Nortel/BNR suffix. % Hello World - PROTEL 2026 (Introductory Manual 5.5.2 / 7.0)
% Run from repo root: export PATH="$PWD:$PATH" && ./examples/Hello.P
% EXTERNAL C I/O via minimal runtime; no INTRINSIC, no iostream. % EXTERNAL C I/O via minimal runtime; no INTRINSIC, no iostream.
% PROTEL strings are char tuples; append 0 explicitly for C calls.
SECTION Hello; SECTION Hello;
+1 -1
View File
@@ -1,6 +1,6 @@
% Hello World - PLS edition suffix .aa01 (Introductory Manual 7.0 / 7.2) % Hello World - PLS edition suffix .aa01 (Introductory Manual 7.0 / 7.2)
% Legacy PLS naming: two letters + two digits (.AA01 through .ZZ99). % Legacy PLS naming: two letters + two digits (.AA01 through .ZZ99).
% Same program as Hello.protel; edition AA01 is illustrative only. % Same program as Hello.P; edition AA01 is illustrative only.
SECTION Hello; SECTION Hello;
-18
View File
@@ -1,18 +0,0 @@
#!/usr/bin/env protel-run
% Hello World - PROTEL 2026 (Introductory Manual 5.5.2 / 7.0)
% Run from repo root: export PATH="$PWD:$PATH" && ./examples/Hello.protel
% EXTERNAL C I/O via minimal runtime; no INTRINSIC, no iostream.
% PROTEL strings are char tuples; append 0 explicitly for C calls.
SECTION Hello;
TYPE char {0 TO 255};
DCL writeln PROC(msg PTR TO char) EXTERNAL;
DCL Start PROC() IS ENTRY;
DCL Start PROC() IS
BLOCK
writeln({'Hello, World!', 0});
ENDBLOCK;
@@ -1,5 +1,5 @@
% ERROR EXAMPLE — incompatible pointer assignment (§11.3 rule 5) % ERROR EXAMPLE — incompatible pointer assignment (§11.3 rule 5)
% Expected: protel: type error: cannot assign PTR TO ... % Expected: Pc: type error: cannot assign PTR TO ...
SECTION err_ptr_mismatch; SECTION err_ptr_mismatch;
@@ -1,5 +1,5 @@
% ERROR EXAMPLE — integer assigned to BOOL (§11.3) % ERROR EXAMPLE — integer assigned to BOOL (§11.3)
% Expected: protel: type error: cannot assign ... to BOOL % Expected: Pc: type error: cannot assign ... to BOOL
SECTION err_int_to_bool; SECTION err_int_to_bool;
@@ -1,5 +1,5 @@
% ERROR EXAMPLE — integer assigned to char (Reference Manual §11.3) % ERROR EXAMPLE — integer assigned to char (Reference Manual §11.3)
% Expected: protel: type error: cannot assign integer to char % Expected: Pc: type error: cannot assign integer to char
SECTION err_int_to_char; SECTION err_int_to_char;
@@ -1,5 +1,5 @@
% ERROR EXAMPLE — integer assigned to PACK byte (§7.2.3 / §11.3) % ERROR EXAMPLE — integer assigned to PACK byte (§7.2.3 / §11.3)
% Expected: protel: type error: cannot assign wide integer to packed byte-sized type % Expected: Pc: type error: cannot assign wide integer to packed byte-sized type
SECTION err_int_to_packed; SECTION err_int_to_packed;
@@ -1,5 +1,5 @@
% ERROR EXAMPLE — numeric literal out of subrange (§11.3) % ERROR EXAMPLE — numeric literal out of subrange (§11.3)
% Expected: protel: type error: value ... out of range for {0 TO 255} % Expected: Pc: type error: value ... out of range for {0 TO 255}
SECTION err_out_of_range; SECTION err_out_of_range;
@@ -1,5 +1,5 @@
% ERROR EXAMPLE — RETURN type incompatible with RETURNS clause (§9.2 / §11.3) % ERROR EXAMPLE — RETURN type incompatible with RETURNS clause (§9.2 / §11.3)
% Expected: protel: type error: RETURN type ... is not compatible with RETURNS BOOL % Expected: Pc: type error: RETURN type ... is not compatible with RETURNS BOOL
SECTION err_return_mismatch; SECTION err_return_mismatch;
+3 -3
View File
@@ -4,7 +4,7 @@ set -euo pipefail
ROOT="$(cd "$(dirname "$0")/../.." && pwd)" ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
BUILD="$ROOT/build/interop" BUILD="$ROOT/build/interop"
PROTEL="$ROOT/protel" PC="$ROOT/Pc"
RUNTIME="$ROOT/src/runtime/protel_io.c" RUNTIME="$ROOT/src/runtime/protel_io.c"
mkdir -p "$BUILD" mkdir -p "$BUILD"
@@ -17,7 +17,7 @@ fi
CXX="$(command -v clang++ || command -v g++)" CXX="$(command -v clang++ || command -v g++)"
echo "=== PROTEL calls Swift ===" echo "=== PROTEL calls Swift ==="
"$PROTEL" "$ROOT/examples/interop/protel_calls_swift.protel" \ "$PC" "$ROOT/examples/interop/protel_calls_swift.P" \
--keep -o "$BUILD/protel_calls_swift.cpp" --keep -o "$BUILD/protel_calls_swift.cpp"
"$CXX" -std=c++20 -Wall -I"$ROOT/src/runtime" -c "$BUILD/protel_calls_swift.cpp" \ "$CXX" -std=c++20 -Wall -I"$ROOT/src/runtime" -c "$BUILD/protel_calls_swift.cpp" \
-o "$BUILD/protel_calls_swift.o" -o "$BUILD/protel_calls_swift.o"
@@ -28,7 +28,7 @@ swiftc -parse-as-library -c "$ROOT/examples/interop/swift_greet.swift" \
"$BUILD/protel_calls_swift" "$BUILD/protel_calls_swift"
echo "=== Swift calls PROTEL ===" echo "=== Swift calls PROTEL ==="
"$PROTEL" "$ROOT/examples/interop/protel_for_swift.protel" \ "$PC" "$ROOT/examples/interop/protel_for_swift.P" \
--keep -o "$BUILD/protel_for_swift.cpp" --keep -o "$BUILD/protel_for_swift.cpp"
"$CXX" -std=c++20 -Wall -I"$ROOT/src/runtime" -c "$BUILD/protel_for_swift.cpp" \ "$CXX" -std=c++20 -Wall -I"$ROOT/src/runtime" -c "$BUILD/protel_for_swift.cpp" \
-o "$BUILD/protel_for_swift.o" -o "$BUILD/protel_for_swift.o"
+3 -3
View File
@@ -4,7 +4,7 @@ set -euo pipefail
ROOT="$(cd "$(dirname "$0")/../.." && pwd)" ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
BUILD="$ROOT/build/interop" BUILD="$ROOT/build/interop"
PROTEL="$ROOT/protel" PC="$ROOT/Pc"
RUNTIME="$ROOT/src/runtime/protel_io.c" RUNTIME="$ROOT/src/runtime/protel_io.c"
INTEROP="$ROOT/examples/interop" INTEROP="$ROOT/examples/interop"
@@ -58,7 +58,7 @@ fi
javac -d "$BUILD" "$INTEROP/GreetHelper.java" "$INTEROP/JavaCallsProtel.java" javac -d "$BUILD" "$INTEROP/GreetHelper.java" "$INTEROP/JavaCallsProtel.java"
echo "=== PROTEL calls Java ===" echo "=== PROTEL calls Java ==="
"$PROTEL" "$INTEROP/protel_calls_java.protel" \ "$PC" "$INTEROP/protel_calls_java.P" \
--keep -o "$BUILD/protel_calls_java.cpp" --keep -o "$BUILD/protel_calls_java.cpp"
"$CXX" -std=c++20 -Wall -I"$ROOT/src/runtime" -c "$BUILD/protel_calls_java.cpp" \ "$CXX" -std=c++20 -Wall -I"$ROOT/src/runtime" -c "$BUILD/protel_calls_java.cpp" \
-o "$BUILD/protel_calls_java.o" -o "$BUILD/protel_calls_java.o"
@@ -70,7 +70,7 @@ echo "=== PROTEL calls Java ==="
PROTEL_ROOT="$ROOT" "$BUILD/protel_calls_java" PROTEL_ROOT="$ROOT" "$BUILD/protel_calls_java"
echo "=== Java calls PROTEL ===" echo "=== Java calls PROTEL ==="
"$PROTEL" "$INTEROP/protel_for_java.protel" \ "$PC" "$INTEROP/protel_for_java.P" \
--keep -o "$BUILD/protel_for_java.cpp" --keep -o "$BUILD/protel_for_java.cpp"
"$CXX" -std=c++20 -Wall -fPIC -I"$ROOT/src/runtime" -c "$BUILD/protel_for_java.cpp" \ "$CXX" -std=c++20 -Wall -fPIC -I"$ROOT/src/runtime" -c "$BUILD/protel_for_java.cpp" \
-o "$BUILD/protel_for_java.o" -o "$BUILD/protel_for_java.o"
+3 -3
View File
@@ -4,7 +4,7 @@ set -euo pipefail
ROOT="$(cd "$(dirname "$0")/../.." && pwd)" ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
BUILD="$ROOT/build/interop" BUILD="$ROOT/build/interop"
PROTEL="$ROOT/protel" PC="$ROOT/Pc"
RUNTIME="$ROOT/src/runtime/protel_io.c" RUNTIME="$ROOT/src/runtime/protel_io.c"
INTEROP="$ROOT/examples/interop" INTEROP="$ROOT/examples/interop"
@@ -52,7 +52,7 @@ else
fi fi
echo "=== PROTEL calls Python ===" echo "=== PROTEL calls Python ==="
"$PROTEL" "$INTEROP/protel_calls_python.protel" \ "$PC" "$INTEROP/protel_calls_python.P" \
--keep -o "$BUILD/protel_calls_python.cpp" --keep -o "$BUILD/protel_calls_python.cpp"
"$CXX" -std=c++20 -Wall -I"$ROOT/src/runtime" -c "$BUILD/protel_calls_python.cpp" \ "$CXX" -std=c++20 -Wall -I"$ROOT/src/runtime" -c "$BUILD/protel_calls_python.cpp" \
-o "$BUILD/protel_calls_python.o" -o "$BUILD/protel_calls_python.o"
@@ -64,7 +64,7 @@ echo "=== PROTEL calls Python ==="
(cd "$ROOT" && "$BUILD/protel_calls_python") (cd "$ROOT" && "$BUILD/protel_calls_python")
echo "=== Python calls PROTEL ===" echo "=== Python calls PROTEL ==="
"$PROTEL" "$INTEROP/protel_for_python.protel" \ "$PC" "$INTEROP/protel_for_python.P" \
--keep -o "$BUILD/protel_for_python.cpp" --keep -o "$BUILD/protel_for_python.cpp"
"$CXX" -std=c++20 -Wall -fPIC -I"$ROOT/src/runtime" -c "$BUILD/protel_for_python.cpp" \ "$CXX" -std=c++20 -Wall -fPIC -I"$ROOT/src/runtime" -c "$BUILD/protel_for_python.cpp" \
-o "$BUILD/protel_for_python.o" -o "$BUILD/protel_for_python.o"
+3 -3
View File
@@ -4,7 +4,7 @@ set -euo pipefail
ROOT="$(cd "$(dirname "$0")/../.." && pwd)" ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
BUILD="$ROOT/build/interop" BUILD="$ROOT/build/interop"
PROTEL="$ROOT/protel" PC="$ROOT/Pc"
RUNTIME="$ROOT/src/runtime/protel_io.c" RUNTIME="$ROOT/src/runtime/protel_io.c"
mkdir -p "$BUILD" mkdir -p "$BUILD"
@@ -17,7 +17,7 @@ fi
CXX="$(command -v clang++ || command -v g++)" CXX="$(command -v clang++ || command -v g++)"
echo "=== PROTEL calls Rust ===" echo "=== PROTEL calls Rust ==="
"$PROTEL" "$ROOT/examples/interop/protel_calls_rust.protel" \ "$PC" "$ROOT/examples/interop/protel_calls_rust.P" \
--keep -o "$BUILD/protel_calls_rust.cpp" --keep -o "$BUILD/protel_calls_rust.cpp"
"$CXX" -std=c++20 -Wall -I"$ROOT/src/runtime" -c "$BUILD/protel_calls_rust.cpp" \ "$CXX" -std=c++20 -Wall -I"$ROOT/src/runtime" -c "$BUILD/protel_calls_rust.cpp" \
-o "$BUILD/protel_calls_rust.o" -o "$BUILD/protel_calls_rust.o"
@@ -28,7 +28,7 @@ rustc --crate-type staticlib "$ROOT/examples/interop/rust_greet.rs" \
"$BUILD/protel_calls_rust" "$BUILD/protel_calls_rust"
echo "=== Rust calls PROTEL ===" echo "=== Rust calls PROTEL ==="
"$PROTEL" "$ROOT/examples/interop/protel_for_rust.protel" \ "$PC" "$ROOT/examples/interop/protel_for_rust.P" \
--keep -o "$BUILD/protel_for_rust.cpp" --keep -o "$BUILD/protel_for_rust.cpp"
"$CXX" -std=c++20 -Wall -I"$ROOT/src/runtime" -c "$BUILD/protel_for_rust.cpp" \ "$CXX" -std=c++20 -Wall -I"$ROOT/src/runtime" -c "$BUILD/protel_for_rust.cpp" \
-o "$BUILD/protel_for_rust.o" -o "$BUILD/protel_for_rust.o"
+2 -1
View File
@@ -1,5 +1,6 @@
#!/usr/bin/env Pc!
% Introductory Manual §1.3 + §5.5.2 + §7.3 % Introductory Manual §1.3 + §5.5.2 + §7.3
% Command-line factorial via USES intro_1_3_factorial.protel (section factorial_demo). % Command-line factorial via USES intro_1_3_factorial.P (section factorial_demo).
% Demonstrates C interop: printf() and atoi() are EXTERNAL; no INTRINSIC I/O. % Demonstrates C interop: printf() and atoi() are EXTERNAL; no INTRINSIC I/O.
SECTION factorial_cli USES factorial_demo; SECTION factorial_cli USES factorial_demo;
+156
View File
@@ -0,0 +1,156 @@
.\" PROTEL 2026 manual — Vincente D'Ingianni
.TH Pb 1 "June 2026" "PROTEL 2026" "User Commands"
.SH NAME
Pb \- PROTEL source beautifier (keyword uppercasing)
.SH SYNOPSIS
.B Pb
[\fIoptions\fR]
[[\fB\-\fR]
.I input
]
[[\fB\-\fR]
.I output
]
.SH DESCRIPTION
.B Pb
is the PROTEL 2026 beautifier. It performs lexical analysis on PROTEL
source and uppercases reserved keywords to match the style of the
PROTEL Reference Manual and historical Nortel/BNR listings.
.PP
.B Pb
is a filter\-style tool: it reads from standard input and writes to
standard output by default, and supports shell redirection, pipes, and
explicit input/output file arguments.
.PP
Non\-keyword identifiers, numeric literals, operators, and whitespace
are preserved exactly. Keywords inside
.B %
comments or inside
.B \(aq...\(aq
string literals are not altered.
.PP
Lines beginning with
.B $LI
(linker directives) are uppercased in full.
.PP
A first\-line UNIX shebang
.RI ( #!... )
is copied unchanged to the output so runnable
.B .P
programs keep their
.B Pc!
interpreter line (see
.BR Pc (1)).
.PP
If very few recognized keywords are found,
.B Pb
emits a warning on standard error but still produces output.
.SH OPTIONS
.TP
.BR \-b ", " \-\-bold
Wrap uppercased keywords in ANSI bold escape sequences
.RI ( \(rs033[1m " ... " \(rs033[0m )
for terminals that support bold text.
.TP
.B \-\-version
Print the
.B Pb
version
.RI ( Pb " 1.0 (PROTEL Beautifier)" )
and exit.
.TP
.BR \-h ", " \-\-help
Print usage and exit.
.SH ARGUMENTS
.TP
.I input
Source file to beautify. Defaults to standard input
.RB ( \- ).
Use
.B \-
explicitly to read from standard input when an output file is given.
.TP
.I output
Destination file. Defaults to standard output
.RB ( \- ).
Use
.B \-
explicitly to write to standard output when an input file is given.
.SH BEHAVIOR
.B Pb
tokenizes the source and matches tokens against the official PROTEL
reserved\-word list (Reference Manual Appendix A, derived from historical
.B oflpr
/
.B oflpi
sources). Matching tokens are forced to UPPERCASE.
.PP
Comment lines start with
.BR % .
String literals use single quotes; an embedded quote is written as two
single quotes
.RI ( \(aq\(aq ).
.PP
In GNU Emacs,
.B Pb
may be invoked on the current buffer via
.B C\-c C\-f
.RI ( M-x protel\-beautify ;
see Introductory Manual \(S7.2).
.SH EXIT STATUS
.TP
.B 0
Success.
.TP
.B 1
Input or output file error.
.SH EXAMPLES
Beautify a file in place (via a second file):
.PP
.RS
.B Pb examples/Hello.P build/Hello.pretty.P
.RE
.PP
Filter from standard input:
.PP
.RS
.B Pb \-\-bold < myprog.P > myprog.pretty.P
.RE
.PP
Pipe through a pager:
.PP
.RS
.B Pb < myprog.P | less
.RE
.PP
Copy input path to output path:
.PP
.RS
.B Pb myprog.P myprog.pretty.P
.RE
.PP
Bold keywords on standard output:
.PP
.RS
.B cat myprog.P | Pb \-\-bold
.RE
.SH INSTALLATION
After
.BR "make install\-system" ,
.B Pb
is available as
.IR /usr/local/bin/Pb
(symlink to
.IR /usr/local/protel/Pb ).
.SH "SEE ALSO"
.BR Pc (1),
.BR protel-mode
(Emacs),
Introductory Manual \(S7.0.1,
\(S7.2.
.SH AUTHORS
Vincente D'Ingianni \(em PROTEL 2026 revival project (original
.B Pb
from the 1990s, recreated 2026).
.SH COPYRIGHT
PROTEL \(co Vincente D'Ingianni / Binary Systems.
+373
View File
@@ -0,0 +1,373 @@
.\" PROTEL 2026 manual — Vincente D'Ingianni
.TH Pc 1 "June 2026" "PROTEL 2026" "User Commands"
.SH NAME
Pc \- PROTEL 2026 compiler (parser, transpiler, and GCC/clang++ driver)
.SH SYNOPSIS
.B Pc
[\fIoptions\fR]
.I input
[\fIinput\fR ...]
[\fB\-\-\fR \fIprogram\-args\fR ...]
.PP
.B Pc!
.I script.P
[\fIprogram\-args\fR ...]
.SH DESCRIPTION
.B Pc
is the PROTEL 2026 compiler driver. It parses PROTEL source, performs
strong type checking, transpiles to C++ (or C with
.BR \-\-emit\-c ),
and optionally invokes
.BR g++ ,
.BR clang++ ,
or
.BR c++
to produce object files or executables.
.PP
On first use,
.B Pc
bootstraps a private Python virtual environment
.RI ( .venv )
in the PROTEL project tree and installs parser dependencies (Lark).
.PP
The default source suffix is
.BR .P
(historical Nortel/BNR convention). The compiler does
.I not
require any particular extension; recognized suffixes are
.BR .P ,
.BR .protel ,
.BR .pt ,
.BR .ptl ,
and PLS edition suffixes
.B .AA01
through
.BR .ZZ99 .
Unrecognized names still compile when the file contains valid PROTEL source.
.PP
PLS edition files (for example
.IR vdi.aa01 )
automatically enable classical preprocessing (keyword normalization;
.B $LI
and
.B $EJECT
linker directives stripped before parse) even without
.BR \-\-classical .
.SH OPTIONS
.TP
.BR \-o ", " \-\-output " " \fIfile\fR
Write generated C/C++ source, an object file, or an executable to
.IR file .
When
.I file
ends in
.B .c
or
.BR .cpp ,
only source is emitted. Otherwise, an
.BR \-\-output
name that does not end in
.B .c
or
.B .cpp
implies compile/link mode.
.TP
.B \-\-classical
Use legacy PROTEL identifier rules (keywords remain UPPERCASE).
Automatically enabled for PLS edition suffixes.
.TP
.B \-\-parse\-only
Parse the source and print an abstract-syntax summary to standard error;
do not transpile or compile.
.TP
.B \-\-emit\-c
Emit C instead of C++ (default output is C++). Compile and link modes
require C++ output; do not combine
.B \-\-emit\-c
with
.BR \-\-compile ,
.BR \-\-run ,
or
.BR \-c .
.TP
.B \-\-compile
Transpile and compile to a native executable or object file.
.TP
.B \-\-run
Compile and run the program (implies
.BR \-\-compile ).
The process exit status is the integer returned by the ENTRY procedure,
or the shell status of the generated executable.
.TP
.BR \-c
Compile only: produce an object file (passed through to the C++ compiler).
.TP
.BR \-g
Generate debug information (passed through to the C++ compiler).
.TP
.B \-\-keep
Retain the generated
.B .cpp
(or
.BR .c )
file after compiling. By default, intermediate source in
.I build/
is removed once linking succeeds.
.TP
.B \-\-version
Print the
.B Pc
version
.RI ( Pc " 0.3.0" )
and exit.
.TP
.BR \-h ", " \-\-help
Print usage and exit.
.SH PROGRAM ARGUMENTS
When
.B \-\-run
is used, arguments intended for the PROTEL ENTRY procedure may follow a
.B \-\-
separator:
.PP
.RS
.B Pc
.I source.P
.B \-\-run \-\-
.I arg1 arg2 ...
.RE
.PP
These are forwarded to
.IR argc / argv
in the ENTRY procedure (Introductory Manual \(S5.5.2).
.SH MODES
.TP
.B Transpile only (default)
With no compile flags and no executable
.BR \-o ,
generated C++ is written to standard output.
.TP
.B Transpile to file
.B Pc
.I source.P \-o
.I out.cpp
writes generated source only.
.TP
.B Compile / link
.BR \-\-compile ,
.BR \-\-run ,
.BR \-c ,
or
.B \-o
naming a non\-source output triggers compilation. Generated C++ is written
under
.I build/
unless
.B \-o
names a
.B .cpp
path. The minimal I/O runtime
.RI ( src/runtime/protel_io.c )
is linked when needed. Default executable name is
.BR a.out .
.TP
.B Multiple inputs
More than one
.I input
file may appear on the command line; only the first is compiled. A warning
is issued for additional files.
.SH "SHEBANG RUNNER (Pc!)"
.B Pc!
(pronounced
.I "P c Bang" )
is a companion helper installed alongside
.BR Pc .
The exclamation mark echoes the
.B \(lq#!\(rq
.I shebang
convention and provides a short command\-line alias for running programs.
.PP
.B Pc!
is equivalent to:
.PP
.RS
.B Pc
.I script.P \-\-run \-\-
[\fIprogram\-args\fR ...]
.RE
.PP
Typical shebang line in an executable
.B .P
file:
.PP
.RS
.B #!/usr/bin/env Pc!
.RE
.PP
Requirements for direct execution:
.IP \(bu 3
Line 1 must be a UNIX shebang naming
.BR Pc! .
.IP \(bu 3
The file must be executable
.RI ( chmod +x ).
.IP \(bu 3
The PROTEL project directory must be on
.BR PATH
so
.B Pc!
and
.B Pc
are found.
.PP
Examples:
.PP
.RS
.nf
export PATH="$PWD:$PATH"
./examples/Hello.P
Pc! examples/Hello.P
Pc! examples/intro_5_5_2_args_exit.P one two
.fi
.RE
.PP
The preprocessor strips the shebang before parse; it is not PROTEL syntax.
.SH INSTALLATION
.TP
.B System\-wide (default)
.RS
.nf
sudo make install-system
.fi
.RE
Installs the toolkit under
.IR /usr/local/protel ,
symlinks
.BR Pc ,
.BR Pb ,
and
.B Pc!
into
.IR /usr/local/bin ,
and installs manual pages in
.IR /usr/local/share/man/man1/ .
.TP
.B Local checkout
.RS
.nf
make install
.fi
.RE
Prepares the source tree for development (local
.I .venv
and
.I man/man1/ ).
.SH ENVIRONMENT
.TP
.B PATH
Must include
.IR /usr/local/bin
after a system install, or the PROTEL checkout directory during
development, so
.B Pc
and
.B Pc!
can be located by the shell and by
.BR "env" .
Quoted
.B \(lq~/PROTEL\(rq
in
.B PATH
does not expand; use
.BR $PWD ,
.BR $HOME/PROTEL ,
or an absolute path.
.SH FILES
.TP
.I /usr/local/protel/
Default system\-wide toolkit root
.RI ( SYSPREFIX ;
see
.BR make install\-system ).
Contains
.BR Pc ,
.BR Pb ,
.BR Pc! ,
.IR src/ ,
.IR examples/ ,
.IR emacs/ ,
and
.IR .venv/ .
.TP
.I .venv/
Python virtual environment (created at install time or on first local run).
.TP
.I build/
Default directory for generated
.B .cpp
files during compilation (under the toolkit root or current working
directory).
.TP
.I src/runtime/protel_io.c
Minimal EXTERNAL I/O runtime linked by default.
.SH EXIT STATUS
.TP
.B 0
Success.
.TP
.B 1
Parse, type, transpile, compile, or I/O error.
.TP
.B >0
When
.B \-\-run
is used, the ENTRY procedure return value or program exit status.
.SH EXAMPLES
Transpile to standard output:
.PP
.RS
.B Pc examples/Hello.P
.RE
.PP
Compile and run:
.PP
.RS
.B Pc examples/Hello.P \-\-run
.RE
.PP
Named executable and ENTRY arguments:
.PP
.RS
.B Pc examples/intro_5_5_2_args_exit.P \-o build/ArgsExit \-\-run \-\- one two
.RE
.PP
Object file (PLS module):
.PP
.RS
.B Pc vdi.aa01 \-c \-o build/vdi.aa01.o
.RE
.PP
Keep generated C++ for inspection:
.PP
.RS
.B Pc myprog.P \-\-compile \-\-keep \-o build/myprog
.RE
.PP
Classical (legacy) identifiers:
.PP
.RS
.B Pc legacy.P \-\-classical \-\-run
.RE
.SH "SEE ALSO"
.BR Pb (1),
.BR protel-mode
(Emacs),
Introductory Manual \(S7.0,
\(S7.1,
\(S7.0.5,
Reference Manual \(S11.3 (type errors),
.IR docs/reference-error-messages.md
.SH AUTHORS
Vincente D'Ingianni \(em PROTEL 2026 revival project.
.SH COPYRIGHT
PROTEL \(co Vincente D'Ingianni / Binary Systems.
+148
View File
@@ -0,0 +1,148 @@
.\" PROTEL 2026 manual — Vincente D'Ingianni
.TH Pb 1 "June 2026" "PROTEL 2026" "User Commands"
.SH NAME
Pb \- PROTEL source beautifier (keyword uppercasing)
.SH SYNOPSIS
.B Pb
[\fIoptions\fR]
[[\fB\-\fR]
.I input
]
[[\fB\-\fR]
.I output
]
.SH DESCRIPTION
.B Pb
is the PROTEL 2026 beautifier. It performs lexical analysis on PROTEL
source and uppercases reserved keywords to match the style of the
PROTEL Reference Manual and historical Nortel/BNR listings.
.PP
.B Pb
is a filter\-style tool: it reads from standard input and writes to
standard output by default, and supports shell redirection, pipes, and
explicit input/output file arguments.
.PP
Non\-keyword identifiers, numeric literals, operators, and whitespace
are preserved exactly. Keywords inside
.B %
comments or inside
.B \(aq...\(aq
string literals are not altered.
.PP
Lines beginning with
.B $LI
(linker directives) are uppercased in full.
.PP
A first\-line UNIX shebang
.RI ( #!... )
is copied unchanged to the output so runnable
.B .P
programs keep their
.B Pc!
interpreter line (see
.BR Pc (1)).
.PP
If very few recognized keywords are found,
.B Pb
emits a warning on standard error but still produces output.
.SH OPTIONS
.TP
.BR \-b ", " \-\-bold
Wrap uppercased keywords in ANSI bold escape sequences
.RI ( \(rs033[1m " ... " \(rs033[0m )
for terminals that support bold text.
.TP
.B \-\-version
Print the
.B Pb
version
.RI ( Pb " 1.0 (PROTEL Beautifier)" )
and exit.
.TP
.BR \-h ", " \-\-help
Print usage and exit.
.SH ARGUMENTS
.TP
.I input
Source file to beautify. Defaults to standard input
.RB ( \- ).
Use
.B \-
explicitly to read from standard input when an output file is given.
.TP
.I output
Destination file. Defaults to standard output
.RB ( \- ).
Use
.B \-
explicitly to write to standard output when an input file is given.
.SH BEHAVIOR
.B Pb
tokenizes the source and matches tokens against the official PROTEL
reserved\-word list (Reference Manual Appendix A, derived from historical
.B oflpr
/
.B oflpi
sources). Matching tokens are forced to UPPERCASE.
.PP
Comment lines start with
.BR % .
String literals use single quotes; an embedded quote is written as two
single quotes
.RI ( \(aq\(aq ).
.PP
In GNU Emacs,
.B Pb
may be invoked on the current buffer via
.B C\-c C\-f
.RI ( M-x protel\-beautify ;
see Introductory Manual \(S7.2).
.SH EXIT STATUS
.TP
.B 0
Success.
.TP
.B 1
Input or output file error.
.SH EXAMPLES
Beautify a file in place (via a second file):
.PP
.RS
.B Pb examples/Hello.P build/Hello.pretty.P
.RE
.PP
Filter from standard input:
.PP
.RS
.B Pb \-\-bold < myprog.P > myprog.pretty.P
.RE
.PP
Pipe through a pager:
.PP
.RS
.B Pb < myprog.P | less
.RE
.PP
Copy input path to output path:
.PP
.RS
.B Pb myprog.P myprog.pretty.P
.RE
.PP
Bold keywords on standard output:
.PP
.RS
.B cat myprog.P | Pb \-\-bold
.RE
.SH "SEE ALSO"
.BR Pc (1),
.BR protel-mode
(Emacs),
Introductory Manual \(S7.0.1,
\(S7.2.
.SH AUTHORS
Vincente D'Ingianni \(em PROTEL 2026 revival project (original
.B Pb
from the 1990s, recreated 2026).
.SH COPYRIGHT
PROTEL \(co Vincente D'Ingianni / Binary Systems.
+324
View File
@@ -0,0 +1,324 @@
.\" PROTEL 2026 manual — Vincente D'Ingianni
.TH Pc 1 "June 2026" "PROTEL 2026" "User Commands"
.SH NAME
Pc \- PROTEL 2026 compiler (parser, transpiler, and GCC/clang++ driver)
.SH SYNOPSIS
.B Pc
[\fIoptions\fR]
.I input
[\fIinput\fR ...]
[\fB\-\-\fR \fIprogram\-args\fR ...]
.PP
.B Pc!
.I script.P
[\fIprogram\-args\fR ...]
.SH DESCRIPTION
.B Pc
is the PROTEL 2026 compiler driver. It parses PROTEL source, performs
strong type checking, transpiles to C++ (or C with
.BR \-\-emit\-c ),
and optionally invokes
.BR g++ ,
.BR clang++ ,
or
.BR c++
to produce object files or executables.
.PP
On first use,
.B Pc
bootstraps a private Python virtual environment
.RI ( .venv )
in the PROTEL project tree and installs parser dependencies (Lark).
.PP
The default source suffix is
.BR .P
(historical Nortel/BNR convention). The compiler does
.I not
require any particular extension; recognized suffixes are
.BR .P ,
.BR .protel ,
.BR .pt ,
.BR .ptl ,
and PLS edition suffixes
.B .AA01
through
.BR .ZZ99 .
Unrecognized names still compile when the file contains valid PROTEL source.
.PP
PLS edition files (for example
.IR vdi.aa01 )
automatically enable classical preprocessing (keyword normalization;
.B $LI
and
.B $EJECT
linker directives stripped before parse) even without
.BR \-\-classical .
.SH OPTIONS
.TP
.BR \-o ", " \-\-output " " \fIfile\fR
Write generated C/C++ source, an object file, or an executable to
.IR file .
When
.I file
ends in
.B .c
or
.BR .cpp ,
only source is emitted. Otherwise, an
.BR \-\-output
name that does not end in
.B .c
or
.B .cpp
implies compile/link mode.
.TP
.B \-\-classical
Use legacy PROTEL identifier rules (keywords remain UPPERCASE).
Automatically enabled for PLS edition suffixes.
.TP
.B \-\-parse\-only
Parse the source and print an abstract-syntax summary to standard error;
do not transpile or compile.
.TP
.B \-\-emit\-c
Emit C instead of C++ (default output is C++). Compile and link modes
require C++ output; do not combine
.B \-\-emit\-c
with
.BR \-\-compile ,
.BR \-\-run ,
or
.BR \-c .
.TP
.B \-\-compile
Transpile and compile to a native executable or object file.
.TP
.B \-\-run
Compile and run the program (implies
.BR \-\-compile ).
The process exit status is the integer returned by the ENTRY procedure,
or the shell status of the generated executable.
.TP
.BR \-c
Compile only: produce an object file (passed through to the C++ compiler).
.TP
.BR \-g
Generate debug information (passed through to the C++ compiler).
.TP
.B \-\-keep
Retain the generated
.B .cpp
(or
.BR .c )
file after compiling. By default, intermediate source in
.I build/
is removed once linking succeeds.
.TP
.B \-\-version
Print the
.B Pc
version
.RI ( Pc " 0.3.0" )
and exit.
.TP
.BR \-h ", " \-\-help
Print usage and exit.
.SH PROGRAM ARGUMENTS
When
.B \-\-run
is used, arguments intended for the PROTEL ENTRY procedure may follow a
.B \-\-
separator:
.PP
.RS
.B Pc
.I source.P
.B \-\-run \-\-
.I arg1 arg2 ...
.RE
.PP
These are forwarded to
.IR argc / argv
in the ENTRY procedure (Introductory Manual \(S5.5.2).
.SH MODES
.TP
.B Transpile only (default)
With no compile flags and no executable
.BR \-o ,
generated C++ is written to standard output.
.TP
.B Transpile to file
.B Pc
.I source.P \-o
.I out.cpp
writes generated source only.
.TP
.B Compile / link
.BR \-\-compile ,
.BR \-\-run ,
.BR \-c ,
or
.B \-o
naming a non\-source output triggers compilation. Generated C++ is written
under
.I build/
unless
.B \-o
names a
.B .cpp
path. The minimal I/O runtime
.RI ( src/runtime/protel_io.c )
is linked when needed. Default executable name is
.BR a.out .
.TP
.B Multiple inputs
More than one
.I input
file may appear on the command line; only the first is compiled. A warning
is issued for additional files.
.SH "SHEBANG RUNNER (Pc!)"
.B Pc!
(pronounced
.I "P c Bang" )
is a companion helper installed alongside
.BR Pc .
The exclamation mark echoes the
.B \(lq#!\(rq
.I shebang
convention and provides a short command\-line alias for running programs.
.PP
.B Pc!
is equivalent to:
.PP
.RS
.B Pc
.I script.P \-\-run \-\-
[\fIprogram\-args\fR ...]
.RE
.PP
Typical shebang line in an executable
.B .P
file:
.PP
.RS
.B #!/usr/bin/env Pc!
.RE
.PP
Requirements for direct execution:
.IP \(bu 3
Line 1 must be a UNIX shebang naming
.BR Pc! .
.IP \(bu 3
The file must be executable
.RI ( chmod +x ).
.IP \(bu 3
The PROTEL project directory must be on
.BR PATH
so
.B Pc!
and
.B Pc
are found.
.PP
Examples:
.PP
.RS
.nf
export PATH="$PWD:$PATH"
./examples/Hello.P
Pc! examples/Hello.P
Pc! examples/intro_5_5_2_args_exit.P one two
.fi
.RE
.PP
The preprocessor strips the shebang before parse; it is not PROTEL syntax.
.SH ENVIRONMENT
.TP
.B PATH
Must include the PROTEL project directory (or install prefix) so
.B Pc
and
.B Pc!
can be located by the shell and by
.BR "env" .
Quoted
.B \(lq~/PROTEL\(rq
in
.B PATH
does not expand; use
.BR $PWD ,
.BR $HOME/PROTEL ,
or an absolute path.
.SH FILES
.TP
.I .venv/
Project Python virtual environment (created on first run).
.TP
.I build/
Default directory for generated
.B .cpp
files during compilation.
.TP
.I src/runtime/protel_io.c
Minimal EXTERNAL I/O runtime linked by default.
.SH EXIT STATUS
.TP
.B 0
Success.
.TP
.B 1
Parse, type, transpile, compile, or I/O error.
.TP
.B >0
When
.B \-\-run
is used, the ENTRY procedure return value or program exit status.
.SH EXAMPLES
Transpile to standard output:
.PP
.RS
.B Pc examples/Hello.P
.RE
.PP
Compile and run:
.PP
.RS
.B Pc examples/Hello.P \-\-run
.RE
.PP
Named executable and ENTRY arguments:
.PP
.RS
.B Pc examples/intro_5_5_2_args_exit.P \-o build/ArgsExit \-\-run \-\- one two
.RE
.PP
Object file (PLS module):
.PP
.RS
.B Pc vdi.aa01 \-c \-o build/vdi.aa01.o
.RE
.PP
Keep generated C++ for inspection:
.PP
.RS
.B Pc myprog.P \-\-compile \-\-keep \-o build/myprog
.RE
.PP
Classical (legacy) identifiers:
.PP
.RS
.B Pc legacy.P \-\-classical \-\-run
.RE
.SH "SEE ALSO"
.BR Pb (1),
.BR protel-mode
(Emacs),
Introductory Manual \(S7.0,
\(S7.1,
\(S7.0.5,
Reference Manual \(S11.3 (type errors),
.IR docs/reference-error-messages.md
.SH AUTHORS
Vincente D'Ingianni \(em PROTEL 2026 revival project.
.SH COPYRIGHT
PROTEL \(co Vincente D'Ingianni / Binary Systems.
-39
View File
@@ -1,39 +0,0 @@
#!/usr/bin/env python3
"""Run a .protel file invoked via shebang (Introductory Manual §7.0.5).
The kernel executes: protel-run /path/to/script.protel [program args]
"""
from __future__ import annotations
import os
import sys
from pathlib import Path
_ROOT = Path(__file__).resolve().parent
_PROTEL = _ROOT / "protel"
def main() -> int:
if len(sys.argv) < 2:
print(
"protel-run: missing PROTEL source path "
"(use #!/usr/bin/env protel-run in a .protel file)",
file=sys.stderr,
)
return 2
source = Path(sys.argv[1]).resolve()
program_args = sys.argv[2:]
if not _PROTEL.is_file():
print(f"protel-run: cannot find protel driver at '{_PROTEL}'", file=sys.stderr)
return 1
argv = [str(_PROTEL), str(source), "--run", "--", *program_args]
os.execv(str(_PROTEL), argv)
return 1
if __name__ == "__main__":
raise SystemExit(main())
+3 -3
View File
@@ -42,7 +42,7 @@ def _sanitize_namespace(name: str) -> str:
class CppTranspiler(CTranspiler): class CppTranspiler(CTranspiler):
def __init__(self, *, classical: bool = False, source_name: str = "input.protel"): def __init__(self, *, classical: bool = False, source_name: str = "input.P"):
super().__init__(classical=classical, source_name=source_name) super().__init__(classical=classical, source_name=source_name)
self._cpp = True self._cpp = True
self._current_namespace: str | None = None self._current_namespace: str | None = None
@@ -724,7 +724,7 @@ def transpile_to_cpp(
compilation_unit, compilation_unit,
*, *,
classical: bool = False, classical: bool = False,
source_name: str = "input.protel", source_name: str = "input.P",
source_path: Path | None = None, source_path: Path | None = None,
) -> str: ) -> str:
from .module_resolver import resolve_compilation_unit from .module_resolver import resolve_compilation_unit
@@ -747,7 +747,7 @@ def transpile_file_cpp(
source: str, source: str,
*, *,
classical: bool = False, classical: bool = False,
source_name: str = "input.protel", source_name: str = "input.P",
) -> str: ) -> str:
from .parser import parse_protel from .parser import parse_protel
+17 -4
View File
@@ -5,14 +5,21 @@ from __future__ import annotations
import re import re
from pathlib import Path from pathlib import Path
# Modern / distribution suffixes (case-insensitive except where noted). # Default distribution suffix (historical Nortel/BNR). The compiler does not
_FIXED_SUFFIXES = frozenset({".protel", ".pt", ".ptl", ".p"}) # require any particular extension; these are conventions for tooling and Emacs.
DEFAULT_SUFFIX = ".P"
# Recognized suffixes (case-insensitive except where noted).
_FIXED_SUFFIXES = frozenset({".p", ".protel", ".pt", ".ptl"})
# PLS edition suffix: .AA01 .. .ZZ99 (two letters + two digits). # PLS edition suffix: .AA01 .. .ZZ99 (two letters + two digits).
_PLS_SUFFIX_RE = re.compile(r"\.[A-Za-z]{2}\d{2}$") _PLS_SUFFIX_RE = re.compile(r"\.[A-Za-z]{2}\d{2}$")
PLS_SUFFIX_DESCRIPTION = ".AA01 through .ZZ99 (two letters + two digits)" PLS_SUFFIX_DESCRIPTION = ".AA01 through .ZZ99 (two letters + two digits)"
# USES module lookup order when the section index has no entry.
_USES_SUFFIXES = (DEFAULT_SUFFIX, ".protel", ".pt", ".ptl")
def is_pls_suffix(suffix: str) -> bool: def is_pls_suffix(suffix: str) -> bool:
"""True when suffix matches legacy PLS edition form (e.g. .AA01, .aa01).""" """True when suffix matches legacy PLS edition form (e.g. .AA01, .aa01)."""
@@ -32,6 +39,12 @@ def is_protel_source(path: str | Path) -> bool:
def format_suffix_list() -> str: def format_suffix_list() -> str:
"""Human-readable suffix list for CLI messages.""" """Human-readable suffix list for CLI messages (.P listed first as default)."""
fixed = ", ".join(sorted(_FIXED_SUFFIXES)) others = sorted(s for s in _FIXED_SUFFIXES if s.lower() != DEFAULT_SUFFIX.lower())
fixed = f"{DEFAULT_SUFFIX} (default), " + ", ".join(others)
return f"{fixed}, {PLS_SUFFIX_DESCRIPTION}" return f"{fixed}, {PLS_SUFFIX_DESCRIPTION}"
def uses_module_candidates(module_name: str) -> list[Path]:
"""Candidate filenames for USES module resolution (stem only; caller adds directory)."""
return [Path(f"{module_name}{suffix}") for suffix in _USES_SUFFIXES]
+6 -5
View File
@@ -6,7 +6,7 @@ import sys
from pathlib import Path from pathlib import Path
from . import ast_nodes as ast from . import ast_nodes as ast
from .extensions import is_protel_source from .extensions import is_protel_source, uses_module_candidates
from .parser import parse_protel from .parser import parse_protel
from .transpiler import TranspileError from .transpiler import TranspileError
@@ -59,9 +59,10 @@ def _find_module_path(
if module_name in index: if module_name in index:
return index[module_name] return index[module_name]
for base in _search_dirs(source_path): for base in _search_dirs(source_path):
candidate = base / f"{module_name}.protel" for candidate in uses_module_candidates(module_name):
if candidate.is_file(): path = base / candidate
return candidate.resolve() if path.is_file():
return path.resolve()
return None return None
@@ -133,7 +134,7 @@ def resolve_compilation_unit(
path = _find_module_path(module_name, source_path=source_path, index=index) path = _find_module_path(module_name, source_path=source_path, index=index)
if path is None: if path is None:
print( print(
f"protel: warning: USES module {module_name!r} not found; " f"Pc: warning: USES module {module_name!r} not found; "
f"skipping embed", f"skipping embed",
file=sys.stderr, file=sys.stderr,
) )
+5 -5
View File
@@ -36,7 +36,7 @@ class TypeContext:
class CTranspiler: class CTranspiler:
def __init__(self, *, classical: bool = False, source_name: str = "input.protel"): def __init__(self, *, classical: bool = False, source_name: str = "input.P"):
self.classical = classical self.classical = classical
self.source_name = source_name self.source_name = source_name
self.types = TypeContext() self.types = TypeContext()
@@ -747,13 +747,13 @@ class CTranspiler:
if protel_str is not None: if protel_str is not None:
msg = ( msg = (
f"protel: warning: call to {proc_name} uses a PROTEL string without " f"Pc: warning: call to {proc_name} uses a PROTEL string without "
f"an explicit NUL (0) suffix; append ', 0' in a char tuple for C " f"an explicit NUL (0) suffix; append ', 0' in a char tuple for C "
f"interoperability" f"interoperability"
) )
else: else:
msg = ( msg = (
f"protel: warning: call to {proc_name} uses a char tuple without " f"Pc: warning: call to {proc_name} uses a char tuple without "
f"a trailing 0 byte for C interoperability" f"a trailing 0 byte for C interoperability"
) )
print(msg, file=sys.stderr) print(msg, file=sys.stderr)
@@ -796,7 +796,7 @@ def transpile_to_c(
compilation_unit, compilation_unit,
*, *,
classical: bool = False, classical: bool = False,
source_name: str = "input.protel", source_name: str = "input.P",
source_path: "Path | None" = None, source_path: "Path | None" = None,
) -> str: ) -> str:
from pathlib import Path from pathlib import Path
@@ -815,7 +815,7 @@ def transpile_to_c(
return CTranspiler(classical=classical, source_name=source_name).transpile(compilation_unit) return CTranspiler(classical=classical, source_name=source_name).transpile(compilation_unit)
def transpile_file(source: str, *, classical: bool = False, source_name: str = "input.protel") -> str: def transpile_file(source: str, *, classical: bool = False, source_name: str = "input.P") -> str:
from .parser import parse_protel from .parser import parse_protel
tree = parse_protel(source, classical=classical) tree = parse_protel(source, classical=classical)
+2 -2
View File
@@ -36,7 +36,7 @@ class TypeInfo:
class TypeChecker: class TypeChecker:
def __init__(self, *, source_name: str = "input.protel"): def __init__(self, *, source_name: str = "input.P"):
self.source_name = source_name self.source_name = source_name
self.types = TypeContext() self.types = TypeContext()
self._scopes: list[dict[str, TypeInfo]] = [{}] self._scopes: list[dict[str, TypeInfo]] = [{}]
@@ -333,6 +333,6 @@ class TypeChecker:
def check_types( def check_types(
compilation_unit: list[ast.Section], compilation_unit: list[ast.Section],
*, *,
source_name: str = "input.protel", source_name: str = "input.P",
) -> None: ) -> None:
TypeChecker(source_name=source_name).check(compilation_unit) TypeChecker(source_name=source_name).check(compilation_unit)
+75 -75
View File
@@ -10,100 +10,100 @@ REF = EXAMPLES / "ref"
# Every numbered Reference Manual section maps to at least one example or test corpus file. # Every numbered Reference Manual section maps to at least one example or test corpus file.
REFERENCE_MANUAL_SECTIONS: dict[str, list[str]] = { REFERENCE_MANUAL_SECTIONS: dict[str, list[str]] = {
"1.0": ["ref/ref_1_0_introduction.protel"], "1.0": ["ref/ref_1_0_introduction.P"],
"2.0": ["ref/ref_9_1_expressions.protel"], "2.0": ["ref/ref_9_1_expressions.P"],
"3.0": ["ref/ref_3_0_lexical.protel"], "3.0": ["ref/ref_3_0_lexical.P"],
"3.1": ["ref/ref_3_0_lexical.protel"], "3.1": ["ref/ref_3_0_lexical.P"],
"3.2": ["ref/ref_3_0_lexical.protel"], "3.2": ["ref/ref_3_0_lexical.P"],
"3.3": ["ref/ref_3_0_lexical.protel"], "3.3": ["ref/ref_3_0_lexical.P"],
"3.4": ["ref/ref_3_0_lexical.protel"], "3.4": ["ref/ref_3_0_lexical.P"],
"4.0": ["ref/ref_4_0_data_elements.protel"], "4.0": ["ref/ref_4_0_data_elements.P"],
"4.1": ["ref/ref_4_0_data_elements.protel"], "4.1": ["ref/ref_4_0_data_elements.P"],
"4.2": ["ref/ref_4_0_data_elements.protel"], "4.2": ["ref/ref_4_0_data_elements.P"],
"4.3": ["ref/ref_4_0_data_elements.protel"], "4.3": ["ref/ref_4_0_data_elements.P"],
"4.4": ["ref/ref_4_0_data_elements.protel"], "4.4": ["ref/ref_4_0_data_elements.P"],
"4.5": ["ref/ref_4_0_data_elements.protel"], "4.5": ["ref/ref_4_0_data_elements.P"],
"5.0": [ "5.0": [
"ref/ref_5_0_compilation_unit.protel", "ref/ref_5_0_compilation_unit.P",
"ref/ref_5_0_directives.aa01", "ref/ref_5_0_directives.aa01",
"Hello.aa01", "Hello.aa01",
], ],
"6.0": ["ref/ref_6_0_module_types.protel"], "6.0": ["ref/ref_6_0_module_types.P"],
"7.0": ["ref/ref_7_0_declarations.protel"], "7.0": ["ref/ref_7_0_declarations.P"],
"7.1": ["ref/ref_7_1_1_simple_types.protel", "ref/ref_7_1_2_aggregates.protel"], "7.1": ["ref/ref_7_1_1_simple_types.P", "ref/ref_7_1_2_aggregates.P"],
"7.1.1": ["ref/ref_7_1_1_simple_types.protel"], "7.1.1": ["ref/ref_7_1_1_simple_types.P"],
"7.1.1.1": ["ref/ref_7_1_1_simple_types.protel"], "7.1.1.1": ["ref/ref_7_1_1_simple_types.P"],
"7.1.1.2": ["intro_2_1_types.protel"], "7.1.1.2": ["intro_2_1_types.P"],
"7.1.1.3": ["ref/ref_7_1_1_simple_types.protel", "intro_2_1_types.protel"], "7.1.1.3": ["ref/ref_7_1_1_simple_types.P", "intro_2_1_types.P"],
"7.1.1.4": ["ref/ref_7_1_1_simple_types.protel"], "7.1.1.4": ["ref/ref_7_1_1_simple_types.P"],
"7.1.1.5": ["ref/ref_7_1_1_simple_types.protel"], "7.1.1.5": ["ref/ref_7_1_1_simple_types.P"],
"7.1.2": ["ref/ref_7_1_2_aggregates.protel"], "7.1.2": ["ref/ref_7_1_2_aggregates.P"],
"7.1.2.1": ["ref/ref_7_1_2_aggregates.protel"], "7.1.2.1": ["ref/ref_7_1_2_aggregates.P"],
"7.1.2.2": ["ref/ref_7_1_2_aggregates.protel", "ref_8_1_task_block_struct.protel"], "7.1.2.2": ["ref/ref_7_1_2_aggregates.P", "ref_8_1_task_block_struct.P"],
"7.1.2.3": ["intro_2_1_types.protel", "intro_3_2_6_sum_table.protel"], "7.1.2.3": ["intro_2_1_types.P", "intro_3_2_6_sum_table.P"],
"7.1.2.4": ["intro_2_1_types.protel"], "7.1.2.4": ["intro_2_1_types.P"],
"7.1.2.5": ["ref/ref_7_1_2_aggregates.protel"], "7.1.2.5": ["ref/ref_7_1_2_aggregates.P"],
"7.1.3": ["ref/ref_7_1_3_procedures.protel"], "7.1.3": ["ref/ref_7_1_3_procedures.P"],
"7.1.3.1": ["ref/ref_7_1_3_procedures.protel"], "7.1.3.1": ["ref/ref_7_1_3_procedures.P"],
"7.1.3.2": ["ref/ref_7_1_3_procedures.protel"], "7.1.3.2": ["ref/ref_7_1_3_procedures.P"],
"7.2": ["ref/ref_7_2_data_declarations.protel"], "7.2": ["ref/ref_7_2_data_declarations.P"],
"7.2.1": ["ref/ref_7_2_data_declarations.protel"], "7.2.1": ["ref/ref_7_2_data_declarations.P"],
"7.2.2": ["intro_2_2_calculate_average.protel"], "7.2.2": ["intro_2_2_calculate_average.P"],
"7.2.3": ["ref/ref_7_2_data_declarations.protel"], "7.2.3": ["ref/ref_7_2_data_declarations.P"],
"7.3": ["ref/ref_7_3_overlays.protel"], "7.3": ["ref/ref_7_3_overlays.P"],
"8.0": ["ref/ref_8_0_scope.protel"], "8.0": ["ref/ref_8_0_scope.P"],
"8.1": ["ref/ref_8_0_scope.protel"], "8.1": ["ref/ref_8_0_scope.P"],
"8.2": ["ref/ref_8_0_scope.protel"], "8.2": ["ref/ref_8_0_scope.P"],
"9.0": ["ref/ref_9_0_statements.protel"], "9.0": ["ref/ref_9_0_statements.P"],
"9.1": ["ref/ref_9_1_expressions.protel"], "9.1": ["ref/ref_9_1_expressions.P"],
"9.1.1": ["ref/ref_9_1_expressions.protel"], "9.1.1": ["ref/ref_9_1_expressions.P"],
"9.1.1.1": ["ref/ref_4_0_data_elements.protel"], "9.1.1.1": ["ref/ref_4_0_data_elements.P"],
"9.1.1.2": ["ref/ref_9_1_expressions.protel"], "9.1.1.2": ["ref/ref_9_1_expressions.P"],
"9.1.1.3": ["ref/ref_7_1_3_procedures.protel"], "9.1.1.3": ["ref/ref_7_1_3_procedures.P"],
"9.1.2": ["ref/ref_9_1_expressions.protel"], "9.1.2": ["ref/ref_9_1_expressions.P"],
"9.2": ["ref/ref_9_2_return.protel", "intro_5_5_2_args_exit.protel"], "9.2": ["ref/ref_9_2_return.P", "intro_5_5_2_args_exit.P"],
"9.3": ["ref/ref_9_3_if.protel"], "9.3": ["ref/ref_9_3_if.P"],
"9.4": ["ref/ref_9_4_case.protel", "intro_3_2_4_case.protel"], "9.4": ["ref/ref_9_4_case.P", "intro_3_2_4_case.P"],
"9.5": ["ref/ref_9_5_select.protel"], "9.5": ["ref/ref_9_5_select.P"],
"9.6": ["ref/ref_9_6_exit.protel"], "9.6": ["ref/ref_9_6_exit.P"],
"9.7": [ "9.7": [
"ref/ref_9_7_iterative.protel", "ref/ref_9_7_iterative.P",
"intro_1_3_factorial.protel", "intro_1_3_factorial.P",
"intro_1_3_factorial_cli.protel", "intro_1_3_factorial_cli.P",
"intro_3_2_6_sum_table.protel", "intro_3_2_6_sum_table.P",
], ],
"10.0": ["ref/ref_10_0_bind_with.protel"], "10.0": ["ref/ref_10_0_bind_with.P"],
"11.0": ["ref/ref_11_0_type_compat.protel"], "11.0": ["ref/ref_11_0_type_compat.P"],
"11.1": ["ref/ref_11_0_type_compat.protel"], "11.1": ["ref/ref_11_0_type_compat.P"],
"11.2": ["ref/ref_11_0_type_compat.protel"], "11.2": ["ref/ref_11_0_type_compat.P"],
"11.3": ["ref/ref_11_0_type_compat.protel"], "11.3": ["ref/ref_11_0_type_compat.P"],
"12.0": ["ref/ref_12_0_intrinsic.protel"], "12.0": ["ref/ref_12_0_intrinsic.P"],
"13.0": [ "13.0": [
"ref/ref_13_0_descriptors.protel", "ref/ref_13_0_descriptors.P",
"interop/protel_for_python.protel", "interop/protel_for_python.P",
"interop/protel_calls_python.protel", "interop/protel_calls_python.P",
"Hello.protel", "Hello.P",
], ],
"14.0": ["ref/ref_14_0_keyword_exercise.protel"], "14.0": ["ref/ref_14_0_keyword_exercise.P"],
"15.0": ["tests/test_parser.py"], "15.0": ["tests/test_parser.py"],
"16.0": ["tests/ref_manual_manifest.py"], "16.0": ["tests/ref_manual_manifest.py"],
"OO": ["ref/ref_oo_classes.protel", "ref_oo_class_with_var.protel", "ref_oo_class_method_invoke.protel"], "OO": ["ref/ref_oo_classes.P", "ref_oo_class_with_var.P", "ref_oo_class_method_invoke.P"],
} }
# Keywords exercised outside .protel examples (preprocessor / tooling). # Keywords exercised outside .P examples (preprocessor / tooling).
KEYWORD_EXTERNAL_SOURCES: dict[str, list[str]] = { KEYWORD_EXTERNAL_SOURCES: dict[str, list[str]] = {
"$EJECT": ["ref/ref_5_0_directives.aa01", "tests/test_pb.py"], "$EJECT": ["ref/ref_5_0_directives.aa01", "tests/test_pb.py"],
"$LI": ["ref/ref_5_0_directives.aa01", "vdi.aa01", "tests/test_pb.py"], "$LI": ["ref/ref_5_0_directives.aa01", "vdi.aa01", "tests/test_pb.py"],
"$OBJECT": ["ref/ref_oo_classes.protel", "ref_oo_class_with_var.protel"], "$OBJECT": ["ref/ref_oo_classes.P", "ref_oo_class_with_var.P"],
"$REFDESC": ["ref/ref_9_1_expressions.protel"], "$REFDESC": ["ref/ref_9_1_expressions.P"],
"$TYPEDESC": ["ref/ref_9_1_expressions.protel"], "$TYPEDESC": ["ref/ref_9_1_expressions.P"],
"$UNIVERSAL_PTR": ["ref/ref_9_1_expressions.protel"], "$UNIVERSAL_PTR": ["ref/ref_9_1_expressions.P"],
"$VARDESC": ["ref/ref_9_1_expressions.protel"], "$VARDESC": ["ref/ref_9_1_expressions.P"],
} }
# All ref_* and intro_* example files that must parse. # All ref_* and intro_* example files that must parse.
REF_EXAMPLE_SOURCES: list[str] = sorted( REF_EXAMPLE_SOURCES: list[str] = sorted(
p.relative_to(EXAMPLES).as_posix() p.relative_to(EXAMPLES).as_posix()
for p in EXAMPLES.rglob("*.protel") for p in EXAMPLES.rglob("*.P")
if p.is_file() and not p.name.endswith("~") if p.is_file() and not p.name.endswith("~")
) )
+2 -2
View File
@@ -10,8 +10,8 @@ from src.parser import parse_protel
from src.transpiler import TranspileError from src.transpiler import TranspileError
ROOT = Path(__file__).resolve().parent.parent ROOT = Path(__file__).resolve().parent.parent
EXAMPLE = ROOT / "examples" / "intro_5_5_2_args_exit.protel" EXAMPLE = ROOT / "examples" / "intro_5_5_2_args_exit.P"
PROTEL = ROOT / "protel" PROTEL = ROOT / "Pc"
PYTHON = ROOT / ".venv" / "bin" / "python" PYTHON = ROOT / ".venv" / "bin" / "python"
+14 -14
View File
@@ -10,26 +10,26 @@ from src.cpp_transpiler import transpile_to_cpp
ROOT = Path(__file__).resolve().parent.parent ROOT = Path(__file__).resolve().parent.parent
EXAMPLES = ROOT / "examples" EXAMPLES = ROOT / "examples"
PROTEL = ROOT / "protel" PROTEL = ROOT / "Pc"
def _transpile_hello() -> str: 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) 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(): def test_cpp_hello_emits_namespace_and_main():
cpp = _transpile_hello() cpp = _transpile_hello()
assert "namespace protel_generated" in cpp assert "namespace protel_generated" in cpp
assert "namespace Hello" 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 "void Start()" in cpp
assert 'extern "C"' in cpp assert 'extern "C"' in cpp
assert "void writeln(const char* msg)" in cpp assert "void writeln(const char* msg)" in cpp
assert "<iostream>" not in cpp assert "<iostream>" not in cpp
assert "IS INTRINSIC" not 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.protel").read_text(encoding="utf-8") assert "EXTERNAL" in (EXAMPLES / "Hello.P").read_text(encoding="utf-8")
assert "int main()" in cpp assert "int main()" in cpp
assert "protel_generated::Hello::Start()" in cpp assert "protel_generated::Hello::Start()" in cpp
assert "(const char[]){" 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(): def test_cpp_hello_class_uses_this():
source = (EXAMPLES / "ref_oo_class_with_var.protel").read_text(encoding="utf-8") 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.protel") cpp = transpile_to_cpp(parse_protel(source), source_name="ref_oo_class_with_var.P")
assert "class class_with_var" in cpp assert "class class_with_var" in cpp
assert "static int16_t class_var" in cpp assert "static int16_t class_var" in cpp
assert "class_with_var::class_method" 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(ROOT / ".venv/bin/python"),
str(PROTEL), str(PROTEL),
str(EXAMPLES / "Hello.protel"), str(EXAMPLES / "Hello.P"),
"-o", "-o",
str(ROOT / "build" / "Hello"), str(ROOT / "build" / "Hello"),
"--run", "--run",
@@ -67,8 +67,8 @@ def test_hello_compiles_and_runs():
def test_hello_shebang_direct_execution(): def test_hello_shebang_direct_execution():
hello = EXAMPLES / "Hello.protel" hello = EXAMPLES / "Hello.P"
assert hello.read_text(encoding="utf-8").startswith("#!/usr/bin/env protel-run") assert hello.read_text(encoding="utf-8").startswith("#!/usr/bin/env Pc!")
mode = hello.stat().st_mode mode = hello.stat().st_mode
hello.chmod(mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) hello.chmod(mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
env = dict(os.environ) env = dict(os.environ)
@@ -86,7 +86,7 @@ def test_hello_shebang_direct_execution():
def test_hello_compiles_and_runs_a_out(): def test_hello_compiles_and_runs_a_out():
result = subprocess.run( 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, capture_output=True,
text=True, text=True,
cwd=ROOT, cwd=ROOT,
@@ -99,11 +99,11 @@ def test_hello_compiles_and_runs_a_out():
def test_cpp_oo_examples_compile(): def test_cpp_oo_examples_compile():
from src.compile import check_cpp_syntax 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 source = EXAMPLES / name
tree = parse_protel(source.read_text(encoding="utf-8")) tree = parse_protel(source.read_text(encoding="utf-8"))
cpp = transpile_to_cpp(tree, source_name=name) 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.parent.mkdir(parents=True, exist_ok=True)
cpp_path.write_text(cpp, encoding="utf-8") cpp_path.write_text(cpp, encoding="utf-8")
check_cpp_syntax(cpp_path) check_cpp_syntax(cpp_path)
+5 -2
View File
@@ -13,14 +13,14 @@ from src.parser import parse_protel
ROOT = Path(__file__).resolve().parent.parent ROOT = Path(__file__).resolve().parent.parent
EXAMPLES = ROOT / "examples" EXAMPLES = ROOT / "examples"
MODE_EL = ROOT / "emacs" / "protel-mode.el" MODE_EL = ROOT / "emacs" / "protel-mode.el"
PROTEL = ROOT / "protel" PROTEL = ROOT / "Pc"
@pytest.mark.parametrize( @pytest.mark.parametrize(
"name,expected", "name,expected",
[ [
("Hello.protel", True),
("Hello.P", True), ("Hello.P", True),
("Hello.protel", True),
("Hello.p", True), ("Hello.p", True),
("Hello.pt", True), ("Hello.pt", True),
("Hello.ptl", True), ("Hello.ptl", True),
@@ -42,11 +42,14 @@ def test_is_protel_source_recognizes_fixed_and_pls_suffixes(name, expected):
def test_is_pls_suffix_matches_letter_digit_pattern(): def test_is_pls_suffix_matches_letter_digit_pattern():
assert is_pls_suffix(".aa01") assert is_pls_suffix(".aa01")
assert is_pls_suffix(".AB99") assert is_pls_suffix(".AB99")
assert not is_pls_suffix(".P")
assert not is_pls_suffix(".protel") assert not is_pls_suffix(".protel")
def test_format_suffix_list_mentions_pls_range(): def test_format_suffix_list_mentions_pls_range():
text = format_suffix_list() text = format_suffix_list()
assert ".P" in text
assert "default" in text
assert ".AA01" in text assert ".AA01" in text
assert ".ZZ99" in text assert ".ZZ99" in text
+2 -2
View File
@@ -21,7 +21,7 @@ SECTION Hello;
DCL Start PROC() IS ENTRY; DCL Start PROC() IS ENTRY;
DCL Start PROC() IS BLOCK ENDBLOCK; DCL Start PROC() IS BLOCK ENDBLOCK;
""" """
cpp = transpile_to_cpp(parse_protel(source), source_name="Hello.protel") cpp = transpile_to_cpp(parse_protel(source), source_name="Hello.P")
assert "/* ENTRY Start */" in cpp assert "/* ENTRY Start */" in cpp
assert "void Start()" in cpp assert "void Start()" in cpp
assert "int main()" in cpp assert "int main()" in cpp
@@ -34,7 +34,7 @@ def test_procedure_named_main_without_entry_has_no_c_main():
SECTION demo; SECTION demo;
DCL main PROC() IS BLOCK ENDBLOCK; DCL main PROC() IS BLOCK ENDBLOCK;
""" """
cpp = transpile_to_cpp(parse_protel(source), source_name="demo.protel") cpp = transpile_to_cpp(parse_protel(source), source_name="demo.P")
assert "void main()" in cpp assert "void main()" in cpp
assert "int main()" not in cpp assert "int main()" not in cpp
+3 -3
View File
@@ -7,9 +7,9 @@ from src.cpp_transpiler import transpile_to_cpp
from src.parser import parse_protel from src.parser import parse_protel
ROOT = Path(__file__).resolve().parent.parent ROOT = Path(__file__).resolve().parent.parent
EXAMPLE = ROOT / "examples" / "intro_1_3_factorial_cli.protel" EXAMPLE = ROOT / "examples" / "intro_1_3_factorial_cli.P"
FACTORIAL = ROOT / "examples" / "intro_1_3_factorial.protel" FACTORIAL = ROOT / "examples" / "intro_1_3_factorial.P"
PROTEL = ROOT / "protel" PROTEL = ROOT / "Pc"
PYTHON = ROOT / ".venv" / "bin" / "python" PYTHON = ROOT / ".venv" / "bin" / "python"
+68
View File
@@ -0,0 +1,68 @@
"""System-wide install Makefile targets (staged under DESTDIR)."""
import os
import shutil
import subprocess
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
def _make(*targets: str, env: dict | None = None) -> subprocess.CompletedProcess:
run_env = os.environ.copy()
if env:
run_env.update(env)
return subprocess.run(
["make", *targets],
cwd=ROOT,
capture_output=True,
text=True,
env=run_env,
)
def test_install_system_staged_layout():
stage = ROOT / "build" / "install-stage"
if stage.exists():
shutil.rmtree(stage)
prefix = "/usr/local/protel"
result = _make(
"install-system",
env={
"DESTDIR": str(stage),
"SYSPREFIX": prefix,
"SYSBINDIR": "/usr/local/bin",
"SYSMANPREFIX": "/usr/local/share/man",
},
)
assert result.returncode == 0, result.stderr + result.stdout
toolkit = stage / prefix.lstrip("/")
bindir = stage / "usr/local/bin"
mandir = stage / "usr/local/share/man/man1"
for name in ("Pc", "Pb", "Pc!"):
tool = toolkit / name
assert tool.is_file(), f"missing {tool}"
assert os.access(tool, os.X_OK)
link = bindir / name
assert link.is_symlink(), f"missing symlink {link}"
assert os.readlink(link) == f"{prefix}/{name}"
assert (toolkit / "src" / "parser.py").is_file()
assert (toolkit / "examples" / "Hello.P").is_file()
assert (toolkit / "emacs" / "protel-mode.el").is_file()
assert (toolkit / ".venv" / "bin" / "python3").is_file()
assert (mandir / "Pc.1").is_file()
assert (mandir / "Pb.1").is_file()
shutil.rmtree(stage)
def test_makefile_declares_install_system_target():
makefile = (ROOT / "Makefile").read_text(encoding="utf-8")
assert "install-system:" in makefile
assert "install-man-system:" in makefile
assert "uninstall-system:" in makefile
assert "SYSPREFIX ?=" in makefile
assert "/usr/local/protel" in makefile
+4 -4
View File
@@ -24,8 +24,8 @@ def _java_runtime_available() -> bool:
def test_protel_calls_java_emits_external_java_greet(): def test_protel_calls_java_emits_external_java_greet():
source = (INTEROP / "protel_calls_java.protel").read_text(encoding="utf-8") source = (INTEROP / "protel_calls_java.P").read_text(encoding="utf-8")
cpp = transpile_to_cpp(parse_protel(source), source_name="protel_calls_java.protel") cpp = transpile_to_cpp(parse_protel(source), source_name="protel_calls_java.P")
assert 'extern "C"' in cpp assert 'extern "C"' in cpp
assert "void java_greet(const char* name, int16_t value)" in cpp assert "void java_greet(const char* name, int16_t value)" in cpp
assert "java_greet(" in cpp assert "java_greet(" in cpp
@@ -33,8 +33,8 @@ def test_protel_calls_java_emits_external_java_greet():
def test_protel_for_java_exports_c_linkage(): def test_protel_for_java_exports_c_linkage():
source = (INTEROP / "protel_for_java.protel").read_text(encoding="utf-8") source = (INTEROP / "protel_for_java.P").read_text(encoding="utf-8")
cpp = transpile_to_cpp(parse_protel(source), source_name="protel_for_java.protel") cpp = transpile_to_cpp(parse_protel(source), source_name="protel_for_java.P")
assert "/* EXPORT protel_add" in cpp assert "/* EXPORT protel_add" in cpp
assert "int16_t protel_add(int16_t a, int16_t b)" in cpp assert "int16_t protel_add(int16_t a, int16_t b)" in cpp
assert "return (a + b)" in cpp assert "return (a + b)" in cpp
+55
View File
@@ -0,0 +1,55 @@
"""Manual page presence and basic content checks."""
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
MAN = ROOT / "man"
def test_pc_man_page_exists_with_required_sections():
text = (MAN / "Pc.1").read_text(encoding="utf-8")
assert '.TH Pc 1' in text
for section in (
"SYNOPSIS",
"DESCRIPTION",
"OPTIONS",
"SHEBANG RUNNER",
"EXIT STATUS",
"EXAMPLES",
"SEE ALSO",
):
assert f".SH {section}" in text or section in text
assert "Pc!" in text
for option in (
"\\-\\-run",
"\\-\\-classical",
"\\-\\-emit\\-c",
"\\-\\-parse\\-only",
"\\-\\-compile",
"\\-\\-keep",
):
assert option in text
def test_pb_man_page_exists_with_required_sections():
text = (MAN / "Pb.1").read_text(encoding="utf-8")
assert '.TH Pb 1' in text
for section in (
"SYNOPSIS",
"DESCRIPTION",
"OPTIONS",
"BEHAVIOR",
"EXIT STATUS",
"EXAMPLES",
"SEE ALSO",
):
assert f".SH {section}" in text or f'.SH "{section}"' in text
assert "\\-\\-bold" in text
assert "shebang" in text.lower()
def test_install_man_layout_after_make():
man1 = MAN / "man1"
# install-man may not have been run; source pages must remain in man/
assert (MAN / "Pc.1").is_file()
assert (MAN / "Pb.1").is_file()
+10 -10
View File
@@ -24,7 +24,7 @@ def test_parse_section_uses_and_of():
def test_parse_factorial_example(): def test_parse_factorial_example():
tree = parse_protel(_read("intro_1_3_factorial.protel")) tree = parse_protel(_read("intro_1_3_factorial.P"))
assert len(tree) == 1 assert len(tree) == 1
section = tree[0] section = tree[0]
assert isinstance(section, ast.Section) assert isinstance(section, ast.Section)
@@ -38,7 +38,7 @@ def test_parse_factorial_example():
def test_parse_types_example(): def test_parse_types_example():
tree = parse_protel(_read("intro_2_1_types.protel")) tree = parse_protel(_read("intro_2_1_types.P"))
section = tree[0] section = tree[0]
type_names = {d.names[0] for d in section.declarations if isinstance(d, ast.TypeDecl)} type_names = {d.names[0] for d in section.declarations if isinstance(d, ast.TypeDecl)}
assert "integer" in type_names assert "integer" in type_names
@@ -47,7 +47,7 @@ def test_parse_types_example():
def test_parse_calculate_average(): def test_parse_calculate_average():
tree = parse_protel(_read("intro_2_2_calculate_average.protel")) tree = parse_protel(_read("intro_2_2_calculate_average.P"))
proc = next( proc = next(
d for d in tree[0].declarations if isinstance(d, ast.ProcDecl) d for d in tree[0].declarations if isinstance(d, ast.ProcDecl)
) )
@@ -69,7 +69,7 @@ def test_classical_keyword_casing():
def test_parse_case_statement(): def test_parse_case_statement():
tree = parse_protel(_read("intro_3_2_4_case.protel")) tree = parse_protel(_read("intro_3_2_4_case.P"))
proc = next(d for d in tree[0].declarations if isinstance(d, ast.ProcDecl)) proc = next(d for d in tree[0].declarations if isinstance(d, ast.ProcDecl))
case_stmt = proc.body.statements[0] case_stmt = proc.body.statements[0]
assert isinstance(case_stmt, ast.CaseStmt) assert isinstance(case_stmt, ast.CaseStmt)
@@ -78,7 +78,7 @@ def test_parse_case_statement():
def test_parse_for_loop_with_upb(): def test_parse_for_loop_with_upb():
tree = parse_protel(_read("intro_3_2_6_sum_table.protel")) tree = parse_protel(_read("intro_3_2_6_sum_table.P"))
proc = next(d for d in tree[0].declarations if isinstance(d, ast.ProcDecl)) proc = next(d for d in tree[0].declarations if isinstance(d, ast.ProcDecl))
for_stmt = next(s for s in proc.body.statements if isinstance(s, ast.ForStmt)) for_stmt = next(s for s in proc.body.statements if isinstance(s, ast.ForStmt))
assert for_stmt.var == "i" assert for_stmt.var == "i"
@@ -87,7 +87,7 @@ def test_parse_for_loop_with_upb():
def test_parse_struct_type(): def test_parse_struct_type():
tree = parse_protel(_read("ref_8_1_task_block_struct.protel")) tree = parse_protel(_read("ref_8_1_task_block_struct.P"))
task_block = next( task_block = next(
d for d in tree[0].declarations d for d in tree[0].declarations
if isinstance(d, ast.TypeDecl) and d.names == ["task_block"] if isinstance(d, ast.TypeDecl) and d.names == ["task_block"]
@@ -97,13 +97,13 @@ def test_parse_struct_type():
def test_var_init_not_wrapped_in_tree(): def test_var_init_not_wrapped_in_tree():
tree = parse_protel(_read("intro_2_1_types.protel")) tree = parse_protel(_read("intro_2_1_types.P"))
primes = next(d for d in tree[0].declarations if isinstance(d, ast.VarDecl) and "primes" in d.names) primes = next(d for d in tree[0].declarations if isinstance(d, ast.VarDecl) and "primes" in d.names)
assert isinstance(primes.init, ast.TupleLit) assert isinstance(primes.init, ast.TupleLit)
def test_parse_class_type_with_operations(): def test_parse_class_type_with_operations():
tree = parse_protel(_read("ref_oo_class_with_var.protel")) tree = parse_protel(_read("ref_oo_class_with_var.P"))
section = tree[0] section = tree[0]
assert section.section_kind == "INTERFACE" assert section.section_kind == "INTERFACE"
class_decl = next( class_decl = next(
@@ -124,7 +124,7 @@ def test_parse_class_type_with_operations():
def test_parse_class_method_invocation(): def test_parse_class_method_invocation():
tree = parse_protel(_read("ref_oo_class_method_invoke.protel")) tree = parse_protel(_read("ref_oo_class_method_invoke.P"))
proc = next(d for d in tree[0].declarations if isinstance(d, ast.ProcDecl)) proc = next(d for d in tree[0].declarations if isinstance(d, ast.ProcDecl))
assert isinstance(proc.body.statements[0], ast.MethodCall) assert isinstance(proc.body.statements[0], ast.MethodCall)
assert proc.body.statements[0].name == "class_method" assert proc.body.statements[0].name == "class_method"
@@ -132,7 +132,7 @@ def test_parse_class_method_invocation():
def test_parse_self_member_assignment(): def test_parse_self_member_assignment():
tree = parse_protel(_read("ref_oo_class_with_var.protel")) tree = parse_protel(_read("ref_oo_class_with_var.P"))
impl = tree[0].class_impls[0] impl = tree[0].class_impls[0]
stmt = impl.declarations[0].body.statements[0] stmt = impl.declarations[0].body.statements[0]
assert isinstance(stmt, ast.AssignExpr) assert isinstance(stmt, ast.AssignExpr)
+2 -2
View File
@@ -34,9 +34,9 @@ def test_dollar_li_line_with_leading_whitespace():
def test_pb_preserves_shebang_first_line(): def test_pb_preserves_shebang_first_line():
pb = _load_pb() pb = _load_pb()
source = "#!/usr/bin/env protel-run\nsection s;\nDCL x BOOL;\n" source = "#!/usr/bin/env Pc!\nsection s;\nDCL x BOOL;\n"
result = pb.beautify_protel(source) result = pb.beautify_protel(source)
assert result.startswith("#!/usr/bin/env protel-run\n") assert result.startswith("#!/usr/bin/env Pc!\n")
assert "SECTION" in result assert "SECTION" in result
assert "DCL" in result assert "DCL" in result
+3 -3
View File
@@ -6,11 +6,11 @@ from src.parser import parse_protel
from src.preprocess import normalize_keywords, strip_shebang from src.preprocess import normalize_keywords, strip_shebang
ROOT = Path(__file__).resolve().parent.parent ROOT = Path(__file__).resolve().parent.parent
HELLO = ROOT / "examples" / "Hello.protel" HELLO = ROOT / "examples" / "Hello.P"
def test_strip_shebang_removes_first_line(): def test_strip_shebang_removes_first_line():
source = "#!/usr/bin/env -S protel --run --\nSECTION s;\n" source = "#!/usr/bin/env -S Pc --run --\nSECTION s;\n"
assert strip_shebang(source) == "SECTION s;\n" assert strip_shebang(source) == "SECTION s;\n"
@@ -20,7 +20,7 @@ def test_strip_shebang_passthrough_without_hash_bang():
def test_normalize_keywords_strips_shebang_before_parse(): def test_normalize_keywords_strips_shebang_before_parse():
source = "#!/usr/bin/env protel --run\n% hi\nSECTION s;\n" source = "#!/usr/bin/env Pc --run\n% hi\nSECTION s;\n"
norm = normalize_keywords(source) norm = normalize_keywords(source)
assert "#!" not in norm assert "#!" not in norm
assert "SECTION" in norm assert "SECTION" in norm
+4 -4
View File
@@ -15,8 +15,8 @@ INTEROP = ROOT / "examples" / "interop"
def test_protel_calls_python_emits_external_python_greet(): def test_protel_calls_python_emits_external_python_greet():
source = (INTEROP / "protel_calls_python.protel").read_text(encoding="utf-8") source = (INTEROP / "protel_calls_python.P").read_text(encoding="utf-8")
cpp = transpile_to_cpp(parse_protel(source), source_name="protel_calls_python.protel") cpp = transpile_to_cpp(parse_protel(source), source_name="protel_calls_python.P")
assert 'extern "C"' in cpp assert 'extern "C"' in cpp
assert "void python_greet(const char* name, int16_t value)" in cpp assert "void python_greet(const char* name, int16_t value)" in cpp
assert "python_greet(" in cpp assert "python_greet(" in cpp
@@ -24,8 +24,8 @@ def test_protel_calls_python_emits_external_python_greet():
def test_protel_for_python_exports_c_linkage(): def test_protel_for_python_exports_c_linkage():
source = (INTEROP / "protel_for_python.protel").read_text(encoding="utf-8") source = (INTEROP / "protel_for_python.P").read_text(encoding="utf-8")
cpp = transpile_to_cpp(parse_protel(source), source_name="protel_for_python.protel") cpp = transpile_to_cpp(parse_protel(source), source_name="protel_for_python.P")
assert "/* EXPORT protel_add" in cpp assert "/* EXPORT protel_add" in cpp
assert "int16_t protel_add(int16_t a, int16_t b)" in cpp assert "int16_t protel_add(int16_t a, int16_t b)" in cpp
assert "return (a + b)" in cpp assert "return (a + b)" in cpp
+1 -1
View File
@@ -28,7 +28,7 @@ _KEYWORD_BOUNDARY = re.compile(
def _corpus_files() -> list[Path]: def _corpus_files() -> list[Path]:
patterns = ( patterns = (
"examples/**/*.protel", "examples/**/*.P",
"examples/**/*.aa01", "examples/**/*.aa01",
"examples/**/*.P", "examples/**/*.P",
"vdi.aa01", "vdi.aa01",
+4 -4
View File
@@ -14,8 +14,8 @@ INTEROP = ROOT / "examples" / "interop"
def test_protel_calls_rust_emits_external_rust_greet(): def test_protel_calls_rust_emits_external_rust_greet():
source = (INTEROP / "protel_calls_rust.protel").read_text(encoding="utf-8") source = (INTEROP / "protel_calls_rust.P").read_text(encoding="utf-8")
cpp = transpile_to_cpp(parse_protel(source), source_name="protel_calls_rust.protel") cpp = transpile_to_cpp(parse_protel(source), source_name="protel_calls_rust.P")
assert 'extern "C"' in cpp assert 'extern "C"' in cpp
assert "void rust_greet(const char* name, int16_t value)" in cpp assert "void rust_greet(const char* name, int16_t value)" in cpp
assert "rust_greet(" in cpp assert "rust_greet(" in cpp
@@ -23,8 +23,8 @@ def test_protel_calls_rust_emits_external_rust_greet():
def test_protel_for_rust_exports_c_linkage(): def test_protel_for_rust_exports_c_linkage():
source = (INTEROP / "protel_for_rust.protel").read_text(encoding="utf-8") source = (INTEROP / "protel_for_rust.P").read_text(encoding="utf-8")
cpp = transpile_to_cpp(parse_protel(source), source_name="protel_for_rust.protel") cpp = transpile_to_cpp(parse_protel(source), source_name="protel_for_rust.P")
assert "/* EXPORT protel_add" in cpp assert "/* EXPORT protel_add" in cpp
assert "int16_t protel_add(int16_t a, int16_t b)" in cpp assert "int16_t protel_add(int16_t a, int16_t b)" in cpp
assert "return (a + b)" in cpp assert "return (a + b)" in cpp
+2 -2
View File
@@ -33,9 +33,9 @@ def test_string_without_nul_emits_no_trailing_zero():
def test_hello_uses_explicit_nul_suffix(): def test_hello_uses_explicit_nul_suffix():
source = (EXAMPLES / "Hello.protel").read_text(encoding="utf-8") source = (EXAMPLES / "Hello.P").read_text(encoding="utf-8")
assert "{'Hello, World!', 0}" in source assert "{'Hello, World!', 0}" in source
cpp = transpile_to_cpp(parse_protel(source), source_name="Hello.protel") cpp = transpile_to_cpp(parse_protel(source), source_name="Hello.P")
assert "(const char[]){" in cpp assert "(const char[]){" in cpp
assert "'!'" in cpp assert "'!'" in cpp
assert ", 0 }" in cpp assert ", 0 }" in cpp
+4 -4
View File
@@ -14,8 +14,8 @@ INTEROP = ROOT / "examples" / "interop"
def test_protel_calls_swift_emits_external_swift_greet(): def test_protel_calls_swift_emits_external_swift_greet():
source = (INTEROP / "protel_calls_swift.protel").read_text(encoding="utf-8") source = (INTEROP / "protel_calls_swift.P").read_text(encoding="utf-8")
cpp = transpile_to_cpp(parse_protel(source), source_name="protel_calls_swift.protel") cpp = transpile_to_cpp(parse_protel(source), source_name="protel_calls_swift.P")
assert 'extern "C"' in cpp assert 'extern "C"' in cpp
assert "void swift_greet(const char* name, int16_t value)" in cpp assert "void swift_greet(const char* name, int16_t value)" in cpp
assert "swift_greet(" in cpp assert "swift_greet(" in cpp
@@ -23,8 +23,8 @@ def test_protel_calls_swift_emits_external_swift_greet():
def test_protel_for_swift_exports_c_linkage(): def test_protel_for_swift_exports_c_linkage():
source = (INTEROP / "protel_for_swift.protel").read_text(encoding="utf-8") source = (INTEROP / "protel_for_swift.P").read_text(encoding="utf-8")
cpp = transpile_to_cpp(parse_protel(source), source_name="protel_for_swift.protel") cpp = transpile_to_cpp(parse_protel(source), source_name="protel_for_swift.P")
assert "/* EXPORT protel_add" in cpp assert "/* EXPORT protel_add" in cpp
assert "int16_t protel_add(int16_t a, int16_t b)" in cpp assert "int16_t protel_add(int16_t a, int16_t b)" in cpp
assert "return (a + b)" in cpp assert "return (a + b)" in cpp
+9 -9
View File
@@ -15,40 +15,40 @@ def _transpile_example(name: str) -> str:
def test_transpile_factorial_contains_procedure(): def test_transpile_factorial_contains_procedure():
c = _transpile_example("intro_1_3_factorial.protel") c = _transpile_example("intro_1_3_factorial.P")
assert "int16_t factorial(" in c assert "int16_t factorial(" in c
assert "while (" in c assert "while (" in c
assert "return result;" in c assert "return result;" in c
def test_transpile_types_emits_typedefs(): def test_transpile_types_emits_typedefs():
c = _transpile_example("intro_2_1_types.protel") c = _transpile_example("intro_2_1_types.P")
assert "typedef int16_t integer;" in c assert "typedef int16_t integer;" in c
assert "typedef int16_t digit_register[16];" in c assert "typedef int16_t digit_register[16];" in c
assert "seconds_per_hour" in c assert "seconds_per_hour" in c
def test_transpile_assignment_maps_arrow_to_equals(): def test_transpile_assignment_maps_arrow_to_equals():
c = _transpile_example("intro_2_2_calculate_average.protel") c = _transpile_example("intro_2_2_calculate_average.P")
assert "average =" in c assert "average =" in c
assert "return average;" in c assert "return average;" in c
def test_transpile_case_emits_switch(): def test_transpile_case_emits_switch():
c = _transpile_example("intro_3_2_4_case.protel") c = _transpile_example("intro_3_2_4_case.P")
assert "switch (n)" in c assert "switch (n)" in c
assert "case 0:" in c assert "case 0:" in c
assert "default:" not in c assert "default:" not in c
def test_transpile_for_emits_c_for_loop(): def test_transpile_for_emits_c_for_loop():
c = _transpile_example("intro_3_2_6_sum_table.protel") c = _transpile_example("intro_3_2_6_sum_table.P")
assert "for (int32_t i = 0;" in c assert "for (int32_t i = 0;" in c
assert "return sum;" in c assert "return sum;" in c
def test_transpile_struct_emits_fields(): def test_transpile_struct_emits_fields():
c = _transpile_example("ref_8_1_task_block_struct.protel") c = _transpile_example("ref_8_1_task_block_struct.P")
assert "typedef struct {" in c assert "typedef struct {" in c
assert "uint8_t priority;" in c assert "uint8_t priority;" in c
assert "uint8_t completed;" in c assert "uint8_t completed;" in c
@@ -56,7 +56,7 @@ def test_transpile_struct_emits_fields():
def test_transpile_class_type_emits_static_class_var(): def test_transpile_class_type_emits_static_class_var():
c = _transpile_example("ref_oo_class_with_var.protel") c = _transpile_example("ref_oo_class_with_var.P")
assert "typedef struct class_with_var_t" in c assert "typedef struct class_with_var_t" in c
assert "static int16_t class_with_var_class_var" in c assert "static int16_t class_with_var_class_var" in c
assert "void class_with_var_class_method(int16_t parameter)" in c assert "void class_with_var_class_method(int16_t parameter)" in c
@@ -64,12 +64,12 @@ def test_transpile_class_type_emits_static_class_var():
def test_transpile_class_method_invocation(): def test_transpile_class_method_invocation():
c = _transpile_example("ref_oo_class_method_invoke.protel") c = _transpile_example("ref_oo_class_method_invoke.P")
assert "class_with_class_method_class_method(5)" in c assert "class_with_class_method_class_method(5)" in c
assert "class_with_class_method_class_method(6)" in c assert "class_with_class_method_class_method(6)" in c
def test_transpile_emits_header(): def test_transpile_emits_header():
c = _transpile_example("intro_1_3_factorial.protel") c = _transpile_example("intro_1_3_factorial.P")
assert "Generated by PROTEL 2026 transpiler" in c assert "Generated by PROTEL 2026 transpiler" in c
assert "#include <stdint.h>" in c assert "#include <stdint.h>" in c
+13 -13
View File
@@ -19,15 +19,15 @@ def _read(name: str) -> str:
@pytest.mark.parametrize( @pytest.mark.parametrize(
"filename,message_fragment", "filename,message_fragment",
[ [
("err_assign_integer_to_char.protel", "cannot assign integer to char"), ("err_assign_integer_to_char.P", "cannot assign integer to char"),
( (
"err_assign_integer_to_packed_byte.protel", "err_assign_integer_to_packed_byte.P",
"packed byte-sized type", "packed byte-sized type",
), ),
("err_assign_integer_to_bool.protel", "cannot assign"), ("err_assign_integer_to_bool.P", "cannot assign"),
("err_constant_out_of_range.protel", "out of range"), ("err_constant_out_of_range.P", "out of range"),
("err_assign_incompatible_pointer.protel", "cannot assign"), ("err_assign_incompatible_pointer.P", "cannot assign"),
("err_return_type_mismatch.protel", "RETURN type"), ("err_return_type_mismatch.P", "RETURN type"),
], ],
) )
def test_error_examples_fail_type_check(filename: str, message_fragment: str): def test_error_examples_fail_type_check(filename: str, message_fragment: str):
@@ -38,9 +38,9 @@ def test_error_examples_fail_type_check(filename: str, message_fragment: str):
def test_ok_char_literal_transpiles(): def test_ok_char_literal_transpiles():
source = _read("ok_assign_char_literal.protel") source = _read("ok_assign_char_literal.P")
tree = parse_protel(source) tree = parse_protel(source)
cpp = transpile_to_cpp(tree, source_name="ok_assign_char_literal.protel") cpp = transpile_to_cpp(tree, source_name="ok_assign_char_literal.P")
assert "Generated by PROTEL" in cpp assert "Generated by PROTEL" in cpp
@@ -50,8 +50,8 @@ def test_protel_driver_reports_type_error():
result = subprocess.run( result = subprocess.run(
[ [
str(ROOT / ".venv" / "bin" / "python"), str(ROOT / ".venv" / "bin" / "python"),
str(ROOT / "protel"), str(ROOT / "Pc"),
str(ERRORS / "err_assign_integer_to_char.protel"), str(ERRORS / "err_assign_integer_to_char.P"),
"--parse-only", "--parse-only",
], ],
capture_output=True, capture_output=True,
@@ -63,13 +63,13 @@ def test_protel_driver_reports_type_error():
result = subprocess.run( result = subprocess.run(
[ [
str(ROOT / ".venv" / "bin" / "python"), str(ROOT / ".venv" / "bin" / "python"),
str(ROOT / "protel"), str(ROOT / "Pc"),
str(ERRORS / "err_assign_integer_to_char.protel"), str(ERRORS / "err_assign_integer_to_char.P"),
], ],
capture_output=True, capture_output=True,
text=True, text=True,
cwd=ROOT, cwd=ROOT,
) )
assert result.returncode == 1 assert result.returncode == 1
assert "protel: type error" in result.stderr assert "Pc: type error" in result.stderr
assert "cannot assign integer to char" in result.stderr assert "cannot assign integer to char" in result.stderr

Some files were not shown because too many files have changed in this diff Show More