Source: ryangjchandler.co.uk

Experimentally compiling PHP code to Rust
Experimentally compiling PHP code to Rust Some of you might already know that I've been working on a handwritten PHP parser in Rust.

Inspired by Tim's work on Natalie, I'm going to start an experiment where I take my handwritten PHP parser and try to write a compiler that turns PHP code into Rust and then compiles that Rust code into a native executable using rustc.

use structopt::StructOpt; use phpc::compile; #[derive(Debug, Structopt)] #[structopt(name = "phpc", about = "Compile a PHP script to Rust.")] struct Args { file: String, } fn main() { let args = Args::from_args(); let compiled = compile(args.file); dbg!(compiled); }

Four lines of incredibly simple PHP code were parsed with a handwritten parser, compiled into a Rust file with a novel compiler and compiled into a native binary using Rust's own toolchain.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners