pike.git/
src/
builtin_functions.c
Branch:
Tag:
Non-build tags
All tags
No tags
2000-04-08
2000-04-08 14:51:07 by Henrik Grubbström (Grubba) <grubba@grubba.org>
3a58ed1960826f6581e9dcf5fd5ea04f33c4d1a3 (
54
lines) (+
47
/-
7
)
[
Show
|
Annotate
]
Branch:
7.9
map() and filter() now get correct optimization information.
Rev: src/builtin_functions.c:1.251
5:
\*/ /**/ #include "global.h"
-
RCSID("$Id: builtin_functions.c,v 1.
250
2000/04/
07
19
:
07
:
55
grubba Exp $");
+
RCSID("$Id: builtin_functions.c,v 1.
251
2000/04/
08
14
:
51:
07 grubba Exp $");
#include "interpret.h" #include "svalue.h" #include "pike_macros.h"
5227:
} }
+
/* map(), map_array() and filter() inherit sideeffects from their
+
* second argument.
+
*/
+
static node *fix_map_node_info(node *n)
+
{
+
int argno;
+
node **cb_;
+
int node_info = 0;
+
+
/* Note: argument 2 has argno 1. */
+
for (argno = 1; cb_ = my_get_arg(&_CDR(n), argno); argno++) {
+
node *cb = *cb_;
+
+
if ((cb->token == F_CONSTANT) &&
+
(cb->u.sval.type == T_FUNCTION) &&
+
(cb->u.sval.subtype == FUNCTION_BUILTIN)) {
+
if (cb->u.sval.u.efun->optimize == fix_map_node_info) {
+
/* map(), map_array() or filter(). */
+
continue;
+
}
+
node_info = cb->u.sval.u.efun->flags & OPT_SIDE_EFFECT;
+
} else {
+
/* Could be anything. Assume worst case. */
+
node_info = OPT_SIDE_EFFECT;
+
}
+
break;
+
}
+
+
if (!cb_) {
+
yyerror("Too few arguments to map() or filter()!\n");
+
node_info = OPT_SIDE_EFFECT;
+
}
+
+
n->node_info |= node_info;
+
n->tree_info |= node_info;
+
+
return 0; /* continue optimization */
+
}
+
void f_enumerate(INT32 args) { struct array *d;
6038:
tFuncV(IN tInt0, tMix, OUTMIX), \ tFuncV(IN, tVoid, OUTMIX) )
-
ADD_
EFUN
("map",f_map,
-
tOr7(
tMapStuff(tArr(tSetvar(1,tMix)),tVar(1),
+
ADD_
EFUN2
("map",
f_map,
+
tOr7(tMapStuff(tArr(tSetvar(1,tMix)),tVar(1),
tArr(tVar(2)), tArr(tInt01), tArr(tObj),
6079:
tFuncV(tArr(tStringIndicable) tString,tMix,tMix), tFuncV(tObj,tMix,tMix) ),
-
OPT_TRY_OPTIMIZE);
+
OPT_TRY_OPTIMIZE
, fix_map_node_info, 0
);
-
ADD_
EFUN
("filter",f_filter,
-
tOr3(
tFuncV(tSetvar(1,tOr4(tArray,tMapping,tMultiset,tString)),
+
ADD_
EFUN2
("filter",
f_filter,
+
tOr3(tFuncV(tSetvar(1,tOr4(tArray,tMapping,tMultiset,tString)),
tMixed,tVar(1)), tFuncV(tOr(tProgram,tFunction),tMixed,tMap(tString,tMix)), tFuncV(tObj,tMix,tMix) ) ,
-
OPT_TRY_OPTIMIZE);
+
OPT_TRY_OPTIMIZE
, fix_map_node_info, 0
);
ADD_EFUN("enumerate",f_enumerate, tOr8(tFunc(tIntPos,tArr(tInt)),