Skip to main content

Cx

Struct Cx 

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

The evaluation context threaded through every checked call.

Cx bundles the registry handle, factory, capability set, eval and control policies, the data substrate (datum/fact/handle stores and ledgers), and the diagnostic sink. The kernel defines this context; libraries supply the behavior reached through it (registered classes, functions, number domains, list/table backends, and so on). See the README sections “Library system” and “Capabilities and trust”.

Implementations§

Source§

impl Cx

Source

pub fn new(eval_policy: EvalPolicyRef, factory: Arc<dyn Factory>) -> Self

Builds a fresh context with the given eval policy and factory.

The registry, capability set, and stores start empty (boot claims aside); libraries register behavior into the returned context.

§Examples
let cx = Cx::new(Arc::new(NoopEvalPolicy), Arc::new(DefaultFactory));
assert!(cx.capabilities().iter().next().is_none());
Source

pub fn env(&self) -> &Env

Returns the active lexical environment.

Source

pub fn env_mut(&mut self) -> &mut Env

Returns the active lexical environment mutably.

Source

pub fn with_env<T>( &mut self, env: Env, f: impl FnOnce(&mut Self) -> Result<T>, ) -> Result<T>

Runs f with env installed as the active environment, then restores it.

Source

pub fn factory(&self) -> &dyn Factory

Returns the active object Factory.

Source

pub fn factory_ref(&self) -> Arc<dyn Factory>

Returns a shared handle to the active object factory.

Source

pub fn with_factory<T>( &mut self, factory: Arc<dyn Factory>, f: impl FnOnce(&mut Self) -> Result<T>, ) -> Result<T>

Runs f with factory installed as the active factory, then restores it.

Source

pub fn registry(&self) -> &Registry

Returns the behavior Registry.

Source

pub fn registry_mut(&mut self) -> &mut Registry

Returns the behavior registry mutably, for registering exports.

Source

pub fn list_registry(&self) -> &ListRegistry

Returns the registered list backend.

Source

pub fn list_registry_mut(&mut self) -> &mut ListRegistry

Returns the list backend mutably.

Source

pub fn table_registry(&self) -> &TableRegistry

Returns the registered table backend.

Source

pub fn table_registry_mut(&mut self) -> &mut TableRegistry

Returns the table backend mutably.

Source

pub fn with_registry<T>( &mut self, registry: Registry, f: impl FnOnce(&mut Self) -> Result<T>, ) -> Result<T>

Runs f with registry installed as the active registry, then restores it.

Source

pub fn new_list(&mut self, items: Vec<Value>) -> Result<Value>

Builds a list value through the registered list backend.

Source

pub fn new_cons(&mut self, car: Value, cdr: Value) -> Result<Value>

Builds a cons cell through the registered list backend.

Source

pub fn new_table(&mut self, entries: Vec<(Symbol, Value)>) -> Result<Value>

Builds a table value through the registered table backend.

Source

pub fn sources(&self) -> &SourceRegistry

Returns the source registry.

Source

pub fn sources_mut(&mut self) -> &mut SourceRegistry

Returns the source registry mutably.

Source

pub fn datum_store(&self) -> &BTreeDatumStore

Returns the datum store.

Source

pub fn datum_store_mut(&mut self) -> &mut BTreeDatumStore

Returns the datum store mutably.

Source

pub fn handles(&self) -> &BTreeHandleStore

Returns the handle store.

Source

pub fn handles_mut(&mut self) -> &mut BTreeHandleStore

Returns the handle store mutably.

Source

pub fn facts(&self) -> &BTreeFactStore

Returns the fact store.

Source

pub fn facts_mut(&mut self) -> &mut BTreeFactStore

Returns the fact store mutably.

Source

pub fn effect_ledger(&self) -> &EffectLedger

Returns the effect ledger.

Source

pub fn effect_ledger_mut(&mut self) -> &mut EffectLedger

Returns the effect ledger mutably.

Source

pub fn control_policy(&self) -> &dyn ControlPolicy

Returns the active control policy.

Source

pub fn control_policy_ref(&self) -> ControlPolicyRef

Returns a shared handle to the active control policy.

Source

pub fn control_policy_name(&self) -> &'static str

Returns the name of the active control policy.

Source

pub fn set_control_policy(&mut self, control_policy: ControlPolicyRef)

Replaces the active control policy.

Source

pub fn insert_fact(&mut self, claim: Claim) -> Result<Ref>

