Changeset 860
- Timestamp:
- Jun 22, 2003, 2:50:35 AM (18 years ago)
- Location:
- to-imperative/trunk/runtime
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
to-imperative/trunk/runtime/rf_expr.hh
r840 r860 139 139 /// Get expression length (in terms) 140 140 inline uintptr_t get_len () const ; 141 private: 141 142 /// 142 143 /// Get expression flags 143 144 inline uintptr_t get_flags () const ; 145 public: 144 146 /// 145 147 /// Dump expression contents (not recursive) … … 159 161 inline uint32_t hash () const ; 160 162 /// 161 /// Compare with subexpression of other expression 163 /// Compare with subexpression of other expression. Attention: doesn't check 164 /// that our expression is not longer then the rest of the other. 162 165 inline bool eq (Expr const& _expr, uintptr_t _index) ; 163 166 /// … … 171 174 /// 172 175 /// Compare our first term with some one of another expression as flat 173 /// symbols. 174 inline bool Expr::sym_eq (Expr const& _expr, uintptr_t _index) const ;176 /// symbols. Should be called only with valid index argument. 177 inline bool sym_eq (Expr const& _expr, uintptr_t _index) const ; 175 178 /// 176 179 /// Equality check operator 180 inline bool operator == (Expr& _expr) ; 181 /// 182 /// Inequality check operator 183 inline bool operator != (Expr& _expr) ; 184 /// 185 /// Same methods for const expressions. 177 186 inline bool operator == (Expr const& _expr) const ; 178 ///179 /// Inequality check operator180 187 inline bool operator != (Expr const& _expr) const ; 181 188 /// … … 252 259 /// beside expression margins. 253 260 INLINE void deref_childs () const ; 254 public:255 261 static INLINE void deref_childs ( 256 262 Term* _first, Term* _last, MemoryChunk* _mem -
to-imperative/trunk/runtime/rf_expr.ih
r855 r860 203 203 inline bool Expr::symbol_at (uintptr_t _index) const 204 204 { 205 return (first + _index)-> get_type() > type_ref;205 return (first + _index)->is_sym(); 206 206 } 207 207 … … 263 263 } 264 264 265 #if 0 265 266 inline void Expr::ref_childs () const 266 267 { … … 269 270 } 270 271 } 272 #endif 271 273 272 274 inline bool Expr::writeln (FILE* _fp) const … … 359 361 inline bool Expr::sym_eq (Expr const& _expr, uintptr_t _index) const 360 362 { 361 // 362 // FIXME: Do not forget to do object comparison for compound symbols 363 return 364 first->get_type() == (_expr.first + _index)->get_type() && 365 first->uint_data2 == (_expr.first + _index)->uint_data2; 366 } 367 368 inline bool Expr::flat_eq (Expr const& _expr, uintptr_t _index) const 363 return *first == *(_expr.first + _index); 364 } 365 366 inline bool Expr::eq (Expr const& _expr, uintptr_t _index) const 369 367 { 370 368 Term *f = _expr.first + _index; 371 if (first == f && last == f + (last - first)) {369 if (first == f) { 372 370 #if DEBUG 373 371 identical++; … … 375 373 return true; 376 374 } 377 return Term:: flat_eq(first, f, last - first);378 } 379 380 inline bool Expr:: flat_eq (Expr const& _expr, uintptr_t _index)375 return Term::eq(first, f, get_len()); 376 } 377 378 inline bool Expr::eq (Expr const& _expr, uintptr_t _index) 381 379 { 382 380 Term *f = _expr.first + _index; 383 Term *l = f + (last - first); 384 if (first == f && last == l) { 381 if (first == f) { 385 382 #if DEBUG 386 383 identical++; … … 388 385 return true; 389 386 } 390 bool res = Term::flat_eq(first, f, last - first); 391 // 392 // I suppouse that in typical situation unification of flat expressions will 393 // slow down the computation. But more statistics are needed. 394 #if 0 387 bool res = Term::eq(first, f, get_len()); 395 388 if (res) { 396 389 #if DEBUG 397 390 unifications++; 398 391 #endif 399 // 400 // Destroy old expression 392 uintptr_t new_flags = flags | _expr.flags; 401 393 drop(); 402 // 403 // Build a copy in place 404 new(this) Expr(f, l, _expr.mem_chunk, flags & _expr.flags); 405 } 406 #endif 394 new(this) Expr(f, f + get_len(), _expr.mem_chunk, new_flags); 395 } 407 396 return res; 408 397 } 409 398 410 inline bool Expr::eq (Expr const& _expr, uintptr_t _index) const411 {412 Term *f = _expr.first + _index;413 Term *l = f + (last - first);414 if (first == f && last == l) {415 #if DEBUG416 identical++;417 #endif418 return true;419 }420 if (is_flat() || _expr.is_flat())421 return Term::flat_eq(first, f, last - first);422 return Term::eq(first, last, f, l);423 }424 425 inline bool Expr::eq (Expr const& _expr, uintptr_t _index)426 {427 Term *f = _expr.first + _index;428 Term *l = f + (last - first);429 if (first == f && last == l) {430 #if DEBUG431 identical++;432 #endif433 return true;434 }435 bool res;436 if (is_flat() || _expr.is_flat())437 res = Term::flat_eq(first, f, last - first);438 else439 res = Term::eq(first, last, f, l);440 #if 0441 if (res) {442 #if DEBUG443 unifications++;444 #endif445 //446 // Destroy old expression447 drop();448 //449 // Build a copy in place450 new(this) Expr(f, l, _expr.mem_chunk, flags & _expr.flags);451 }452 #endif453 return res;454 }455 456 399 inline bool Expr::operator == (Expr const& _expr) const 400 { 401 if (get_len() != _expr.get_len()) return false; 402 return eq(_expr, 0); 403 } 404 405 inline bool Expr::operator != (Expr const& _expr) const 406 { 407 if (get_len() != _expr.get_len()) return true; 408 return !eq(_expr, 0); 409 } 410 411 inline bool Expr::operator == (Expr& _expr) 457 412 { 458 413 if (first == _expr.first && last == _expr.last) { … … 463 418 } else { 464 419 bool res = Term::eq(first, last, _expr.first, _expr.last); 465 #if 0466 420 if (res) { 467 421 #if DEBUG … … 469 423 #endif 470 424 if (mem_chunk->get_ref_count() >= _expr.mem_chunk->get_ref_count()) { 471 (Expr&)_expr = self; 425 flags |= _expr.flags; 426 _expr = self; 472 427 } else { 473 (Expr&)self = _expr; 428 _expr.flags |= flags; 429 self = _expr; 474 430 } 475 431 } 476 #endif477 432 return res; 478 433 } 479 // return Term::eq(first, last, _expr.first, _expr.last); 480 } 481 482 inline bool Expr::operator != (Expr const& _expr) const 483 { 484 if (first == _expr.first && last == _expr.last) { 485 #if DEBUG 486 identical++; 487 #endif 488 return false; 489 } else { 490 bool res = Term::eq(first, last, _expr.first, _expr.last); 491 if (res) { 492 #if DEBUG 493 unifications++; 494 #endif 495 if (mem_chunk->get_ref_count() >= _expr.mem_chunk->get_ref_count()) { 496 (Expr&)_expr = self; 497 } else { 498 (Expr&)self = _expr; 499 } 500 } 501 return res; 502 } 503 // return !Term::eq(first, last, _expr.first, _expr.last); 434 } 435 436 inline bool Expr::operator != (Expr& _expr) 437 { 438 return !(self == _expr); 504 439 } 505 440 -
to-imperative/trunk/runtime/rf_term.cc
r835 r860 11 11 12 12 #include "rf_term.ih" 13 #include "rf_char.ih"14 13 15 14 namespace rfrt { -
to-imperative/trunk/runtime/rf_term.hh
r836 r860 142 142 inline Term& operator = (Term const& _t) ; 143 143 144 typedef void (Term::*ctor_func_t)(Term const& _t) ;145 typedef void (Term::*dtor_func_t)() ;146 typedef bool (Term::*eq_func_t)(Term const& _t) const ;147 typedef pxx::WString (Term::*to_string_func_t)() const ;148 typedef size_t (Term::*get_char_len_func_t)() const ;149 typedef Term* (Term::*to_chars_func_t)(Term* _p) const ;150 151 144 static void ref_ctor (Term* _to, Term const* _from) ; 152 145 static void ref_dtor (Term* _term) ; … … 171 164 Term const* _f1, Term const* _l1, Term const* _f2, Term const* _l2 172 165 ) ; 166 static inline bool eq ( 167 Term const* _p1, Term const* _p2, uintptr_t _len 168 ) ; 173 169 /// 174 170 /// Check whether two flat term sequences are equal 175 171 static inline bool flat_eq ( 176 Term const* _ f1, Term const* _f2, uintptr_t _len172 Term const* _p1, Term const* _p2, uintptr_t _len 177 173 ) ; 178 174 /// -
to-imperative/trunk/runtime/rf_term.ih
r839 r860 44 44 inline Term::~Term () 45 45 { 46 #if 047 if (is_ref()) {48 // Expr e(this);49 // e.get_mem_chunk()->dec_ref_count();50 MemoryChunk* m = get_mem_chunk();51 //52 // Decrement reference counter and destroy an object if it is zero53 if (m->dec_ref_count() == 0) {54 //55 // Walk through and decrement reference counters on childs56 // bool f = (data1 & REF_BIT) == 0 ? true : false;57 Expr::deref_childs(58 get_first(), (data1 & FLAT_BIT) != 0 ? get_last() : get_first(), m59 );60 //61 // Deallocate expression holder in memory62 MemoryChunk::destroy_instance(m);63 }64 }65 #else66 // (this->*dtor_funcs[get_class()])();67 46 void (*pf)(Term*) = short_type_funcs[get_type()]->dtor; 68 47 if (pf != null) (*pf)(this); 69 #endif70 48 } 71 49 72 50 inline Term::Term (Term const& _t) 73 51 { 74 // (this->*ctor_funcs[_t.get_class()])(_t);75 52 void (*pf)(Term*, Term const*) = short_type_funcs[_t.get_type()]->ctor; 76 53 if (pf != null) (*pf)(this, &_t); … … 154 131 inline bool Term::operator == (Term const& _t) const 155 132 { 156 #if 0 157 term_class_t cl = get_class(); 158 // 159 // If both terms have the same type... 160 if (cl == _t.get_class()){ 161 // 162 // ...compare them 163 return (this->*eq_funcs[cl])(_t); 164 } else { 165 return false; 166 } 167 #endif 168 // 169 // If symbol types are equal... 170 if (get_type() == _t.get_type()) { 171 if (uint_data2 == _t.uint_data2) return true; 172 else { 173 bool (*pf)(Term const*, Term const*) = short_type_funcs[get_type()]->eq; 174 if (pf != null) return (*pf)(this, &_t); 175 } 176 } 133 if (data1 != _t.data1) return false; 134 if (uint_data2 == _t.uint_data2) return true; 135 bool (*pf)(Term const*, Term const*) = short_type_funcs[get_type()]->eq; 136 if (pf && (*pf)(this, &_t)) return true; 177 137 return false; 178 138 } … … 200 160 } 201 161 162 inline bool Term::eq ( 163 Term const* _p1, Term const* _p2, uintptr_t _len 164 ) 165 { 166 for (; _len--; _p1++, _p2++) 167 { 168 if (*_p1 != *_p2) return false; 169 } 170 return true; 171 } 172 202 173 inline bool Term::flat_eq ( 203 Term const* _ f1, Term const* _f2, uintptr_t _len174 Term const* _p1, Term const* _p2, uintptr_t _len 204 175 ) 205 176 { 206 for (; _len--; _f1++, _f2++) { 207 // 208 // FIXME: Do not forget to do object comparison for compound symbols 209 if (_f1->get_type() != _f2->get_type() || _f1->uint_data2 != _f2->uint_data2) 177 for (; _len--; _p1++, _p2++) 178 { 179 if (_p1->data1 != _p2->data1 || _p1->uint_data2 != _p2->uint_data2) 210 180 return false; 211 181 } … … 234 204 } 235 205 236 237 206 inline Term::operator pxx::WString () const 238 207 {
Note: See TracChangeset
for help on using the changeset viewer.