Skip to main content

Crate phplang

Crate phplang 

Source
Expand description

phplang — PHP as a fusevm frontend.

Pipeline: lexer → parser builds a PHP AST → compiler lowers it to a fusevm::Chunk (plus a table of function sub-chunks) → fusevm executes it, calling back into the host (through registered builtins and the strict numeric hook) for every PHP-specific operation. There is no bespoke VM or JIT here — execution and codegen live in fusevm.

Re-exports§

pub use embed::run_program;

Modules§

argsig
Declared arity and parameter NAMES for the standard library, and the two checks PHP 8 runs against them before a builtin sees its arguments: the argument COUNT, and the binding of PHP 8.0 named arguments.
argtypes
Declared parameter types for the standard library, and the check PHP 8 runs against them before a builtin sees its arguments.
ast
The PHP abstract syntax tree produced by parser and consumed by compiler.
ast_export
zend_ast_export (Zend/zend_ast.c) for the constant expressions a parameter or property default may hold: what Reflection*::__toString prints for a default the reference keeps as an AST because it could not evaluate it while compiling (self::A, N\UC + 1, new \N\Foo()).
banner
The REPL banner (shown only for the interactive php -a, never for script execution).
builtins
Te phplang builtins: the CallBuiltin handlers the compiler emits, the strict numeric hook, and the PHP standard-library functions reached through CALL.
bytes
PHP strings are byte strings; fusevm::Value::Str holds a Rust String, which must be valid UTF-8. This module is the bridge.
cli
Command-line interface for the php binary.
compiler
Lower the PHP AST to fusevm::Chunk.
corpus
The language corpus: the exact (name, chapter, signature, description, example) table that documents every name the current phplang build recognizes.
dap
Debug Adapter Protocol over stdio (php --dap).
embed
The embedding entry point: run a whole PHP program with a given standard input and get back what it wrote to standard output.
errlevel
PHP’s E_* error levels and the error_reporting mask.
host
The PHP object heap and runtime, reached from fusevm through registered builtins (builtins::install) and the strict numeric hook.
intercepts
Function-call intercepts (aspect-oriented advice) — a glob-matched registry of before/after/around hooks keyed by function-name pattern.
internal_interfaces
GENERATED by scripts/gen-internal-interfaces.php from PHP 8.5.12 — do not edit.
lexer
The PHP lexer.
lsp
The Language Server (php --lsp): a self-contained, read-only server (run) that answers completion and hover from the language corpus and publishes diagnostics from the runtime’s own parser::parse. No output ever reaches the terminal — JSON-RPC on stdio only. Structure follows the sibling -rs frontends’ lsp.rs (see pythonrs/src/lsp.rs).
parser
Recursive-descent parser: lexer tokens → PHP AST (ast::Stmt).
promote
Which locals may live in a fusevm FRAME SLOT instead of the host scope.
repl
The interactive REPL (php -a).
rust_ffi
PHP wiring for inline Rust FFI (rust { ... } blocks).
stdlib
The extended PHP standard library, one module per category. Each module exposes dispatch(name, args) -> Option<Result<Value, String>>, returning None when the name is not one of its functions. builtins::call_library consults this chain for every name its own core match does not handle, so categories can be developed independently without touching a shared table.
tiers
Which fusevm execution tier a program’s bytecode actually reaches.
timelib
A port of the parts of timelib (the date library bundled with the reference interpreter, ext/date/lib, version 2022.17) that strtotime, date_parse and the DateTime classes stand on: the free-form date scanner (parse_date.re), timelib_parse_from_format, the relative-time resolution of tm2unixtime.c, the calendar helpers of dow.c and unixtime2tm.c, and the interval arithmetic of interval.c.

Enums§

Value
Core value type — what lives on the stack and in variables.

Constants§

FROM_CALLABLE_FORWARDER
The function-table key the Closure a Closure::fromCallable($c) builds runs out of: a variadic forwarder holding the callable it was made from.

Functions§

compile
Compile a PHP source string to a runnable program.
compile_debug
Compile with per-statement DAP line markers enabled (php --dap).
eval_capture
Evaluate src and return the captured program output. The convenience entry point for tests: installs an output buffer, runs, and returns what echo wrote (PHP is output-oriented — its observable result is stdout, not a value).
eval_capture_with
Evaluate src with vars bound and return the captured program output — eval_capture for an embedder that has input to hand the program.
eval_cli
eval_str for the CLI: identical, except a syntax error is displayed in PHP’s shape rather than left to the caller to print tersely, and the trailing command-line arguments reach the program as $argv.
eval_file
Read and run a .php file on a fresh host.
eval_file_cli
eval_file for the CLI — see eval_cli.
eval_file_debug
Read and run a .php file under the DAP debugger (per-statement line markers, tracing JIT disabled so the markers fire).
eval_stdin_cli
eval_cli for a script read from standard input (php < script.php).
eval_str
Parse, compile, load, and run a PHP source string on a fresh host; return the value of the last top-level expression.
load_merged
Merge an already-compiled program onto the current host (install the exception prelude, then the program’s user functions/classes/try-defs) and return the main chunk for the caller to run.
run_compiled
Run an already-compiled program on the current host.