Inserts a claim into the fact store, subject to capability authorization.

Source

pub fn insert_fact_for_lib( &mut self, lib_id: LibId, claim: Claim, ) -> Result<Ref>

Inserts a claim and records it as part of a loaded library’s receipt.

When the claim did not already exist, unload_lib retracts it with the rest of lib_id’s recorded load effects. Pre-existing identical claims are left owned by their original publisher.

Source

pub fn query_facts(&self, pattern: ClaimPattern) -> Result<Vec<Claim>>

Queries the fact store for claims matching pattern, applying read policy.

Source

pub fn promotion_search_limits(&self) -> PromotionSearchLimits

Returns the limits bounding number-domain promotion search.

Source

pub fn set_promotion_search_limits(&mut self, limits: PromotionSearchLimits)

Sets the limits bounding number-domain promotion search.

Source

pub fn eval_policy(&self) -> &dyn EvalPolicy

Returns the active evaluation policy.

Source

pub fn eval_policy_ref(&self) -> EvalPolicyRef

Returns a shared handle to the active evaluation policy.

Source

pub fn eval_policy_name(&self) -> &'static str

Returns the name of the active evaluation policy.

Source

pub fn set_eval_policy(&mut self, eval_policy: EvalPolicyRef)

Replaces the active evaluation policy.

Source

pub fn set_macro_expander(&mut self, macro_expander: MacroExpanderRef)

Installs a macro expander.

Source

pub fn clear_macro_expander(&mut self)

Removes any installed macro expander.

Source

pub fn macro_expander_ref(&self) -> Option<MacroExpanderRef>

Returns the installed macro expander, if any.

Source

pub fn expand_macros(&mut self, phase: Phase, expr: Expr) -> Result<Expr>

Expands macros in expr for the given phase, or returns it unchanged.

Source

pub fn diagnostics(&self) -> &Diagnostics

Returns the accumulated diagnostics.

Source

pub fn take_diagnostics(&mut self) -> Vec<Diagnostic>

Drains and returns the accumulated diagnostics.

Source

pub fn push_diagnostic(&mut self, diagnostic: Diagnostic)

Records an already-built diagnostic.

Source

pub fn push_info(&mut self, message: impl Into<String>)

Records an info-level diagnostic from a message.

Source

pub fn grant(&mut self, capability: CapabilityName)

Grants a capability to this context.

Source

