[][src]Enum wlambda::vval::VVal

pub enum VVal {
    Nul,
    Err(Rc<RefCell<(VVal, SynPos)>>),
    Bol(bool),
    Sym(Rc<RefCell<String>>),
    Str(Rc<RefCell<String>>),
    Byt(Rc<RefCell<Vec<u8>>>),
    Int(i64),
    Flt(f64),
    Syn(SynPos),
    Lst(Rc<RefCell<Vec<VVal>>>),
    Map(Rc<RefCell<FnvHashMap<String, VVal>>>),
    Fun(Rc<VValFun>),
    DropFun(Rc<DropVVal>),
    Ref(Rc<RefCell<VVal>>),
    CRef(Rc<RefCell<VVal>>),
    WWRef(Weak<RefCell<VVal>>),
    Usr(Box<dyn VValUserData>),
}

VVal aka. VariantValue is a data structure to represent all kinds of WLambda data structures.

It's used for the AST, for internal data and for runtime data structures.

Variants

Nul

The none value, the default value of all non initialized data.

The err value is a special sentinel value for representing any kind of application error condition. It's created using the special $e or $error syntax.

Bol(bool)

Representation of a boolean value.

Representation of a symbol or key.

This one might be interned at some point, so that it only contains an Rc in future.

Representation of a unicode/text string.

Byt(Rc<RefCell<Vec<u8>>>)

Representation of a byte buffer.

Int(i64)

Integer value

Flt(f64)

Float value

Syn(SynPos)

A syntax node in the AST, records the position too.

Lst(Rc<RefCell<Vec<VVal>>>)

A list (or vector) of VVals.

A mapping of strings to VVals.

Fun(Rc<VValFun>)

A function, see also VValFun

DropFun(Rc<DropVVal>)

A guarded VVal, that executes a given function when it is no longer referenced.

Ref(Rc<RefCell<VVal>>)

A (strong) reference to a VVal.

CRef(Rc<RefCell<VVal>>)

A (still strong) reference to a VVal, which becomes a weak reference if captured by a closure.

WWRef(Weak<RefCell<VVal>>)

A (weak) reference to a VVal. Might turn VVal::Nul anytime.

Usr(Box<dyn VValUserData>)

A vval that can box some user data which can later be accessed from inside user supplied Rust functions via std::any::Any.

Methods

impl VVal[src]

pub fn new_str(s: &str) -> VVal[src]

pub fn new_str_mv(s: String) -> VVal[src]

pub fn new_sym(s: &str) -> VVal[src]

pub fn new_sym_mv(s: String) -> VVal[src]

pub fn new_byt(v: Vec<u8>) -> VVal[src]

pub fn err(v: VVal, pos: SynPos) -> VVal[src]

pub fn err_msg(s: &str) -> VVal[src]

pub fn vec() -> VVal[src]

pub fn to_vec(&self) -> Vec<VVal>[src]

pub fn vec_from(vl: &[VVal]) -> VVal[src]

pub fn vec_mv(v: Vec<VVal>) -> VVal[src]

pub fn call(&self, env: &mut Env, args: &[VVal]) -> Result<VVal, StackAction>[src]

pub fn compare_str(&self, b: &VVal) -> Ordering[src]

pub fn shallow_clone(&self) -> VVal[src]

pub fn compare_num(&self, b: &VVal) -> Ordering[src]

pub fn sort<F>(&mut self, compare: F) where
    F: FnMut(&VVal, &VVal) -> Ordering
[src]

pub fn fisher_yates_shuffle<I>(&mut self, rand: I) where
    I: FnMut() -> i64
[src]

pub fn iter(&self) -> FromFn<Box<dyn FnMut() -> Option<VVal>>>[src]

This function returns you an iterator over the VVal. It will iterate over data such as VVal::Str, VVal::Sym, VVal::Lst, VVal::Map and VVal::Byt.

This functionality provides the for keyword/function in WLambda.

use wlambda::*;

let some_vec = VVal::vec();
some_vec.push(VVal::Int(10));
some_vec.push(VVal::Int(22));
some_vec.push(VVal::Int(36));

let mut sum = 0;
for v in some_vec.iter() {
    sum += v.i();
}

assert_eq!(sum, 68);

pub fn disable_function_arity(&self) -> VVal[src]

This method will disable all arity checks of the function in the VVal. Does nothing if the VVal is not a function.

It is used for disabling checks of drop functions, as they are evaluated in their own environment and there is no proper way to report errors upwards.

pub fn call_no_args(&self, env: &mut Env) -> Result<VVal, StackAction>[src]

pub fn call_internal(
    &self,
    env: &mut Env,
    argc: usize
) -> Result<VVal, StackAction>
[src]

