Skip to main content

Options

Struct Options 

Source
pub struct Options { /* private fields */ }
Expand description

Compilation options: the dynamic profile’s array and key semantics, the body’s role, host linkage, the intrinsic table, and budgets.

The default is the PHP profile Mox needs: value arrays and PHP keys.

§Examples

use bcgen_lang::{ArraySemantics, Options};

let opts = Options::new()
    .with_arrays(ArraySemantics::Reference)
    .with_file("app.mox")
    .with_max_instructions(1_000_000);
assert_eq!(opts.arrays(), ArraySemantics::Reference);
assert_eq!(opts.file(), "app.mox");

Implementations§

Source§

impl Options

Source

pub const DEFAULT_MAX_INSTRUCTIONS: u64

The default budget: 64 Mi instructions per module.

Source

pub fn new() -> Self

The PHP profile: ArraySemantics::Php, KeyCoercion::Php, BodyMode::Start, file name <hir>, host module host, no hooks, the built-in intrinsics (Intrinsics::core), extra arguments refused, string offsets read as bytes, and PHP’s magic method names (__construct, __destruct, __clone).

§Examples
use bcgen_lang::{BodyMode, Options};

assert_eq!(Options::new().body(), BodyMode::Start);
assert_eq!(Options::new().host_module(), "host");
Source

pub fn with_arrays(self, arrays: ArraySemantics) -> Self

Sets the array semantics.

§Examples
use bcgen_lang::{ArraySemantics, Options};

let o = Options::new().with_arrays(ArraySemantics::Reference);
assert_eq!(o.arrays(), ArraySemantics::Reference);
Source

pub fn with_keys(self, keys: KeyCoercion) -> Self

Sets the key coercion.

§Examples
use bcgen_lang::{KeyCoercion, Options};

assert_eq!(Options::new().with_keys(KeyCoercion::None).keys(), KeyCoercion::None);
Source

pub fn with_body(self, body: BodyMode) -> Self

Sets what the module body compiles to.

§Examples
use bcgen_lang::{BodyMode, Options};

assert_eq!(Options::new().with_body(BodyMode::Entry).body(), BodyMode::Entry);
Source

pub fn with_file(self, file: &str) -> Self

Sets the file name written into line-table rows when no Locate is given.

§Examples
use bcgen_lang::Options;

assert_eq!(Options::new().with_file("main.mox").file(), "main.mox");
Source

pub fn with_host_module(self, module: &str) -> Self

Sets the import module for host symbols that have no . in their name (echo imports as host.echo by default; mox.concat imports as mox.concat whatever this is).

§Examples
use bcgen_lang::Options;

assert_eq!(Options::new().with_host_module("env").host_module(), "env");
Source

pub fn with_hook(self, hook: Hook, module: &str, name: &str) -> Self

Binds an LSB hook (§5.8) to the host function module.name, with the hook’s signature (every operand dyn). A later binding of the same hook replaces an earlier one.

§Examples
use bcgen_lang::Options;
use bytecode_lang::Hook;

let o = Options::new().with_hook(Hook::Eq, "mox", "loose_eq");
assert_eq!(o.hooks().len(), 1);
Source

pub fn with_intrinsics(self, intrinsics: Intrinsics) -> Self

Sets the intrinsic table: how each named intrinsic compiles (an LSB sequence, a host function, or a guarded fast path over one). Names not in it do not compile (CompileError::UnknownIntrinsic).

§Examples
use bcgen_lang::{Intrinsics, Options};

let o = Options::new().with_intrinsics(Intrinsics::mox());
assert!(o.intrinsics().get("mox.loose_eq").is_some());
Source

pub fn with_max_instructions(self, limit: u64) -> Self

Sets the instruction budget for the whole module; compilation stops with CompileError::BudgetExceeded beyond it.

§Examples
use bcgen_lang::Options;

assert_eq!(Options::new().with_max_instructions(10).max_instructions(), 10);
Source

pub fn with_ignore_extra(self, ignore: bool) -> Self

Whether user functions, closures, and methods ignore extra positional arguments (PHP: f(1, 2, 3) of function f($a) drops the extras after evaluating them) instead of raising ArgumentError (E0114, Python’s rule and the default). Sets LSB’s ignore_extra on every parameter list the module carries, and direct calls evaluate and discard the extras. Named arguments that match no parameter are an error either way.

§Examples
use bcgen_lang::Options;

assert!(Options::new().with_ignore_extra(true).ignore_extra());
assert!(!Options::new().ignore_extra());
Source

pub fn with_string_offsets(self, name: &str) -> Self

Routes string-offset reads ($s[i] where $s holds a string) through the intrinsic name of the intrinsic table, called with the string and the (coerced) key; every other indexed read stays LSB’s dget_index. Without it, a string offset reads LSB’s answer: the byte as an int (LSB §5.7). PHP gives a one-character string, which Fast::StrOffset computes inline (Intrinsics::mox() maps mox.str_offset to it). The entry must exist and take two operands, or compilation fails with CompileError::InvalidOption. String writes ($s[0] = "x") are unchanged: LSB strings are immutable, so they go to the set_index hook.

