Skip to content

Commit

Permalink
run_step_by_step in runner
Browse files Browse the repository at this point in the history
  • Loading branch information
noskill committed Oct 23, 2023
1 parent fad8565 commit 22052af
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions python/hyperon/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"""

Expand Down

0 comments on commit 22052af

Please sign in to comment.