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.
88
2000/04/
08
15
:
29
:
02
grubba
Exp $");
+
RCSID("$Id: operators.c,v 1.
89
2000/04/
12
11
:
14
:
50
mirar
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:645:
sp[-3]=sp[-1]; sp--; dmalloc_touch_svalue(sp); pop_stack(); return 1; } return 0; }
+
struct mapping *merge_mapping_array_ordered(struct mapping *a,
+
struct array *b, INT32 op);
+
struct mapping *merge_mapping_array_unordered(struct mapping *a,
+
struct array *b, INT32 op);
+
void o_subtract(void) { if (sp[-2].type != sp[-1].type && !float_promote()) { if(call_lfun(LFUN_SUBTRACT, LFUN_RSUBTRACT)) return;
-
+
+
if (sp[-2].type==T_MAPPING)
+
switch (sp[-1].type)
+
{
+
case T_ARRAY:
+
{
+
struct mapping *m;
+
+
m=merge_mapping_array_unordered(sp[-2].u.mapping,
+
sp[-1].u.array,
+
PIKE_ARRAY_OP_SUB);
+
pop_n_elems(2);
+
push_mapping(m);
+
return;
+
}
+
case T_MULTISET:
+
{
+
struct mapping *m;
+
+
m=merge_mapping_array_ordered(sp[-2].u.mapping,
+
sp[-1].u.multiset->ind,
+
PIKE_ARRAY_OP_SUB);
+
pop_n_elems(2);
+
push_mapping(m);
+
return;
+
}
+
}
+
bad_arg_error("`-", sp-2, 2, 2, get_name_of_type(sp[-2].type), sp-1, "Subtract on different types.\n"); } switch(sp[-2].type) { case T_OBJECT: CALL_OPERATOR(LFUN_SUBTRACT,2); break;
pike.git/src/operators.c:775:
emit2(F_SUBTRACT); return 1; } return 0; } void o_and(void) { if(sp[-1].type != sp[-2].type) {
-
if(call_lfun(LFUN_AND, LFUN_RAND))
{
+
if(call_lfun(LFUN_AND, LFUN_RAND))
return;
-
}
else if (((sp[-1].type == T_TYPE) || (sp[-1].type == T_PROGRAM) ||
+
else if (((sp[-1].type == T_TYPE) || (sp[-1].type == T_PROGRAM) ||
(sp[-1].type == T_FUNCTION)) && ((sp[-2].type == T_TYPE) || (sp[-2].type == T_PROGRAM) ||
-
(sp[-2].type == T_FUNCTION))) {
-
if (sp[-2].type != T_TYPE) {
+
(sp[-2].type == T_FUNCTION)))
+
{
+
if (sp[-2].type != T_TYPE)
+
{
struct program *p = program_from_svalue(sp - 2); if (!p) { int args = 2; SIMPLE_BAD_ARG_ERROR("`&", 1, "type"); } type_stack_mark(); push_type_int(p->id); push_type(0); push_type(T_OBJECT); free_svalue(sp - 2); sp[-2].u.string = pop_unfinished_type(); sp[-2].type = T_TYPE; }
-
if (sp[-1].type != T_TYPE) {
+
if (sp[-1].type != T_TYPE)
+
{
struct program *p = program_from_svalue(sp - 1);
-
if (!p) {
+
if (!p)
+
{
int args = 2; SIMPLE_BAD_ARG_ERROR("`&", 2, "type"); } type_stack_mark(); push_type_int(p->id); push_type(0); push_type(T_OBJECT); free_svalue(sp - 1); sp[-1].u.string = pop_unfinished_type(); sp[-1].type = T_TYPE; }
-
} else {
+
}
+
else
if (sp[-2].type==T_MAPPING)
+
switch (sp[-1].type)
+
{
+
case T_ARRAY:
+
{
+
struct mapping *m;
+
+
m=merge_mapping_array_unordered(sp[-2].u.mapping,
+
sp[-1].u.array,
+
PIKE_ARRAY_OP_AND);
+
pop_n_elems(2);
+
push_mapping(m);
+
return;
+
}
+
case T_MULTISET:
+
{
+
struct mapping *m;
+
+
m=merge_mapping_array_ordered(sp[-2].u.mapping,
+
sp[-1].u.multiset->ind,
+
PIKE_ARRAY_OP_AND);
+
pop_n_elems(2);
+
push_mapping(m);
+
return;
+
}
+
}
+
else
+
{
int args = 2; SIMPLE_BAD_ARG_ERROR("`&", 2, get_name_of_type(sp[-2].type)); } } switch(sp[-2].type) { case T_OBJECT: CALL_OPERATOR(LFUN_AND,2); break;
pike.git/src/operators.c:2507:
tOr(tVar(0),tVar(1)))), OPT_TRY_OPTIMIZE,optimize_binary,generate_sum); ADD_EFUN2("`-",f_minus, 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)), tFuncV(tArr(tSetvar(0,tMix)),tArray,tArr(tVar(0))), tFuncV(tMap(tSetvar(1,tMix),tSetvar(2,tMix)),
-
tMapping,tMap(tVar(1),tVar(2))),
+
tOr3(
tMapping,
tArray,tMultiset),
+
tMap(tVar(1),tVar(2))),
tFunc(tSet(tSetvar(3,tMix)) tMultiset,tSet(tVar(3))), tFuncV(tStr,tStr,tStr)), OPT_TRY_OPTIMIZE,0,generate_minus);
-
+
/*
+
+
object & mixed -> mixed
+
mixed & object -> mixed
+
+
int & int -> int
+
array & array -> array
+
multiset & multiset -> multiset
+
mapping & mapping -> mapping
+
string & string -> string
+
type|program & type|program -> type|program
+
+
mapping & array -> mapping
+
array & mapping -> mapping
+
mapping & multiset -> mapping
+
multiset & mapping -> mapping
+
+
*/
+
+
+
#define F_AND_TYPE(Z) \
+
tOr(tFunc(tSetvar(0,Z),tVar(0)), \
+
tIfnot(tFunc(Z,tMix), \
+
tFuncV(tSetvar(1,Z),tSetvar(2,Z), \
+
tOr(tVar(1),tVar(2)))))
+
+
ADD_EFUN2("`&",f_and,
-
tOr8
(tFunc(tSetvar(0,tMix),tVar(0)),
+
tOr4
(
+
tFunc(tSetvar(0,tMix),tVar(0)),
+
tOr(tFuncV(tMix tObj,tMix,tMix), tFuncV(tObj tMix,tMix,tMix)),
-
tFuncV(tInt tInt,tInt,tInt),
-
tOr
(
tFunc(tMapping
tSetvar
(
1,tMapping
),
tVar(1)),
-
tFuncV
(
tMapping tMapping tSetvar(2,tMapping
),
-
tSetvar
(
3,
tMapping),
tOr(tVar(2),tVar(3)))),
-
tOr(tFunc(tMultiset
tSetvar
(
4,
tMultiset),
tVar(4)),
-
tFuncV
(
tMultiset tMultiset tSetvar(5,tMultiset
),
-
tSetvar
(
6,tMultiset),
tOr(
tVar(5)
,
tVar(6
)))
)
,
-
tOr
(
tFunc
(
tArray tSetvar(7
,tArray),
tVar(7
)
)
,
-
tFuncV(
tArray tArray tSetvar(8
,
tArray),
-
tSetvar
(
9,
tArray
)
,
tOr(tVar(8)
,
tVar
(
9
))
))
,
-
tFuncV
(
tString
tString,tString,tString
)
,
-
tFuncV(tOr(tType,tPrg)
tOr(tType,tPrg),tOr(tType,tPrg),tType)),
+
+
tOr6
(
F_AND_TYPE
(
tInt
),
+
F_AND_TYPE
(
tArray
),
+
F_AND_TYPE
(tMapping),
+
F_AND_TYPE
(tMultiset),
+
F_AND_TYPE
(
tString
),
+
F_AND_TYPE
(tOr(
tType
,
tPrg
))
),
+
+
tIfnot(tFuncV(tNone,
tOr(tArray,
tMultiset
),
tMix
),
+
tFuncV(
tNone
,
+
tOr3
(tArray,
tMultiset,tSetvar
(
4
,
tMapping
)),
+
tVar
(
4))
)
+
),
+
OPT_TRY_OPTIMIZE,optimize_binary,generate_and); #define LOG_TYPE \ tOr7(tOr(tFuncV(tMix tObj,tMix,tMix), \ tFuncV(tObj,tMix,tMix)), \ tFuncV(tInt,tInt,tInt), \ tFuncV(tSetvar(1,tMapping),tSetvar(2,tMapping),tOr(tVar(1),tVar(2))), \ tFuncV(tSetvar(3,tMultiset),tSetvar(4,tMultiset),tOr(tVar(3),tVar(4))), \ tFuncV(tSetvar(5,tArray),tSetvar(6,tArray),tOr(tVar(5),tVar(6))), \ tFuncV(tString,tString,tString), \