Branch: Tag:

1996-02-25

1996-02-25 00:25:47 by Fredrik Hübinette (Hubbe) <hubbe@hubbe.net>

`+ optimization done

Rev: doc/builtin/gc:1.1
Rev: doc/simulated/implode:1.2
Rev: lib/master.lpc:1.4
Rev: src/add_efun.h:1.3
Rev: src/backend.c:1.4
Rev: src/backend.h:1.4
Rev: src/builtin_efuns.c:1.12
Rev: src/call_out.h:1.3
Rev: src/configure:1.2
Rev: src/configure.in:1.7
Rev: src/debug.c:1.3(DEAD)
Rev: src/debug.h:1.3(DEAD)
Rev: src/docode.c:1.4
Rev: src/gc.c:1.1
Rev: src/gc.h:1.1
Rev: src/language.y:1.10
Rev: src/las.c:1.5
Rev: src/las.h:1.5
Rev: src/lex.c:1.7
Rev: src/lpc_signal.c:1.8
Rev: src/machine.h.in:1.7
Rev: src/main.c:1.3
Rev: src/modules/files/configure.in:1.4
Rev: src/operators.c:1.3
Rev: src/rusage.c:1.4
Rev: src/test/create_testsuite:1.9

21:      #define COMPARISON(ID,NAME,EXPR) \   void ID(INT32 args) \ - {\ + { \    int i; \    if(args > 2) \    pop_n_elems(args-2); \
218:    }   }    + static node *optimize_binary(node *n) + { +  node **first_arg, **second_arg, *ret; +  if(count_args(CDR(n))==2) +  { +  first_arg=my_get_arg(&CDR(n), 0); +  second_arg=my_get_arg(&CDR(n), 1); +  + #ifdef DEBUG +  if(!first_arg || !second_arg) +  fatal("Couldn't find argument!\n"); + #endif +  +  if((*second_arg)->type == (*first_arg)->type) +  { +  if((*first_arg)->token == F_APPLY && +  CAR(*first_arg)->token == F_CONSTANT && +  is_eq(& CAR(*first_arg)->u.sval, & CAR(n)->u.sval)) +  { +  ret=mknode(F_APPLY, +  CAR(n), +  mknode(F_ARG_LIST, +  CDR(*first_arg), +  *second_arg)); +  CAR(n)=0; +  CDR(*first_arg)=0; +  *second_arg=0; +  +  return ret; +  } +  +  if((*second_arg)->token == F_APPLY && +  CAR(*second_arg)->token == F_CONSTANT && +  is_eq(& CAR(*second_arg)->u.sval, & CAR(n)->u.sval)) +  { +  ret=mknode(F_APPLY, +  CAR(n), +  mknode(F_ARG_LIST, +  *first_arg, +  CDR(*second_arg))); +  CAR(n)=0; +  *first_arg=0; +  CDR(*second_arg)=0; +  +  return ret; +  } +  } +  } +  return 0; + } +  +    static int generate_comparison(node *n)   {    if(count_args(CDR(n))==2)
650:    case 0: error("Too few arguments to `*\n");    case 1: return;    case 2: o_multiply(); return; -  case 3: while(--args > 0) o_multiply(); +  default: while(--args > 0) o_multiply();    }   }   
902:      void init_operators()   { -  -  +     add_efun2("`==",f_eq,"function(mixed,mixed:int)",0,0,generate_comparison);    add_efun2("`!=",f_ne,"function(mixed,mixed:int)",0,0,generate_comparison);    add_efun2("`<", f_lt,"function(int,int:int)|function(float,float:int)|function(string,string:int)",0,0,generate_comparison);
911:    add_efun2("`>", f_gt,"function(int,int:int)|function(float,float:int)|function(string,string:int)",0,0,generate_comparison);    add_efun2("`>=",f_ge,"function(int,int:int)|function(float,float:int)|function(string,string:int)",0,0,generate_comparison);    -  add_efun2("`+",f_add,"function(int ...:int)|function(float ...:float)|function(string,string|int|float ...:string)|function(string,string|int|float ...:string)|function(int|float,string,string|int|float:string)|function(array ...:array)|function(mapping ...:mapping)|function(list...:list)",0,0,generate_sum); +  add_efun2("`+",f_add,"function(int ...:int)|function(float ...:float)|function(string,string|int|float ...:string)|function(string,string|int|float ...:string)|function(int|float,string,string|int|float:string)|function(array ...:array)|function(mapping ...:mapping)|function(list...:list)",0,optimize_binary,generate_sum);       add_efun2("`-",f_minus,"function(int:int)|function(float:float)|function(array,array:array)|function(mapping,mapping:mapping)|function(list,list:list)|function(float,float:float)|function(int,int:int)|function(string,string:string)",0,0,generate_minus);    -  add_efun2("`&",f_and,"function(int...:int)|function(mapping...:mapping)|function(list...:list)|function(array...:array)",0,0,generate_and); +  add_efun2("`&",f_and,"function(int...:int)|function(mapping...:mapping)|function(list...:list)|function(array...:array)",0,optimize_binary,generate_and);    -  add_efun2("`|",f_and,"function(int...:int)|function(mapping...:mapping)|function(list...:list)|function(array...:array)",0,0,generate_or); +  add_efun2("`|",f_and,"function(int...:int)|function(mapping...:mapping)|function(list...:list)|function(array...:array)",0,optimize_binary,generate_or);    -  add_efun2("`^",f_and,"function(int...:int)|function(mapping...:mapping)|function(list...:list)|function(array...:array)",0,0,generate_xor); +  add_efun2("`^",f_and,"function(int...:int)|function(mapping...:mapping)|function(list...:list)|function(array...:array)",0,optimize_binary,generate_xor);       add_efun2("`<<",f_lsh,"function(int,int:int)",0,0,generate_lsh);    add_efun2("`>>",f_rsh,"function(int,int:int)",0,0,generate_rsh);    -  add_efun2("`*",f_multiply,"function(int...:int)|function(float...:float)|function(string*,string:string)",0,0,generate_multiply); +  add_efun2("`*",f_multiply,"function(int...:int)|function(float...:float)|function(string*,string:string)",0,optimize_binary,generate_multiply);       add_efun2("`/",f_divide,"function(int,int:int)|function(float,float:float)|function(string,string:string*)",0,0,generate_divide);