pike.git / src / operators.c

version» Context lines:

pike.git/src/operators.c:1:   /*\   ||| This file a part of Pike, and is copyright by Fredrik Hubinette   ||| Pike is distributed as GPL (General Public License)   ||| See the files COPYING and DISCLAIMER for more information.   \*/   #include <math.h>   #include "global.h" - RCSID("$Id: operators.c,v 1.34 1998/05/25 16:42:07 grubba Exp $"); + RCSID("$Id: operators.c,v 1.35 1998/06/06 03:22:15 hubbe Exp $");   #include "interpret.h"   #include "svalue.h"   #include "multiset.h"   #include "mapping.h"   #include "array.h"   #include "stralloc.h"   #include "opcodes.h"   #include "operators.h"   #include "language.h"   #include "pike_memory.h"
pike.git/src/operators.c:299:    case 2:    do_docode(CDR(n),DO_NOT_COPY);    emit2(F_ADD);    return 1;       default:    return 0;    }   }    + static node *optimize_eq(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(node_is_false(*first_arg) && !node_may_overload(*second_arg,LFUN_EQ)) +  { +  ret=*second_arg; +  *second_arg=0; +  return mkopernode("`!",ret,0); +  } +  +  if(node_is_false(*second_arg) && !node_may_overload(*first_arg,LFUN_EQ)) +  { +  ret=*first_arg; +  *first_arg=0; +  return mkopernode("`!",ret,0); +  } +  } +  return 0; + } +  + static node *optimize_not(node *n) + { +  node **first_arg, **more_args; +  int e; +  +  if(count_args(CDR(n))==1) +  { +  first_arg=my_get_arg(&CDR(n), 0); + #ifdef DEBUG +  if(!first_arg) +  fatal("Couldn't find argument!\n"); + #endif +  if(node_is_true(*first_arg)) return mkintnode(0); +  if(node_is_false(*first_arg)) return mkintnode(1); +  + #define TMP_OPT(X,Y) do { \ +  if((more_args=is_call_to(*first_arg, X))) \ +  { \ +  node *tmp=*more_args; \ +  *more_args=0; \ +  return mkopernode(Y,tmp,0); \ +  } } while(0) +  +  TMP_OPT(f_eq, "`!="); +  TMP_OPT(f_ne, "`=="); +  TMP_OPT(f_lt, "`>="); +  TMP_OPT(f_gt, "`<="); +  TMP_OPT(f_le, "`>"); +  TMP_OPT(f_ge, "`<"); + #undef TMP_OPT +  } +  +  return 0; + } +  +    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)
pike.git/src/operators.c:1793:   }      void init_operators(void)   {    add_efun2("`[]",f_index,    "function(string,int:int)|function(object,string:mixed)|function(array(0=mixed),int:0)|function(mapping(mixed:1=mixed),mixed:1)|function(multiset,mixed:int)|function(string,int,int:string)|function(array(2=mixed),int,int:array(2))|function(program:mixed)",OPT_TRY_OPTIMIZE,0,0);       add_efun2("`->",f_arrow,    "function(array(object|mapping|multiset|array),string:array(mixed))|function(object|mapping|multiset|program,string:mixed)",OPT_TRY_OPTIMIZE,0,0);    -  add_efun2("`==",f_eq,"function(mixed...:int)",OPT_TRY_OPTIMIZE,0,generate_comparison); +  add_efun2("`==",f_eq,"function(mixed...:int)",OPT_TRY_OPTIMIZE,optimize_eq,generate_comparison);    add_efun2("`!=",f_ne,"function(mixed...:int)",OPT_TRY_OPTIMIZE,0,generate_comparison); -  add_efun2("`!",f_not,"function(mixed:int)",OPT_TRY_OPTIMIZE,0,generate_not); +  add_efun2("`!",f_not,"function(mixed:int)",OPT_TRY_OPTIMIZE,optimize_not,generate_not);      #define CMP_TYPE "!function(!object...:mixed)&function(mixed...:int)|function(int|float...:int)|function(string...:int)"    add_efun2("`<", f_lt,CMP_TYPE,OPT_TRY_OPTIMIZE,0,generate_comparison);    add_efun2("`<=",f_le,CMP_TYPE,OPT_TRY_OPTIMIZE,0,generate_comparison);    add_efun2("`>", f_gt,CMP_TYPE,OPT_TRY_OPTIMIZE,0,generate_comparison);    add_efun2("`>=",f_ge,CMP_TYPE,OPT_TRY_OPTIMIZE,0,generate_comparison);       add_efun2("`+",f_add,    "!function(!object...:mixed)&function(mixed...:mixed)|"    "function(int...:int)|"