diff options
Diffstat (limited to 'python/py_scope.cc')
-rw-r--r-- | python/py_scope.cc | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/python/py_scope.cc b/python/py_scope.cc index e4eef37d..51a72c59 100644 --- a/python/py_scope.cc +++ b/python/py_scope.cc @@ -37,36 +37,42 @@ namespace ledger { using namespace boost::python; -#define EXC_TRANSLATOR(type) \ - void exc_translate_ ## type(const type& err) { \ - PyErr_SetString(PyExc_ArithmeticError, err.what()); \ +namespace { + void py_scope_define(scope_t& scope, const string& name, expr_t& def) + { + return scope.define(name, def.get_op()); } -//EXC_TRANSLATOR(scope_error) + expr_t py_scope_lookup(scope_t& scope, const string& name) + { + return scope.lookup(name); + } -void export_scope() -{ -#if 0 - class_< scope_t > ("Scope") - ; - class_< child_scope_t > ("ChildScope") - ; - class_< symbol_scope_t > ("SymbolScope") - ; - class_< call_scope_t > ("CallScope") - ; - class_< bind_scope_t > ("BindScope") - ; -#endif + expr_t py_scope_getattr(scope_t& scope, const string& name) + { + return scope.lookup(name); + } - //register_optional_to_python<amount_t>(); + struct scope_wrapper : public scope_t + { + PyObject * self; - //implicitly_convertible<string, amount_t>(); + scope_wrapper(PyObject * self_) : self(self_) {} -#define EXC_TRANSLATE(type) \ - register_exception_translator<type>(&exc_translate_ ## type); + virtual expr_t::ptr_op_t lookup(const string& name) { + return NULL; + } + }; +} - //EXC_TRANSLATE(scope_error); +void export_scope() +{ + class_< scope_t, scope_wrapper, boost::noncopyable > ("Scope", no_init) + .def("define", py_scope_define) + .def("lookup", py_scope_lookup) + .def("resolve", &scope_t::resolve) + .def("__getattr__", py_scope_getattr) + ; } } // namespace ledger |