pike.git
/
src
/
operators.c
version
»
Context lines:
10
20
40
80
file
none
3
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 "global.h" #include <math.h>
-
RCSID("$Id: operators.c,v 1.
72
1999/12/
11
19:
28
:
43
grubba Exp $");
+
RCSID("$Id: operators.c,v 1.
73
1999/12/
13
19:
58
:
44
grubba 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:800:
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_TYPE:
+
{
+
struct pike_string *t;
+
t = and_pike_types(sp[-2].u.string, sp[-1].u.string);
+
pop_n_elems(2);
+
push_string(t);
+
sp[-1].type = T_STRING;
+
return;
+
}
+
#define STRING_BITOP(OP,STROP) \ case T_STRING: \ { \ struct pike_string *s; \ INT32 len, i; \ \ len = sp[-2].u.string->len; \ if (len != sp[-1].u.string->len) \ PIKE_ERROR("`" #OP, "Bitwise "STROP \ " on strings of different lengths.\n", sp, 2); \
pike.git/src/operators.c:988:
case T_ARRAY: { struct array *a; a=merge_array_with_order(sp[-2].u.array, sp[-1].u.array, PIKE_ARRAY_OP_OR); pop_n_elems(2); push_array(a); return; }
+
case T_TYPE:
+
{
+
struct pike_string *t;
+
t = or_pike_types(sp[-2].u.string, sp[-1].u.string, 0);
+
pop_n_elems(2);
+
push_string(t);
+
sp[-1].type = T_TYPE;
+
return;
+
}
+
STRING_BITOP(|,"OR") default: PIKE_ERROR("`|", "Bitwise or on illegal type.\n", sp, 2); } } void f_or(INT32 args) { switch(args)
pike.git/src/operators.c:1081:
case T_ARRAY: { struct array *a; a=merge_array_with_order(sp[-2].u.array, sp[-1].u.array, PIKE_ARRAY_OP_XOR); pop_n_elems(2); push_array(a); return; }
+
case T_TYPE:
+
{
+
/* a ^ b == (a&!b)|(!a&b) */
+
struct pike_string *a;
+
struct pike_string *b;
+
copy_shared_string(a, sp[-2].u.string);
+
copy_shared_string(b, sp[-1].u.string);
+
o_not(); /* !b */
+
o_and(); /* a&!b */
+
push_string(a);
+
sp[-1].type = T_TYPE;
+
o_not(); /* !a */
+
push_string(b);
+
sp[-1].type = T_TYPE;
+
o_and(); /* !a&b */
+
o_or(); /* (a&!b)|(!a&b) */
+
return;
+
}
+
STRING_BITOP(^,"XOR") default: PIKE_ERROR("`^", "Bitwise XOR on illegal type.\n", sp, 2); } } void f_xor(INT32 args) { switch(args)
pike.git/src/operators.c:1780:
if(IS_ZERO(sp-1)) { pop_stack(); push_int(1); }else{ pop_stack(); push_int(0); } break;
+
case T_TYPE:
+
type_stack_mark();
+
push_unfinished_type(sp[-1].u.string);
+
push_type(T_NOT);
+
pop_stack();
+
push_string(pop_unfinished_type());
+
sp[-1].type = T_TYPE;
+
break;
+
default: free_svalue(sp-1); sp[-1].type=T_INT; sp[-1].u.integer=0; } } void f_not(INT32 args) { if(args != 1) {
pike.git/src/operators.c:2153:
tFunc(tSet(tSetvar(4,tMix)) tVar(4) tSetvar(5,tMix), tVar(5))), 0); /* OPT_ASSIGNMENT|OPT_TRY_OPTIMIZE); ? */ ADD_EFUN("`->=", f_arrow_assign, tOr3(tFunc(tArr(tOr4(tArray,tObj,tMultiset,tMapping)) tStr tSetvar(0,tMix), tVar(0)), tFunc(tOr(tObj, tMultiset) tStr tSetvar(1,tMix), tVar(1)), tFunc(tMap(tMix, tSetvar(2,tMix)) tStr tVar(2), tVar(2))), 0); /* OPT_ASSIGNMENT|OPT_TRY_OPTIMIZE); ? */ /* function(mixed...:int) */
-
ADD_EFUN2("`==",f_eq,tFuncV(tNone,tMix,
tInt
),OPT_TRY_OPTIMIZE,optimize_eq,generate_comparison);
+
ADD_EFUN2("`==",f_eq,tFuncV(tNone,tMix,
tInt01
),OPT_TRY_OPTIMIZE,optimize_eq,generate_comparison);
/* function(mixed...:int) */
-
ADD_EFUN2("`!=",f_ne,tFuncV(tNone,tMix,
tInt
),OPT_TRY_OPTIMIZE,0,generate_comparison);
+
ADD_EFUN2("`!=",f_ne,tFuncV(tNone,tMix,
tInt01
),OPT_TRY_OPTIMIZE,0,generate_comparison);
/* function(mixed:int) */
-
add_efun2("`!",f_not,"function(
mixed
:int(0..1))",OPT_TRY_OPTIMIZE,optimize_not,generate_not);
+
add_efun2("`!",f_not,"function(
!type
:int(0..1))
|function(type:type)
",OPT_TRY_OPTIMIZE,optimize_not,generate_not);
-
#define CMP_TYPE "!function(!(object|mixed)...:mixed)&function(mixed...:int(0..1))|function(int|float...:int(0..1))|function(string...:int(0..1))"
+
#define CMP_TYPE "!function(!(object|mixed)...:mixed)&function(mixed...:int(0..1))|function(int|float...:int(0..1))|function(string...:int(0..1))
|function(type,type,type...:int(0..1))
"
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, tOr7(tIfnot(tFuncV(tNone,tNot(tOr(tObj,tMix)),tMix),tFunction), tFuncV(tInt,tInt,tInt), tIfnot(tFuncV(tInt,tInt,tMix), tFuncV(tOr(tInt,tFlt),tOr(tInt,tFlt),tFlt)),
pike.git/src/operators.c:2193:
tFuncV(tInt,tInt,tInt), tIfnot(tFuncV(tInt,tInt,tMix), tFuncV(tOr(tInt,tFlt),tOr(tInt,tFlt),tFlt)), tFuncV(tArr(tSetvar(0,tMix)),tArray,tArr(tVar(0))), tFuncV(tMap(tSetvar(1,tMix),tSetvar(2,tMix)), tMapping,tMap(tVar(1),tVar(2))), tFunc(tSet(tSetvar(3,tMix)) tMultiset,tSet(tVar(3))), tFuncV(tStr,tStr,tStr)), OPT_TRY_OPTIMIZE,0,generate_minus);
-
#define LOG_TYPE "function(mixed,object...:mixed)|function(object,mixed...:mixed)|function(int...:int)|function(mapping(0=mixed:1=mixed)...:mapping(0:1))|function(multiset(2=mixed)...:multiset(2))|function(array(3=mixed)...:array(3))|function(string...:string)"
+
#define LOG_TYPE "function(mixed,object...:mixed)|function(object,mixed...:mixed)|function(int...:int)|function(mapping(0=mixed:1=mixed)...:mapping(0:1))|function(multiset(2=mixed)...:multiset(2))|function(array(3=mixed)...:array(3))|function(string...:string)
|function(type,type...:type)
"
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(mixed,object:mixed)|function(int,int:int)" add_efun2("`<<",f_lsh,SHIFT_TYPE,OPT_TRY_OPTIMIZE,0,generate_lsh);