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.7 1997/02/11 07:11:51 hubbe Exp $"); + RCSID("$Id: operators.c,v 1.8 1997/02/13 02:38:58 nisse 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:484:    }       case T_ARRAY:    {    struct array *a;    a=and_arrays(sp[-2].u.array, sp[-1].u.array);    pop_n_elems(2);    push_array(a);    return;    } +  case T_STRING: +  { +  struct pike_string *s; +  INT32 len, i; +  +  len = sp[-2].u.string->len; +  if (len != sp[-1].u.string->len) +  error("Bitwise AND on strings of different lengths.\n"); +  s = begin_shared_string(len); +  for (i=0; i<len; i++) +  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");    }   }      void f_and(INT32 args)   {    switch(args)    {    case 0: error("Too few arguments to `&\n");
pike.git/src/operators.c:568:       case T_ARRAY:    {    struct array *a;    a=merge_array_without_order(sp[-2].u.array, sp[-1].u.array, OP_OR);    pop_n_elems(2);    push_array(a);    return;    }    +  case T_STRING: +  { +  struct pike_string *s; +  INT32 len, i; +  +  len = sp[-2].u.string->len; +  if (len != sp[-1].u.string->len) +  error("Bitwise OR on strings of different lengths.\n"); +  s = begin_shared_string(len); +  for (i=0; i<len; i++) +  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 or on illegal type.\n");    }   }      void f_or(INT32 args)   {    switch(args)    {    case 0: error("Too few arguments to `|\n");
pike.git/src/operators.c:652:    }       case T_ARRAY:    {    struct array *a;    a=merge_array_without_order(sp[-2].u.array, sp[-1].u.array, OP_XOR);    pop_n_elems(2);    push_array(a);    return;    } +  +  case T_STRING: +  { +  struct pike_string *s; +  INT32 len, i; +  +  len = sp[-2].u.string->len; +  if (len != sp[-1].u.string->len) +  error("Bitwise XOR on strings of different lengths.\n"); +  s = begin_shared_string(len); +  for (i=0; i<len; i++) +  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 xor on illegal type.\n");    }   }      void f_xor(INT32 args)   {    switch(args)    {    case 0: error("Too few arguments to `^\n");
pike.git/src/operators.c:1022:    break;       case T_INT:    sp[-1].u.integer = ~ sp[-1].u.integer;    break;       case T_FLOAT:    sp[-1].u.float_number = -1.0 - sp[-1].u.float_number;    break;    +  case T_STRING: +  { +  struct pike_string *s; +  INT32 len, i; +  +  len = sp[-1].u.string->len; +  s = begin_shared_string(len); +  for (i=0; i<len; i++) +  s->str[i] = ~ sp[-1].u.string->str[i]; +  pop_n_elems(1); +  push_string(end_shared_string(s)); +  break; +  } +     default:    error("Bad argument to ~\n");    }   }      void f_compl(INT32 args)   {    if(args != 1) error("Bad number of args to `~\n");    o_compl();   }
pike.git/src/operators.c:1169:   #define CMP_TYPE "function(object,mixed:int)|function(mixed,object:int)|function(int|float,int|float:int)|function(string,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...:mixed)|function(int...:int)|!function(int...:mixed)&function(int|float...:float)|!function(int|float...:mixed)&function(string|int|float...:string)|function(array...:array)|function(mapping...:mapping)|function(multiset...:multiset)",OPT_TRY_OPTIMIZE,optimize_binary,generate_sum);       add_efun2("`-",f_minus,"function(object,mixed...:mixed)|function(int:int)|function(float:float)|function(array,array:array)|function(mapping,mapping:mapping)|function(multiset,multiset:multiset)|function(float|int,float:float)|function(float,int:float)|function(int,int:int)|function(string,string:string)",OPT_TRY_OPTIMIZE,0,generate_minus);    - #define LOG_TYPE "function(object,mixed...:mixed)|function(int...:int)|function(mapping...:mapping)|function(multiset...:multiset)|function(array...:array)" + #define LOG_TYPE "function(object,mixed...:mixed)|function(int...:int)|function(mapping...:mapping)|function(multiset...:multiset)|function(array...:array)|function(string...:string)"       add_efun2("`&",f_and,LOG_TYPE,OPT_TRY_OPTIMIZE,optimize_binary,generate_and);       add_efun2("`|",f_or,LOG_TYPE,OPT_TRY_OPTIMIZE,optimize_binary,generate_or);       add_efun2("`^",f_xor,LOG_TYPE,OPT_TRY_OPTIMIZE,optimize_binary,generate_xor);         #define SHIFT_TYPE "function(object,mixed:mixed)|function(int,int:int)"       add_efun2("`<<",f_lsh,SHIFT_TYPE,OPT_TRY_OPTIMIZE,0,generate_lsh);    add_efun2("`>>",f_rsh,SHIFT_TYPE,OPT_TRY_OPTIMIZE,0,generate_rsh);       add_efun2("`*",f_multiply,"function(object,mixed...:mixed)|function(int...:int)|!function(int...:mixed)&function(float|int...:float)|function(string*,string:string)",OPT_TRY_OPTIMIZE,optimize_binary,generate_multiply);       add_efun2("`/",f_divide,"function(object,mixed:mixed)|function(int,int:int)|function(float|int,float:float)|function(float,int:float)|function(string,string:string*)",OPT_TRY_OPTIMIZE,0,generate_divide);       add_efun2("`%",f_mod,"function(object,mixed:mixed)|function(int,int:int)|!function(int,int:mixed)&function(int|float,int|float:float)",OPT_TRY_OPTIMIZE,0,generate_mod);    -  add_efun2("`~",f_compl,"function(object:mixed)|function(int:int)|function(float:float)",OPT_TRY_OPTIMIZE,0,generate_compl); +  add_efun2("`~",f_compl,"function(object:mixed)|function(int:int)|function(float:float)|function(string:string)",OPT_TRY_OPTIMIZE,0,generate_compl);    add_efun2("sizeof", f_sizeof, "function(string|multiset|array|mapping|object:int)",0,0,generate_sizeof);   }