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,
and the built-in intrinsics (Intrinsics::core).
§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 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);