§Examples
use bcgen_lang::{Intrinsics, Options};

let o = Options::new()
    .with_intrinsics(Intrinsics::mox())
    .with_string_offsets("mox.str_offset");
assert_eq!(o.string_offsets(), Some("mox.str_offset"));
Source

pub fn with_constructor(self, name: Option<&str>) -> Self

Names the constructor method new calls after initializing the instance’s properties (None: classes have no constructor, and new evaluates and drops its arguments).

§Examples
use bcgen_lang::Options;

assert_eq!(Options::new().constructor(), Some("__construct"));
assert_eq!(Options::new().with_constructor(Some("__init__")).constructor(), Some("__init__"));
Source

pub fn with_destructor(self, name: Option<&str>) -> Self

Names the destructor method. bcgen-lang does not call it: LSB format 2 has no destructor flag, so the host passes Compiled::destructor to bvm-lang’s Vm::set_destructor. A class method of this name must take no parameters (ClassProblem::BadDestructor).

§Examples
use bcgen_lang::Options;

assert_eq!(Options::new().destructor(), Some("__destruct"));
assert_eq!(Options::new().with_destructor(None).destructor(), None);
Source

pub fn with_reference_counting(self, rc: bool) -> Self

Emits code for a VM that counts references (bvm-lang’s Memory::Rc, the language’s [runtime] memory = "rc"), so objects die where PHP frees them: every temporary register and call window that may hold a reference is cleared (load_nil) when it dies, and a variable keeps its register until the function returns (PHP variables are function-scoped). Without it, a dead temporary keeps its object alive until the register is reused, which delays destructors. The cost is one load_nil per dying reference register; nothing changes under a tracing collector.

§Examples
use bcgen_lang::Options;

assert!(Options::new().with_reference_counting(true).reference_counting());
assert!(!Options::new().reference_counting());
Source

pub fn with_clone_method(self, name: Option<&str>) -> Self

Names the method a clone (ClassOp::Clone) calls on the new copy (PHP’s __clone), when the class has one.

§Examples
use bcgen_lang::Options;

assert_eq!(Options::new().clone_method(), Some("__clone"));
Source

pub fn arrays(&self) -> ArraySemantics

The array semantics.

§Examples
assert_eq!(bcgen_lang::Options::new().arrays(), bcgen_lang::ArraySemantics::Php);
Source

pub fn keys(&self) -> KeyCoercion

The key coercion.

§Examples
assert_eq!(bcgen_lang::Options::new().keys(), bcgen_lang::KeyCoercion::Php);
Source

pub fn body(&self) -> BodyMode

What the module body compiles to.

§Examples
assert_eq!(bcgen_lang::Options::new().body(), bcgen_lang::BodyMode::Start);
Source

pub fn file(&self) -> &str

The default file name for line-table rows.

§Examples
assert_eq!(bcgen_lang::Options::new().file(), "<hir>");
Source

pub fn host_module(&self) -> &str

The import module for host symbols without a ..

§Examples
assert_eq!(bcgen_lang::Options::new().host_module(), "host");
Source

pub fn hooks(&self) -> &[(Hook, String, String)]

The hook bindings, as (hook, module, name).

§Examples
assert!(bcgen_lang::Options::new().hooks().is_empty());
Source

pub fn intrinsics(&self) -> &Intrinsics

The intrinsic table.

§Examples
assert_eq!(bcgen_lang::Options::new().intrinsics(), &bcgen_lang::Intrinsics::core());
Source

pub fn max_instructions(&self) -> u64

The instruction budget.

§Examples
use bcgen_lang::Options;

assert_eq!(Options::new().max_instructions(), Options::DEFAULT_MAX_INSTRUCTIONS);
Source

pub fn ignore_extra(&self) -> bool

Whether extra positional arguments are ignored (see with_ignore_extra).

§Examples
assert!(!bcgen_lang::Options::new().ignore_extra());
Source

pub fn string_offsets(&self) -> Option<&str>

The intrinsic string-offset reads go through, if any (see with_string_offsets).

§Examples
assert_eq!(bcgen_lang::Options::new().string_offsets(), None);
Source

pub fn constructor(&self) -> Option<&str>

The constructor method name.

§Examples

See with_constructor.

Source

pub fn destructor(&self) -> Option<&str>

The destructor method name.

§Examples

See with_destructor.

Source

pub fn reference_counting(&self) -> bool

Whether code is emitted for a reference-counting VM (see with_reference_counting).

§Examples

See with_reference_counting.

Source

pub fn clone_method(&self) -> Option<&str>

The clone method name.

§Examples

See with_clone_method.

Trait Implementations§

Source§

impl Clone for Options

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Options

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Options

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Options

Source§

impl PartialEq for Options

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Options

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.