pub struct InterpreterState<'a> {
pub application_tables: HashMap<TypeId, ApplicationTable<'a>>,
pub type_spaces: HashMap<TypeId, TypeSpace>,
pub ctxt: &'a Context,
}Expand description
Represents the state of a simple interpreter for the combinatorial language
defined through the referenced Context, with the given TypeId-indexed
TypeSpaces and ApplicationTables memoizing all known non-primitive terms
and results of term evaluations, respectively.
Fields§
§application_tables: HashMap<TypeId, ApplicationTable<'a>>§type_spaces: HashMap<TypeId, TypeSpace>§ctxt: &'a ContextImplementations§
Source§impl<'a> InterpreterState<'a>
impl<'a> InterpreterState<'a>
Sourcepub fn get_context(&self) -> &Context
pub fn get_context(&self) -> &Context
Gets the Context that this InterpreterState operates within.
Sourcepub fn store_term(
&mut self,
type_id: TypeId,
term: PartiallyAppliedTerm,
) -> NonPrimitiveTermPointer
pub fn store_term( &mut self, type_id: TypeId, term: PartiallyAppliedTerm, ) -> NonPrimitiveTermPointer
Stores the given PartiallyAppliedTerm in the TypeSpace for the
given TypeId, if it wasn’t already present. Returns a
NonPrimitiveTermPointer referencing where it was stored
in this InterpreterState.
Sourcepub fn get(&self, term_ptr: TermPointer) -> PartiallyAppliedTerm
pub fn get(&self, term_ptr: TermPointer) -> PartiallyAppliedTerm
Given a TermPointer, yields the PartiallyAppliedTerm which
is stored at that location within this InterpreterState (or,
in the case of a primitive, within the containing Context)
Sourcepub fn get_nonprimitive(
&self,
term_ptr: NonPrimitiveTermPointer,
) -> &PartiallyAppliedTerm
pub fn get_nonprimitive( &self, term_ptr: NonPrimitiveTermPointer, ) -> &PartiallyAppliedTerm
Given a NonPrimitiveTermPointer, yields the PartiallyAppliedTerm
which is stored at that location within this InterpreterState.
Sourcepub fn get_app_results_with_arg(
&self,
arg: &TermReference,
) -> Vec<TermApplicationResult>
pub fn get_app_results_with_arg( &self, arg: &TermReference, ) -> Vec<TermApplicationResult>
Gets all currently-known TermApplicationResults which use the given TermReference argument.
Sourcepub fn get_app_results_with_func(
&self,
func: TermPointer,
) -> Vec<TermApplicationResult>
pub fn get_app_results_with_func( &self, func: TermPointer, ) -> Vec<TermApplicationResult>
Gets all currently-known TermApplicationResults which involve the function
that the given TermPointer points to.
Sourcepub fn get_app_results_with_result(
&self,
result_term: &TermReference,
) -> Vec<TermApplicationResult>
pub fn get_app_results_with_result( &self, result_term: &TermReference, ) -> Vec<TermApplicationResult>
Gets all currently-known TermApplicationResults which had the given TermReference
result.
Sourcepub fn evaluate(
&mut self,
term_app: &TermApplication,
) -> (TermReference, NewlyEvaluatedTerms)
pub fn evaluate( &mut self, term_app: &TermApplication, ) -> (TermReference, NewlyEvaluatedTerms)
Evaluates the given TermApplication against this InterpreterState, assuming
that the function pointed to in the TermApplication is a primitive. Yields
a TermReference to the result of the evaluation, and a list of NewlyEvaluatedTerms
for this InterpreterState which resulted from evaluating the application.
Sourcepub fn ensure_every_type_has_a_term_on_init(&mut self) -> NewlyEvaluatedTerms
pub fn ensure_every_type_has_a_term_on_init(&mut self) -> NewlyEvaluatedTerms
Convenience method that ensures that every type has at least one term, assuming
that this InterpreterState was just-initialized. Returns NewlyEvaluatedTerms
for evaluations that were performed as a result of this operation.
Sourcepub fn new(ctxt: &'a Context) -> InterpreterState<'a>
pub fn new(ctxt: &'a Context) -> InterpreterState<'a>
Constructs a fresh InterpreterState operating within the given Context.