Branch: Tag:

2004-09-22

2004-09-22 17:55:29 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Reduce stack use in the non machine code cases.

Rev: src/interpret_functions.h:1.170
Rev: src/interpreter.h:1.87

2:   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: interpret_functions.h,v 1.169 2004/08/26 16:12:12 grubba Exp $ + || $Id: interpret_functions.h,v 1.170 2004/09/22 17:55:29 grubba Exp $   */      /*
104:   #define DONT_BRANCH SKIPJUMP   #endif    + #ifndef LOCAL_VAR + #define LOCAL_VAR(X) X + #endif +    #ifndef OVERRIDE_JUMPS      #undef GET_JUMP
201:      #undef DO_INDEX   #define DO_INDEX do { \ -  struct svalue s; \ -  index_no_free(&s,Pike_sp-2,Pike_sp-1); \ +  LOCAL_VAR(struct svalue tmp); \ +  index_no_free(&tmp,Pike_sp-2,Pike_sp-1); \    pop_2_elems(); \ -  *Pike_sp=s; \ +  *Pike_sp=tmp; \    Pike_sp++; \    dmalloc_touch_svalue(Pike_sp-1); \ -  print_return_value(); \ +  print_return_value(); \   }while(0)      
304:   });      OPCODE1(F_LOOKUP_LFUN, "->lfun", 0, { -  struct svalue tmp; -  struct object *o; +  LOCAL_VAR(struct object *o); +  LOCAL_VAR(struct svalue tmp);       if ((Pike_sp[-1].type == T_OBJECT) && ((o = Pike_sp[-1].u.object)->prog) &&    (FIND_LFUN(o->prog, LFUN_ARROW) == -1)) {
321:    tmp.u.integer = 0;    }    } else { -  struct svalue tmp2; +  LOCAL_VAR(struct svalue tmp2);    tmp2.type = PIKE_T_STRING;    tmp2.u.string = lfun_strings[arg1];    tmp2.subtype = 1;
339:   });      OPCODE2(F_TRAMPOLINE, "trampoline", I_UPDATE_SP, { -  struct object *o=low_clone(pike_trampoline_program); +     struct pike_frame *f=Pike_fp;    DO_IF_DEBUG(INT32 arg2_ = arg2); -  +  LOCAL_VAR(struct object *o); +  o = low_clone(pike_trampoline_program);       while(arg2--) {    DO_IF_DEBUG({
376:    *(Pike_mark_sp++)=Pike_sp;       OPCODE2(F_EXTERNAL,"external", I_UPDATE_SP, { -  struct external_variable_context loc; +  LOCAL_VAR(struct external_variable_context loc);       loc.o=Pike_fp->current_object;    loc.parent_identifier=Pike_fp->fun;
406:         OPCODE2(F_EXTERNAL_LVALUE, "& external", I_UPDATE_SP, { -  struct external_variable_context loc; +  LOCAL_VAR(struct external_variable_context loc);       loc.o=Pike_fp->current_object;    loc.parent_identifier=Pike_fp->fun;
662:    if( (1 << Pike_sp[-2].type) &    (BIT_ARRAY | BIT_MULTISET | BIT_MAPPING | BIT_STRING) )    { -  struct svalue s; -  s.type = PIKE_T_INT; -  s.subtype = 0; -  s.u.integer = 0; -  assign_lvalue(Pike_sp-4, &s); +  LOCAL_VAR(struct svalue tmp); +  tmp.type = PIKE_T_INT; +  tmp.subtype = 0; +  tmp.u.integer = 0; +  assign_lvalue(Pike_sp-4, &tmp);    }   });   
686:    if( (1 << Pike_sp[-3].type) &    (BIT_ARRAY | BIT_MULTISET | BIT_MAPPING | BIT_STRING) )    { -  struct svalue s; -  s.type = PIKE_T_INT; -  s.subtype = 0; -  s.u.integer = 0; -  assign_lvalue(Pike_sp-5, &s); +  LOCAL_VAR(struct svalue tmp); +  tmp.type = PIKE_T_INT; +  tmp.subtype = 0; +  tmp.u.integer = 0; +  assign_lvalue(Pike_sp-5, &tmp);    }   });   
725:    if( (1 << Pike_sp[-2].type) &    (BIT_ARRAY | BIT_MULTISET | BIT_MAPPING | BIT_STRING) )    { -  struct svalue s; -  s.type=PIKE_T_INT; -  s.subtype=0; -  s.u.integer=0; -  assign_lvalue(Pike_sp-4,&s); +  LOCAL_VAR(struct svalue tmp); +  tmp.type=PIKE_T_INT; +  tmp.subtype=0; +  tmp.u.integer=0; +  assign_lvalue(Pike_sp-4, &tmp);    } else if (Pike_sp[-2].type == T_OBJECT) {    /* One ref in the lvalue, and one on the stack. */    int i;
782:    if( (1 << Pike_sp[-2].type) &    (BIT_ARRAY | BIT_MULTISET | BIT_MAPPING | BIT_STRING) )    { -  struct svalue s; -  s.type=PIKE_T_INT; -  s.subtype=0; -  s.u.integer=0; -  assign_lvalue(Pike_sp-4,&s); +  LOCAL_VAR(struct svalue tmp); +  tmp.type=PIKE_T_INT; +  tmp.subtype=0; +  tmp.u.integer=0; +  assign_lvalue(Pike_sp-4, &tmp);    } else if (Pike_sp[-2].type == PIKE_T_OBJECT) {    /* One ref in the lvalue, and one on the stack. */    int i;
1060:   });      OPCODE2_BRANCH(F_BRANCH_IF_NOT_LOCAL_ARROW, "branch if !local->x", 0, { -  struct svalue tmp; +  LOCAL_VAR(struct svalue tmp);    tmp.type=PIKE_T_STRING;    tmp.u.string=Pike_fp->context.prog->strings[arg1];    tmp.subtype=1;
1280:      OPCODE1_JUMP(F_SWITCH_ON_INDEX, "switch on index", I_UPDATE_ALL, {    INT32 tmp; -  struct svalue s; +     PIKE_OPCODE_T *addr; -  +  LOCAL_VAR(struct svalue tmp2);    JUMP_SET_TO_PC_AT_NEXT (addr); -  index_no_free(&s,Pike_sp-2,Pike_sp-1); -  Pike_sp++[0]=s; +  index_no_free(&tmp2, Pike_sp-2, Pike_sp-1); +  Pike_sp++[0] = tmp2;       tmp=switch_lookup(Pike_fp->context.prog->    constants[arg1].sval.u.array,Pike_sp-1);
1630:   });      OPCODE2(F_LOCAL_LOCAL_INDEX, "local[local]", I_UPDATE_SP, { -  struct svalue *s=Pike_fp->locals+arg1; +  LOCAL_VAR(struct svalue *s); +  s = Pike_fp->locals + arg1;    if(s->type == PIKE_T_STRING) s->subtype=0;    Pike_sp++->type=PIKE_T_INT;    index_no_free(Pike_sp-1,Pike_fp->locals+arg2,s);   });      OPCODE1(F_LOCAL_INDEX, "local index", 0, { -  struct svalue tmp; -  struct svalue *s = Pike_fp->locals+arg1; +  LOCAL_VAR(struct svalue *s); +  LOCAL_VAR(struct svalue tmp); +  s = Pike_fp->locals + arg1;    if(s->type == PIKE_T_STRING) s->subtype=0;    index_no_free(&tmp,Pike_sp-1,s);    free_svalue(Pike_sp-1);
1646:   });      OPCODE2(F_GLOBAL_LOCAL_INDEX, "global[local]", I_UPDATE_SP, { -  struct svalue tmp; -  struct svalue *s; +  LOCAL_VAR(struct svalue *s); +  LOCAL_VAR(struct svalue tmp);    low_object_index_no_free(Pike_sp,    Pike_fp->current_object,    arg1 + Pike_fp->context.identifier_level);
1660:   });      OPCODE2(F_LOCAL_ARROW, "local->x", I_UPDATE_SP, { -  struct svalue tmp; +  LOCAL_VAR(struct svalue tmp);    tmp.type=PIKE_T_STRING;    tmp.u.string=Pike_fp->context.prog->strings[arg1];    tmp.subtype=1;
1671:   });      OPCODE1(F_ARROW, "->x", 0, { -  struct svalue tmp; -  struct svalue tmp2; +  LOCAL_VAR(struct svalue tmp); +  LOCAL_VAR(struct svalue tmp2);    tmp.type=PIKE_T_STRING;    tmp.u.string=Pike_fp->context.prog->strings[arg1];    tmp.subtype=1;
1683:   });      OPCODE1(F_STRING_INDEX, "string index", 0, { -  struct svalue tmp; -  struct svalue tmp2; +  LOCAL_VAR(struct svalue tmp); +  LOCAL_VAR(struct svalue tmp2);    tmp.type=PIKE_T_STRING;    tmp.u.string=Pike_fp->context.prog->strings[arg1];    tmp.subtype=0;
1796:   OPCODE0_ALIAS(F_RANGE, "range", I_UPDATE_SP, o_range);      OPCODE0(F_COPY_VALUE, "copy_value", 0, { -  struct svalue tmp; +  LOCAL_VAR(struct svalue tmp);    copy_svalues_recursively_no_free(&tmp,Pike_sp-1,1,0);    free_svalue(Pike_sp-1);    Pike_sp[-1]=tmp;
1804:   });      OPCODE0(F_INDIRECT, "indirect", I_UPDATE_SP, { -  struct svalue s; -  lvalue_to_svalue_no_free(&s,Pike_sp-2); -  if(s.type != PIKE_T_STRING) +  LOCAL_VAR(struct svalue tmp); +  lvalue_to_svalue_no_free(&tmp, Pike_sp-2); +  if(tmp.type != PIKE_T_STRING)    {    pop_2_elems(); -  *Pike_sp=s; +  *Pike_sp = tmp;    Pike_sp++;    }else{ -  struct object *o; +  LOCAL_VAR(struct object *o);    o=low_clone(string_assignment_program);    ((struct string_assignment_storage *)o->storage)->lval[0]=Pike_sp[-2];    ((struct string_assignment_storage *)o->storage)->lval[1]=Pike_sp[-1]; -  ((struct string_assignment_storage *)o->storage)->s=s.u.string; +  ((struct string_assignment_storage *)o->storage)->s=tmp.u.string;    Pike_sp-=2;    push_object(o);    }
1940:      OPCODE1_JUMP(F_CALL_OTHER,"call other", I_UPDATE_ALL, {    INT32 args=DO_NOT_WARN((INT32)(Pike_sp - *--Pike_mark_sp)); -  struct svalue *s=Pike_sp-args; +  LOCAL_VAR(struct svalue *s); +  s = Pike_sp-args;    JUMP_SET_TO_PC_AT_NEXT (Pike_fp->return_addr);    if(s->type == T_OBJECT)    { -  struct object *o=s->u.object; -  struct program *p; +  LOCAL_VAR(struct object *o); +  LOCAL_VAR(struct program *p); +  o = s->u.object;    if((p=o->prog))    {    if(FIND_LFUN(p, LFUN_ARROW) == -1)
1969:    }       { -  struct svalue tmp; -  struct svalue tmp2; +  LOCAL_VAR(struct svalue tmp); +  LOCAL_VAR(struct svalue tmp2);       tmp.type=PIKE_T_STRING;    tmp.u.string=Pike_fp->context.prog->strings[arg1];
1994:      OPCODE1_JUMP(F_CALL_OTHER_AND_POP,"call other & pop", I_UPDATE_ALL, {    INT32 args=DO_NOT_WARN((INT32)(Pike_sp - *--Pike_mark_sp)); -  struct svalue *s=Pike_sp-args; +  LOCAL_VAR(struct svalue *s); +  s = Pike_sp-args;    JUMP_SET_TO_PC_AT_NEXT (Pike_fp->return_addr);    if(s->type == T_OBJECT)    { -  struct object *o=s->u.object; -  struct program *p; +  LOCAL_VAR(struct object *o); +  LOCAL_VAR(struct program *p); +  o = s->u.object;    if((p=o->prog))    {    if(FIND_LFUN(p, LFUN_ARROW) == -1)
2025:    }       { -  struct svalue tmp; -  struct svalue tmp2; +  LOCAL_VAR(struct svalue tmp); +  LOCAL_VAR(struct svalue tmp2);       tmp.type=PIKE_T_STRING;    tmp.u.string=Pike_fp->context.prog->strings[arg1];
2051:      OPCODE1_JUMP(F_CALL_OTHER_AND_RETURN,"call other & return", I_UPDATE_ALL, {    INT32 args=DO_NOT_WARN((INT32)(Pike_sp - *--Pike_mark_sp)); -  struct svalue *s=Pike_sp-args; +  LOCAL_VAR(struct svalue *s); +  s = Pike_sp - args;    if(s->type == T_OBJECT)    { -  struct object *o=s->u.object; -  struct program *p; +  LOCAL_VAR(struct object *o); +  LOCAL_VAR(struct program *p); +  o = s->u.object;    if((p=o->prog))    {    if(FIND_LFUN(p, LFUN_ARROW) == -1)
2081:    }       { -  struct svalue tmp; -  struct svalue tmp2; +  LOCAL_VAR(struct svalue tmp); +  LOCAL_VAR(struct svalue tmp2);       tmp.type=PIKE_T_STRING;    tmp.u.string=Pike_fp->context.prog->strings[arg1];
2109:   #define DO_CALL_BUILTIN(ARGS) do { \    int args=(ARGS); \    struct svalue *expected_stack=Pike_sp-args; \ -  struct svalue *s=&Pike_fp->context.prog->constants[arg1].sval; \ +  LOCAL_VAR(struct svalue *s); \ +  s = &Pike_fp->context.prog->constants[arg1].sval; \    if(Pike_interpreter.trace_level) \    { \ -  dynamic_buffer save_buf; \ +  LOCAL_VAR(dynamic_buffer save_buf); \    init_buf(&save_buf); \    if (s->u.efun->name->size_shift) \    my_strcat ("[widestring function name]"); \
2140:    s->u.efun->name->str, s->u.efun->may_return_void); \    } \    if(Pike_interpreter.trace_level>1) { \ -  dynamic_buffer save_buf; \ +  LOCAL_VAR(dynamic_buffer save_buf); \    init_buf(&save_buf); \    if (s->u.efun->name->size_shift) \    my_strcat ("[widestring function name]"); \
2278:      /* Assume that the number of arguments is correct */   OPCODE1_PTRJUMP(F_COND_RECUR, "recur if not overloaded", I_UPDATE_ALL, { -  struct program *p = Pike_fp->current_object->prog; +     PIKE_OPCODE_T *addr; -  +  LOCAL_VAR(struct program *p); +  p = Pike_fp->current_object->prog;    JUMP_SET_TO_PC_AT_NEXT (addr);    Pike_fp->return_addr = (PIKE_OPCODE_T *)(((INT32 *)addr) + 1);   
2387:   #endif      OPCODE1(F_THIS_OBJECT, "this_object", I_UPDATE_SP, { -  struct object *o = Pike_fp->current_object; +     int level; -  +  LOCAL_VAR(struct object *o); +  o = Pike_fp->current_object;    for (level = 0; level < arg1; level++) { -  struct program *p = o->prog; +  LOCAL_VAR(struct program *p); +  p = o->prog;    if (!p)    Pike_error ("Object %d level(s) up is destructed - cannot get the parent.\n",    level);