Installation
py4 has no external runtime dependencies. You need make, a C compiler, and Python 3 (for the bootstrap compiler).
Prerequisites
- GCC or Clang
- GNU Make
- Python 3.9+
Build from source
git clone https://github.com/alekgreen/py4.gitcd py4makeThis produces a py4 binary in the project root.
Verify the build
./py4 --versionRunning the test suite
make testTests are end-to-end integration fixtures in tests/cases/. Each .p4 file has a matching .out (for expected stdout) or .err (for expected compile errors or runtime failures).
Compiling programs
py4 compiles to a native binary by default. The default C backend is GCC.
# Compile to native binary./py4 program.p4
# Specify output path./py4 -o out/program program.p4
# Use Clang instead of GCC./py4 --backend clang -o out/program program.p4
# Optimize for release (-O2)./py4 --release -o out/program program.p4
# Explicit optimization level./py4 --opt-level 3 -o out/program program.p4
# Emit C source instead of compiling./py4 --emit-c program.p4./py4 --emit-c -o out/program.c program.p4CLI flags
| Flag | Description |
|---|---|
-o, --output <path> | Output path (binary or C file depending on mode) |
--backend <gcc|clang> | C compiler backend (default: gcc) |
--release | Compile with -O2 (convenience alias) |
--opt-level <0|1|2|3|s|z> | Explicit optimization level |
--emit-c | Emit C source instead of compiling to a binary |
libcurl (http module)
If your program imports http, py4 resolves libcurl build flags automatically:
- System
pkg-config libcurl - System
curl-config - System
libcurlshared library with vendored headers - Locally bootstrapped copy via
scripts/ensure_libcurl.sh
No manual setup is required in most cases.