libperl-rs 0.4.0

Embed the Perl 5 runtime in a Rust application — safe wrapper around libperl-sys
Documentation
//! Walk the op tree from `PL_main_start` to `op_next == NULL`, printing
//! each op's address and op-name.
//!
//! ```text
//! cargo run --example 100_scan_ops -- -e 'print "FOO\n"'
//! ```
//!
//! North-star example for Step 1 of the rebuild plan
//! (`docs/plan/README.md` §4 Step 1.3): exercises the new `Perl` struct
//! (NonNull-backed), the `PL_main_start!(my_perl)` macro generated by
//! libperl-macrogen, and `PL_op_name` lookups.

use std::env;
use std::ffi::CStr;

use libperl_rs::{op, Perl, PL_main_start, PL_op_name};

fn scan_ops(mut op: *const op) {
    while !op.is_null() {
        let ty = unsafe { (*op).op_type() } as usize;
        let name = unsafe { CStr::from_ptr(PL_op_name[ty]) }
            .to_str()
            .unwrap_or("<utf8 error>");
        println!("{op:#?} {name}");
        op = unsafe { (*op).op_next as *const op };
    }
}

fn main() {
    let mut perl = Perl::new();
    perl.parse_env_args(env::args(), env::vars());

    // Standard C-style THX setup at the top of the function:
    let my_perl = perl.as_ptr();
    scan_ops(PL_main_start!(my_perl));
}