Changeset 705


Ignore:
Timestamp:
Apr 30, 2003, 7:14:11 PM (18 years ago)
Author:
pooh
Message:
  • Started Word implementation.
Location:
to-imperative/trunk/runtime
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • to-imperative/trunk/runtime/rf_char.cc

    r630 r705  
    142142  Char::ctor,
    143143  Char::dtor,
     144  null, // Char::eq,
    144145  Char::compare,
    145146  Char::hash,
  • to-imperative/trunk/runtime/rf_char.hh

    r667 r705  
    6262  static uintptr_t ctor (uintptr_t _data) ;
    6363  static void dtor (uintptr_t _data) ;
     64  static bool eq (uintptr_t _data1, uintptr_t _data2) ;
    6465  static int compare (uintptr_t _data1, uintptr_t _data2) ;
    6566  static uint32_t hash (uintptr_t _data) ;
    6667  static pxx::WString to_string (uintptr_t _data) ;
    67   static size_t Char::get_char_len (uintptr_t _data) ;
    68   static Term* Char::to_chars (uintptr_t _data, Term* _p) ;
     68  static size_t get_char_len (uintptr_t _data) ;
     69  static Term* to_chars (uintptr_t _data, Term* _p) ;
    6970  static short_type_funcs_t funcs ;
    7071  static TypeRegister reg ;
  • to-imperative/trunk/runtime/rf_short_int.cc

    r678 r705  
    147147  ShortInt::ctor,
    148148  ShortInt::dtor,
     149  null, // ShortInt::eq,
    149150  ShortInt::compare,
    150151  ShortInt::hash,
    151152  ShortInt::to_string,
    152   ShortInt::get_char_len
    153   // ShortInt::to_chars
     153  ShortInt::get_char_len,
     154  null // ShortInt::to_chars
    154155};
    155156
  • to-imperative/trunk/runtime/rf_short_int.hh

    r624 r705  
    3030  static uintptr_t ctor (uintptr_t _data) ;
    3131  static void dtor (uintptr_t _data) ;
     32  static bool eq (uintptr_t _data1, uintptr_t _data2) ;
    3233  static int compare (uintptr_t _data1, uintptr_t _data2) ;
    3334  static uint32_t hash (uintptr_t _data) ;
    3435  static pxx::WString to_string (uintptr_t _data) ;
    35   static size_t ShortInt::get_char_len(uintptr_t _data);
     36  static size_t get_char_len(uintptr_t _data) ;
     37  static Term* to_chars (uintptr_t _data, Term* _p) ;
    3638  static short_type_funcs_t funcs ;
    3739  static TypeRegister reg ;
  • to-imperative/trunk/runtime/rf_term.cc

    r507 r705  
    5656{
    5757  data1 = _t.data1;
    58   uint_data2 = _t.uint_data2;
     58  uintptr_t (*pf)(uintptr_t) = short_type_funcs[get_type()]->ctor;
     59  if (pf != null) uint_data2 = (*pf)(_t.uint_data2);
     60  else uint_data2 = _t.uint_data2;
    5961}
    6062
     
    7577
    7678void Term::dtor_sym ()
    77 {}
     79{
     80  void (*pf)(uintptr_t) = short_type_funcs[get_type()]->dtor;
     81  if (pf != null) (*pf)(uint_data2);
     82}
    7883
    7984void Term::dtor_ref ()
  • to-imperative/trunk/runtime/rf_types.hh

    r561 r705  
    4141  void (*dtor)(uintptr_t) ;
    4242  ///
     43  /// Equality check for short symbol (may be faster than compare)
     44  bool (*eq)(uintptr_t, uintptr_t) ;
     45  ///
    4346  /// Compare function for short symbol
    4447  int (*compare)(uintptr_t, uintptr_t) ;
  • to-imperative/trunk/runtime/rf_word.cc

    r703 r705  
    11#include "rf_word.ih"
     2
     3namespace rftype
     4{
     5
     6using namespace rfrt ;
     7
     8uintptr_t Word::ctor (uintptr_t _data)
     9{
     10  Header* h = reinterpret_cast<Header*>(_data);
     11  h->ref_count++;
     12  return _data;
     13}
     14
     15void Word::dtor (uintptr_t _data)
     16{
     17  Header* h = reinterpret_cast<Header*>(_data);
     18  if (--(h->ref_count) == 0) allocator.deallocate(h);
     19}
     20
     21bool Word::eq (uintptr_t _data1, uintptr_t _data2)
     22{
     23  Header* h1 = reinterpret_cast<Header*>(_data1);
     24  Header* h2 = reinterpret_cast<Header*>(_data2);
     25  if (h1 == h2) return true;
     26  else {
     27    if (hash(_data1) != hash(_data2)) return false;
     28    else if (h1->length != h2->length) return false;
     29    else if (wmemcmp(h1->content, h2->content, h1->length) == 0) return true;
     30    else return false;
     31  }
     32}
     33
     34int Word::compare (uintptr_t _data1, uintptr_t _data2)
     35{
     36  Header* h1 = reinterpret_cast<Header*>(_data1);
     37  Header* h2 = reinterpret_cast<Header*>(_data2);
     38  if (h1 == h2) return 0;
     39  else {
     40    int r = wmemcmp(h1->content, h2->content, pxx_min(h1->length, h2->length));
     41    if (r != 0) return r;
     42    else {
     43      if (h1->length == h2->length) return 0;
     44      else return h1->length > h2->length ? 1 : -1;
     45    }
     46  }
     47}
     48
     49uint32_t Word::hash (uintptr_t _data)
     50{
     51  Header* h = reinterpret_cast<Header*>(_data);
     52  if (h->hash == 0xffffffff) {
     53    // Should never occur, because we always compute hash for words
     54    h->hash = compute_hash(h->content, h->length * sizeof(wchar_t));
     55  }
     56  return h->hash;
     57}
     58
     59short_type_funcs_t Word::funcs = {
     60  Word::ctor,
     61  Word::dtor,
     62  Word::eq,
     63  Word::compare,
     64  Word::hash,
     65  Word::to_string,
     66  Word::get_char_len,
     67  Word::to_chars
     68};
     69
     70}
  • to-imperative/trunk/runtime/rf_word.hh

    r703 r705  
    3030  /// Constructor from a locale-dependent string
    3131  inline Word (char const* _str, char const* _locale = null) ;
     32  ///
     33  /// Copy constructor
     34  inline Word (Word const& _word) ;
     35  ///
     36  /// Destructor
     37  inline ~Word () ;
     38  ///
     39  /// Assignment operator
     40  inline Word& operator = (Word const& _word) ;
    3241
    3342  static Expr create_expr (wchar_t const* _wstr) ;
    3443
    3544  static Expr create_expr (char const* _str, char const* _locale = null) ;
     45
     46  static uintptr_t ctor (uintptr_t _data) ;
     47  static void dtor (uintptr_t _data) ;
     48  static bool eq (uintptr_t _data1, uintptr_t _data2) ;
     49  static int compare (uintptr_t _data1, uintptr_t _data2) ;
     50  static uint32_t hash (uintptr_t _data) ;
     51  static pxx::WString to_string (uintptr_t _data) ;
     52  static size_t get_char_len (uintptr_t _data) ;
     53  static Term* to_chars (uintptr_t _data, Term* _p) ;
     54  static short_type_funcs_t funcs ;
     55  static TypeRegister reg ;
    3656
    3757};
  • to-imperative/trunk/runtime/rf_word.ih

    r703 r705  
    5959}
    6060
     61inline Word::Word (Word const& _word) :
     62  Term (term_sym, type_word)
     63{
     64  ptr_data2 = _word.ptr_data2;
     65  Header* h = static_cast<Header*>(ptr_data2);
     66  h->ref_count++;
     67}
     68
     69inline Word::~Word ()
     70{
     71  Header* h = static_cast<Header*>(ptr_data2);
     72  if (--(h->ref_count) == 0) allocator.deallocate(h);
     73}
     74
     75inline Word& Word::operator = (Word const& _word)
     76{
     77  if (this != &_word) {
     78    Header* h = static_cast<Header*>(ptr_data2);
     79    if (--(h->ref_count) == 0) allocator.deallocate(h);
     80    ptr_data2 = _word.ptr_data2;
     81    h = static_cast<Header*>(ptr_data2);
     82    h->ref_count++;
     83  }
     84  return self;
     85}
     86
    6187Expr Word::create_expr (wchar_t const* _wstr)
    6288{
Note: See TracChangeset for help on using the changeset viewer.