Skip to main content

Intrinsics

Struct Intrinsics 

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

The intrinsic table: named intrinsic → arity and lowering. A name that is not in the table is CompileError::UnknownIntrinsic.

Options::new starts from Intrinsics::core; Mox uses Intrinsics::mox.

§Examples

use bcgen_lang::{Arity, Fast, Intrinsics, LsbOp, Options};

let table = Intrinsics::new()
    .with_lsb("concat", LsbOp::Concat)
    .with_host("lang.format", Arity::exact(1), "lang", "format")
    .with_fast("lang.eq", Fast::StrictEq, "lang", "eq");
assert_eq!(table.len(), 3);
let opts = Options::new().with_intrinsics(table);
assert!(opts.intrinsics().get("lang.eq").is_some());

Implementations§

Source§

impl Intrinsics

Source

pub fn new() -> Self

An empty table.

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

pub fn core() -> Self

The built-in LSB intrinsics (see LsbOp): concat, len, truthy, lnot, type_of, iter, iter_next, the coroutine controls resume, resume_throw, coro_close, coro_key, coro_result, coro_status (what a runtime’s generator object lowers to), and err_code, err_payload (what a runtime’s exception mapping reads from a caught error value).

§Examples
assert_eq!(bcgen_lang::Intrinsics::core().len(), 15);
Source

pub fn mox() -> Self

core plus every intrinsic of the Mox sketch (_lexersketch/sketches/mox.lsf), each a Fast path over the host function mox.<name> where one is exact, a ClassOp over it for mox.instanceof and mox.clone, else the host function alone (mox.cast_object); plus mox.new (the sketch’s new_object template calls the extern mox.new) as ClassOp::New, and mox.str_offset (Fast::StrOffset) for Options::with_string_offsets. The table in docs/API.md gives every mapping and the semantics its host function must implement.

§Examples
use bcgen_lang::{Fast, Intrinsics, Lowering};

let t = Intrinsics::mox();
assert!(matches!(
    t.get("mox.loose_eq").unwrap().lowering(),
    Lowering::Fast { fast: Fast::LooseEq, .. }
));
assert!(matches!(t.get("mox.clone").unwrap().lowering(), Lowering::Class { .. }));
assert!(matches!(t.get("mox.cast_object").unwrap().lowering(), Lowering::Host { .. }));
Source

pub fn with_lsb(self, name: &str, op: LsbOp) -> Self

Registers name as the LSB sequence op (its arity is the op’s), replacing any earlier entry of that name.

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

assert!(Intrinsics::new().with_lsb("strlen", LsbOp::Len).get("strlen").is_some());
Source

pub fn with_host( self, name: &str, arity: Arity, module: &str, func: &str, ) -> Self

Registers name as a call to the host function module.func taking arity operands, replacing any earlier entry.

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

let t = Intrinsics::new().with_host("php.clone", Arity::exact(1), "php", "clone");
assert_eq!(t.get("php.clone").unwrap().lowering().host(), Some(("php", "clone")));
Source

pub fn with_fast(self, name: &str, fast: Fast, module: &str, func: &str) -> Self

Registers name as the guarded fast path fast (its arity is the fast path’s) over the host function module.func, replacing any earlier entry.

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

let t = Intrinsics::new().with_fast("cmp", Fast::IntSpaceship, "rt", "cmp");
assert_eq!(t.len(), 1);
Source

pub fn with_class( self, name: &str, op: ClassOp, module: &str, func: &str, ) -> Self

Registers name as the class operation op (its arity is the operation’s) over the host function module.func, replacing any earlier entry.

§Examples
use bcgen_lang::{ClassOp, Intrinsics, Lowering};

let t = Intrinsics::new().with_class("rt.new", ClassOp::New, "rt", "new");
assert!(matches!(t.get("rt.new").unwrap().lowering(), Lowering::Class { op: ClassOp::New, .. }));
Source

pub fn get(&self, name: &str) -> Option<&IntrinsicDef>

The entry for name.

§Examples
assert!(bcgen_lang::Intrinsics::core().get("mox.concat").is_none());
Source

pub fn len(&self) -> usize

The number of entries.

§Examples
assert_eq!(bcgen_lang::Intrinsics::mox().len(), 43);
Source

pub fn is_empty(&self) -> bool

Whether the table is empty.

§Examples
assert!(!bcgen_lang::Intrinsics::core().is_empty());
Source

pub fn iter(&self) -> impl Iterator<Item = (&str, &IntrinsicDef)>

Every entry, in name order.

§Examples
let core = bcgen_lang::Intrinsics::core();
let names: Vec<&str> = core.iter().map(|(n, _)| n).collect();
assert_eq!(names[0], "concat");

Trait Implementations§

Source§

impl Clone for Intrinsics

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 Intrinsics

Source§

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

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

impl Default for Intrinsics

Source§

fn default() -> Self

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

impl Eq for Intrinsics

Source§

impl Hash for Intrinsics

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Intrinsics

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 Intrinsics

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.