pub fn grant_named(&mut self, capability: &'static str)

Grants a capability named by a static string.

Source

pub fn capabilities(&self) -> &Capabilities

Returns the granted capability set.

Source

pub fn with_capabilities<T>( &mut self, capabilities: Capabilities, f: impl FnOnce(&mut Self) -> Result<T>, ) -> Result<T>

Runs f with capabilities installed, then restores the prior set.

Source

pub fn resolve_class(&self, symbol: &Symbol) -> Result<Value>

Resolves a registered class by symbol.

Source

pub fn resolve_function(&self, symbol: &Symbol) -> Result<Value>

Resolves a registered function by symbol.

Source

pub fn resolve_macro(&self, symbol: &Symbol) -> Result<Value>

Resolves a registered macro by symbol.

Source

pub fn resolve_shape(&self, symbol: &Symbol) -> Result<Value>

Resolves a registered shape by symbol.

Source

pub fn resolve_codec(&self, symbol: &Symbol) -> Result<Value>

Resolves a registered codec by symbol.

Source

pub fn resolve_number_domain(&self, symbol: &Symbol) -> Result<Value>

Resolves a registered number domain by symbol.

Source

pub fn resolve_value(&self, symbol: &Symbol) -> Result<Value>

Resolves a registered value binding by symbol.

Source

pub fn call_value(&mut self, value: Value, args: Args) -> Result<Value>

Calls a callable value with already-evaluated arguments.

Source

pub fn call_exprs(&mut self, value: Value, args: Vec<Expr>) -> Result<Value>

Calls a callable value with raw, unevaluated argument expressions.

Source

pub fn call_function(&mut self, symbol: &Symbol, args: Args) -> Result<Value>

Resolves a function by symbol and calls it.

Source

pub fn call_class(&mut self, symbol: &Symbol, args: Args) -> Result<Value>

Resolves a class by symbol and calls its constructor.

Source

pub fn read_construct( &mut self, class: &Symbol, args: Vec<Value>, ) -> Result<Value>

Constructs an instance of class from read-time arguments.

Requires the read_construct_capability.

Source

pub fn force(&mut self, value: Value, demand: Demand) -> Result<Value>

Forces a value to the requested demand through the active eval policy.

Source

pub fn eval_expr(&mut self, expr: Expr) -> Result<Value>

Evaluates an expression through the active eval policy.

Source

pub fn symbol_is_bound(&mut self, name: &Symbol) -> bool

Returns true when name resolves across environment or registry layers.

Source

pub fn resolve_unbound_symbol(&mut self, symbol: Symbol) -> Result<Value>

Resolves an unbound value-position symbol through the active eval policy.

Source

pub fn resolve_unbound_call( &mut self, operator: Symbol, args: Vec<Expr>, ) -> Result<Value>

Resolves an unbound call through the active eval policy.

Source

pub fn require(&self, capability: &CapabilityName) -> Result<()>

Demands a capability, returning Error::CapabilityDenied when absent.

Source

pub fn require_all(&self, capabilities: &[CapabilityName]) -> Result<()>

Demands every capability in turn, failing on the first absent one.

Source§

impl Cx

Source

pub fn parse_number_literal( &mut self, text: &str, ) -> Result<Option<NumberLiteral>>

Parses a number literal by trying registered number domains in sorted_number_domains order.

That ordering is only a parse-disambiguation rule. Codecs that already have an explicit source NumberLiteral must preserve its domain instead of relying on this order to recover the same domain from canonical text.

Source

pub fn encode_number_value( &mut self, value: Value, ) -> Result<Option<NumberLiteral>>

Encodes a value to a number literal via the first domain that accepts it.

Source

pub fn number_value_ref( &mut self, value: Value, ) -> Result<Option<NumberValueRef>>

Resolves a value to a NumberValueRef carrying its domain and literal.

Source

pub fn apply_value_number_binary_op( &mut self, operator: &Symbol, left: Value, right: Value, ) -> Result<Value>

Applies a binary numeric operator to two values, selecting the best registered rule after promoting operands.

Errors with Error::AmbiguousNumberDispatch when no single rule wins.

Source

pub fn apply_number_binary_op( &mut self, operator: &Symbol, left: NumberLiteral, right: NumberLiteral, ) -> Result<Value>

Applies a binary numeric operator to two literals.

Convenience over apply_value_number_binary_op.

Source

pub fn apply_value_number_unary_op( &mut self, operator: &Symbol, operand: Value, ) -> Result<Value>

Applies a unary numeric operator to a value, selecting the best registered rule after promoting the operand.

Source

pub fn apply_number_unary_op( &mut self, operator: &Symbol, operand: NumberLiteral, ) -> Result<Value>

Applies a unary numeric operator to a literal.

Convenience over apply_value_number_unary_op.

Source

pub fn apply_value_number_reduction_op( &mut self, operator: &Symbol, operands: Vec<Value>, ) -> Result<Value>

Applies a reduction numeric operator across many values, selecting the best registered rule after promoting all operands to a common domain.

Source

pub fn apply_number_reduction_op( &mut self, operator: &Symbol, operands: Vec<NumberLiteral>, ) -> Result<Value>

Applies a reduction numeric operator across many literals.

Convenience over apply_value_number_reduction_op.

Source§

impl Cx

Source

pub fn load_lib(&mut self, lib: &dyn Lib) -> Result<LibId>

Loads a single library: checks its requested capabilities and dependency versions, runs its Lib::load against a load transaction, commits the result, and publishes its load claims.

Source

pub fn load_libs(&mut self, libs: &[&dyn Lib]) -> Result<Vec<LibId>>

Loads several libraries in dependency order, returning their ids in load order.

Source

pub fn unload_lib(&mut self, lib_id: LibId) -> Result<Vec<LibId>>

Unloads a loaded library by id and retracts the claims published for it.

Already-live values may continue to exist, but fresh registry resolution for the unloaded library’s exports is removed.

Source

pub fn unload_lib_cascade(&mut self, lib_id: LibId) -> Result<Vec<LibId>>

Unloads a library and every loaded dependent in reverse dependency order, retracting the claims published for each unloaded lib.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Cx

§

impl !UnwindSafe for Cx

§

impl Freeze for Cx

§

impl Send for Cx

§

impl Sync for Cx

§

impl Unpin for Cx

§

impl UnsafeUnpin for Cx

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.