Skip to content

Commit

Permalink
Document minimal MeTTa interpreter structures and methods
Browse files Browse the repository at this point in the history
  • Loading branch information
vsbogd committed Jul 10, 2024
1 parent 8cae12e commit e7e6dfa
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/src/metta/interpreter_minimal.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
//! MeTTa assembly language implementation.
//!
//! # Algorithm
//!
//! TODO: explain an algorithm
//! MeTTa assembly language implementation. See
//! [minimal MeTTa documentation](https://github.com/trueagi-io/hyperon-experimental/blob/main/docs/minimal-metta.md) for details.
use crate::*;
use crate::atom::matcher::*;
Expand Down Expand Up @@ -157,14 +154,20 @@ impl<T: Space> InterpreterContext<T> {
}
}

// TODO: This wrapper is for compatibility with interpreter.rs only
/// This wrapper is to keep interpreter interface compatible with previous
/// implementation and will be removed in future.
// TODO: MINIMAL: This wrapper is for compatibility with old_interpreter.rs only
pub trait SpaceRef<'a> : Space + 'a {}
impl<'a, T: Space + 'a> SpaceRef<'a> for T {}

/// State of the interpreter which passed between `interpret_step` calls.
#[derive(Debug)]
pub struct InterpreterState<'a, T: SpaceRef<'a>> {
/// List of the alternatives to evaluate further.
plan: Vec<InterpretedAtom>,
/// List of the completely evaluated results to be returned.
finished: Vec<Atom>,
/// Evaluation context.
context: InterpreterContext<T>,
phantom: std::marker::PhantomData<dyn SpaceRef<'a>>,
}
Expand Down Expand Up @@ -194,10 +197,13 @@ impl<'a, T: SpaceRef<'a>> InterpreterState<'a, T> {
}
}

/// Returns true if there are alternatives which can be evaluated further.
pub fn has_next(&self) -> bool {
!self.plan.is_empty()
}

/// Returns vector of fully evaluated results or error if there are still
/// alternatives to be evaluated.
pub fn into_result(self) -> Result<Vec<Atom>, String> {
if self.has_next() {
Err("Evaluation is not finished".into())
Expand Down

0 comments on commit e7e6dfa

Please sign in to comment.