Struct Interpreter

Source
pub struct Interpreter<Buffer: IoWrite, LibCore: StdCore> { /* private fields */ }

Implementations§

Source§

impl<Buffer: IoWrite, LibCore: StdCore> Interpreter<Buffer, LibCore>

Source

pub fn new(buffer: Buffer) -> Self

Create a new interpreter instance

Source

pub fn repl(&mut self, repl: bool) -> &mut Self

Enable or disable REPL mode (print last value to output buffer)

Source

pub fn with_search_path(&mut self, path: PathBuf) -> Result<(), Error>

Add module search path

Source

pub fn with_color(buffer: Buffer) -> Self

Enable ansi colored error message

Source

pub fn load_ext( &mut self, extension: Extension<Buffer>, ) -> Result<(), Extension<Buffer>>

Source

pub fn impl_extern_function<F>(&mut self, name: impl Into<String>, f: F)
where F: Fn(&mut State<'_, Buffer>, &[DiatomValue], &mut Buffer) -> Result<DiatomValue, String> + 'static + Send + Sync,

Directly declare external function as variable

Source

pub fn verify_input_completeness(&self, code: impl AsRef<str>) -> bool

Check if input is completeness

Incomplete input usually contains unclosed parentheses, quotes or open expression.

Source

pub fn decompile( &mut self, code: impl AsRef<str>, source: impl AsRef<OsStr>, is_phony: bool, ) -> Result<String, String>

Show decompiled byte code for given source code.

If compilation failed, Err will be returned.

Source

pub fn replace_buffer(&mut self, buffer: Buffer) -> Buffer

Replace output buffer and get the old one

Source

pub fn exec( &mut self, code: impl AsRef<str>, source: impl AsRef<OsStr>, is_phony: bool, ) -> Result<(), String>

Run a piece of diatom source code

§Parameters
  • code - Source code
  • source - name of source code file or where it is from
  • is_phony - Whether source is a real path or a place holder
§Return
  • Return the output of the program
  • If compilation failed or error occurs durning execution, an Err(String) that illustrates the error is returned.

Auto Trait Implementations§

§

impl<Buffer, LibCore> Freeze for Interpreter<Buffer, LibCore>
where Buffer: Freeze,

§

impl<Buffer, LibCore> !RefUnwindSafe for Interpreter<Buffer, LibCore>

§

impl<Buffer, LibCore> Send for Interpreter<Buffer, LibCore>
where Buffer: Send,

§

impl<Buffer, LibCore> !Sync for Interpreter<Buffer, LibCore>

§

impl<Buffer, LibCore> Unpin for Interpreter<Buffer, LibCore>
where Buffer: Unpin, LibCore: Unpin,

§

impl<Buffer, LibCore> !UnwindSafe for Interpreter<Buffer, LibCore>

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.