pub fn to_ref(&self) -> VVal[src]

pub fn to_weakened_upvalue_ref(&self) -> VVal[src]

pub fn set_ref(&self, v: VVal) -> VVal[src]

pub fn deref(&self) -> VVal[src]

pub fn upgrade(self) -> VVal[src]

pub fn downgrade(self) -> VVal[src]

pub fn map() -> VVal[src]

pub fn sym(s: &str) -> VVal[src]

pub fn ref_id(&self) -> Option<i64>[src]

pub fn eqv(&self, v: &VVal) -> bool[src]

pub fn map_ok_skip<T, R>(&self, op: T, skip: usize) -> Vec<R> where
    T: FnMut(&VVal) -> R, 
[src]

pub fn map_skip<R, E, T>(&self, op: T, skip: usize) -> Result<Vec<R>, E> where
    T: FnMut(&VVal) -> Result<R, E>, 
[src]

pub fn unshift(&self, val: VVal) -> &VVal[src]

pub fn insert_at(&self, index: usize, val: VVal)[src]

pub fn set(&self, index: usize, val: VVal)[src]

pub fn set_at(&self, index: usize, val: VVal)[src]

pub fn at(&self, index: usize) -> Option<VVal>[src]

pub fn proto_data(&self) -> VVal[src]

pub fn proto_lookup(&self, key: &str) -> Option<VVal>[src]

pub fn get_key(&self, key: &str) -> Option<VVal>[src]

pub fn set_map_key_fun<T>(
    &self,
    key: String,
    fun: T,
    min_args: Option<usize>,
    max_args: Option<usize>,
    err_arg_ok: bool
) where
    T: 'static + Fn(&mut Env, usize) -> Result<VVal, StackAction>, 
[src]

pub fn set_map_key(&self, key: String, val: VVal)[src]

pub fn set_key_mv(&self, key: String, val: VVal)[src]

pub fn list_operation<O, R>(&self, op: O) -> Result<R, StackAction> where
    O: FnMut(&mut RefMut<Vec<VVal>>) -> R, 
[src]

pub fn set_key(&self, key: &VVal, val: VVal) -> Result<(), StackAction>[src]

pub fn pop(&self) -> VVal[src]

pub fn push(&self, val: VVal) -> &VVal[src]

pub fn is_empty(&self) -> bool[src]

pub fn len(&self) -> usize[src]

pub fn s_len(&self) -> usize[src]

pub fn s_raw(&self) -> String[src]

Returns string data unescaped and also turns VVal::Nul into an empty string.

Use this if you need the raw unescaped contents of VVal::Str, VVal::Sym, VVal::Byt and other VVals.

As this is used usually for generating output a VVal::Nul is turned into an empty string

use wlambda::VVal;

assert_eq!(VVal::Nul.s_raw(), "");
assert_eq!(VVal::new_str("Test").s_raw(), "Test");

pub fn is_float(&self) -> bool[src]

pub fn is_int(&self) -> bool[src]

pub fn is_sym(&self) -> bool[src]

pub fn is_syn(&self) -> bool[src]

pub fn get_syn_pos(&self) -> SynPos[src]

pub fn set_syn(&mut self, syn: Syntax)[src]

pub fn set_syn_at(&mut self, idx: usize, syn: Syntax)[src]

pub fn get_syn(&self) -> Syntax[src]

pub fn to_compile_err(&self, msg: String) -> Result<EvalNode, CompileError>[src]

pub fn is_ref(&self) -> bool[src]

pub fn is_wref(&self) -> bool[src]

pub fn is_bool(&self) -> bool[src]

pub fn is_bytes(&self) -> bool[src]

pub fn is_str(&self) -> bool[src]

pub fn is_fun(&self) -> bool[src]

pub fn is_vec(&self) -> bool[src]

pub fn is_map(&self) -> bool[src]

pub fn is_none(&self) -> bool[src]

pub fn is_err(&self) -> bool[src]

pub fn type_name(&self) -> String[src]

pub fn v_(&self, idx: usize) -> VVal[src]

Quick access method for retrieving the VVal at index idx. Returns VVal::Nul if the VVal is not a VVal::Lst or no such index exists. See also the shorthands v_i, v_f, v_s and v_s_raw.

 use wlambda::VVal;
 let v = VVal::vec();
 v.push(VVal::Int(10));
 v.push(VVal::Int(11));

 assert_eq!(v.v_(1).i(), 11);
 assert_eq!(v.v_i(1),    11);

pub fn v_k(&self, key: &str) -> VVal[src]

