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.11 1997/03/11 23:32:32 grubba Exp $"); + RCSID("$Id: operators.c,v 1.12 1997/03/14 04:37:17 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 "memory.h"
pike.git/src/operators.c:504:    s->str[i] = sp[-2].u.string->str[i] & sp[-1].u.string->str[i];    pop_n_elems(2);    push_string(end_shared_string(s));    return;    }    default:    error("Bitwise and on illegal type.\n");    }   }    + /* This function is used to speed up or/xor/and on +  * arrays multisets and mappings. This is done by +  * calling the operator for each pair of arguments +  * first, then recursively doing the same on the +  * results until only one value remains. +  */ + static void speedup(INT32 args, void (*func)(void)) + { +  switch(sp[-args].type) +  { +  case T_MAPPING: +  case T_ARRAY: +  case T_MULTISET: +  { +  int e=-1; +  while(args > 1) +  { +  struct svalue tmp; +  func(); +  args--; +  e++; +  if(e - args >= -1) +  { +  e=0; +  }else{ +  tmp=sp[e-args]; +  sp[e-args]=sp[-1]; +  sp[-1]=tmp; +  } +  } +  return; +  } +  +  default: +  while(--args > 0) func(); +  } + } +    void f_and(INT32 args)   {    switch(args)    {    case 0: error("Too few arguments to `&\n");    case 1: return;    case 2: o_and(); return;    default:    if(sp[-args].type == T_OBJECT)    {    CALL_OPERATOR(LFUN_AND, args);    }else{ -  while(--args > 0) o_and(); +  speedup(args, o_and);    }    }   }      static int generate_and(node *n)   {    switch(count_args(CDR(n)))    {    case 1:    do_docode(CDR(n),0);
pike.git/src/operators.c:616:    switch(args)    {    case 0: error("Too few arguments to `|\n");    case 1: return;    case 2: o_or(); return;    default:    if(sp[-args].type==T_OBJECT)    {    CALL_OPERATOR(LFUN_OR, args);    } else { -  while(--args > 0) o_or(); +  speedup(args, o_or);    }    }   }      static int generate_or(node *n)   {    switch(count_args(CDR(n)))    {    case 1:    do_docode(CDR(n),0);
pike.git/src/operators.c:717:    switch(args)    {    case 0: error("Too few arguments to `^\n");    case 1: return;    case 2: o_xor(); return;    default:    if(sp[-args].type==T_OBJECT)    {    CALL_OPERATOR(LFUN_XOR, args);    } else { -  while(--args > 0) o_xor(); +  speedup(args, o_xor);    }    }   }      static int generate_xor(node *n)   {    switch(count_args(CDR(n)))    {    case 1:    do_docode(CDR(n),0);