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

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners