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.
57
1999/08/16
18
:
35
:
22
hubbe
Exp $");
+
RCSID("$Id: operators.c,v 1.
58
1999/08/16
20
:
43
:
07
mast
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:1913:
case 2: if(sp[-1].type==T_STRING) sp[-1].subtype=1; o_index(); break; default: PIKE_ERROR("`->", "Too many arguments.\n", sp, args); } }
+
void f_index_assign(INT32 args)
+
{
+
switch (args) {
+
case 0:
+
case 1:
+
case 2:
+
PIKE_ERROR("`[]=", "Too few arguments.\n", sp, args);
+
break;
+
case 3:
+
switch (sp[-3].type) {
+
case T_STRING: {
+
INT32 i, c;
+
get_all_args ("`[]=", 2, "%i%i", &i, &c);
+
modify_shared_string (sp[-3].u.string, i, c);
+
break;
+
}
+
case T_OBJECT:
+
object_set_index (sp[-3].u.object, sp-2, sp-1);
+
break;
+
case T_ARRAY:
+
simple_set_index (sp[-3].u.array, sp-2, sp-1);
+
break;
+
case T_MAPPING:
+
mapping_insert (sp[-3].u.mapping, sp-2, sp-1);
+
break;
+
case T_MULTISET:
+
if (svalue_is_true (sp-1))
+
multiset_insert (sp[-3].u.multiset, sp-2);
+
else
+
multiset_delete (sp[-3].u.multiset, sp-2);
+
break;
+
default:
+
SIMPLE_BAD_ARG_ERROR ("`[]=", 1, "string|object|array|mapping|multiset");
+
}
+
assign_svalue (sp-3, sp-1);
+
pop_n_elems (args-1);
+
break;
+
default:
+
PIKE_ERROR("`[]=", "Too many arguments.\n", sp, args);
+
}
+
}
+
void f_sizeof(INT32 args) { INT32 tmp; if(args<1) PIKE_ERROR("sizeof", "Too few arguments.\n", sp, args); tmp=pike_sizeof(sp-args); pop_n_elems(args); push_int(tmp);
pike.git/src/operators.c:2014:
} void init_operators(void) { /* 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) */ ADD_EFUN2("`[]",f_index,tOr7(tFunc(tStr tInt,tInt),tFunc(tObj tStr,tMix),tFunc(tArr(tSetvar(0,tMix)) tInt,tVar(0)),tFunc(tMap(tMix,tSetvar(1,tMix)) tMix,tVar(1)),tFunc(tMultiset tMix,tInt),tFunc(tStr tInt tInt,tStr),tOr(tFunc(tArr(tSetvar(2,tMix)) tInt tInt,tArr(tVar(2))),tFunc(tPrg,tMix))),OPT_TRY_OPTIMIZE,0,0); /* function(array(object|mapping|multiset|array),string:array(mixed))|function(object|mapping|multiset|program,string:mixed) */ ADD_EFUN2("`->",f_arrow,tOr(tFunc(tArr(tOr4(tObj,tMapping,tMultiset,tArray)) tStr,tArr(tMix)),tFunc(tOr4(tObj,tMapping,tMultiset,tPrg) tStr,tMix)),OPT_TRY_OPTIMIZE,0,0);
+
ADD_EFUN("`[]=", f_index_assign,
+
tOr5(tFunc(tStr tInt tInt, tInt),
+
tFunc(tObj tStr tSetvar(0,tMix), tVar(0)),
+
tFunc(tArr(tSetvar(1,tMix)) tInt tVar(1), tVar(1)),
+
tFunc(tMap(tSetvar(2,tMix), tSetvar(3,tMix)) tVar(2) tVar(3), tVar(3)),
+
tFunc(tSet(tSetvar(4,tMix)) tVar(4) tSetvar(5,tMix), tVar(5))),
+
0); /* OPT_ASSIGNMENT|OPT_TRY_OPTIMIZE); ? */
+
/* function(mixed...:int) */ ADD_EFUN2("`==",f_eq,tFuncV(tNone,tMix,tInt),OPT_TRY_OPTIMIZE,optimize_eq,generate_comparison); /* function(mixed...:int) */ ADD_EFUN2("`!=",f_ne,tFuncV(tNone,tMix,tInt),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); #define CMP_TYPE "!function(!object...:mixed)&function(mixed...:int(0..1))|function(int|float...:int(0..1))|function(string...: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);