[][src]Crate ketos

Ketos is a Lisp dialect functional programming language, designed to be a scripting and extension language for Rust programs.

use ketos::{Interpreter, FromValueRef};

// Create an interpreter.
let interp = Interpreter::new();

// Define a function.
interp.run_code(r#"
    (define (foo a)
      (* a 2))
    "#, None).unwrap();

// Call the function.
let result = interp.call("foo", vec![123.into()]).unwrap();

// Get a Rust value back.
let n = i32::from_value_ref(&result).unwrap();

assert_eq!(n, 246);

See examples/ for more examples on interacting with the Ketos interpreter.

Re-exports

pub use crate::bytecode::Code;
pub use crate::bytes::Bytes;
pub use crate::completion::complete_name;
pub use crate::compile::CompileError;
pub use crate::encode::DecodeError;
pub use crate::encode::EncodeError;
pub use crate::error::Error;
pub use crate::exec::Context;
pub use crate::exec::ExecError;
pub use crate::exec::panic;
pub use crate::exec::panic_none;
pub use crate::function::Arity;
pub use crate::interpreter::Builder;
pub use crate::interpreter::Interpreter;
pub use crate::integer::Integer;
pub use crate::integer::Ratio;
pub use crate::io::File;
pub use crate::io::GlobalIo;
pub use crate::io::IoError;
pub use crate::io::SharedWrite;
pub use crate::module::BuiltinModuleLoader;
pub use crate::module::FileModuleLoader;
pub use crate::module::Module;
pub use crate::module::ModuleBuilder;
pub use crate::module::ModuleLoader;
pub use crate::name::Name;
pub use crate::name::NameStore;
pub use crate::parser::ParseError;
pub use crate::parser::ParseErrorKind;
pub use crate::restrict::RestrictConfig;
pub use crate::restrict::RestrictError;
pub use crate::run::run_code;
pub use crate::scope::GlobalScope;
pub use crate::scope::Scope;
pub use crate::structs::StructDef;
pub use crate::structs::StructValue;
pub use crate::trace::clear_traceback;
pub use crate::trace::get_traceback;
pub use crate::trace::set_traceback;
pub use crate::trace::take_traceback;
pub use crate::trace::Trace;
pub use crate::value::ForeignValue;
pub use crate::value::FromValue;
pub use crate::value::FromValueRef;
pub use crate::value::Value;

Modules

any

Support for Any trait usage

args

Provides a helper macro for extracting arguments from Ketos values.

bytecode

Implements encoding and decoding of bytecode instruction format.

bytes

Implements a reference-counted byte string supporting efficient subslicing.

compile

Compiles expressions into bytecode objects.

completion

Performs name-based text completion using a GlobalScope.

encode

Implements encoding and decoding of compiled bytecode file format.

error

Contains consolidated Error type.

exec

Implements a virtual machine which interprets bytecode functions.

function

Contains implementations of core system functions.

integer

Arbitrary precision integer and ratio types.

interpreter

Provides a context in which to compile and execute code.

io

Creates an abstraction layer to I/O operations

lexer

Produces tokens from an input stream.

module

Implements loading named values from code modules.

name

Implements name interning and containers using names as keys.

parser

Parses a series of lexer tokens into a code expression.

pretty

Facilities for pretty-printing Values.

rc_vec

Implements a reference-counted Vec supporting efficient subslicing.

restrict

Configuration of runtime execution restrictions

run

Provides a facility for running code within an existing scope.

scope

Contains values associated with names in a given execution context.

string_fmt

Implements string formatting syntax.

structs

Implementation of Struct and StructDef values

trace

Provides facilities for expressing and storing tracebacks.

value

Represents any possible value type.

Macros

ketos_args

Parses a set of arguments from a &[Value].

ketos_closure

Similar to ketos_fn, this is a convenience macro fo redefining foreign functions, with automatic conversion between rust and ketos values. The difference is that this takes a closure instead.

ketos_fn

Creates a foreign function that implicitly converts input arguments into Rust values and converts its result into a ketos value.