aboutsummaryrefslogtreecommitdiff
path: root/rust/src/types.rs
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-10-27 21:42:46 -0500
committerJoel Martin <github@martintribe.org>2015-01-06 21:59:00 -0600
commit06fef9b51830a2aa696f3e108c56f306967ce465 (patch)
treed3568abe85505a7c825ad96ffabd44adc7b4d456 /rust/src/types.rs
parentb12d98e4e3424be6b1e851c9450e9532910996ec (diff)
downloadmal-06fef9b51830a2aa696f3e108c56f306967ce465.tar.gz
mal-06fef9b51830a2aa696f3e108c56f306967ce465.zip
rust: add atom support. Fix vector params.
Diffstat (limited to 'rust/src/types.rs')
-rw-r--r--rust/src/types.rs26
1 files changed, 21 insertions, 5 deletions
diff --git a/rust/src/types.rs b/rust/src/types.rs
index 80079ce..7c74894 100644
--- a/rust/src/types.rs
+++ b/rust/src/types.rs
@@ -1,6 +1,7 @@
#![allow(dead_code)]
use std::rc::Rc;
+use std::cell::RefCell;
use std::collections::HashMap;
use std::fmt;
use super::printer::{escape_str,pr_list};
@@ -22,6 +23,7 @@ pub enum MalType {
//Func(fn(&[MalVal]) -> MalRet),
//Func(|Vec<MalVal>|:'a -> MalRet),
MalFunc(MalFuncData),
+ Atom(RefCell<MalVal>),
}
pub type MalVal = Rc<MalType>;
@@ -63,6 +65,7 @@ pub struct MalFuncData {
pub env: Env,
pub params: MalVal,
pub is_macro: bool,
+ pub meta: MalVal,
}
impl MalType {
@@ -110,9 +113,9 @@ impl MalType {
MalFunc(ref mf) => {
res.push_str(format!("(fn* {} {})", mf.params, mf.exp).as_slice())
},
- /*
- Atom(ref v) => v.fmt(f),
- */
+ Atom(ref v) => {
+ res = format!("(atom {})", v.borrow());
+ },
};
res
}
@@ -299,14 +302,27 @@ pub fn func(f: fn(Vec<MalVal>) -> MalRet ) -> MalVal {
}
pub fn malfunc(eval: fn(MalVal, Env) -> MalRet,
exp: MalVal, env: Env, params: MalVal) -> MalVal {
- Rc::new(MalFunc(MalFuncData{eval: eval, exp: exp, env: env,
- params: params, is_macro: false}))
+ Rc::new(MalFunc(MalFuncData{eval: eval,
+ exp: exp,
+ env: env,
+ params: params,
+ is_macro: false,
+ meta: _nil()}))
}
pub fn malfuncd(mfd: MalFuncData) -> MalVal {
Rc::new(MalFunc(mfd))
}
+// Atoms
+pub fn atom(a:Vec<MalVal>) -> MalRet {
+ if a.len() != 1 {
+ return err_str("Wrong arity to atom call");
+ }
+ Ok(Rc::new(Atom(RefCell::new(a[0].clone()))))
+}
+
+
// General functions
pub fn sequential_q(a:Vec<MalVal>) -> MalRet {
if a.len() != 1 {