pike.git / src / las.c

version» Context lines:

pike.git/src/las.c:14:   #include "lex.h"   #include "pike_types.h"   #include "constants.h"   #include "mapping.h"   #include "multiset.h"   #include "error.h"   #include "docode.h"   #include "main.h"   #include "memory.h"   #include "operators.h" + #include "callback.h"      #define LASDEBUG      int lasdebug=0;      static node *eval(node *);   static void optimize(node *n);      dynamic_buffer areas[NUM_AREAS];   node *init_node = 0;
pike.git/src/las.c:1288:    int inc;    int token;       /* for(;0; X) Y; -> 0; */    if(node_is_false(CAR(n)))    {    tmp1=mkintnode(0);    goto use_tmp1;    }    +  /* for(;1;); -> for(;1;) sleep(255); (saves cpu) */ +  if(node_is_true(CAR(n)) && +  (!CDR(n) || (CDR(n)->token==':' && !CADR(n) && !CDDR(n)))) +  { +  tmp1=mknode(F_FOR, CAR(n), mknode(':',mkefuncallnode("sleep",mkintnode(255)),0)); +  CAR(n)=0; +  goto use_tmp1; +  } +     /*    * if X and Y are free from 'continue' or X is null,    * then the following optimizations can be done:    * for(;++e; X) Y; -> ++ne_loop(e, -1) { Y ; X }    * for(;e++; X) Y; -> ++ne_loop(e, 0) { Y; X }    * for(;--e; X) Y; -> --ne_loop(e, 1) { Y; X }    * for(;e--; X) Y; -> --ne_loop(e, 0) { Y; X }    */    if(CAR(n) &&    (CAR(n)->token==F_INC ||
pike.git/src/las.c:1500:   #endif    continue;       }    n->node_info |= OPT_OPTIMIZED;    n=n->parent;    }while(n);    current_line = save_line;   }    + struct timer_oflo + { +  INT32 counter; +  int yes; + }; +  + static void check_evaluation_time(struct callback *cb,void *ignored,void *tmp) + { +  struct timer_oflo *foo=(struct timer_oflo *)tmp; +  if(foo->counter-- < 0) +  { +  foo->yes=1; +  throw(); +  } + } +    int eval_low(node *n)   {    unsigned INT16 num_strings, num_constants;    INT32 jump;    struct svalue *save_sp = sp;    int ret;       if(num_parse_error) return -1;    setup_fake_program();   
pike.git/src/las.c:1523:       store_linenumbers=0;    docode(n);    ins_f_byte(F_DUMB_RETURN);    store_linenumbers=1;       setup_fake_program();    ret=-1;    if(!num_parse_error)    { +  struct callback *tmp_callback; +  struct timer_oflo foo; +  +  /* This is how long we try to optimize before giving up... */ +  foo.counter=10000; +  foo.yes=0; +     setup_fake_object(); -  +  +  tmp_callback=add_to_callback(&evaluator_callbacks, +  check_evaluation_time, +  (void *)&foo,0); +     if(apply_low_safe_and_stupid(&fake_object, jump))    {    /* Generate error message */    if(throw_value.type == T_ARRAY && throw_value.u.array->size)    {    union anything *a;    a=low_array_get_item_ptr(throw_value.u.array, 0, T_STRING);    if(a)    {    yyerror(a->string->str);    }else{    yyerror("Nonstandard error format.");    }    }else{    yyerror("Nonstandard error format.");    }    }else{ -  +  if(foo.yes) +  pop_n_elems(sp-save_sp); +  else    ret=sp-save_sp;    } -  +  +  remove_callback(tmp_callback);    }       while(fake_program.num_strings > num_strings)    {    fake_program.num_strings--;    free_string(fake_program.strings[fake_program.num_strings]);    areas[A_STRINGS].s.len-=sizeof(struct pike_string *);    }       while(fake_program.num_constants > num_constants)