Branch: Tag:

2017-11-18

2017-11-18 10:13:13 by Arne Goedeke <el@laramies.com>

Interpreter: moved tailcall optimization

Tailcall optimizations now happen inside of two API variants.
This is an initial step towards refactoring the tailcall optimization
code to not allocate new frames.

2140:    return NULL;   }    + void* lower_mega_apply_tailcall(INT32 args, struct object *o, ptrdiff_t fun) { +  struct pike_frame *frame = Pike_fp; +  void *ret; +  +  if (frame->flags & PIKE_FRAME_NO_REUSE) { +  /* We cannot reuse this frame. So we simply call mega_apply_low and are done. */ +  mega_apply_low(args, o, fun); +  return NULL; +  } +  +  ret = lower_mega_apply(args, o, fun); +  +  if (ret) { + #ifdef PIKE_DEBUG +  frame->pc = 0; + #endif +  unlink_previous_frame(); +  } +  +  return ret; + } +    /* Apply a function.    *    * Application types:
2197:    return NULL;   }    + void* low_mega_apply_tailcall(enum apply_type type, INT32 args, void *arg1, void *arg2) { +  struct pike_frame *frame = Pike_fp; +  void *ret;    -  +  if (frame->flags & PIKE_FRAME_NO_REUSE) { +  /* We cannot reuse this frame. So we simply call mega_apply and are done. */ +  mega_apply(type, args, arg1, arg2); +  return NULL; +  }    -  +  ret = low_mega_apply(type, args, arg1, arg2); +  +  if (ret) { + #ifdef PIKE_DEBUG +  frame->pc = 0; + #endif +  unlink_previous_frame(); +  } +  +  +  return ret; + } +    void low_return(void)   {    struct svalue *save_sp = frame_get_save_sp(Pike_fp);
2366:    CALL_AND_UNSET_ONERROR(uwp);   }    - PMOD_EXPORT void mega_apply_low(INT32 args, void *arg1, ptrdiff_t arg2) + PMOD_EXPORT void mega_apply_low(INT32 args, struct object *o, ptrdiff_t fun)   {    /* Save and clear Pike_interpreter.catching_eval_jmpbuf so that the    * following eval_instruction will install a LOW_JMP_BUF of its
2381:    * practically zero. */    check_c_stack(Pike_interpreter.c_stack_margin ?    Pike_interpreter.c_stack_margin : 100); -  if( lower_mega_apply( args, arg1, arg2 ) ) +  if( lower_mega_apply( args, o, fun ) )    {    eval_instruction(Pike_fp->pc   #ifdef ENTRY_PROLOGUE_SIZE