Changeset 2053


Ignore:
Timestamp:
Aug 10, 2006, 12:35:38 AM (14 years ago)
Author:
orlov
Message:
  • Fixed stack capture with +trap_stack RTS option

(prevented destruction of expressions on stack when an exception is thrown).

Location:
to-imperative/trunk/runtime
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • to-imperative/trunk/runtime/rf_arg.hh

    r1772 r2053  
    5555
    5656  inline ~Arg ()
    57   {}
     57  {
     58#ifndef RFRT_STINGY_STACK
     59    if (__keep_stack && mem_chunk)
     60      mem_chunk->inc_ref_count();
     61#endif
     62  }
    5863
    5964};
  • to-imperative/trunk/runtime/rf_core.cc

    r2040 r2053  
    272272  D( printf("=== Init is done! ===\n"); )
    273273  Expr res;
    274   try {
     274  RF_TRAP {
    275275    RF_CALL(rfrt::entry, /*void*/, res);
    276276  }
    277   catch (Expr const& err) {
     277  RF_WITH {
    278278    printf("\n$error: ");
    279279    err.writeln(stdout);
     
    298298      }
    299299    }
     300    RF_CLEANUP;
    300301  }
    301302  printf("Time elapsed: %.2fs\n", (clock () - start) / CLOCKS_PER_SEC);
  • to-imperative/trunk/runtime/rf_macros.cc

    r1778 r2053  
    99rftype::Closure* __rf_closure_to_call;
    1010
     11bool __keep_stack = false;
     12
    1113}
  • to-imperative/trunk/runtime/rf_macros.hh

    r1986 r2053  
    1515
    1616#ifndef RFRT_STINGY_STACK
     17
     18extern bool __keep_stack;
    1719
    1820#define RF_start_push   stack->start_push_mode()
     
    268270
    269271#ifndef RFRT_STINGY_STACK
    270 # define RF_CLEANUP stack->cleanup(__trap_depth)
     272# define RF_CLEANUP \
     273    do { \
     274      __keep_stack = false; \
     275      stack->cleanup(__trap_depth); \
     276    } while (0)
    271277#else
    272278# define RF_CLEANUP stack->destroy_results(__trap_top, __trap_depth)
     
    275281#ifdef RFRT_COMPATIBLE
    276282# define RF_ERROR(x) \
    277     { \
     283    do { \
     284      if (trap_stack_on) __keep_stack = true; \
    278285      Expr y = x; \
    279286      throw Expr(y, y.get_len() - 2, 2); \
    280     }
    281 #else
    282 # define RF_ERROR(x) throw (x)
     287    } while (0)
     288#else
     289# define RF_ERROR(x) \
     290    do { \
     291      if (trap_stack_on) __keep_stack = true; \
     292      throw (x); \
     293    } while (0)
    283294#endif
    284295
     
    288299# define RF_FUNC_ERROR(msg) \
    289300    do { \
     301      if (trap_stack_on) __keep_stack = true; \
    290302      wchar_t const* fname; \
    291303      size_t len = stack->get_func(stack->get_depth())->get_name(&fname); \
  • to-imperative/trunk/runtime/rf_stack.hh

    r1778 r2053  
    124124  inline Expr get_part (size_t _offset, size_t _len) const ;
    125125
     126  inline void dump () const ;
     127
    126128};
    127129
  • to-imperative/trunk/runtime/rf_stack.ih

    r1778 r2053  
    6262inline void Stack::cleanup (size_t _saved_depth)
    6363{
    64   if (trap_stack_on) trap_stack = get_part(0, depth - _saved_depth);
    65   while (depth > _saved_depth) {
    66     destroy_results();
     64  if (trap_stack_on)
     65  {
     66    trap_stack = get_part(0, depth - _saved_depth);
     67    while (depth > _saved_depth)
     68      destroy_results();
     69  }
     70  else
     71  {
     72    top = get_upper(depth - _saved_depth);
     73    depth = _saved_depth;
    6774  }
    6875}
     
    8592}
    8693
     94/*
     95 * Add to the stack special node -- 3 words:
     96 *   - number of the results
     97 *   - number of the arguments
     98 *   - pointer to the function
     99 */
    87100inline void Stack::stop_ress_mode (rftype::Func const* _f)
    88101{
     
    162175{
    163176  uintptr_t* p = reinterpret_cast<uintptr_t*>(get_upper(depth - _depth) - 1);
    164   *_args = reinterpret_cast<Expr*>(p) - *p - *(p + 1);
     177  *_args = (reinterpret_cast<Expr*>(p) - *p) - *(p + 1);
    165178  return *(p + 1);
    166179}
    167180
     181/*
     182 * _p is a ponter to special node.
     183 * Returns pointer to that node function.
     184 */
    168185inline rftype::Func* Stack::getf (Expr const* _p)
    169186{
     
    172189}
    173190
     191/*
     192 * _p is a ponter to special node.
     193 * Returns number of arguments in corresponding call.
     194 */
    174195inline int Stack::getn (Expr const* _p)
    175196{
     
    177198}
    178199
     200/*
     201 * _p is a ponter to special node.
     202 * Returns pointer to the first argument.
     203 */
    179204inline Expr const* Stack::geta (Expr const* _p)
    180205{
    181   return _p - *reinterpret_cast<uintptr_t const*>(_p)
     206  return (_p - *reinterpret_cast<uintptr_t const*>(_p))
    182207            - *(reinterpret_cast<uintptr_t const*>(_p) + 1);
    183208}
    184209
     210/*
     211 * _p is a ponter to special node.
     212 * Returns pointer to the previous special node.
     213 */
    185214inline Expr const* Stack::getup (Expr const* _p)
    186215{
     
    196225  while (_len--)
    197226  {
    198     int  n  = getn(p);
     227    int n = getn(p);
    199228    Expr const* ap = geta(p);
    200229    Expr e_args;
     
    207236}
    208237
     238/*
     239 * For debugging purposes.
     240 */
     241inline void Stack::dump () const
     242{
     243  Expr const* p = top - 1;
     244  for (int i = depth; i; i--, p = getup(p))
     245  {
     246    printf("Node %d:\n", i);
     247    Expr const* ap = geta(p);
     248    for (int n = getn(p); n; n--, ap++)
     249    {
     250      printf("    (%p,%p,%p:%u)\n",
     251          ap->get_first(), ap->get_last(),
     252          ap->get_mem_chunk(), ap->get_mem_chunk() ? ap->get_mem_chunk()->get_ref_count() : 0);
     253    }
     254  }
     255}
    209256
    210257
Note: See TracChangeset for help on using the changeset viewer.