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
impl Intrinsics
Sourcepub fn core() -> Self
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);Sourcepub fn mox() -> Self
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 { .. }));Sourcepub fn with_lsb(self, name: &str, op: LsbOp) -> Self
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());Sourcepub fn with_host(
self,
name: &str,
arity: Arity,
module: &str,
func: &str,
) -> Self
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")));Sourcepub fn with_fast(self, name: &str, fast: Fast, module: &str, func: &str) -> Self
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);Sourcepub fn with_class(
self,
name: &str,
op: ClassOp,
module: &str,
func: &str,
) -> Self
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, .. }));