diff options
author | John Wiegley <johnw@newartisans.com> | 2009-02-08 04:30:05 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-02-08 04:30:05 -0400 |
commit | 2d5ad7dee89ebe9c014270882e44d3a7a8a626fd (patch) | |
tree | 20a6d2c34d86dcc9f68201dc1028f9053834ba7b /src/scope.h | |
parent | f7f5ed3d0fe96854f048609433fc68a3fb6fcf34 (diff) | |
download | fork-ledger-2d5ad7dee89ebe9c014270882e44d3a7a8a626fd.tar.gz fork-ledger-2d5ad7dee89ebe9c014270882e44d3a7a8a626fd.tar.bz2 fork-ledger-2d5ad7dee89ebe9c014270882e44d3a7a8a626fd.zip |
Added support for value expression definitions.
Example:
] expr f(x) := x + 100
] expr f(100)
200
Diffstat (limited to 'src/scope.h')
-rw-r--r-- | src/scope.h | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/scope.h b/src/scope.h index 37ca1ccd..8323f224 100644 --- a/src/scope.h +++ b/src/scope.h @@ -66,6 +66,7 @@ public: TRACE_DTOR(scope_t); } + virtual void define(const string& name, expr_t::ptr_op_t def) {} virtual expr_t::ptr_op_t lookup(const string& name) = 0; value_t resolve(const string& name) { @@ -98,6 +99,11 @@ public: TRACE_DTOR(child_scope_t); } + virtual void define(const string& name, expr_t::ptr_op_t def) { + if (parent) + parent->define(name, def); + } + virtual expr_t::ptr_op_t lookup(const string& name) { if (parent) return parent->lookup(name); @@ -127,12 +133,6 @@ public: TRACE_DTOR(symbol_scope_t); } - void define(const string& name, const value_t& val) { - define(name, expr_t::op_t::wrap_value(val)); - } - void define(const string& name, const function_t& func) { - define(name, expr_t::op_t::wrap_functor(func)); - } virtual void define(const string& name, expr_t::ptr_op_t def); virtual expr_t::ptr_op_t lookup(const string& name); @@ -211,6 +211,11 @@ public: TRACE_DTOR(bind_scope_t); } + virtual void define(const string& name, expr_t::ptr_op_t def) { + parent->define(name, def); + grandchild.define(name, def); + } + virtual expr_t::ptr_op_t lookup(const string& name) { if (expr_t::ptr_op_t def = grandchild.lookup(name)) return def; |