// $Id$ #ifndef __rf_closure_ih__ #define __rf_closure_ih__ #include "rf_closure.hh" #include "rf_symbol.ih" #include "rf_expr.ih" namespace rftype { using namespace rfrt; inline Closure::Closure (Func* _func) : func (_func), args (null), current_arg (null) {} inline Closure::~Closure () { for (Arg* a = current_arg, *p; a; a = p) { p = a->prev; a->expr.~Expr(); expr_allocator->deallocate(reinterpret_cast(a)); } } inline void Closure::push_arg (Expr const& _expr) { Arg* a = reinterpret_cast(expr_allocator->allocate()); new (a) Arg(current_arg, _expr); args = current_arg = a; } inline Expr const* Closure::pop_arg () { if (current_arg) { Expr const* e = ¤t_arg->expr; current_arg = current_arg->prev; return e; } current_arg = args; return null; } inline Func const* Closure::get_func () const { return func; } inline Closure::InitParams::InitParams () : Expr (*__rf_closure_to_call->pop_arg()) {} inline bool Closure::operator == (Closure const& _c) const { if (func != _c.func) return false; for (Arg* a = args, *b = _c.args; a; a = a->prev, b = b->prev) { if (a->expr != b->expr) return false; } return true; } inline int Closure::compare (Closure const& _c1, Closure const& _c2) { if (_c1.func > _c2.func) return 1; if (_c1.func < _c2.func) return -1; for (Arg* a = _c1.args, *b = _c2.args; a; a = a->prev, b = b->prev) { int i = Expr::compare(a->expr, b->expr); if (i) return i; } return 0; } RF_NEW_SYMBOL(Closure, ObjectTerm); template <> inline bool RF_SYMBOL(Closure)::eq ( RF_SYMBOL(Closure) const* _s1, RF_SYMBOL(Closure) const* _s2 ) { return *_s1->get_obj_ptr() == *_s2->get_obj_ptr(); } template <> inline int RF_SYMBOL(Closure)::compare ( RF_SYMBOL(Closure) const* _s1, RF_SYMBOL(Closure) const* _s2 ) { return Closure::compare(*_s1->get_obj_ptr(), *_s2->get_obj_ptr()); } template <> inline pxx::WString RF_SYMBOL(Closure)::to_string (RF_SYMBOL(Closure) const* _s) { Closure* c = _s->get_obj_ptr(); int len = swprintf(temp_string, temp_string_len, L"pop_arg(); e; e = c->pop_arg()) str = str + L"|" + *e; return str + L">"; } } #endif // __rf_closure_ih__