Changeset 1772
- Timestamp:
- Jun 9, 2005, 7:13:32 AM (16 years ago)
- Location:
- to-imperative/trunk/runtime
- Files:
-
- 2 added
- 4 deleted
- 29 edited
Legend:
- Unmodified
- Added
- Removed
-
to-imperative/trunk/runtime/Makefile
r1763 r1772 16 16 rf_memory_chunk \ 17 17 rf_types \ 18 rf_parenth \19 18 rf_char \ 20 19 rf_word \ … … 25 24 rf_static_object \ 26 25 rf_object_ref \ 27 rf_box \28 26 rf_vector \ 29 27 rf_string \ -
to-imperative/trunk/runtime/file_list
r1763 r1772 11 11 rf_memory_chunk 12 12 rf_types 13 rf_parenth14 13 rf_char 15 14 rf_word … … 20 19 rf_static_object 21 20 rf_object_ref 22 rf_box23 21 rf_vector 24 22 rf_string -
to-imperative/trunk/runtime/rf_arg.hh
r1490 r1772 25 25 26 26 #include "rf_expr.ih" 27 #include "rf_stack. hh"27 #include "rf_stack.ih" 28 28 29 29 namespace rfrt -
to-imperative/trunk/runtime/rf_box.hh
r1730 r1772 2 2 #define __rf_box_hh__ 3 3 4 #include "rf_types.hh" 5 #include "rf_object.hh" 6 #include "rf_expr.hh" 4 #include "rf_symbol.ih" 5 #include "rf_expr.ih" 7 6 8 7 namespace rftype 9 8 { 10 9 11 using namespace rfrt ; 10 class BoxContents : public Expr 11 { 12 public: 12 13 13 class Box : 14 public Object 15 { 14 BoxContents () : Expr() 15 {} 16 17 BoxContents (Expr const& _e) : Expr(_e) 18 {} 19 20 Expr& operator = (Expr const& _e) 21 { 22 return Expr::operator=(_e); 23 }; 24 }; 16 25 17 private: 26 RF_NEW_SYMBOL(BoxContents, ObjectTerm); 27 RF_NEW_SYMBOL(NamedObject<BoxContents>, ObjectTerm); 18 28 19 Expr content ; 20 21 static ObjectRegister reg ; 22 23 NO_COPY_CTOR(Box) 24 25 public: 26 27 inline Box () ; 28 inline Box (Expr const& _expr) ; 29 inline Box& operator = (Box const& _box) ; 30 31 inline unsigned get_type () const ; 32 inline uint32_t hash () const ; 33 34 inline void put (Expr const& _expr) ; 35 inline Expr get () const ; 36 37 inline pxx::WString to_string () const ; 38 39 }; 29 inline pxx::WString RF_SYMBOL(BoxContents)::to_string (RF_SYMBOL(BoxContents) const* _s) 30 { 31 size_t max_len = hex_ptr_len + 10; 32 wchar_t* str = static_cast<wchar_t*>(alloca(max_len * sizeof(wchar_t))); 33 Expr* ptr = _s->get_obj_ptr(); 34 int len = swprintf(str, max_len, L"<Box|%p|", ptr); 35 if (-1 == len) 36 FATAL("<Box|%p| is more then %u wide characters", ptr, max_len); 37 return pxx::WString(str, len) + pxx::WString(*ptr) + pxx::WString(L">"); 38 } 40 39 41 40 } -
to-imperative/trunk/runtime/rf_char.cc
r1763 r1772 65 65 { 66 66 if (p->is_ref()) 67 e = e + lp + to_chars( static_cast<Parenth*>(p)->get_expr()) + rp;67 e = e + lp + to_chars(*p->get_obj_ptr<Expr>()) + rp; 68 68 else 69 69 e = e + Char::create_expr(WString(*p)); … … 140 140 141 141 short_type_funcs_t Char::funcs = { 142 0, 142 143 null, // Char::ctor, 143 144 null, // Char::dtor, … … 145 146 null, // (int (*)(Term const*, Term const*))(Char::compare), 146 147 null, // (uint32_t (*)(Term const*))(Char::hash), 147 (pxx::WString (*)(Term const*))(Char::to_string) 148 (pxx::WString (*)(Term const*))(Char::to_string), 149 null 148 150 }; 149 151 -
to-imperative/trunk/runtime/rf_common.cc
r1700 r1772 30 30 void* stack_start = (void*)0; 31 31 uintptr_t stack_size = default_stack_size ; 32 bool init_done = false; 32 33 bool use_rts = true; 33 34 bool trap_stack_on = false; -
to-imperative/trunk/runtime/rf_common.hh
r1730 r1772 27 27 extern uintptr_t stack_size ; 28 28 extern void* stack_start ; 29 extern bool init_done ; 29 30 extern bool use_rts ; 30 31 extern bool trap_stack_on ; -
to-imperative/trunk/runtime/rf_core.cc
r1768 r1772 186 186 using namespace rfrt; 187 187 188 TypeRegister rftype::Parenth::reg(&Parenth::funcs, type_parenth) ; 188 RF_REGISTER_SYMBOL(Expr); 189 //TypeRegister rftype::Parenth::reg(&Parenth::funcs, type_parenth) ; 189 190 TypeRegister rftype::ObjectRef::reg(&ObjectRef::funcs, type_object) ; 190 191 TypeRegister rftype::Char::reg(&Char::funcs, type_char) ; … … 197 198 #endif // !defined RFRT_WITHOUT_GMP 198 199 199 ObjectRegister rftype::Box::reg(type_box) ;200 200 ObjectRegister rftype::Vector::reg(type_vector) ; 201 201 ObjectRegister rftype::Channel::reg(type_channel) ; … … 203 203 ObjectRegister rftype::Table::reg(type_table) ; 204 204 ObjectRegister rftype::Func::reg(type_func) ; 205 206 RF_REGISTER_SYMBOL(BoxContents); 207 RF_REGISTER_SYMBOL_VARIANT(NamedObject<BoxContents>, BoxContents); 205 208 206 209 int main (int _argc, char* _argv[]) … … 246 249 } 247 250 if (init_StdIn) init_StdIn(); 251 init_done = true; 252 D( printf("=== Init is done! ===\n"); ) 248 253 Expr res; 249 254 try { -
to-imperative/trunk/runtime/rf_core.hh
r1763 r1772 27 27 #include "rf_term.ih" 28 28 #include "rf_expr.ih" 29 #include "rf_stack. hh"29 #include "rf_stack.ih" 30 30 #include "rf_arg.hh" 31 31 #include "rf_result.hh" 32 #include "rf_retval. hh"32 #include "rf_retval.ih" 33 33 #include "rf_macros.hh" 34 34 #include "rf_memory_chunk.hh" … … 38 38 #include "rf_integer.ih" 39 39 #include "rf_word.ih" 40 #include "rf_box.ih"41 40 #include "rf_vector.ih" 42 41 #include "rf_channel.ih" … … 46 45 #include "rf_static_object.ih" 47 46 #include "rf_symbol.ih" 47 #include "rf_box.hh" 48 48 49 49 #include "pxx_heap_allocator.ih" -
to-imperative/trunk/runtime/rf_expr.hh
r1768 r1772 237 237 template <class ObjClass, class CppType1, class CppType2> 238 238 static inline Expr create_sym (const CppType1& _arg1, const CppType2& _arg2) ; 239 240 template <class ObjClass> 241 static inline Expr create_static_sym (wchar_t const* _name) ; 239 242 240 243 private: -
to-imperative/trunk/runtime/rf_expr.ih
r1768 r1772 14 14 #include "rf_expr.hh" 15 15 #include "rf_term.ih" 16 #include "rf_parenth. ih"16 #include "rf_parenth.hh" 17 17 #include "rf_object_ref.ih" 18 #include "rf_static_object.ih" 18 19 #include "rf_integer.ih" 19 20 #include "rf_short_int.ih" … … 111 112 // If we really have a reference term... 112 113 if (_cp->is_ref()) { 113 const Parenth* p = static_cast<const Parenth*>(_cp);114 new(this) Expr( p->get_expr());114 // const Parenth* p = static_cast<const Parenth*>(_cp); 115 new(this) Expr(*_cp->get_obj_ptr<Expr>()); 115 116 } 116 117 // … … 162 163 inline Expr& Expr::operator = (Expr const& _expr) 163 164 { 164 D(printf("%p(%p,%p,%p) = %p(%p,%p,%p) ,",165 D(printf("%p(%p,%p,%p) = %p(%p,%p,%p)", 165 166 this, first, last, mem_chunk, 166 167 &_expr, _expr.first, _expr.last, _expr.mem_chunk); 167 _expr.writeln(stdout); 168 ) 168 if (init_done) { 169 printf(", "); 170 _expr.writeln(stdout); 171 } 172 else 173 printf("\n"); 174 ) 169 175 // 170 176 // If we are not assigning to self … … 185 191 { 186 192 // return Expr(Term(self)); 187 Expr res(1, 0); 188 new(res.first) Parenth(self); 189 return res; 193 // Expr res(1, 0); 194 // new(res.first) Parenth(self); 195 // return res; 196 return create_sym<Expr>(self); 190 197 } 191 198 … … 497 504 { 498 505 Expr e(1); 499 new (e.first) Symbol<ObjClass, typename SymbolType<ObjClass>:: type>();500 e.set_flat_bit<typename SymbolType<ObjClass>:: type>();506 new (e.first) Symbol<ObjClass, typename SymbolType<ObjClass>::Type>(); 507 e.set_flat_bit<typename SymbolType<ObjClass>::Type>(); 501 508 return e; 502 509 } 510 511 template <class ObjClass> 512 inline Expr Expr::create_static_sym (wchar_t const* _name) 513 { 514 Expr e(1); 515 new (e.first) Symbol<NamedObject<ObjClass>, ObjectTerm>(_name); 516 e.set_flat_bit<ObjectTerm>(); 517 return e; 518 } 519 503 520 504 521 template <class ObjClass, class CppType1> … … 506 523 { 507 524 Expr e(1); 508 new (e.first) Symbol<ObjClass, typename SymbolType<ObjClass>:: type>(_arg1);509 e.set_flat_bit<typename SymbolType<ObjClass>:: type>();525 new (e.first) Symbol<ObjClass, typename SymbolType<ObjClass>::Type>(_arg1); 526 e.set_flat_bit<typename SymbolType<ObjClass>::Type>(); 510 527 return e; 511 528 } … … 516 533 Expr e(1); 517 534 new (e.first) 518 Symbol<ObjClass, typename SymbolType<ObjClass>:: type>(_arg1, _arg2);519 e.set_flat_bit<typename SymbolType<ObjClass>:: type>();535 Symbol<ObjClass, typename SymbolType<ObjClass>::Type>(_arg1, _arg2); 536 e.set_flat_bit<typename SymbolType<ObjClass>::Type>(); 520 537 return e; 521 538 } … … 928 945 } 929 946 if (p != first) fputc(' ', _fp); 930 if (p-> get_type() == type_parenth) {947 if (p->is_ref()) { 931 948 if (fputc('(', _fp) == EOF) return false; 932 949 Expr e(p); … … 992 1009 if (p->is_sym()) { 993 1010 res = res + (WString)(*p); 994 } else if (p->is_ref()) { 1011 } 1012 else { 995 1013 res = res + WString(L"(") + (WString)(Expr(p)) + WString(L")"); 996 } else {997 FATAL("Not supported yet");998 1014 } 999 1015 } -
to-imperative/trunk/runtime/rf_integer.cc
r1730 r1772 52 52 53 53 short_type_funcs_t Integer::funcs = { 54 0, 54 55 (void (*)(Term*, Term const*))(Integer::ctor), 55 56 (void (*)(Term*))(Integer::dtor), … … 57 58 (int (*)(Term const*, Term const*))(Integer::compare), 58 59 (uint32_t (*)(Term const*))(Integer::hash), 59 (pxx::WString (*)(Term const*))(Integer::to_string) 60 (pxx::WString (*)(Term const*))(Integer::to_string), 61 null 60 62 }; 61 63 -
to-imperative/trunk/runtime/rf_macros.cc
r1730 r1772 1 #include "rf_retval.hh"2 #include "rf_expr.hh"3 1 #include "rf_macros.hh" 4 #include "rf_func.ih"5 2 6 3 namespace rfrt -
to-imperative/trunk/runtime/rf_macros.hh
r1768 r1772 275 275 #endif 276 276 277 #define RF_NEW_SYMBOL( t, c) \277 #define RF_NEW_SYMBOL(CppType, TermClass) \ 278 278 template<> \ 279 struct SymbolType< t> \279 struct SymbolType< CppType > \ 280 280 { \ 281 281 /*enum { type = c };*/ \ 282 typedef c type; \282 typedef TermClass Type; \ 283 283 }; 284 284 285 #define RF_SYMBOL(t) Symbol<t, SymbolType<t>::type> 285 #define RF_SYMBOL(CppType) Symbol<CppType, SymbolType< CppType >::Type> 286 287 #define RF_REGISTER_SYMBOL(CppType) \ 288 template <> \ 289 const TypeRegister RF_SYMBOL(CppType)::reg(&RF_SYMBOL(CppType)::funcs) 290 291 #define RF_REGISTER_SYMBOL_VARIANT(CppType, InstCppType) \ 292 template <> \ 293 const TypeRegister RF_SYMBOL(CppType)::reg( \ 294 RF_SYMBOL(InstCppType)::get_type(), \ 295 &RF_SYMBOL(CppType)::funcs \ 296 ) 286 297 287 298 } -
to-imperative/trunk/runtime/rf_object_ref.cc
r1678 r1772 30 30 31 31 short_type_funcs_t ObjectRef::funcs = { 32 0, 32 33 (void (*)(Term*, Term const*))(ObjectRef::ctor), 33 34 (void (*)(Term*))(ObjectRef::dtor), … … 35 36 null, // (int (*)(Term const*, Term const*))(ObjectRef::compare), FIXME: 36 37 null, // (uint32_t (*)(Term const*))(ObjectRef::hash), FIXME: 37 (pxx::WString (*)(Term const*))(ObjectRef::to_string) 38 (pxx::WString (*)(Term const*))(ObjectRef::to_string), 39 null 38 40 }; 39 41 -
to-imperative/trunk/runtime/rf_parenth.hh
r1381 r1772 2 2 #define __rf_parenth_hh__ 3 3 4 #include "rf_ types.hh"4 #include "rf_symbol.ih" 5 5 #include "rf_expr.hh" 6 6 … … 10 10 using namespace rfrt ; 11 11 12 class Parenth : 13 public Term 12 RF_NEW_SYMBOL(Expr, ObjectTerm); 13 14 inline bool RF_SYMBOL(Expr)::eq ( 15 RF_SYMBOL(Expr) const* _s1, RF_SYMBOL(Expr) const* _s2 16 ) 14 17 { 18 return (*_s1->get_obj_ptr()) == (*_s2->get_obj_ptr()); 19 } 15 20 16 struct Content 17 { 18 uintptr_t ref_count; 19 Expr expr; 20 }; 21 inline int RF_SYMBOL(Expr)::compare ( 22 RF_SYMBOL(Expr) const* _s1, RF_SYMBOL(Expr) const* _s2 23 ) 24 { 25 return Expr::compare(*_s1->get_obj_ptr(), *_s2->get_obj_ptr()); 26 } 21 27 22 NO_COPY_CTOR(Parenth) 23 NO_ASSIGN(Parenth) 24 25 public: 26 27 inline Parenth (const Expr& _expr) ; 28 29 inline ~Parenth () ; 30 31 inline const Expr& get_expr () const ; 32 33 static void ctor (Parenth* _to, Parenth const* _from) ; 34 static void dtor (Parenth* _parenth) ; 35 static bool eq (Parenth const* _parenth1, Parenth const* _parenth2) ; 36 static int compare (Parenth const* _parenth1, Parenth const* _parenth2) ; 37 static uint32_t hash (Parenth const* _parenth) ; 38 static pxx::WString to_string (Parenth const* _parenth) ; 39 static short_type_funcs_t funcs ; 40 static TypeRegister reg ; 41 42 }; 43 44 28 inline pxx::WString RF_SYMBOL(Expr)::to_string (RF_SYMBOL(Expr) const* _s) 29 { 30 return pxx::WString(L"(") 31 + pxx::WString(*_s->get_obj_ptr()) 32 + pxx::WString(L")"); 33 } 45 34 46 35 } -
to-imperative/trunk/runtime/rf_result.hh
r1533 r1772 25 25 26 26 #include "rf_stack.hh" 27 #include "rf_expr.ih" 27 28 28 29 namespace rfrt -
to-imperative/trunk/runtime/rf_retval.cc
r299 r1772 1 #include "rf_retval. hh"1 #include "rf_retval.ih" 2 2 3 3 // -
to-imperative/trunk/runtime/rf_retval.hh
r1700 r1772 25 25 26 26 #include "rf_expr.hh" 27 #include "rf_stack.hh"28 27 29 28 namespace rftype { … … 50 49 {} 51 50 52 inline RetVal (bool _b = true) 53 { 54 if (_b) 55 data = 0; 56 else { 57 data = 1; 58 stack->destroy_results(); 59 } 60 } 51 inline RetVal (bool _b = true) ; 61 52 62 inline RetVal (Expr* _saved_top) : 63 data (1) 64 { 65 stack->destroy_results(_saved_top, stack->get_depth() - 1); 66 } 53 inline RetVal (Expr* _saved_top) ; 67 54 68 55 inline ~RetVal () 69 56 {} 70 57 71 inline operator bool () const 72 { 73 return (data & uintptr_t(0x01)) == 0; 74 } 58 inline operator bool () const ; 75 59 76 inline bool is_tail () const 77 { 78 return data > 1; 79 } 60 inline bool is_tail () const ; 80 61 81 inline rftype::Func* get_ptr () const 82 { 83 // return (rf_func_t)(data & ~(uintptr_t(0x01))); 84 return reinterpret_cast<rftype::Func*>(data); 85 } 62 inline rftype::Func* get_ptr () const ; 86 63 87 64 }; -
to-imperative/trunk/runtime/rf_short_int.cc
r1671 r1772 122 122 123 123 short_type_funcs_t Int32::funcs = { 124 0, 124 125 null, // (void (*)(Term*, Term const*))(Int32::ctor), 125 126 null, // ShortInt::dtor, … … 127 128 (int (*)(Term const*, Term const*))(Int32::compare), 128 129 (uint32_t (*)(Term const*))(Int32::hash), 129 (pxx::WString (*)(Term const*))(Int32::to_string) 130 (pxx::WString (*)(Term const*))(Int32::to_string), 131 null 130 132 }; 131 133 -
to-imperative/trunk/runtime/rf_stack.cc
r1490 r1772 21 21 // Author: Andrey Slepuhin <pooh@msu.ru> 22 22 23 #include "rf_stack. hh"23 #include "rf_stack.ih" 24 24 25 25 namespace rfrt -
to-imperative/trunk/runtime/rf_stack.hh
r1763 r1772 19 19 // $Revision$ 20 20 // $Date$ 21 // Author: Andrey Slepuhin <pooh@msu.ru>22 21 23 22 #ifndef __rf_stack_hh__ 24 23 #define __rf_stack_hh__ 25 24 26 #include "rf_expr.ih" 27 #include "rf_integer.ih" 25 #include "rf_expr.hh" 28 26 #include "pxx_heap.ih" 29 27 … … 64 62 {} 65 63 66 inline void push (Expr const& _expr) 67 { 68 if (top > last) FATAL("Stack exhausted"); 69 new (top++) Expr(_expr); 70 } 64 inline void push (Expr const& _expr) ; 71 65 72 66 inline void pop () 73 67 {} 74 68 75 inline void pop (Expr& _expr) 76 { 77 _expr.~Expr(); 78 new (&_expr) Expr(top++); 79 } 69 inline void pop (Expr& _expr) ; 80 70 81 inline void pop (Result& _res) ;71 inline void pop (Result& _res) ; 82 72 83 inline Expr const* get () 84 { 85 return top++; 86 } 73 inline Expr const* get () ; 87 74 88 inline Expr* get_top () 89 { 90 args_num = -1; 91 return top; 92 } 75 inline Expr* get_top () ; 93 76 94 inline void set_top (Expr* _top) 95 { 96 top = _top; 97 } 77 inline void set_top (Expr* _top) ; 98 78 99 inline void destroy_results (Expr* _saved_top, size_t _saved_depth) 100 { 101 while (top > _saved_top) { 102 top--; 103 D( printf("destroy_results: %p(%p,%p,%p)\n", 104 top, top->get_first(), top->get_last(), top->get_mem_chunk()); ) 105 top->~Expr(); 106 } 107 depth = _saved_depth; 108 } 79 inline void destroy_results (Expr* _saved_top, size_t _saved_depth) ; 109 80 110 inline void destroy_results () 111 { 112 top--; 113 Expr* ress = top - *(reinterpret_cast<uintptr_t*>(top)); 114 Expr* args = ress - *(reinterpret_cast<uintptr_t*>(top) + 1); 115 while (top > ress) 116 (--top)->~Expr(); 117 top = args; 118 dec_depth(); 119 } 81 inline void destroy_results () ; 120 82 121 inline void cleanup (size_t _saved_depth) 122 { 123 if (trap_stack_on) trap_stack = get_part(0, depth - _saved_depth); 124 while (depth > _saved_depth) { 125 destroy_results(); 126 } 127 } 83 inline void cleanup (size_t _saved_depth) ; 128 84 129 inline void start_push_mode () 130 { 131 args_num = -1; 132 saved_top = top; 133 } 85 inline void start_push_mode () ; 134 86 135 inline void stop_push_mode () 136 { 137 args_num = top - saved_top; 138 top = saved_top; 139 }; 87 inline void stop_push_mode () ; 140 88 141 inline void start_ress_mode () 142 { 143 saved_top = top; 144 } 89 inline void start_ress_mode () ; 145 90 146 inline void stop_ress_mode (rftype::Object const* _f) 147 { 148 if (top > last) FATAL("Stack exhausted"); 149 uintptr_t* p = reinterpret_cast<uintptr_t*>(top); 150 *p++ = top - saved_top; 151 *p++ = args_num; 152 *p = reinterpret_cast<uintptr_t>(_f); 153 top++; 154 inc_depth(); 155 } 91 inline void stop_ress_mode (rftype::Object const* _f) ; 156 92 157 inline void start_pop_mode () 158 { 159 top--; 160 top -= *reinterpret_cast<uintptr_t*>(top); 161 } 93 inline void start_pop_mode () ; 162 94 163 inline void start_pop_mode (Expr* const __rf_call_saved_top) 164 { 165 top = __rf_call_saved_top; 166 args_num = 0; 167 } 95 inline void start_pop_mode (Expr* const __rf_call_saved_top) ; 168 96 169 inline void stop_pop_mode () 170 { 171 uintptr_t* p = reinterpret_cast<uintptr_t*>(top); 172 top -= *p + *(p + 1); 173 dec_depth(); 174 } 97 inline void stop_pop_mode () ; 175 98 176 inline bool is_in_push_mode () const 177 { 178 return args_num == -1; 179 } 99 inline bool is_in_push_mode () const ; 180 100 181 inline Expr* get_upper (size_t _offset) const 182 { 183 Expr* node = top; 184 while (_offset--) 185 { 186 node--; 187 uintptr_t* p = reinterpret_cast<uintptr_t*>(node); 188 node -= *p + *(p + 1); 189 } 190 return node; 191 } 101 inline Expr* get_upper (size_t _offset) const ; 192 102 193 inline void up () 194 { 195 top = get_upper(1); 196 dec_depth(); 197 } 103 inline void up () ; 198 104 199 inline void inc_depth () 200 { 201 depth++; 202 } 105 inline void inc_depth () ; 203 106 204 inline void dec_depth () 205 { 206 depth--; 207 } 107 inline void dec_depth () ; 208 108 209 inline size_t get_depth () const 210 { 211 return depth; 212 } 109 inline size_t get_depth () const ; 213 110 214 inline rftype::Object* get_func (size_t _depth) const 215 { 216 uintptr_t* p = reinterpret_cast<uintptr_t*>(get_upper(depth - _depth) - 1); 217 return reinterpret_cast<rftype::Object*>(*(p + 2)); 218 } 111 inline rftype::Object* get_func (size_t _depth) const ; 219 112 220 inline int get_args (size_t _depth, Expr** _args) const 221 { 222 uintptr_t* p = reinterpret_cast<uintptr_t*>(get_upper(depth - _depth) - 1); 223 *_args = reinterpret_cast<Expr*>(p) - *p - *(p + 1); 224 return *(p + 1); 225 } 113 inline int get_args (size_t _depth, Expr** _args) const ; 226 114 227 inline static rftype::Object* getf (Expr const* _p) 228 { 229 return reinterpret_cast<rftype::Object*>( 230 *(reinterpret_cast<uintptr_t const*>(_p) + 2)); 231 } 115 inline static rftype::Object* getf (Expr const* _p) ; 232 116 233 inline static int getn (Expr const* _p) 234 { 235 return *(reinterpret_cast<uintptr_t const*>(_p) + 1); 236 } 117 inline static int getn (Expr const* _p) ; 237 118 238 inline static Expr const* geta (Expr const* _p) 239 { 240 return _p - *reinterpret_cast<uintptr_t const*>(_p) 241 - *(reinterpret_cast<uintptr_t const*>(_p) + 1); 242 } 119 inline static Expr const* geta (Expr const* _p) ; 243 120 244 inline static Expr const* getup (Expr const* _p) 245 { 246 return geta(_p) - 1; 247 } 121 inline static Expr const* getup (Expr const* _p) ; 248 122 249 inline Expr get_part (size_t _offset, size_t _len) const 250 { 251 size_t depth = get_depth() - _offset; 252 if (!_len) _len = depth; 253 Expr const* p = get_upper(_offset) - 1; 254 Expr e; 255 while (_len--) 256 { 257 Expr s_f(getf(p)); 258 int n = getn(p); 259 Expr const* ap = geta(p); 260 Expr e_args; 261 while (n--) e_args = e_args + (*ap++)(); 262 e = e + (Expr::create<Integer>(depth--) + s_f + e_args)(); 263 p = getup(p); 264 } 265 return e; 266 } 123 inline Expr get_part (size_t _offset, size_t _len) const ; 267 124 268 125 }; … … 270 127 extern Stack* stack ; 271 128 272 inline Expr const& Expr::operator , (Expr const& _expr) const273 {274 stack->push(*this);275 return _expr;276 }277 278 inline Expr const& Expr::operator , (Expr const& _expr)279 {280 stack->push(*this);281 return _expr;282 }283 284 inline Expr& Expr::operator , (Expr& _expr)285 {286 if (stack->is_in_push_mode())287 stack->push(*this);288 else289 stack->pop(*this);290 return _expr;291 }292 293 inline Result& Expr::operator , (Result& _res)294 {295 stack->pop(*this);296 return _res;297 }298 299 129 } 300 130 -
to-imperative/trunk/runtime/rf_symbol.hh
r1768 r1772 85 85 86 86 static short_type_funcs_t funcs ; 87 87 88 static const TypeRegister reg ; 88 89 … … 94 95 struct SymbolType; 95 96 97 template<class C> 98 class NamedObject : 99 public C 100 { 101 public: 102 pxx::WString name; 103 inline NamedObject (wchar_t const* _name) : C(), name(_name) {}; 104 }; 105 106 template<class C> 107 class Symbol<NamedObject<C>, ObjectTerm> : 108 public Term 109 { 110 111 struct Wrapper 112 { 113 size_t ref_count; 114 NamedObject<C> object; 115 }; 116 117 NO_COPY_CTOR(Symbol) 118 NO_ASSIGN(Symbol) 119 120 public: 121 122 inline Symbol () ; 123 124 template<typename CppType1> 125 inline Symbol (CppType1 _arg1) ; 126 127 template<typename CppType1, typename CppType2> 128 inline Symbol (CppType1 _arg1, CppType2 _arg2) ; 129 130 inline NamedObject<C>* get_obj_ptr () const ; 131 132 static void ctor (Symbol* _to, Symbol const* _from) ; 133 static void dtor (Symbol* _term) ; 134 static bool eq (Symbol const* _term1, Symbol const* _term2) ; 135 static int compare (Symbol const* _term1, Symbol const* _term2) ; 136 static uint32_t hash (Symbol const* _term) ; 137 static pxx::WString to_string (Symbol const* _term) ; 138 static size_t get_name (Symbol const* _s, wchar_t const** _np) ; 139 140 static short_type_funcs_t funcs ; 141 142 static const TypeRegister reg ; 143 144 static inline unsigned get_type() ; 145 146 }; 147 96 148 } 97 149 -
to-imperative/trunk/runtime/rf_symbol.ih
r1768 r1772 8 8 9 9 #include "rf_symbol.hh" 10 #include "rf_macros.hh" 10 11 11 12 namespace rftype … … 86 87 allocator->deallocate(w); 87 88 } 89 } 90 91 template <class C> 92 bool Symbol<C, ObjectTerm>::eq ( 93 Symbol<C, ObjectTerm> const* _s1, Symbol<C, ObjectTerm> const* _s2 94 ) 95 { 96 return _s1->get_obj_ptr() == _s2->get_obj_ptr(); 97 } 98 99 template <class C> 100 int Symbol<C, ObjectTerm>::compare ( 101 Symbol<C, ObjectTerm> const* _s1, Symbol<C, ObjectTerm> const* _s2 102 ) 103 { 104 if (_s1->get_obj_ptr() > _s2->get_obj_ptr()) return 1; 105 if (_s1->get_obj_ptr() < _s2->get_obj_ptr()) return -1; 106 return 0; 88 107 } 89 108 … … 104 123 template <class C> 105 124 short_type_funcs_t Symbol<C, ObjectTerm>::funcs = { 125 0, 106 126 (void (*)(Term*, Term const*)) (Symbol<C, ObjectTerm>::ctor), 107 127 (void (*)(Term*)) (Symbol<C, ObjectTerm>::dtor), 108 null, //(bool (*)(Term const*, Term const*)) (Symbol<C, ObjectTerm>::eq),109 null, //(int (*)(Term const*, Term const*)) (Symbol<C, ObjectTerm>::compare),128 (bool (*)(Term const*, Term const*)) (Symbol<C, ObjectTerm>::eq), 129 (int (*)(Term const*, Term const*)) (Symbol<C, ObjectTerm>::compare), 110 130 null, // (uint32_t (*)(Term const*)) (Symbol<C, ObjectTerm>::hash), 111 (pxx::WString (*)(Term const*)) (Symbol<C, ObjectTerm>::to_string) 131 (pxx::WString (*)(Term const*)) (Symbol<C, ObjectTerm>::to_string), 132 null 112 133 }; 113 134 135 136 template <class C> 137 inline Symbol<NamedObject<C>, ObjectTerm>::Symbol () : 138 Term (reg.get_type()) 139 { 140 Wrapper* w = static_cast<Wrapper*>(allocator->allocate(sizeof(Wrapper))); 141 new (&(w->object)) NamedObject<C>(); 142 w->ref_count = 1; 143 ptr_data2 = w; 144 } 145 146 template <class C> 147 template <typename CppType1> 148 inline Symbol<NamedObject<C>, ObjectTerm>::Symbol (CppType1 _arg1) : 149 Term (reg.get_type()) 150 { 151 Wrapper* w = static_cast<Wrapper*>(allocator->allocate(sizeof(Wrapper))); 152 new (&(w->object)) NamedObject<C>(_arg1); 153 w->ref_count = 1; 154 ptr_data2 = w; 155 } 156 157 template <class C> 158 template <typename CppType1, typename CppType2> 159 inline Symbol<NamedObject<C>, ObjectTerm>::Symbol (CppType1 _arg1, CppType2 _arg2) : 160 Term (reg.get_type()) 161 { 162 Wrapper* w = static_cast<Wrapper*>(allocator->allocate(sizeof(Wrapper))); 163 new (&(w->object)) NamedObject<C>(_arg1, _arg2); 164 w->ref_count = 1; 165 ptr_data2 = w; 166 } 167 168 template <class C> 169 inline NamedObject<C>* Symbol<NamedObject<C>, ObjectTerm>::get_obj_ptr () const 170 { 171 return &static_cast<Wrapper*>(ptr_data2)->object; 172 } 173 174 template <class C> 175 void Symbol<NamedObject<C>, ObjectTerm>::dtor (Symbol<NamedObject<C>, ObjectTerm>* _s) 176 { 177 Wrapper* w = static_cast<Wrapper*>(_s->ptr_data2); 178 if (--(w->ref_count) == 0) { 179 w->object.~NamedObject<C>(); 180 allocator->deallocate(w); 181 } 182 } 183 184 template <class C> 185 pxx::WString Symbol<NamedObject<C>, ObjectTerm>::to_string ( 186 Symbol<NamedObject<C>, ObjectTerm> const* _s 187 ) 188 { 189 NamedObject<C>* ptr = _s->get_obj_ptr(); 190 return ptr->name; 191 } 192 193 template <class C> 194 size_t Symbol<NamedObject<C>, ObjectTerm>::get_name ( 195 Symbol<NamedObject<C>, ObjectTerm> const* _s, wchar_t const** _np 196 ) 197 { 198 NamedObject<C>* ptr = _s->get_obj_ptr(); 199 *_np = ptr->name.get_data(); 200 return ptr->name.get_length(); 201 } 202 203 template <class C> 204 short_type_funcs_t Symbol<NamedObject<C>, ObjectTerm>::funcs = { 205 0, 206 (void (*)(Term*, Term const*)) (Symbol<C, ObjectTerm>::ctor), 207 (void (*)(Term*)) (Symbol<NamedObject<C>, ObjectTerm>::dtor), 208 (bool (*)(Term const*, Term const*)) (Symbol<C, ObjectTerm>::eq), 209 (int (*)(Term const*, Term const*)) (Symbol<C, ObjectTerm>::compare), 210 null, // (uint32_t (*)(Term const*)) (Symbol<C, ObjectTerm>::hash), 211 (pxx::WString (*)(Term const*)) (Symbol<NamedObject<C>, ObjectTerm>::to_string), 212 (size_t (*)(Term const*, wchar_t const**)) (Symbol<NamedObject<C>, ObjectTerm>::get_name) 213 }; 214 215 /* 114 216 template <class C> 115 217 const TypeRegister Symbol<C, ObjectTerm>::reg(&Symbol<C, ObjectTerm>::funcs); 218 */ 116 219 117 220 template <class C> -
to-imperative/trunk/runtime/rf_term.hh
r1763 r1772 163 163 164 164 inline operator pxx::WString () const ; 165 /// 166 /// If term has a name then make _np point to it and return its length. 167 /// Else return (size_t)-1. 168 inline size_t get_name (wchar_t const** _np) const ; 165 169 166 170 static inline int compare (Term const& _t1, Term const& _t2) ; -
to-imperative/trunk/runtime/rf_term.ih
r1768 r1772 15 15 #include "rf_types.ih" 16 16 #include "rf_expr.hh" 17 #include "rf_ symbol.ih"17 #include "rf_parenth.hh" 18 18 #include "rf_object_ref.ih" 19 19 #include "rf_word.ih" … … 76 76 inline bool Term::is_sym () const 77 77 { 78 return get_short_type() > type_parenth; 78 // return get_short_type() > type_parenth; 79 return !is_ref(); 79 80 } 80 81 81 82 inline bool Term::is_ref () const 82 83 { 83 return get_short_type() == type_parenth; 84 // return get_short_type() == type_parenth; 85 return is_instance_of<Expr>(); 84 86 } 85 87 … … 102 104 { 103 105 unsigned type = get_short_type(); 104 if (type != type_object) return type;106 if (type != type_object) return short_type_funcs[type]->type; 105 107 return static_cast<const ObjectRef*>(this)->get_obj_ptr()->get_type(); 106 108 } … … 185 187 { 186 188 return 187 static_cast<Symbol<C, typename SymbolType<C>:: type> const*>(this)->189 static_cast<Symbol<C, typename SymbolType<C>::Type> const*>(this)-> 188 190 get_obj_ptr(); 189 191 } … … 193 195 { 194 196 return 195 get_short_type() == Symbol<C, typename SymbolType<C>::type>::get_type(); 197 short_type_funcs[get_short_type()]->type == 198 Symbol<C, typename SymbolType<C>::Type>::get_type(); 196 199 } 197 200 … … 210 213 } 211 214 215 inline size_t Term::get_name (wchar_t const** _np) const 216 { 217 size_t (*fp)(Term const*, wchar_t const**) = 218 short_type_funcs[get_short_type()]->get_name; 219 if (fp) return (*fp)(this, _np); 220 return (size_t)-1; 221 } 222 212 223 inline int Term::compare (Term const& _t1, Term const& _t2) 213 224 { 214 unsigned type1 = _t1.get_short_type(); 215 unsigned type2 = _t2.get_short_type(); 225 unsigned t1 = _t1.get_short_type(); 226 unsigned t2 = _t2.get_short_type(); 227 unsigned type1 = short_type_funcs[t1]->type; 228 unsigned type2 = short_type_funcs[t2]->type; 216 229 if (type1 == type_parenth && type2 != type_parenth) return 1; 217 230 if (type1 != type_parenth && type2 == type_parenth) return -1; 218 231 if (type1 > type2) return 1; 219 232 if (type1 < type2) return -1; 220 int (*cmp)(Term const*, Term const*) = short_type_funcs[t ype1]->compare;233 int (*cmp)(Term const*, Term const*) = short_type_funcs[t1]->compare; 221 234 if (cmp) return (*cmp)(&_t1, &_t2); 222 235 if (_t1.uint_data2 > _t2.uint_data2) return 1; -
to-imperative/trunk/runtime/rf_types.hh
r1768 r1772 39 39 typedef struct 40 40 { 41 unsigned type ; 41 42 /// 42 43 /// Copy constructor for short symbol … … 57 58 /// Conversion to string. 58 59 pxx::WString (*to_string)(Term const*) ; 60 /// 61 /// If the term has a name then set pointer to it and return its length. 62 /// Else return (size_t)-1. 63 size_t (*get_name)(Term const*, wchar_t const**) ; 59 64 } short_type_funcs_t ; 60 65 … … 66 71 public: 67 72 inline TypeRegister (short_type_funcs_t* _funcs, unsigned _typenum = 0) ; 73 inline TypeRegister (unsigned _type, short_type_funcs_t* _funcs) ; 68 74 inline unsigned get_type () const ; 69 75 }; -
to-imperative/trunk/runtime/rf_types.ih
r1655 r1772 15 15 } 16 16 short_type_funcs[_typenum] = _funcs; 17 short_type_funcs[_typenum]->type = _typenum; 17 18 type = _typenum; 19 } 20 21 inline TypeRegister::TypeRegister ( 22 unsigned _type, short_type_funcs_t* _funcs 23 ) 24 { 25 type = current_short_type++; 26 short_type_funcs[type] = _funcs; 27 short_type_funcs[type]->type = _type; 18 28 } 19 29 -
to-imperative/trunk/runtime/rf_word.cc
r1490 r1772 98 98 99 99 short_type_funcs_t Word::funcs = { 100 0, 100 101 (void (*)(Term*, Term const*))(Word::ctor), 101 102 (void (*)(Term*))(Word::dtor), … … 103 104 (int (*)(Term const*, Term const*))(Word::compare), 104 105 (uint32_t (*)(Term const*))(Word::hash), 105 (pxx::WString (*)(Term const*))(Word::to_string) 106 (pxx::WString (*)(Term const*))(Word::to_string), 107 null 106 108 }; 107 109
Note: See TracChangeset
for help on using the changeset viewer.