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, 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");
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 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);

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.