Skip to main content

Interpreter

Struct Interpreter 

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

The Patchwork interpreter.

Executes Patchwork code synchronously. Think blocks block on channel operations waiting for LLM responses from the agent.

Implementations§

Source§

impl Interpreter

Source

pub fn new() -> Self

Create a new interpreter without an agent.

Think blocks will return placeholder values instead of blocking on LLM.

Source

pub fn with_agent(agent: AgentHandle) -> Self

Create a new interpreter with an agent handle.

Think blocks will block on the agent channel waiting for LLM responses.

Source

pub fn with_working_dir_and_agent( working_dir: PathBuf, agent: AgentHandle, ) -> Self

Create a new interpreter with a specific working directory and agent.

Source

pub fn with_working_dir(working_dir: PathBuf) -> Self

Create a new interpreter with a specific working directory.

Source

pub fn runtime(&self) -> &Runtime

Get a reference to the runtime.

Source

pub fn runtime_mut(&mut self) -> &mut Runtime

Get a mutable reference to the runtime.

Source

pub fn agent(&self) -> Option<&AgentHandle>

Get a reference to the agent handle, if present.

Source

pub fn set_print_sink(&mut self, sink: PrintSink)

Set a print sink for redirecting print() output.

When set, all print() calls will send to this channel instead of stdout.

Source

pub fn eval(&mut self, code: &str) -> Result<Value>

Evaluate Patchwork code.

Parses and executes the code, returning the final value or an error.

For ACP usage, code starting with { is wrapped in a skill for execution.

Source

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

Evaluate a single expression directly (for testing).

Source

pub fn eval_stmt(&mut self, stmt: &Statement<'_>) -> Result<Value>

Evaluate a single statement directly (for testing).

Trait Implementations§

Source§

impl Default for Interpreter

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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.