Skip to content

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

Terminal window
git clone https://github.com/alekgreen/py4.git
cd py4
make

This produces a py4 binary in the project root.

Verify the build

Terminal window
./py4 --version

Running the test suite

Terminal window
make test

Tests 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.

Terminal window
# 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.p4

CLI flags

FlagDescription
-o, --output <path>Output path (binary or C file depending on mode)
--backend <gcc|clang>C compiler backend (default: gcc)
--releaseCompile with -O2 (convenience alias)
--opt-level <0|1|2|3|s|z>Explicit optimization level
--emit-cEmit C source instead of compiling to a binary

libcurl (http module)

If your program imports http, py4 resolves libcurl build flags automatically:

  1. System pkg-config libcurl
  2. System curl-config
  3. System libcurl shared library with vendored headers
  4. Locally bootstrapped copy via scripts/ensure_libcurl.sh

No manual setup is required in most cases.