pike.git
/
src
/
program.c
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/program.c:123:
struct pike_string *compat_lfun_destroy_string; /* NOTE: There is a corresponding list to this one in Tools.AutoDoc.PikeObjects If new lfuns are added it might be beneficial to also add them to that list. */ const char *const lfun_names[] = {
+
#ifdef PIKE_NEW_LFUN_LOOKUP
"__INIT", "create", "_destruct",
-
+
"_sprintf",
+
0,
+
"`+", "`-",
-
+
"`*",
+
"`/",
+
"`%",
"`&", "`|", "`^", "`<<", "`>>",
-
+
"`**",
+
0,
+
+
"``+",
+
"``-",
+
"``&",
+
"``|",
+
"``^",
+
"``<<",
+
"``>>",
+
"``*",
+
"``/",
+
"``%",
+
"``**",
+
0,
+
+
"`~",
+
"`!",
+
"`()",
+
"cast",
+
"__hash",
+
"_sqrt",
+
"_random",
+
"_reverse",
+
0,
+
+
"`==",
+
"`<",
+
"`>",
+
"_equal",
+
"_is_type",
+
0,
+
+
"`[]",
+
"`->",
+
"`[..]",
+
"_search",
+
"_size_object",
+
0,
+
+
"_sizeof",
+
"_indices",
+
"_values",
+
"_types",
+
"_annotations",
+
"_get_iterator",
+
0,
+
+
"`+=",
+
"`[]=",
+
"`->=",
+
"_m_delete",
+
"_m_clear",
+
"_m_add",
+
0,
+
+
"_serialize",
+
"_deserialize",
+
0,
+
+
"next",
+
"index",
+
"value",
+
0,
+
0, /* End marker. */
+
#else
+
"__INIT",
+
"create",
+
"_destruct",
+
"`+",
+
"`-",
+
"`&",
+
"`|",
+
"`^",
+
"`<<",
+
"`>>",
"`*", "`/", "`%", "`~", "`==", "`<", "`>", "__hash", "cast", "`!",
pike.git/src/program.c:182:
"_deserialize", "_size_object", "_random", "`**", "``**", "_sqrt", "_annotations", "_m_clear", "_m_add", "_reverse",
+
#endif
};
-
+
#ifdef PIKE_NEW_LFUN_LOOKUP
+
struct pike_string *lfun_strings[0x100];
+
#else
struct pike_string *lfun_strings[NELEM(lfun_names)];
-
+
#endif
static struct mapping *lfun_ids; /* mapping(string:type) */ static struct mapping *lfun_types; static const char *const raw_lfun_types[] = {
-
+
#ifdef PIKE_NEW_LFUN_LOOKUP
tFuncV(tNone,tVoid,tVoid), /* "__INIT", */ tFuncV(tNone,tZero,tVoid), /* "create", */ tFuncV(tOr(tVoid,tInt),tVoid,tInt01), /* "_destruct", */
-
+
tFuncV(tInt tOr(tMap(tStr,tInt),tVoid),tVoid,tStr), /* "_sprintf", */
+
0,
+
tFuncV(tZero,tZero,tMix), /* "`+", */ tFunc(tOr(tVoid,tZero),tMix), /* "`-", */
-
+
tFuncV(tNone,tZero,tMix), /* "`*", */
+
tFuncV(tNone,tZero,tMix), /* "`/", */
+
tFuncV(tNone,tZero,tMix), /* "`%", */
tFuncV(tNone,tZero,tMix), /* "`&", */ tFuncV(tNone,tZero,tMix), /* "`|", */ tFuncV(tNone,tZero,tMix), /* "`^", */ tFuncV(tZero,tVoid,tMix), /* "`<<", */ tFuncV(tZero,tVoid,tMix), /* "`>>", */
-
+
tFuncV(tOr3(tInt,tFloat,tObj),tVoid,tOr3(tObj,tInt,tFloat)), /* "pow", */
+
0,
+
+
tFuncV(tZero,tZero,tMix), /* "``+", */
+
tFuncV(tZero,tVoid,tMix), /* "``-", */
+
tFuncV(tNone,tZero,tMix), /* "``*", */
+
tFuncV(tNone,tZero,tMix), /* "``/", */
+
tFuncV(tNone,tZero,tMix), /* "``%", */
+
tFuncV(tNone,tZero,tMix), /* "``&", */
+
tFuncV(tNone,tZero,tMix), /* "``|", */
+
tFuncV(tNone,tZero,tMix), /* "``^", */
+
tFuncV(tZero,tVoid,tMix), /* "``<<", */
+
tFuncV(tZero,tVoid,tMix), /* "``>>", */
+
tFuncV(tOr3(tInt,tFloat,tObj),tVoid,tOr3(tObj,tInt,tFloat)), /* "rpow", */
+
0,
+
+
tFuncV(tNone,tVoid,tMix), /* "`~", */
+
tFuncV(tNone,tVoid,tInt), /* "`!", */
+
tFuncV(tNone,tZero,tMix), /* "`()", */
+
tFuncV(tString,tVoid,tMix), /* "cast", */
+
tFuncV(tNone,tVoid,tInt), /* "__hash", */
+
tFunc(tVoid,tMix), /* "_sqrt", */
+
tFuncV(tFunction tFunction, tVoid, tMix), /* "_random", */
+
tFuncV(tNone, tOr(tZero, tVoid), tVoid), /* "_reverse", */
+
0,
+
+
tFuncV(tMix,tVoid,tInt), /* "`==", */
+
tFuncV(tMix,tVoid,tInt), /* "`<", */
+
tFuncV(tMix,tVoid,tInt), /* "`>", */
+
tFuncV(tMix,tVoid,tInt), /* "_equal", */
+
tFuncV(tStr,tVoid,tInt), /* "_is_type", */
+
0,
+
+
tFuncV(tZero,tVoid,tMix), /* "`[]", */
+
tFuncV(tStr tOr(tVoid,tObj) tOr(tVoid,tInt),tVoid,tMix), /* "`->", */
+
tFuncV(tZero tRangeBound tZero tRangeBound, tVoid, tMix), /* "`[..]" */
+
tFuncV(tZero tOr(tZero, tVoid), tZero, tMix), /* "_search", */
+
tFuncV(tNone, tVoid, tInt), /* "_size_object", */
+
0,
+
+
tFuncV(tOr(tVoid,tObj) tOr(tVoid,tInt),tVoid,tInt), /* "_sizeof", */
+
tFuncV(tOr(tVoid,tObj) tOr(tVoid,tInt),tVoid,tArray), /* "_indices", */
+
tFuncV(tOr(tVoid,tObj) tOr(tVoid,tInt),tVoid,tArray), /* "_values", */
+
tFuncV(tNone,tVoid,tArray), /* "_types", */
+
tFuncV(tOr(tVoid,tObj) tOr(tVoid,tInt)
+
tOr(tInt01,tVoid),tVoid,tArray), /* "_annotations", */
+
tFuncV(tNone,tVoid,tObj), /* "_get_iterator", */
+
0,
+
+
tFuncV(tZero,tZero,tMix), /* "`+=", */
+
tFuncV(tZero tSetvar(0,tZero),tVoid,tVar(0)), /* "`[]=", */
+
tFuncV(tStr tSetvar(0,tZero) tOr(tVoid,tObj) tOr(tVoid,tInt),tVoid,tVar(0)), /* "`->=", */
+
tFuncV(tZero,tVoid,tMix), /* "_m_delete", */
+
tFuncV(tNone, tVoid, tVoid), /* "_m_clear", */
+
tFuncV(tZero, tVoid, tVoid), /* "_m_add", */
+
0,
+
+
tFuncV(tObj tZero, tVoid, tVoid), /* "_serialize", */
+
tFuncV(tObj tZero, tVoid, tVoid), /* "_deserialize", */
+
0,
+
+
tFuncV(tNone, tZero, tMix), /* "next", */
+
tFuncV(tNone, tZero, tMix), /* "index", */
+
tFuncV(tNone, tZero, tMix), /* "value", */
+
0,
+
0, /* End marker. */
+
+
#else
+
tFuncV(tNone,tVoid,tVoid), /* "__INIT", */
+
tFuncV(tNone,tZero,tVoid), /* "create", */
+
tFuncV(tOr(tVoid,tInt),tVoid,tInt01), /* "_destruct", */
+
tFuncV(tZero,tZero,tMix), /* "`+", */
+
tFunc(tOr(tVoid,tZero),tMix), /* "`-", */
+
tFuncV(tNone,tZero,tMix), /* "`&", */
+
tFuncV(tNone,tZero,tMix), /* "`|", */
+
tFuncV(tNone,tZero,tMix), /* "`^", */
+
tFuncV(tZero,tVoid,tMix), /* "`<<", */
+
tFuncV(tZero,tVoid,tMix), /* "`>>", */
tFuncV(tNone,tZero,tMix), /* "`*", */ tFuncV(tNone,tZero,tMix), /* "`/", */ tFuncV(tNone,tZero,tMix), /* "`%", */ tFuncV(tNone,tVoid,tMix), /* "`~", */ tFuncV(tMix,tVoid,tInt), /* "`==", */ tFuncV(tMix,tVoid,tInt), /* "`<", */ tFuncV(tMix,tVoid,tInt), /* "`>", */ tFuncV(tNone,tVoid,tInt), /* "__hash", */ tFuncV(tString,tVoid,tMix), /* "cast", */ tFuncV(tNone,tVoid,tInt), /* "`!", */
pike.git/src/program.c:252:
tFuncV(tNone, tVoid, tInt), /* "_size_object", */ tFuncV(tFunction tFunction, tVoid, tMix), /* "_random", */ tFuncV(tOr3(tInt,tFloat,tObj),tVoid,tOr3(tObj,tInt,tFloat)), /* "pow", */ tFuncV(tOr3(tInt,tFloat,tObj),tVoid,tOr3(tObj,tInt,tFloat)), /* "rpow", */ tFunc(tVoid,tMix), /* "_sqrt", */ tFuncV(tOr(tVoid,tObj) tOr(tVoid,tInt) tOr(tInt01,tVoid),tVoid,tArray), /* "_annotations", */ tFuncV(tNone, tVoid, tVoid), /* "_m_clear", */ tFuncV(tZero, tVoid, tVoid), /* "_m_add", */ tFuncV(tNone, tOr(tZero, tVoid), tVoid), /* "_reverse", */
+
#endif
}; /* These two are not true LFUNs! */ static struct pike_type *lfun_getter_type_string = NULL; static struct pike_type *lfun_setter_type_string = NULL; /*! @namespace lfun:: *! *! Callback functions used to overload various builtin functions. *!
pike.git/src/program.c:3060:
continue; } p->identifier_index[i++] = p->identifier_index[e]; id = probe; } p->num_identifier_index = i; } p->flags |= PROGRAM_FIXED;
+
#ifdef PIKE_NEW_LFUN_LOOKUP
+
{
+
int found = 1; /* Assume __INIT */
+
int n;
+
size_t num_lfuns = 1; /* Assume __INIT */
+
INT16 *lfuns;
+
/* Yes, it is supposed to start at 1 /Hubbe */
-
+
for (n = i = 1; i < (int)NELEM(lfun_names); i++,n++) {
+
if (!lfun_names[i]) {
+
n |= 0xf;
+
found = 0;
+
continue;
+
}
+
if (found) {
+
num_lfuns++;
+
continue;
+
}
+
found = low_find_lfun(p, n) != -1;
+
if (found) {
+
num_lfuns += (n & 0xf) + 1;
+
}
+
}
+
+
lfuns = malloc(sizeof(INT16) * ((NUM_LFUNS >> 4) + num_lfuns + 1));
+
lfuns[0] = (NUM_LFUNS >> 4) + 1; /* Always space for __INIT et al. */
+
for (i = 1; i <= (NUM_LFUNS >> 4); i++) {
+
lfuns[i] = 0;
+
}
+
memset(lfuns + ((NUM_LFUNS >> 4) + 1), 0xff,
+
sizeof(INT16) * num_lfuns); /* -1 */
+
+
/* Copy __INIT from original lfuns. */
+
num_lfuns = (NUM_LFUNS>>4) + 1;
+
lfuns[num_lfuns] = p->lfuns[num_lfuns];
+
num_lfuns++;
+
+
free(p->lfuns);
+
p->lfuns = lfuns;
+
+
/* Yes, it is supposed to start at 1 /Hubbe */
+
for (n = i = 1; i < (int)NELEM(lfun_names); i++,n++) {
+
if (!lfun_names[i]) {
+
n |= 0xf;
+
continue;
+
}
+
found = low_find_lfun(p, n);
+
if (found != -1) {
+
if (!lfuns[n>>4]) {
+
lfuns[n>>4] = num_lfuns;
+
num_lfuns += n & 0x0f;
+
}
+
lfuns[lfuns[n>>4] + (n & 0x0f)] = found;
+
}
+
if (lfuns[n>>4]) {
+
num_lfuns++;
+
}
+
}
+
}
+
#else
+
/* Yes, it is supposed to start at 1 /Hubbe */
for(i=1;i<NUM_LFUNS;i++) { int id = p->lfuns[i] = low_find_lfun(p, i); if (id >= 0) { // LFUNs are used. p->identifier_references[id].id_flags |= ID_USED; } }
-
+
#endif
/* Complain about unused private symbols. */ for (i = 0; i < p->num_identifier_references; i++) { struct reference *ref = p->identifier_references + i; if (ref->id_flags & ID_HIDDEN) continue; if (ref->id_flags & ID_VARIANT) continue; if (ref->inherit_offset != 0) continue; if ((ref->id_flags & (ID_HIDDEN|ID_PRIVATE|ID_USED)) == ID_PRIVATE) { yywarning("%S is private but not used anywhere.",
pike.git/src/program.c:3268:
gc_init_marker(p); p->flags|=PROGRAM_VIRGIN; p->alignment_needed=1; GC_ALLOC(p); p->id=++current_program_id; INIT_PIKE_MEMOBJ(p, T_PROGRAM); DOUBLELINK(first_program, p); ACCURATE_GETTIMEOFDAY(& p->timestamp);
+
+
#ifdef PIKE_NEW_LFUN_LOOKUP
+
p->lfuns = malloc(sizeof(INT16) * ((NUM_LFUNS >> 4) + 1 + 16));
+
memset(p->lfuns, 0x00, sizeof(INT16) * ((NUM_LFUNS >> 4) + 1)); /* 0 */
+
memset(p->lfuns + (NUM_LFUNS >> 4) + 1, 0xff, sizeof(INT16) * 16); /* -1 */
+
p->lfuns[0] = (NUM_LFUNS >> 4) + 1; /* __INIT et al. */
+
#endif
return p; } /** * Start building a new program */ void low_start_new_program(struct program *p, int pass, struct pike_string *name, int flags,
pike.git/src/program.c:3702:
mexec_free((char *)p->NAME); p->NAME=0; \ } #endif /* PIKE_USE_MACHINE_CODE */ #define FOO(NUMTYPE,TYPE,ARGTYPE,NAME) \ if(p->NAME) { \ dmfree((char *)p->NAME); p->NAME=0; \ } #include "program_areas.h" }
+
#ifdef PIKE_NEW_LFUN_LOOKUP
+
if (p->lfuns) {
+
free(p->lfuns);
+
}
+
#endif
+
EXIT_PIKE_MEMOBJ(p); GC_FREE(p); } #ifdef PIKE_DEBUG void dump_program_desc(struct program *p) { int e,d,q; /* fprintf(stderr,"Program '%s':\n",p->name->str); */
pike.git/src/program.c:4077:
indent, "", indent, ""); for (d = 0; d < p->num_strings; d++) { fprintf(stderr, "%*s %4d: [%p]\"%s\"(%"PRINTPTRDIFFT"d characters)\n", indent, "", (int)d, p->strings[d], p->strings[d]->str, p->strings[d]->len); } fprintf(stderr, "\n" "%*sLFUN table:\n" "%*s LFUN Ref# Name\n", indent, "", indent, "");
+
#ifdef PIKE_NEW_LFUN_LOOKUP
+
{
+
int n = 0;
+
for (d = 0; d < (int)NELEM(lfun_names); d++,n++) {
+
if (!lfun_names[d]) {
+
n |= 0xf;
+
continue;
+
}
+
if (QUICK_FIND_LFUN(p, n) != -1) {
+
fprintf(stderr, "%*s 0x%02x: %04d %s\n",
+
indent, "", n, QUICK_FIND_LFUN(p, n), lfun_names[d]);
+
}
+
}
+
}
+
#else
for (d = 0; d < NUM_LFUNS; d++) { if (p->lfuns[d] != -1) { fprintf(stderr, "%*s %4d: %04d %s\n", indent, "", d, p->lfuns[d], lfun_names[d]); } }
-
+
#endif
fprintf(stderr, "\n" "%*sLinenumber table:\n", indent, ""); { INT32 off = 0; INT_TYPE line = 0; char *cnt = p->linenumbers; while (cnt < p->linenumbers + p->num_linenumbers) {
pike.git/src/program.c:4736:
/* Just a prototype. Make sure not to call it. */ e = -1; } }else{ /* Note that we may zap an __INIT that existed in pass 1 here. * This is intentional to avoid having to keep track of whether * __INIT() is just a prototype or not. */ e=-1; }
-
Pike_compiler->new_program->lfuns[LFUN___INIT]=e;
+
#ifdef
PIKE_NEW_LFUN_LOOKUP
+
/* NB: We know that LFUN___INIT is 0! */
+
assert(!LFUN___INIT);
+
Pike_compiler->new_program->lfuns[
Pike_compiler->new_program->lfuns[0]] = e;
+
#else
+
Pike_compiler->new_program->lfuns[
LFUN___INIT]
=
e;
+
#endif
pop_compiler_frame(); /* Pop __INIT local variables */ if(Pike_compiler->num_parse_error > 0) { CDFPRINTF("th(%ld) %p Compilation errors (%d).\n", (long)th_self(), Pike_compiler->new_program, Pike_compiler->num_parse_error); prog=0; }else{
pike.git/src/program.c:9117:
} #endif void init_program(void) { size_t i; struct svalue key; struct svalue val; struct svalue id;
+
#ifdef PIKE_NEW_LFUN_LOOKUP
+
size_t n = 0;
+
#endif
MAKE_CONST_STRING(this_function_string,"this_function"); MAKE_CONST_STRING(this_program_string,"this_program"); MAKE_CONST_STRING(this_string,"this"); MAKE_CONST_STRING(UNDEFINED_string,"UNDEFINED"); MAKE_CONST_STRING(args_string, "__args__"); MAKE_CONST_STRING(parser_system_string, "parser"); MAKE_CONST_STRING(type_check_system_string, "type_check"); MAKE_CONST_STRING(compat_lfun_destroy_string, "destroy"); /* NB: One extra entry needed for lfun::destroy(). */ lfun_ids = allocate_mapping(NUM_LFUNS + 1); lfun_types = allocate_mapping(NUM_LFUNS + 1);
-
+
#ifdef PIKE_NEW_LFUN_LOOKUP
+
for (i=0; i < NELEM(lfun_names); i++,n++) {
+
if (!lfun_names[i]) {
+
n |= 0xf;
+
continue;
+
}
+
lfun_strings[n] =
+
make_shared_static_string(lfun_names[i],
+
strlen(lfun_names[i]), eightbit);
+
+
SET_SVAL(id, T_INT, NUMBER_NUMBER, integer, n);
+
SET_SVAL(key, T_STRING, 0, string, lfun_strings[n]);
+
mapping_insert(lfun_ids, &key, &id);
+
+
SET_SVAL(val, T_TYPE, 0, type, make_pike_type(raw_lfun_types[i]));
+
mapping_insert(lfun_types, &key, &val);
+
+
if (n == LFUN__DESTRUCT) {
+
/* Special case for lfun::destroy(). */
+
SET_SVAL(key, T_STRING, 0, string, compat_lfun_destroy_string);
+
/* FIXME: Adjust the type to be __deprecated__? */
+
mapping_insert(lfun_types, &key, &val);
+
free_type(val.u.type);
+
+
SET_SVAL(id, T_INT, NUMBER_NUMBER, integer, n);
+
mapping_insert(lfun_ids, &key, &id);
+
} else {
+
free_type(val.u.type);
+
}
+
}
+
#else
for (i=0; i < NELEM(lfun_names); i++) { lfun_strings[i] = make_shared_static_string(lfun_names[i], strlen(lfun_names[i]), eightbit); SET_SVAL(id, T_INT, NUMBER_NUMBER, integer, i); SET_SVAL(key, T_STRING, 0, string, lfun_strings[i]); mapping_insert(lfun_ids, &key, &id); SET_SVAL(val, T_TYPE, 0, type, make_pike_type(raw_lfun_types[i])); mapping_insert(lfun_types, &key, &val);
pike.git/src/program.c:9155:
/* FIXME: Adjust the type to be __deprecated__? */ mapping_insert(lfun_types, &key, &val); free_type(val.u.type); SET_SVAL(id, T_INT, NUMBER_NUMBER, integer, i); mapping_insert(lfun_ids, &key, &id); } else { free_type(val.u.type); } }
+
#endif
lfun_getter_type_string = make_pike_type(tFuncV(tNone, tVoid, tMix)); lfun_setter_type_string = make_pike_type(tFuncV(tZero, tVoid, tVoid)); low_init_pike_compiler(); enter_compiler(NULL, 0); exit_compiler(); } void cleanup_program(void) { size_t e; free_type(lfun_setter_type_string); free_type(lfun_getter_type_string); free_mapping(lfun_types); free_mapping(lfun_ids);
-
+
#ifdef PIKE_NEW_LFUN_LOOKUP
+
for (e=0; e < NELEM(lfun_strings); e++) {
+
if (!lfun_strings[e]) continue;
+
free_string(lfun_strings[e]);
+
}
+
#else
for (e=0; e < NELEM(lfun_names); e++) { free_string(lfun_strings[e]); }
-
+
#endif
#ifdef FIND_FUNCTION_HASHSIZE for(e=0;e<FIND_FUNCTION_HASHSIZE;e++) { if(cache[e].name) { free_string(cache[e].name); cache[e].name=0; } } #endif