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
impl Options
Sourcepub const DEFAULT_MAX_INSTRUCTIONS: u64
pub const DEFAULT_MAX_INSTRUCTIONS: u64
The default budget: 64 Mi instructions per module.
Sourcepub fn new() -> Self
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");Sourcepub fn with_arrays(self, arrays: ArraySemantics) -> Self
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);Sourcepub fn with_keys(self, keys: KeyCoercion) -> Self
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);Sourcepub fn with_body(self, body: BodyMode) -> Self
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);Sourcepub fn with_host_module(self, module: &str) -> Self
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");Sourcepub fn with_hook(self, hook: Hook, module: &str, name: &str) -> Self
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);Sourcepub fn with_intrinsics(self, intrinsics: Intrinsics) -> Self
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());Sourcepub fn with_max_instructions(self, limit: u64) -> Self
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);Sourcepub fn with_ignore_extra(self, ignore: bool) -> Self
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());Sourcepub fn with_string_offsets(self, name: &str) -> Self
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"));Sourcepub fn with_constructor(self, name: Option<&str>) -> Self
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__"));Sourcepub fn with_destructor(self, name: Option<&str>) -> Self
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);Sourcepub fn with_reference_counting(self, rc: bool) -> Self
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());Sourcepub fn with_clone_method(self, name: Option<&str>) -> Self
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"));Sourcepub fn arrays(&self) -> ArraySemantics
pub fn arrays(&self) -> ArraySemantics
The array semantics.
§Examples
assert_eq!(bcgen_lang::Options::new().arrays(), bcgen_lang::ArraySemantics::Php);Sourcepub fn keys(&self) -> KeyCoercion
pub fn keys(&self) -> KeyCoercion
The key coercion.
§Examples
assert_eq!(bcgen_lang::Options::new().keys(), bcgen_lang::KeyCoercion::Php);Sourcepub fn body(&self) -> BodyMode
pub fn body(&self) -> BodyMode
What the module body compiles to.
§Examples
assert_eq!(bcgen_lang::Options::new().body(), bcgen_lang::BodyMode::Start);Sourcepub fn file(&self) -> &str
pub fn file(&self) -> &str
The default file name for line-table rows.
§Examples
assert_eq!(bcgen_lang::Options::new().file(), "<hir>");Sourcepub fn host_module(&self) -> &str
pub fn host_module(&self) -> &str
The import module for host symbols without a ..
§Examples
assert_eq!(bcgen_lang::Options::new().host_module(), "host");Sourcepub fn hooks(&self) -> &[(Hook, String, String)]
pub fn hooks(&self) -> &[(Hook, String, String)]
The hook bindings, as (hook, module, name).
§Examples
assert!(bcgen_lang::Options::new().hooks().is_empty());Sourcepub fn intrinsics(&self) -> &Intrinsics
pub fn intrinsics(&self) -> &Intrinsics
The intrinsic table.
§Examples
assert_eq!(bcgen_lang::Options::new().intrinsics(), &bcgen_lang::Intrinsics::core());Sourcepub fn max_instructions(&self) -> u64
pub fn max_instructions(&self) -> u64
The instruction budget.
§Examples
use bcgen_lang::Options;
assert_eq!(Options::new().max_instructions(), Options::DEFAULT_MAX_INSTRUCTIONS);Sourcepub fn ignore_extra(&self) -> bool
pub fn ignore_extra(&self) -> bool
Whether extra positional arguments are ignored (see
with_ignore_extra).
§Examples
assert!(!bcgen_lang::Options::new().ignore_extra());Sourcepub fn string_offsets(&self) -> Option<&str>
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);Sourcepub fn constructor(&self) -> Option<&str>
pub fn constructor(&self) -> Option<&str>
Sourcepub fn destructor(&self) -> Option<&str>
pub fn destructor(&self) -> Option<&str>
Sourcepub fn reference_counting(&self) -> bool
pub fn reference_counting(&self) -> bool
Whether code is emitted for a reference-counting VM (see
with_reference_counting).