aboutsummaryrefslogtreecommitdiff
path: root/model.cpp
diff options
context:
space:
mode:
authorTeddy <ted.sybil@gmail.com>2013-08-04 10:00:30 +0800
committerTeddy <ted.sybil@gmail.com>2013-08-04 10:00:30 +0800
commit9c1af3a6e77d7a0e1dc66aa9166d0ead6a56d963 (patch)
treeb12624f6170e77c1e7c0d8d0885838176dadc186 /model.cpp
parent9e834528d38a89eb4075b09b35fb7b6e7636740d (diff)
modified the API of Env: add_binding
Diffstat (limited to 'model.cpp')
-rw-r--r--model.cpp15
1 files changed, 5 insertions, 10 deletions
diff --git a/model.cpp b/model.cpp
index ee578f2..95f70c6 100644
--- a/model.cpp
+++ b/model.cpp
@@ -131,8 +131,11 @@ string BuiltinProcObj::_debug_repr() { return ext_repr(); }
Environment::Environment(Environment *_prev_envt) : prev_envt(_prev_envt) {}
-void Environment::add_binding(SymObj *sym_obj, EvalObj *eval_obj) {
+bool Environment::add_binding(SymObj *sym_obj, EvalObj *eval_obj, bool def) {
+ bool has_key = binding.count(sym_obj->val);
+ if (!def && !has_key) return false;
binding[sym_obj->val] = eval_obj;
+ return true;
}
EvalObj *Environment::get_obj(EvalObj *obj) {
@@ -145,15 +148,7 @@ EvalObj *Environment::get_obj(EvalObj *obj) {
bool has_key = ptr->binding.count(name);
if (has_key) return ptr->binding[name];
}
- //TODO: exc key not found
-}
-
-bool Environment::has_obj(SymObj *sym_obj) {
- string name(sym_obj->val);
- for (Environment *ptr = this; ptr; ptr = ptr->prev_envt)
- if (ptr->binding.count(name))
- return true;
- return false;
+ return NULL; // Object not found
}
Continuation::Continuation(Environment *_envt, Cons *_pc,