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.