Quick access method for retrieving the VVal at key idx. Returns VVal::Nul if the VVal is not a VVal::Map or no such index exists. See also the shorthands v_ik, v_fk, v_sk and v_s_rawk.

 use wlambda::VVal;
 let v = VVal::map();
 v.set_map_key(String::from("aaa"), VVal::Int(12));
 v.set_map_key(String::from("abc"), VVal::Int(13));
 v.set_map_key(String::from("zyy"), VVal::Int(14));

 assert_eq!(v.v_k("abc").i(), 13);
 assert_eq!(v.v_ik("aaa"),    12);
 assert_eq!(v.v_ik("zyy"),    14);

pub fn v_i(&self, idx: usize) -> i64[src]

Quick access of an integer at the given idx. See also v_.

 let v = wlambda::VVal::vec();
 v.push(wlambda::VVal::Int(11));
 assert_eq!(v.v_i(0),    11);

pub fn v_ik(&self, key: &str) -> i64[src]

Quick access of the integer at the given key. See also v_k.

 let v = wlambda::VVal::map();
 v.set_map_key(String::from("aaa"), wlambda::VVal::new_str("10"));
 assert_eq!(v.v_ik("aaa"), 10);

pub fn v_s_raw(&self, idx: usize) -> String[src]

Quick access of a raw string at the given idx. See also v_.

 let v = wlambda::VVal::vec();
 v.push(wlambda::VVal::Int(12));
 assert_eq!(v.v_s_raw(0), "12");

pub fn v_s_rawk(&self, key: &str) -> String[src]

Quick access of the string at the given key. See also v_k.

 let v = wlambda::VVal::map();
 v.set_map_key(String::from("aaa"), wlambda::VVal::new_str("XYX"));
 assert_eq!(v.v_s_rawk("aaa"), "XYX");

pub fn v_s(&self, idx: usize) -> String[src]

Quick access of the string representation at the given idx. See also v_.

 let v = wlambda::VVal::vec();
 v.push(wlambda::VVal::Int(13));
 assert_eq!(v.v_s(0), "13");

pub fn v_sk(&self, key: &str) -> String[src]

Quick access of the string represenation at the given key. See also v_k.

 let v = wlambda::VVal::map();
 v.set_map_key(String::from("aaa"), wlambda::VVal::Flt(12.2));
 assert_eq!(v.v_sk("aaa"), "12.2");

pub fn v_f(&self, idx: usize) -> f64[src]

Quick access of the float at the given idx. See also v_.

 let v = wlambda::VVal::vec();
 v.push(wlambda::VVal::Flt(13.2));
 assert_eq!(v.v_f(0), 13.2);

pub fn v_fk(&self, key: &str) -> f64[src]

Quick access of the float at the given key. See also v_k.

 let v = wlambda::VVal::map();
 v.set_map_key(String::from("aaa"), wlambda::VVal::Flt(12.2));
 assert_eq!(v.v_fk("aaa"), 12.2);

pub fn for_each<T>(&self, op: T) where
    T: FnMut(&VVal), 
[src]

pub fn for_eachk<T>(&self, op: T) where
    T: FnMut(&str, &VVal), 
[src]

pub fn f(&self) -> f64[src]

pub fn i(&self) -> i64[src]

pub fn b(&self) -> bool[src]

pub fn as_bytes(&self) -> Vec<u8>[src]

pub fn s(&self) -> String[src]

Returns a string representation of the VVal data structure. It handles cyclic data structures fine. The purpose is to return an unambigous represenation of the data structure. That means strings are quoted and VVal::Nul becomes $n for instance.

If you need strings in pure form, use the s_raw() method.

use wlambda::VVal;

let v = VVal::Nul;
assert_eq!(v.s(), "$n");

assert_eq!(VVal::new_str("Foo").s(), "\"Foo\"");

pub fn to_msgpack(&self) -> Result<Vec<u8>, String>[src]

Serializes the VVal (non cyclic) structure to a msgpack byte vector.

pub fn from_msgpack(s: &[u8]) -> Result<VVal, String>[src]

Creates a VVal structure from a msgpack byte vector.

pub fn to_json(&self, not_pretty: bool) -> Result<String, String>[src]

Serializes the VVal (non cyclic) structure to a JSON string.

pub fn from_json(s: &str) -> Result<VVal, String>[src]

Creates a VVal structure from a JSON string.

Trait Implementations

impl Clone for VVal[src]

impl Debug for VVal[src]

impl<'de> Deserialize<'de> for VVal[src]

impl Serialize for VVal[src]

Auto Trait Implementations

impl !RefUnwindSafe for VVal

impl !Send for VVal

impl !Sync for VVal

impl Unpin for VVal

impl !UnwindSafe for VVal

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.