From 5ac55a084c613f27aea0e072e5168d53f7505b3d Mon Sep 17 00:00:00 2001 From: Anatoly Belikov Date: Mon, 23 Oct 2023 12:22:09 +0300 Subject: [PATCH] run_step_by_step in runner --- python/hyperon/runner.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/python/hyperon/runner.py b/python/hyperon/runner.py index 664063a26..af351a28b 100644 --- a/python/hyperon/runner.py +++ b/python/hyperon/runner.py @@ -24,6 +24,9 @@ def __del__(self): """Frees a RunnerState and all associated resources.""" hp.runner_state_free(self.cstate) + def __str__(self): + return self.cstate.__str__() + def run_step(self): """ Executes the next step in the interpretation plan, or begins interpretation of the next atom in the stream of MeTTa code. @@ -185,6 +188,18 @@ def run(self, program, flat=False): else: return [[Atom._from_catom(catom) for catom in result] for result in results] + def run_step_by_step(self, program): + """Runs program step by step, yielding state and result""" + state = RunnerState(self, program) + state.run_step() + results = state.current_results() + yield state, results + while not state.is_complete(): + state.run_step() + results = state.current_results() + yield state, results + + class Environment: """This class contains the API for configuring the host platform interface used by MeTTa"""