diff options
| author | Joel Martin <github@martintribe.org> | 2014-10-25 16:51:52 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2015-01-06 21:58:58 -0600 |
| commit | 4ee7c0f2970accc0f49eeac7fb2a0359b159c8ae (patch) | |
| tree | 91aee7451aefe68050ec797f6054c205df2358cf /rust/src/types.rs | |
| parent | 85bec8a08b76b5b4797ddd9976a138b22974e1c4 (diff) | |
| download | mal-4ee7c0f2970accc0f49eeac7fb2a0359b159c8ae.tar.gz mal-4ee7c0f2970accc0f49eeac7fb2a0359b159c8ae.zip | |
rust: add step7_quote. Refactor with type constructors.
Diffstat (limited to 'rust/src/types.rs')
| -rw-r--r-- | rust/src/types.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/rust/src/types.rs b/rust/src/types.rs index 8bd658f..85262c7 100644 --- a/rust/src/types.rs +++ b/rust/src/types.rs @@ -1,3 +1,5 @@ +#![allow(dead_code)] + use std::rc::Rc; use std::collections; use std::fmt; @@ -111,3 +113,22 @@ impl fmt::Show for MalType { write!(f, "{}", self.pr_str(true)) } } + +// Convenience constructor functions +pub fn _nil() -> MalVal { Rc::new(Nil) } +pub fn _true() -> MalVal { Rc::new(True) } +pub fn _false() -> MalVal { Rc::new(False) } +pub fn _int(i: int) -> MalVal { Rc::new(Int(i)) } + +pub fn symbol(strn: &str) -> MalVal { Rc::new(Sym(strn.to_string())) } +pub fn strn(strn: &str) -> MalVal { Rc::new(Strn(strn.to_string())) } +pub fn string(strn: String) -> MalVal { Rc::new(Strn(strn)) } + +pub fn list(lst: Vec<MalVal>) -> MalVal { Rc::new(List(lst)) } + +pub fn func(f: fn(Vec<MalVal>) -> MalRet ) -> MalVal { + Rc::new(Func(f)) +} +pub fn malfunc(exp: MalVal, env: Env, params: MalVal) -> MalVal { + Rc::new(MalFunc(MalFuncData{ exp: exp, env: env, params: params})) +} |
