Changeset 1772


Ignore:
Timestamp:
Jun 9, 2005, 7:13:32 AM (16 years ago)
Author:
orlov
Message:
  • A lot of runtime changes towards interfaces simplification.
Location:
to-imperative/trunk/runtime
Files:
2 added
4 deleted
29 edited

Legend:

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

    r1763 r1772  
    1616  rf_memory_chunk \
    1717  rf_types \
    18   rf_parenth \
    1918  rf_char \
    2019  rf_word \
     
    2524  rf_static_object \
    2625  rf_object_ref \
    27   rf_box \
    2826  rf_vector \
    2927  rf_string \
  • to-imperative/trunk/runtime/file_list

    r1763 r1772  
    1111rf_memory_chunk
    1212rf_types
    13 rf_parenth
    1413rf_char
    1514rf_word
     
    2019rf_static_object
    2120rf_object_ref
    22 rf_box
    2321rf_vector
    2422rf_string
  • to-imperative/trunk/runtime/rf_arg.hh

    r1490 r1772  
    2525
    2626#include "rf_expr.ih"
    27 #include "rf_stack.hh"
     27#include "rf_stack.ih"
    2828
    2929namespace rfrt
  • to-imperative/trunk/runtime/rf_box.hh

    r1730 r1772  
    22#define __rf_box_hh__
    33
    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"
    76
    87namespace rftype
    98{
    109
    11 using namespace rfrt ;
     10class BoxContents : public Expr
     11{
     12  public:
    1213
    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};
    1625
    17 private:
     26RF_NEW_SYMBOL(BoxContents, ObjectTerm);
     27RF_NEW_SYMBOL(NamedObject<BoxContents>, ObjectTerm);
    1828
    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 };
     29inline 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}
    4039
    4140}
  • to-imperative/trunk/runtime/rf_char.cc

    r1763 r1772  
    6565  {
    6666    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;
    6868    else
    6969      e = e + Char::create_expr(WString(*p));
     
    140140
    141141short_type_funcs_t Char::funcs = {
     142  0,
    142143  null, // Char::ctor,
    143144  null, // Char::dtor,
     
    145146  null, // (int (*)(Term const*, Term const*))(Char::compare),
    146147  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
    148150};
    149151
  • to-imperative/trunk/runtime/rf_common.cc

    r1700 r1772  
    3030void* stack_start = (void*)0;
    3131uintptr_t stack_size = default_stack_size ;
     32bool init_done = false;
    3233bool use_rts = true;
    3334bool trap_stack_on = false;
  • to-imperative/trunk/runtime/rf_common.hh

    r1730 r1772  
    2727extern uintptr_t stack_size ;
    2828extern void* stack_start ;
     29extern bool init_done ;
    2930extern bool use_rts ;
    3031extern bool trap_stack_on ;
  • to-imperative/trunk/runtime/rf_core.cc

    r1768 r1772  
    186186using namespace rfrt;
    187187
    188 TypeRegister rftype::Parenth::reg(&Parenth::funcs, type_parenth) ;
     188RF_REGISTER_SYMBOL(Expr);
     189//TypeRegister rftype::Parenth::reg(&Parenth::funcs, type_parenth) ;
    189190TypeRegister rftype::ObjectRef::reg(&ObjectRef::funcs, type_object) ;
    190191TypeRegister rftype::Char::reg(&Char::funcs, type_char) ;
     
    197198#endif // !defined RFRT_WITHOUT_GMP
    198199
    199 ObjectRegister rftype::Box::reg(type_box) ;
    200200ObjectRegister rftype::Vector::reg(type_vector) ;
    201201ObjectRegister rftype::Channel::reg(type_channel) ;
     
    203203ObjectRegister rftype::Table::reg(type_table) ;
    204204ObjectRegister rftype::Func::reg(type_func) ;
     205
     206RF_REGISTER_SYMBOL(BoxContents);
     207RF_REGISTER_SYMBOL_VARIANT(NamedObject<BoxContents>, BoxContents);
    205208
    206209int main (int _argc, char* _argv[])
     
    246249  }
    247250  if (init_StdIn) init_StdIn();
     251  init_done = true;
     252  D( printf("=== Init is done! ===\n"); )
    248253  Expr res;
    249254  try {
  • to-imperative/trunk/runtime/rf_core.hh

    r1763 r1772  
    2727#include "rf_term.ih"
    2828#include "rf_expr.ih"
    29 #include "rf_stack.hh"
     29#include "rf_stack.ih"
    3030#include "rf_arg.hh"
    3131#include "rf_result.hh"
    32 #include "rf_retval.hh"
     32#include "rf_retval.ih"
    3333#include "rf_macros.hh"
    3434#include "rf_memory_chunk.hh"
     
    3838#include "rf_integer.ih"
    3939#include "rf_word.ih"
    40 #include "rf_box.ih"
    4140#include "rf_vector.ih"
    4241#include "rf_channel.ih"
     
    4645#include "rf_static_object.ih"
    4746#include "rf_symbol.ih"
     47#include "rf_box.hh"
    4848
    4949#include "pxx_heap_allocator.ih"
  • to-imperative/trunk/runtime/rf_expr.hh

    r1768 r1772  
    237237  template <class ObjClass, class CppType1, class CppType2>
    238238  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) ;
    239242
    240243private:
  • to-imperative/trunk/runtime/rf_expr.ih

    r1768 r1772  
    1414#include "rf_expr.hh"
    1515#include "rf_term.ih"
    16 #include "rf_parenth.ih"
     16#include "rf_parenth.hh"
    1717#include "rf_object_ref.ih"
     18#include "rf_static_object.ih"
    1819#include "rf_integer.ih"
    1920#include "rf_short_int.ih"
     
    111112  // If we really have a reference term...
    112113  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>());
    115116  }
    116117  //
     
    162163inline Expr& Expr::operator = (Expr const& _expr)
    163164{
    164   D(printf("%p(%p,%p,%p) = %p(%p,%p,%p), ",
     165  D(printf("%p(%p,%p,%p) = %p(%p,%p,%p)",
    165166           this, first, last, mem_chunk,
    166167           &_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  )
    169175  //
    170176  // If we are not assigning to self
     
    185191{
    186192//  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);
    190197}
    191198
     
    497504{
    498505  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>();
    501508  return e;
    502509}
     510
     511template <class ObjClass>
     512inline 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
    503520
    504521template <class ObjClass, class CppType1>
     
    506523{
    507524  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>();
    510527  return e;
    511528}
     
    516533  Expr e(1);
    517534  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>();
    520537  return e;
    521538}
     
    928945      }
    929946      if (p != first) fputc(' ', _fp);
    930       if (p->get_type() == type_parenth) {
     947      if (p->is_ref()) {
    931948        if (fputc('(', _fp) == EOF) return false;
    932949        Expr e(p);
     
    9921009    if (p->is_sym()) {
    9931010      res = res + (WString)(*p);
    994     } else if (p->is_ref()) {
     1011    }
     1012    else {
    9951013      res = res + WString(L"(") + (WString)(Expr(p)) + WString(L")");
    996     } else {
    997       FATAL("Not supported yet");
    9981014    }
    9991015  }
  • to-imperative/trunk/runtime/rf_integer.cc

    r1730 r1772  
    5252
    5353short_type_funcs_t Integer::funcs = {
     54  0,
    5455  (void (*)(Term*, Term const*))(Integer::ctor),
    5556  (void (*)(Term*))(Integer::dtor),
     
    5758  (int (*)(Term const*, Term const*))(Integer::compare),
    5859  (uint32_t (*)(Term const*))(Integer::hash),
    59   (pxx::WString (*)(Term const*))(Integer::to_string)
     60  (pxx::WString (*)(Term const*))(Integer::to_string),
     61  null
    6062};
    6163
  • to-imperative/trunk/runtime/rf_macros.cc

    r1730 r1772  
    1 #include "rf_retval.hh"
    2 #include "rf_expr.hh"
    31#include "rf_macros.hh"
    4 #include "rf_func.ih"
    52
    63namespace rfrt
  • to-imperative/trunk/runtime/rf_macros.hh

    r1768 r1772  
    275275#endif
    276276
    277 #define RF_NEW_SYMBOL(t, c) \
     277#define RF_NEW_SYMBOL(CppType, TermClass) \
    278278  template<> \
    279   struct SymbolType<t> \
     279  struct SymbolType< CppType > \
    280280  { \
    281281    /*enum { type = c };*/ \
    282     typedef c type; \
     282    typedef TermClass Type; \
    283283  };
    284284
    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  )
    286297
    287298}
  • to-imperative/trunk/runtime/rf_object_ref.cc

    r1678 r1772  
    3030
    3131short_type_funcs_t ObjectRef::funcs = {
     32  0,
    3233  (void (*)(Term*, Term const*))(ObjectRef::ctor),
    3334  (void (*)(Term*))(ObjectRef::dtor),
     
    3536  null, // (int (*)(Term const*, Term const*))(ObjectRef::compare), FIXME:
    3637  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
    3840};
    3941
  • to-imperative/trunk/runtime/rf_parenth.hh

    r1381 r1772  
    22#define __rf_parenth_hh__
    33
    4 #include "rf_types.hh"
     4#include "rf_symbol.ih"
    55#include "rf_expr.hh"
    66
     
    1010using namespace rfrt ;
    1111
    12 class Parenth :
    13   public Term
     12RF_NEW_SYMBOL(Expr, ObjectTerm);
     13
     14inline bool RF_SYMBOL(Expr)::eq (
     15    RF_SYMBOL(Expr) const* _s1, RF_SYMBOL(Expr) const* _s2
     16)
    1417{
     18  return (*_s1->get_obj_ptr()) == (*_s2->get_obj_ptr());
     19}
    1520
    16   struct Content
    17   {
    18     uintptr_t ref_count;
    19     Expr expr;
    20   };
     21inline 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}
    2127
    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 
     28inline 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}
    4534
    4635}
  • to-imperative/trunk/runtime/rf_result.hh

    r1533 r1772  
    2525
    2626#include "rf_stack.hh"
     27#include "rf_expr.ih"
    2728
    2829namespace rfrt
  • to-imperative/trunk/runtime/rf_retval.cc

    r299 r1772  
    1 #include "rf_retval.hh"
     1#include "rf_retval.ih"
    22
    33//
  • to-imperative/trunk/runtime/rf_retval.hh

    r1700 r1772  
    2525
    2626#include "rf_expr.hh"
    27 #include "rf_stack.hh"
    2827
    2928namespace rftype {
     
    5049  {}
    5150
    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) ;
    6152
    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) ;
    6754
    6855  inline ~RetVal ()
    6956  {}
    7057
    71   inline operator bool () const
    72   {
    73     return (data & uintptr_t(0x01)) == 0;
    74   }
     58  inline operator bool () const ;
    7559
    76   inline bool is_tail () const
    77   {
    78     return data > 1;
    79   }
     60  inline bool is_tail () const ;
    8061
    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 ;
    8663
    8764};
  • to-imperative/trunk/runtime/rf_short_int.cc

    r1671 r1772  
    122122
    123123short_type_funcs_t Int32::funcs = {
     124  0,
    124125  null, // (void (*)(Term*, Term const*))(Int32::ctor),
    125126  null, // ShortInt::dtor,
     
    127128  (int (*)(Term const*, Term const*))(Int32::compare),
    128129  (uint32_t (*)(Term const*))(Int32::hash),
    129   (pxx::WString (*)(Term const*))(Int32::to_string)
     130  (pxx::WString (*)(Term const*))(Int32::to_string),
     131  null
    130132};
    131133
  • to-imperative/trunk/runtime/rf_stack.cc

    r1490 r1772  
    2121// Author: Andrey Slepuhin <pooh@msu.ru>
    2222
    23 #include "rf_stack.hh"
     23#include "rf_stack.ih"
    2424
    2525namespace rfrt
  • to-imperative/trunk/runtime/rf_stack.hh

    r1763 r1772  
    1919// $Revision$
    2020// $Date$
    21 // Author: Andrey Slepuhin <pooh@msu.ru>
    2221
    2322#ifndef __rf_stack_hh__
    2423#define __rf_stack_hh__
    2524
    26 #include "rf_expr.ih"
    27 #include "rf_integer.ih"
     25#include "rf_expr.hh"
    2826#include "pxx_heap.ih"
    2927
     
    6462  {}
    6563
    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) ;
    7165
    7266  inline void pop ()
    7367  {}
    7468 
    75   inline void pop (Expr& _expr)
    76   {
    77     _expr.~Expr();
    78     new (&_expr) Expr(top++);
    79   }
     69  inline void pop (Expr& _expr) ;
    8070
    81   inline void pop (Result& _res);
     71  inline void pop (Result& _res) ;
    8272
    83   inline Expr const* get ()
    84   {
    85     return top++;
    86   }
     73  inline Expr const* get () ;
    8774
    88   inline Expr* get_top ()
    89   {
    90     args_num = -1;
    91     return top;
    92   }
     75  inline Expr* get_top () ;
    9376
    94   inline void set_top (Expr* _top)
    95   {
    96     top = _top;
    97   }
     77  inline void set_top (Expr* _top) ;
    9878
    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) ;
    10980
    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 () ;
    12082
    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) ;
    12884
    129   inline void start_push_mode ()
    130   {
    131     args_num = -1;
    132     saved_top = top;
    133   }
     85  inline void start_push_mode () ;
    13486
    135   inline void stop_push_mode ()
    136   {
    137     args_num = top - saved_top;
    138     top = saved_top;
    139   };
     87  inline void stop_push_mode () ;
    14088
    141   inline void start_ress_mode ()
    142   {
    143     saved_top = top;
    144   }
     89  inline void start_ress_mode () ;
    14590
    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) ;
    15692
    157   inline void start_pop_mode ()
    158   {
    159     top--;
    160     top -= *reinterpret_cast<uintptr_t*>(top);
    161   }
     93  inline void start_pop_mode () ;
    16294
    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) ;
    16896
    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 () ;
    17598
    176   inline bool is_in_push_mode () const
    177   {
    178     return args_num == -1;
    179   }
     99  inline bool is_in_push_mode () const ;
    180100
    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 ;
    192102
    193   inline void up ()
    194   {
    195     top = get_upper(1);
    196     dec_depth();
    197   }
     103  inline void up () ;
    198104
    199   inline void inc_depth ()
    200   {
    201     depth++;
    202   }
     105  inline void inc_depth () ;
    203106
    204   inline void dec_depth ()
    205   {
    206     depth--;
    207   }
     107  inline void dec_depth () ;
    208108
    209   inline size_t get_depth () const
    210   {
    211     return depth;
    212   }
     109  inline size_t get_depth () const ;
    213110
    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 ;
    219112
    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 ;
    226114
    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) ;
    232116
    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) ;
    237118
    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) ;
    243120
    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) ;
    248122
    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 ;
    267124
    268125};
     
    270127extern Stack* stack ;
    271128
    272 inline Expr const& Expr::operator , (Expr const& _expr) const
    273 {
    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   else
    289     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 
    299129}
    300130
  • to-imperative/trunk/runtime/rf_symbol.hh

    r1768 r1772  
    8585
    8686  static short_type_funcs_t funcs ;
     87
    8788  static const TypeRegister reg ;
    8889
     
    9495struct SymbolType;
    9596
     97template<class C>
     98class NamedObject :
     99  public C
     100{
     101public:
     102  pxx::WString name;
     103  inline NamedObject (wchar_t const* _name) : C(), name(_name) {};
     104};
     105
     106template<class C>
     107class 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
     120public:
     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
    96148}
    97149
  • to-imperative/trunk/runtime/rf_symbol.ih

    r1768 r1772  
    88
    99#include "rf_symbol.hh"
     10#include "rf_macros.hh"
    1011
    1112namespace rftype
     
    8687    allocator->deallocate(w);
    8788  }
     89}
     90
     91template <class C>
     92bool 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
     99template <class C>
     100int 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;
    88107}
    89108
     
    104123template <class C>
    105124short_type_funcs_t Symbol<C, ObjectTerm>::funcs = {
     125  0,
    106126  (void (*)(Term*, Term const*))   (Symbol<C, ObjectTerm>::ctor),
    107127  (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),
    110130  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
    112133};
    113134
     135
     136template <class C>
     137inline 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
     146template <class C>
     147template <typename CppType1>
     148inline 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
     157template <class C>
     158template <typename CppType1, typename CppType2>
     159inline 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
     168template <class C>
     169inline NamedObject<C>* Symbol<NamedObject<C>, ObjectTerm>::get_obj_ptr () const
     170{
     171  return &static_cast<Wrapper*>(ptr_data2)->object;
     172}
     173
     174template <class C>
     175void 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
     184template <class C>
     185pxx::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
     193template <class C>
     194size_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
     203template <class C>
     204short_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/*
    114216template <class C>
    115217const TypeRegister Symbol<C, ObjectTerm>::reg(&Symbol<C, ObjectTerm>::funcs);
     218*/
    116219
    117220template <class C>
  • to-imperative/trunk/runtime/rf_term.hh

    r1763 r1772  
    163163
    164164  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 ;
    165169
    166170  static inline int compare (Term const& _t1, Term const& _t2) ;
  • to-imperative/trunk/runtime/rf_term.ih

    r1768 r1772  
    1515#include "rf_types.ih"
    1616#include "rf_expr.hh"
    17 #include "rf_symbol.ih"
     17#include "rf_parenth.hh"
    1818#include "rf_object_ref.ih"
    1919#include "rf_word.ih"
     
    7676inline bool Term::is_sym () const
    7777{
    78   return get_short_type() > type_parenth;
     78//  return get_short_type() > type_parenth;
     79  return !is_ref();
    7980}
    8081
    8182inline bool Term::is_ref () const
    8283{
    83   return get_short_type() == type_parenth;
     84//  return get_short_type() == type_parenth;
     85  return is_instance_of<Expr>();
    8486}
    8587
     
    102104{
    103105  unsigned type = get_short_type();
    104   if (type != type_object) return type;
     106  if (type != type_object) return short_type_funcs[type]->type;
    105107  return static_cast<const ObjectRef*>(this)->get_obj_ptr()->get_type();
    106108}
     
    185187{
    186188  return
    187     static_cast<Symbol<C, typename SymbolType<C>::type> const*>(this)->
     189    static_cast<Symbol<C, typename SymbolType<C>::Type> const*>(this)->
    188190      get_obj_ptr();
    189191}
     
    193195{
    194196  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();
    196199}
    197200
     
    210213}
    211214
     215inline 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
    212223inline int Term::compare (Term const& _t1, Term const& _t2)
    213224{
    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;
    216229  if (type1 == type_parenth && type2 != type_parenth) return 1;
    217230  if (type1 != type_parenth && type2 == type_parenth) return -1;
    218231  if (type1 > type2) return 1;
    219232  if (type1 < type2) return -1;
    220   int (*cmp)(Term const*, Term const*) = short_type_funcs[type1]->compare;
     233  int (*cmp)(Term const*, Term const*) = short_type_funcs[t1]->compare;
    221234  if (cmp) return (*cmp)(&_t1, &_t2);
    222235  if (_t1.uint_data2 > _t2.uint_data2) return 1;
  • to-imperative/trunk/runtime/rf_types.hh

    r1768 r1772  
    3939typedef struct
    4040{
     41  unsigned type ;
    4142  ///
    4243  /// Copy constructor for short symbol
     
    5758  /// Conversion to string.
    5859  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**) ;
    5964} short_type_funcs_t ;
    6065
     
    6671public:
    6772  inline TypeRegister (short_type_funcs_t* _funcs, unsigned _typenum = 0) ;
     73  inline TypeRegister (unsigned _type, short_type_funcs_t* _funcs) ;
    6874  inline unsigned get_type () const ;
    6975};
  • to-imperative/trunk/runtime/rf_types.ih

    r1655 r1772  
    1515  }
    1616  short_type_funcs[_typenum] = _funcs;
     17  short_type_funcs[_typenum]->type = _typenum;
    1718  type = _typenum;
     19}
     20
     21inline 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;
    1828}
    1929
  • to-imperative/trunk/runtime/rf_word.cc

    r1490 r1772  
    9898
    9999short_type_funcs_t Word::funcs = {
     100  0,
    100101  (void (*)(Term*, Term const*))(Word::ctor),
    101102  (void (*)(Term*))(Word::dtor),
     
    103104  (int (*)(Term const*, Term const*))(Word::compare),
    104105  (uint32_t (*)(Term const*))(Word::hash),
    105   (pxx::WString (*)(Term const*))(Word::to_string)
     106  (pxx::WString (*)(Term const*))(Word::to_string),
     107  null
    106108};
    107109
Note: See TracChangeset for help on using the changeset viewer.