Changeset 1763


Ignore:
Timestamp:
May 18, 2005, 3:44:45 AM (16 years ago)
Author:
orlov
Message:
  • RF_NEW_SYMBOL and RF_SYMBOL macros for work with symbol types.
  • Expr::create_sym() static method for creation of symbols.
  • Term::is_instance_of() and Term::get_obj_ptr() methods for work with symbols.
  • Dir class is moved to the library.
Location:
to-imperative/trunk/runtime
Files:
9 deleted
15 edited

Legend:

Unmodified
Added
Removed
  • to-imperative/trunk/runtime/Makefile

    r1744 r1763  
    2222  rf_integer \
    2323  rf_func \
    24   rf_dir \
    2524  rf_object \
    2625  rf_static_object \
  • to-imperative/trunk/runtime/file_list

    r1737 r1763  
    1717rf_integer
    1818rf_func
    19 rf_dir_win
    2019rf_object
    2120rf_static_object
  • to-imperative/trunk/runtime/rf_char.cc

    r1605 r1763  
    133133}
    134134
    135 int Char::compare (Char const* _char1, Char const* _char2)
    136 {
    137   if (_char1->uint_data2 == _char2->uint_data2) return 0;
    138   else if (_char1->uint_data2 < _char2->uint_data2) return -1;
    139   else return 1;
    140 }
    141 
    142 uint32_t Char::hash (Char const* _char)
    143 {
    144   return _char->uint_data2;
    145 }
    146 
    147135pxx::WString Char::to_string (Char const* _char)
    148136{
     
    155143  null, // Char::dtor,
    156144  null, // Char::eq,
    157   (int (*)(Term const*, Term const*))(Char::compare),
    158   (uint32_t (*)(Term const*))(Char::hash),
     145  null, // (int (*)(Term const*, Term const*))(Char::compare),
     146  null, // (uint32_t (*)(Term const*))(Char::hash),
    159147  (pxx::WString (*)(Term const*))(Char::to_string)
    160148};
  • to-imperative/trunk/runtime/rf_char.hh

    r1678 r1763  
    7474  static inline bool is_flat () ;
    7575
    76   static int compare (Char const* _char1, Char const* _char2) ;
    77   static uint32_t hash (Char const* _char) ;
    7876  static pxx::WString to_string (Char const* _char) ;
    7977  static short_type_funcs_t funcs ;
  • to-imperative/trunk/runtime/rf_core.cc

    r1743 r1763  
    205205#ifdef WINDOWS
    206206ObjectRegister rftype::Dir::reg(type_dir) ;
    207 #else
    208 TypeRegister rftype::Dir::reg(&Dir::funcs, type_dir) ;
    209207#endif
    210208
  • to-imperative/trunk/runtime/rf_core.hh

    r1743 r1763  
    4545#include "rf_string.ih"
    4646#include "rf_static_object.ih"
     47#include "rf_symbol.ih"
    4748
    48 #ifdef WINDOWS
    49 #include "rf_dir_win.ih"
    50 #else
    51 #include "rf_dir.ih"
    52 #endif
    5349#include "pxx_heap_allocator.ih"
    5450#include "pxx_common.ih"
  • to-imperative/trunk/runtime/rf_expr.hh

    r1700 r1763  
    228228  template<term_class_t, class ObjClass, class CppType1, class CppType2>
    229229  friend class CreateExpr2;
     230
     231  template <class ObjClass>
     232  static inline Expr create_sym () ;
     233
     234  template <class ObjClass, class CppType1>
     235  static inline Expr create_sym (const CppType1& _arg1) ;
     236
     237  template <class ObjClass, class CppType1, class CppType2>
     238  static inline Expr create_sym (const CppType1& _arg1, const CppType2& _arg2) ;
    230239
    231240private:
  • to-imperative/trunk/runtime/rf_expr.ih

    r1678 r1763  
    491491  return CreateExpr2<ObjClass::term_class, ObjClass, CppType1, CppType2>(
    492492      _arg1, _arg2);
     493}
     494
     495template <class ObjClass>
     496inline Expr Expr::create_sym ()
     497{
     498  Expr e(1);
     499  if (SymbolType<ObjClass>::type == unsigned(flat_term)) e.flags |= FLAT_BIT;
     500  new (e.first) Symbol< ObjClass, SymbolType<ObjClass>::type >();
     501  return e;
     502}
     503
     504template <class ObjClass, class CppType1>
     505inline Expr Expr::create_sym (const CppType1& _arg1)
     506{
     507  Expr e(1);
     508  if (SymbolType<ObjClass>::type == unsigned(flat_term)) e.flags |= FLAT_BIT;
     509  new (e.first) Symbol< ObjClass, SymbolType<ObjClass>::type >(_arg1);
     510  return e;
     511}
     512
     513template <class ObjClass, class CppType1, class CppType2>
     514inline Expr Expr::create_sym (const CppType1& _arg1, const CppType2& _arg2)
     515{
     516  Expr e(1);
     517  if (SymbolType<ObjClass>::type == unsigned(flat_term)) e.flags |= FLAT_BIT;
     518  new (e.first) Symbol< ObjClass, SymbolType<ObjClass>::type >(_arg1, _arg2);
     519  return e;
    493520}
    494521
  • to-imperative/trunk/runtime/rf_macros.hh

    r1734 r1763  
    275275#endif
    276276
     277#define RF_NEW_SYMBOL(t, c) \
     278  struct SymbolType<t> \
     279  { \
     280    enum { type = c }; \
     281  };
     282
     283#define RF_SYMBOL(t) Symbol< t, SymbolType<t>::type >
     284
    277285}
    278286
  • to-imperative/trunk/runtime/rf_stack.hh

    r1700 r1763  
    2525
    2626#include "rf_expr.ih"
     27#include "rf_integer.ih"
    2728#include "pxx_heap.ih"
    2829
  • to-imperative/trunk/runtime/rf_symbol.hh

    r1761 r1763  
    2121{};
    2222
    23 template<class C, term_class_t tc = object_term>
     23//template<class C, term_class_t tc = object_term>
     24//class Symbol;
     25template<class C, unsigned tc>
    2426class Symbol;
    2527
     
    4547  static short_type_funcs_t funcs ;
    4648  static const TypeRegister reg ;
    47 
    48   ///
    49   /// Term class for template instantiations
    50   static const term_class_t term_class;
    5149
    5250};
     
    9088  static inline unsigned get_type() ;
    9189
    92   ///
    93   /// Term class for template instantiations
    94   static const term_class_t term_class;
    95 
    9690};
    9791
    9892template<class C>
    99 class SymbolType
    100 {
    101 public:
    102   static const term_class_t type;
    103 };
     93struct SymbolType;
    10494
    10595}
  • to-imperative/trunk/runtime/rf_symbol.ih

    r1761 r1763  
    2929*/
    3030
    31 
    32 template <class C>
    33 const term_class_t Symbol<C, object_term>::term_class = object_term;
    3431
    3532template <class C>
     
    107104template <class C>
    108105short_type_funcs_t Symbol<C, object_term>::funcs = {
    109   (ctor_t)   (Symbol<C, object_term>::ctor),
    110   (dtor_t)   (Symbol<C, object_term>::dtor),
    111   null, // (eq_t)     (Symbol<C, object_term>::eq),
    112   null, // (compare_t)(Symbol<C, object_term>::compare),
    113   null, // (hash_t)   (Symbol<C, object_term>::hash),
    114   (to_string_t)(Symbol<C, object_term>::to_string)
     106  (void (*)(Term*, Term const*))   (Symbol<C, object_term>::ctor),
     107  (void (*)(Term*))                (Symbol<C, object_term>::dtor),
     108  null, // (bool (*)(Term const*, Term const*))   (Symbol<C, object_term>::eq),
     109  null, // (int  (*)(Term const*, Term const*))   (Symbol<C, object_term>::compare),
     110  null, // (uint32_t (*)(Term const*))            (Symbol<C, object_term>::hash),
     111  (pxx::WString (*)(Term const*))  (Symbol<C, object_term>::to_string)
    115112};
    116113
     
    124121}
    125122
    126 template <class C>
    127 const term_class_t SymbolType<C>::type = short_term;
    128 
    129123}
    130124
  • to-imperative/trunk/runtime/rf_term.hh

    r1655 r1763  
    156156  inline C* cast_to () ;
    157157
     158  template <class C>
     159  inline C* get_obj_ptr () const ;
     160
     161  template <class C>
     162  inline bool is_instance_of () const ;
     163
    158164  inline operator pxx::WString () const ;
    159165
  • to-imperative/trunk/runtime/rf_term.ih

    r1655 r1763  
    1515#include "rf_types.ih"
    1616#include "rf_expr.hh"
     17#include "rf_symbol.ih"
    1718#include "rf_object_ref.ih"
    1819#include "rf_word.ih"
     
    180181}
    181182
     183template <class C>
     184inline C* Term::get_obj_ptr () const
     185{
     186  return static_cast<Symbol< C, SymbolType<C>::type > const*>(this)->get_obj_ptr();
     187}
     188
     189template <class C>
     190inline bool Term::is_instance_of () const
     191{
     192  return get_short_type() == Symbol< C, SymbolType<C>::type >::get_type();
     193}
     194
    182195inline Term::operator pxx::WString () const
    183196{
    184   return (*(short_type_funcs[get_short_type()]->to_string))(this);
     197  pxx::WString (*to_wstr)(Term const*) =
     198    short_type_funcs[get_short_type()]->to_string;
     199  if (to_wstr) return (*to_wstr)(this);
     200  size_t max_len = 2 * max_int_len + 4;
     201  wchar_t* str = static_cast<wchar_t*>(alloca(max_len * sizeof(wchar_t)));
     202  int len = swprintf(str, max_len, L"<%u|%u>", data1, uint_data2);
     203  if (-1 == len)
     204    FATAL("<%u|%u> is more then %u wide characters",
     205        data1, uint_data2, max_len);
     206  return pxx::WString(str, len);
    185207}
    186208
  • to-imperative/trunk/runtime/rf_types.hh

    r1678 r1763  
    2222  type_int,
    2323  type_int32,
    24   type_dir,
    2524  type_user,
    2625  type_object_begin = short_types_count,
Note: See TracChangeset for help on using the changeset viewer.