mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-05-30 08:20:40 +00:00
move to using a hash table for builtin number -> builtin lookup so sparse
ranges can be used efficiently. move the auto-allocated builtins to 0x10000000-0x7fffffff. should be more than enough :) use static builtin tables ("nul" terminated) instead of a series of function calls to add builtins to a vm. should be more memory efficient.
This commit is contained in:
parent
a87fc16d12
commit
acd54afff7
23 changed files with 620 additions and 526 deletions
|
@ -102,16 +102,20 @@ bi_cbuf_clear (progs_t *pr, void *data)
|
|||
{
|
||||
}
|
||||
|
||||
static builtin_t builtins[] = {
|
||||
{"Cbuf_AddText", bi_Cbuf_AddText, -1},
|
||||
{"Cbuf_InsertText", bi_Cbuf_InsertText, -1},
|
||||
{"Cbuf_Execute", bi_Cbuf_Execute, -1},
|
||||
{"Cbuf_Execute_Sets", bi_Cbuf_Execute_Sets, -1},
|
||||
{0}
|
||||
};
|
||||
|
||||
void
|
||||
Cbuf_Progs_Init (progs_t *pr)
|
||||
{
|
||||
cbuf_resources_t *res = calloc (sizeof (cbuf_resources_t), 1);
|
||||
PR_Resources_Register (pr, "Cbuf", res, bi_cbuf_clear);
|
||||
|
||||
PR_AddBuiltin (pr, "Cbuf_AddText", bi_Cbuf_AddText, -1);
|
||||
PR_AddBuiltin (pr, "Cbuf_InsertText", bi_Cbuf_InsertText, -1);
|
||||
PR_AddBuiltin (pr, "Cbuf_Execute", bi_Cbuf_Execute, -1);
|
||||
PR_AddBuiltin (pr, "Cbuf_Execute_Sets", bi_Cbuf_Execute_Sets, -1);
|
||||
PR_RegisterBuiltins (pr, builtins);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -147,6 +147,14 @@ bi_Cmd_Args (progs_t *pr)
|
|||
//Cmd_ExecuteString
|
||||
//Cmd_ForwardToServer
|
||||
|
||||
static builtin_t builtins[] = {
|
||||
{"Cmd_AddCommand", bi_Cmd_AddCommand, -1},
|
||||
{"Cmd_Argc", bi_Cmd_Argc, -1},
|
||||
{"Cmd_Argv", bi_Cmd_Argv, -1},
|
||||
{"Cmd_Args", bi_Cmd_Args, -1},
|
||||
{0}
|
||||
};
|
||||
|
||||
void
|
||||
Cmd_Progs_Init (progs_t *pr)
|
||||
{
|
||||
|
@ -157,8 +165,5 @@ Cmd_Progs_Init (progs_t *pr)
|
|||
|
||||
bi_cmds = Hash_NewTable (1021, bi_cmd_get_key, bi_cmd_free, 0);
|
||||
|
||||
PR_AddBuiltin (pr, "Cmd_AddCommand", bi_Cmd_AddCommand, -1);
|
||||
PR_AddBuiltin (pr, "Cmd_Argc", bi_Cmd_Argc, -1);
|
||||
PR_AddBuiltin (pr, "Cmd_Argv", bi_Cmd_Argv, -1);
|
||||
PR_AddBuiltin (pr, "Cmd_Args", bi_Cmd_Args, -1);
|
||||
PR_RegisterBuiltins (pr, builtins);
|
||||
}
|
||||
|
|
|
@ -56,8 +56,13 @@ bi_Cvar_GetCvarString (progs_t *pr)
|
|||
RETURN_STRING (pr, Cvar_VariableString (varname));
|
||||
}
|
||||
|
||||
static builtin_t builtins[] = {
|
||||
{"Cvar_GetCvarString", bi_Cvar_GetCvarString, -1},
|
||||
{0}
|
||||
};
|
||||
|
||||
void
|
||||
Cvar_Progs_Init (progs_t *pr)
|
||||
{
|
||||
PR_AddBuiltin (pr, "Cvar_GetCvarString", bi_Cvar_GetCvarString, -1);
|
||||
PR_RegisterBuiltins (pr, builtins);
|
||||
}
|
||||
|
|
|
@ -173,8 +173,13 @@ error:
|
|||
R_INT (pr) = 0;
|
||||
}
|
||||
|
||||
static builtin_t builtins[] = {
|
||||
{"File_Open", bi_File_Open, -1},
|
||||
{0}
|
||||
};
|
||||
|
||||
void
|
||||
File_Progs_Init (progs_t *pr)
|
||||
{
|
||||
PR_AddBuiltin (pr, "File_Open", bi_File_Open, -1);
|
||||
PR_RegisterBuiltins (pr, builtins);
|
||||
}
|
||||
|
|
|
@ -176,6 +176,15 @@ bi_GIB_Handle_Get (progs_t *pr)
|
|||
// R_INT (pr) = 0;
|
||||
}
|
||||
|
||||
static builtin_t builtins[] = {
|
||||
{"GIB_Builtin_Add", bi_GIB_Builtin_Add, -1},
|
||||
{"GIB_Return", bi_GIB_Return, -1},
|
||||
{"GIB_Handle_New", bi_GIB_Handle_New, -1},
|
||||
{"GIB_Handle_Free", bi_GIB_Handle_Free, -1},
|
||||
{"GIB_Handle_Get", bi_GIB_Handle_Get, -1},
|
||||
{0}
|
||||
};
|
||||
|
||||
void
|
||||
GIB_Progs_Init (progs_t *pr)
|
||||
{
|
||||
|
@ -184,11 +193,8 @@ GIB_Progs_Init (progs_t *pr)
|
|||
|
||||
PR_Resources_Register (pr, "GIB", res, bi_gib_builtin_clear);
|
||||
|
||||
bi_gib_builtins = Hash_NewTable (1021, bi_gib_builtin_get_key, bi_gib_builtin_free, 0);
|
||||
bi_gib_builtins = Hash_NewTable (1021, bi_gib_builtin_get_key,
|
||||
bi_gib_builtin_free, 0);
|
||||
|
||||
PR_AddBuiltin (pr, "GIB_Builtin_Add", bi_GIB_Builtin_Add, -1);
|
||||
PR_AddBuiltin (pr, "GIB_Return", bi_GIB_Return, -1);
|
||||
PR_AddBuiltin (pr, "GIB_Handle_New", bi_GIB_Handle_New, -1);
|
||||
PR_AddBuiltin (pr, "GIB_Handle_Free", bi_GIB_Handle_Free, -1);
|
||||
PR_AddBuiltin (pr, "GIB_Handle_Get", bi_GIB_Handle_Get, -1);
|
||||
PR_RegisterBuiltins (pr, builtins);
|
||||
}
|
||||
|
|
|
@ -303,6 +303,27 @@ bi_hash_clear (progs_t *pr, void *data)
|
|||
res->tabs = 0;
|
||||
}
|
||||
|
||||
static builtin_t builtins[] = {
|
||||
{"Hash_NewTable", bi_Hash_NewTable, -1},
|
||||
{"Hash_SetHashCompare", bi_Hash_SetHashCompare, -1},
|
||||
{"Hash_DelTable", bi_Hash_DelTable, -1},
|
||||
{"Hash_FlushTable", bi_Hash_FlushTable, -1},
|
||||
{"Hash_Add", bi_Hash_Add, -1},
|
||||
{"Hash_AddElement", bi_Hash_AddElement, -1},
|
||||
{"Hash_Find", bi_Hash_Find, -1},
|
||||
{"Hash_FindElement", bi_Hash_FindElement, -1},
|
||||
{"Hash_FindList", bi_Hash_FindList, -1},
|
||||
{"Hash_FindElementList", bi_Hash_FindElementList, -1},
|
||||
{"Hash_Del", bi_Hash_Del, -1},
|
||||
{"Hash_DelElement", bi_Hash_DelElement, -1},
|
||||
{"Hash_Free", bi_Hash_Free, -1},
|
||||
{"Hash_String", bi_Hash_String, -1},
|
||||
{"Hash_Buffer", bi_Hash_Buffer, -1},
|
||||
{"Hash_GetList", bi_Hash_GetList, -1},
|
||||
{"Hash_Stats", bi_Hash_Stats, -1},
|
||||
{0}
|
||||
};
|
||||
|
||||
void
|
||||
Hash_Progs_Init (progs_t *pr)
|
||||
{
|
||||
|
@ -310,21 +331,5 @@ Hash_Progs_Init (progs_t *pr)
|
|||
res->tabs = 0;
|
||||
|
||||
PR_Resources_Register (pr, "Hash", res, bi_hash_clear);
|
||||
PR_AddBuiltin (pr, "Hash_NewTable", bi_Hash_NewTable, -1);
|
||||
PR_AddBuiltin (pr, "Hash_SetHashCompare", bi_Hash_SetHashCompare, -1);
|
||||
PR_AddBuiltin (pr, "Hash_DelTable", bi_Hash_DelTable, -1);
|
||||
PR_AddBuiltin (pr, "Hash_FlushTable", bi_Hash_FlushTable, -1);
|
||||
PR_AddBuiltin (pr, "Hash_Add", bi_Hash_Add, -1);
|
||||
PR_AddBuiltin (pr, "Hash_AddElement", bi_Hash_AddElement, -1);
|
||||
PR_AddBuiltin (pr, "Hash_Find", bi_Hash_Find, -1);
|
||||
PR_AddBuiltin (pr, "Hash_FindElement", bi_Hash_FindElement, -1);
|
||||
PR_AddBuiltin (pr, "Hash_FindList", bi_Hash_FindList, -1);
|
||||
PR_AddBuiltin (pr, "Hash_FindElementList", bi_Hash_FindElementList, -1);
|
||||
PR_AddBuiltin (pr, "Hash_Del", bi_Hash_Del, -1);
|
||||
PR_AddBuiltin (pr, "Hash_DelElement", bi_Hash_DelElement, -1);
|
||||
PR_AddBuiltin (pr, "Hash_Free", bi_Hash_Free, -1);
|
||||
PR_AddBuiltin (pr, "Hash_String", bi_Hash_String, -1);
|
||||
PR_AddBuiltin (pr, "Hash_Buffer", bi_Hash_Buffer, -1);
|
||||
PR_AddBuiltin (pr, "Hash_GetList", bi_Hash_GetList, -1);
|
||||
PR_AddBuiltin (pr, "Hash_Stats", bi_Hash_Stats, -1);
|
||||
PR_RegisterBuiltins (pr, builtins);
|
||||
}
|
||||
|
|
|
@ -224,6 +224,19 @@ bi_il_clear (progs_t *pr, void *data)
|
|||
}
|
||||
}
|
||||
|
||||
static builtin_t builtins[] = {
|
||||
{"InputLine_Create", bi_InputLine_Create, -1},
|
||||
{"InputLine_SetUserData", bi_InputLine_SetUserData, -1},
|
||||
{"InputLine_SetWidth", bi_InputLine_SetWidth, -1},
|
||||
{"InputLine_SetText", bi_InputLine_SetText, -1},
|
||||
{"InputLine_GetText", bi_InputLine_GetText, -1},
|
||||
{"InputLine_Destroy", bi_InputLine_Destroy, -1},
|
||||
{"InputLine_Clear", bi_InputLine_Clear, -1},
|
||||
{"InputLine_Process", bi_InputLine_Process, -1},
|
||||
{"InputLine_Draw", bi_InputLine_Draw, -1},
|
||||
{0}
|
||||
};
|
||||
|
||||
void
|
||||
InputLine_Progs_Init (progs_t *pr)
|
||||
{
|
||||
|
@ -232,16 +245,7 @@ InputLine_Progs_Init (progs_t *pr)
|
|||
res->lines = calloc (sizeof (inputline_t *), res->max_lines);
|
||||
|
||||
PR_Resources_Register (pr, "InputLine", res, bi_il_clear);
|
||||
PR_AddBuiltin (pr, "InputLine_Create", bi_InputLine_Create, -1);
|
||||
PR_AddBuiltin (pr, "InputLine_SetUserData",
|
||||
bi_InputLine_SetUserData, -1);
|
||||
PR_AddBuiltin (pr, "InputLine_SetWidth", bi_InputLine_SetWidth, -1);
|
||||
PR_AddBuiltin (pr, "InputLine_SetText", bi_InputLine_SetText, -1);
|
||||
PR_AddBuiltin (pr, "InputLine_GetText", bi_InputLine_GetText, -1);
|
||||
PR_AddBuiltin (pr, "InputLine_Destroy", bi_InputLine_Destroy, -1);
|
||||
PR_AddBuiltin (pr, "InputLine_Clear", bi_InputLine_Clear, -1);
|
||||
PR_AddBuiltin (pr, "InputLine_Process", bi_InputLine_Process, -1);
|
||||
PR_AddBuiltin (pr, "InputLine_Draw", bi_InputLine_Draw, -1);
|
||||
PR_RegisterBuiltins (pr, builtins);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -169,6 +169,20 @@ plist_compare (void *k1, void *k2, void *unused)
|
|||
return k1 == k2;
|
||||
}
|
||||
|
||||
static builtin_t builtins[] = {
|
||||
{"PL_GetPropertyList", bi_PL_GetPropertyList, -1},
|
||||
{"PL_ObjectForKey", bi_PL_ObjectForKey, -1},
|
||||
{"PL_ObjectAtIndex", bi_PL_ObjectAtIndex, -1},
|
||||
{"PL_D_AddObject", bi_PL_D_AddObject, -1},
|
||||
{"PL_A_AddObject", bi_PL_A_AddObject, -1},
|
||||
{"PL_A_InsertObjectAtIndex", bi_PL_A_InsertObjectAtIndex, -1},
|
||||
{"PL_NewDictionary", bi_PL_NewDictionary, -1},
|
||||
{"PL_NewArray", bi_PL_NewArray, -1},
|
||||
// {"PL_NewData", bi_PL_NewData, -1},
|
||||
{"PL_NewString", bi_PL_NewString, -1},
|
||||
{0}
|
||||
};
|
||||
|
||||
void
|
||||
Plist_Progs_Init (progs_t *pr)
|
||||
{
|
||||
|
@ -177,14 +191,5 @@ Plist_Progs_Init (progs_t *pr)
|
|||
Hash_SetHashCompare (res->items, plist_get_hash, plist_compare);
|
||||
|
||||
PR_Resources_Register (pr, "plist", res, bi_plist_clear);
|
||||
PR_AddBuiltin (pr, "PL_GetPropertyList", bi_PL_GetPropertyList, -1);
|
||||
PR_AddBuiltin (pr, "PL_ObjectForKey", bi_PL_ObjectForKey, -1);
|
||||
PR_AddBuiltin (pr, "PL_ObjectAtIndex", bi_PL_ObjectAtIndex, -1);
|
||||
PR_AddBuiltin (pr, "PL_D_AddObject", bi_PL_D_AddObject, -1);
|
||||
PR_AddBuiltin (pr, "PL_A_AddObject", bi_PL_A_AddObject, -1);
|
||||
PR_AddBuiltin (pr, "PL_A_InsertObjectAtIndex", bi_PL_A_InsertObjectAtIndex, -1);
|
||||
PR_AddBuiltin (pr, "PL_NewDictionary", bi_PL_NewDictionary, -1);
|
||||
PR_AddBuiltin (pr, "PL_NewArray", bi_PL_NewArray, -1);
|
||||
//PR_AddBuiltin (pr, "PL_NewData", bi_PL_NewData, -1);
|
||||
PR_AddBuiltin (pr, "PL_NewString", bi_PL_NewString, -1);
|
||||
PR_RegisterBuiltins (pr, builtins);
|
||||
}
|
||||
|
|
|
@ -268,6 +268,37 @@ bi_Qfilesize (progs_t *pr)
|
|||
R_INT (pr) = Qfilesize (*h);
|
||||
}
|
||||
|
||||
static builtin_t secure_builtins[] = {
|
||||
{"Qrename", secured, -1},
|
||||
{"Qremove", secured, -1},
|
||||
{"Qopen", secured, -1},
|
||||
{0}
|
||||
};
|
||||
|
||||
static builtin_t insecure_builtins[] = {
|
||||
{"Qrename", bi_Qrename, -1},
|
||||
{"Qremove", bi_Qremove, -1},
|
||||
{"Qopen", bi_Qopen, -1},
|
||||
{0}
|
||||
};
|
||||
|
||||
static builtin_t builtins[] = {
|
||||
{"Qclose", bi_Qclose, -1},
|
||||
{"Qgetline", bi_Qgetline, -1},
|
||||
{"Qread", bi_Qread, -1},
|
||||
{"Qwrite", bi_Qwrite, -1},
|
||||
{"Qputs", bi_Qputs, -1},
|
||||
// {"Qgets", bi_Qgets, -1},
|
||||
{"Qgetc", bi_Qgetc, -1},
|
||||
{"Qputc", bi_Qputc, -1},
|
||||
{"Qseek", bi_Qseek, -1},
|
||||
{"Qtell", bi_Qtell, -1},
|
||||
{"Qflush", bi_Qflush, -1},
|
||||
{"Qeof", bi_Qeof, -1},
|
||||
{"Qfilesize", bi_Qfilesize, -1},
|
||||
{0}
|
||||
};
|
||||
|
||||
void
|
||||
QFile_Progs_Init (progs_t *pr, int secure)
|
||||
{
|
||||
|
@ -275,25 +306,9 @@ QFile_Progs_Init (progs_t *pr, int secure)
|
|||
|
||||
PR_Resources_Register (pr, "QFile", res, bi_qfile_clear);
|
||||
if (secure) {
|
||||
PR_AddBuiltin (pr, "Qrename", secured, -1);
|
||||
PR_AddBuiltin (pr, "Qremove", secured, -1);
|
||||
PR_AddBuiltin (pr, "Qopen", secured, -1);
|
||||
PR_RegisterBuiltins (pr, secure_builtins);
|
||||
} else {
|
||||
PR_AddBuiltin (pr, "Qrename", bi_Qrename, -1);
|
||||
PR_AddBuiltin (pr, "Qremove", bi_Qremove, -1);
|
||||
PR_AddBuiltin (pr, "Qopen", bi_Qopen, -1);
|
||||
PR_RegisterBuiltins (pr, insecure_builtins);
|
||||
}
|
||||
PR_AddBuiltin (pr, "Qclose", bi_Qclose, -1);
|
||||
PR_AddBuiltin (pr, "Qgetline", bi_Qgetline, -1);
|
||||
PR_AddBuiltin (pr, "Qread", bi_Qread, -1);
|
||||
PR_AddBuiltin (pr, "Qwrite", bi_Qwrite, -1);
|
||||
PR_AddBuiltin (pr, "Qputs", bi_Qputs, -1);
|
||||
// PR_AddBuiltin (pr, "Qgets", bi_Qgets, -1);
|
||||
PR_AddBuiltin (pr, "Qgetc", bi_Qgetc, -1);
|
||||
PR_AddBuiltin (pr, "Qputc", bi_Qputc, -1);
|
||||
PR_AddBuiltin (pr, "Qseek", bi_Qseek, -1);
|
||||
PR_AddBuiltin (pr, "Qtell", bi_Qtell, -1);
|
||||
PR_AddBuiltin (pr, "Qflush", bi_Qflush, -1);
|
||||
PR_AddBuiltin (pr, "Qeof", bi_Qeof, -1);
|
||||
PR_AddBuiltin (pr, "Qfilesize", bi_Qfilesize, -1);
|
||||
PR_RegisterBuiltins (pr, builtins);
|
||||
}
|
||||
|
|
|
@ -116,11 +116,16 @@ bi_QFS_WriteFile (progs_t *pr)
|
|||
QFS_WriteFile (va ("%s/%s", qfs_gamedir->dir.def, filename), buf, count);
|
||||
}
|
||||
|
||||
static builtin_t builtins[] = {
|
||||
{"QFS_Rename", bi_QFS_Rename, -1},
|
||||
{"QFS_LoadFile", bi_QFS_LoadFile, -1},
|
||||
{"QFS_OpenFile", bi_QFS_OpenFile, -1},
|
||||
{"QFS_WriteFile", bi_QFS_WriteFile, -1},
|
||||
{0}
|
||||
};
|
||||
|
||||
void
|
||||
QFS_Progs_Init (progs_t *pr)
|
||||
{
|
||||
PR_AddBuiltin (pr, "QFS_Rename", bi_QFS_Rename, -1);
|
||||
PR_AddBuiltin (pr, "QFS_LoadFile", bi_QFS_LoadFile, -1);
|
||||
PR_AddBuiltin (pr, "QFS_OpenFile", bi_QFS_OpenFile, -1);
|
||||
PR_AddBuiltin (pr, "QFS_WriteFile", bi_QFS_WriteFile, -1);
|
||||
PR_RegisterBuiltins (pr, builtins);
|
||||
}
|
||||
|
|
|
@ -626,16 +626,11 @@ static builtin_t builtins[] = {
|
|||
{"stoi", PF_stoi, 113},
|
||||
{"stov", PF_stov, 114},
|
||||
{"gametype", PR_gametype, 115},
|
||||
{0}
|
||||
};
|
||||
|
||||
void
|
||||
PR_Cmds_Init (progs_t *pr)
|
||||
{
|
||||
int i;
|
||||
builtin_t *bi;
|
||||
|
||||
for (i = 0; i < sizeof (builtins) / sizeof (builtins[0]); i++) {
|
||||
bi = builtins + i;
|
||||
PR_AddBuiltin (pr, bi->name, bi->proc, bi->binum);
|
||||
}
|
||||
};
|
||||
PR_RegisterBuiltins (pr, builtins);
|
||||
}
|
||||
|
|
|
@ -54,52 +54,82 @@ static __attribute__ ((unused)) const char rcsid[] =
|
|||
|
||||
#include "compat.h"
|
||||
|
||||
/*
|
||||
Builtins are arranged into groups of 65536 to allow for diffent expantion
|
||||
sets. eg, stock id is 0x0000xxxx, quakeforge is 0x000fxxxx. predefined
|
||||
groups go up to 0x0fffxxxx allowing 4096 different groups. Builtins
|
||||
0x10000000 to 0x7fffffff are reserved for auto-allocation. The range
|
||||
0x8000000 to 0xffffffff is unavailable due to the builtin number being
|
||||
a negative statement address.
|
||||
*/
|
||||
#define PR_AUTOBUILTIN 0x10000000
|
||||
|
||||
static const char *
|
||||
builtin_get_key (void *_bi, void *unused)
|
||||
{
|
||||
builtin_t *bi = (builtin_t *)_bi;
|
||||
|
||||
return bi->name;
|
||||
}
|
||||
|
||||
#define PR_AUTOBUILTIN 120
|
||||
void
|
||||
PR_AddBuiltin (progs_t *pr, const char *name, builtin_proc builtin, int num)
|
||||
static unsigned long
|
||||
builtin_get_hash (void *_bi, void *unused)
|
||||
{
|
||||
int i;
|
||||
builtin_t *bi = (builtin_t *)_bi;
|
||||
|
||||
if (!pr->builtin_hash)
|
||||
return bi->binum;
|
||||
}
|
||||
|
||||
static int
|
||||
builtin_compare (void *_bia, void *_bib, void *unused)
|
||||
{
|
||||
builtin_t *bia = (builtin_t *)_bia;
|
||||
builtin_t *bib = (builtin_t *)_bib;
|
||||
|
||||
return bia->binum == bib->binum;
|
||||
}
|
||||
|
||||
static int
|
||||
builtin_next (progs_t *pr)
|
||||
{
|
||||
if (!pr->bi_next)
|
||||
pr->bi_next = PR_AUTOBUILTIN;
|
||||
if (pr->bi_next == 0x80000000)
|
||||
PR_Error (pr, "too many auto-allocated builtins");
|
||||
return pr->bi_next++;
|
||||
}
|
||||
|
||||
void
|
||||
PR_RegisterBuiltins (progs_t *pr, builtin_t *builtins)
|
||||
{
|
||||
builtin_t *bi;
|
||||
|
||||
if (!pr->builtin_hash) {
|
||||
pr->builtin_hash = Hash_NewTable (1021, builtin_get_key, 0, pr);
|
||||
|
||||
if (pr->numbuiltins == 0) {
|
||||
pr->builtins = calloc (PR_AUTOBUILTIN, sizeof (builtin_t*));
|
||||
pr->numbuiltins = PR_AUTOBUILTIN;
|
||||
if (!pr->builtins)
|
||||
PR_Error (pr, "PR_AddBuiltin: memory allocation error!");
|
||||
pr->builtin_num_hash = Hash_NewTable (1021, 0, 0, pr);
|
||||
Hash_SetHashCompare (pr->builtin_num_hash, builtin_get_hash,
|
||||
builtin_compare);
|
||||
}
|
||||
|
||||
if (num < 0) {
|
||||
for (i = PR_AUTOBUILTIN;
|
||||
i < pr->numbuiltins && pr->builtins[i]; i++)
|
||||
;
|
||||
if (i >= pr->numbuiltins) {
|
||||
pr->numbuiltins++;
|
||||
pr->builtins = realloc (pr->builtins,
|
||||
pr->numbuiltins * sizeof (builtin_t*));
|
||||
if (!pr->builtins)
|
||||
PR_Error (pr, "PR_AddBuiltin: memory allocation error!");
|
||||
}
|
||||
} else {
|
||||
if (num >= PR_AUTOBUILTIN || num == 0)
|
||||
PR_Error (pr, "PR_AddBuiltin: invalid builtin number.");
|
||||
if (pr->builtins[num])
|
||||
PR_Error (pr, "PR_AddBuiltin: builtin number already exists.");
|
||||
i = num;
|
||||
while (builtins->name) {
|
||||
if (builtins->binum == 0 || builtins->binum >= PR_AUTOBUILTIN)
|
||||
PR_Error (pr, "bad builtin number: %s = #%d", builtins->name,
|
||||
builtins->binum);
|
||||
|
||||
if (builtins->binum < 0)
|
||||
builtins->binum = builtin_next (pr);
|
||||
|
||||
if ((bi = Hash_Find (pr->builtin_hash, builtins->name))
|
||||
|| (bi = Hash_FindElement (pr->builtin_num_hash, builtins)))
|
||||
PR_Error (pr, "builtin %s = #%d already defined (%s = #%d)",
|
||||
builtins->name, builtins->binum,
|
||||
bi->name, bi->binum);
|
||||
|
||||
Hash_Add (pr->builtin_hash, builtins);
|
||||
Hash_AddElement (pr->builtin_num_hash, builtins);
|
||||
|
||||
builtins++;
|
||||
}
|
||||
pr->builtins[i] = malloc (sizeof (builtin_t));
|
||||
pr->builtins[i]->proc = builtin;
|
||||
pr->builtins[i]->name = name;
|
||||
pr->builtins[i]->binum = i;
|
||||
Hash_Add (pr->builtin_hash, pr->builtins[i]);
|
||||
}
|
||||
|
||||
builtin_t *
|
||||
|
@ -108,6 +138,15 @@ PR_FindBuiltin (progs_t *pr, const char *name)
|
|||
return (builtin_t *) Hash_Find (pr->builtin_hash, name);
|
||||
}
|
||||
|
||||
builtin_t *
|
||||
PR_FindBuiltinNum (progs_t *pr, int num)
|
||||
{
|
||||
builtin_t bi;
|
||||
|
||||
bi.binum = num;
|
||||
return (builtin_t *) Hash_FindElement (pr->builtin_num_hash, &bi);
|
||||
}
|
||||
|
||||
static void
|
||||
bi_no_function (progs_t *pr)
|
||||
{
|
||||
|
@ -150,9 +189,8 @@ PR_RelocateBuiltins (progs_t *pr)
|
|||
func->first_statement = -bi->binum;
|
||||
}
|
||||
|
||||
ind = -func->first_statement;
|
||||
if (ind >= pr->numbuiltins || !(bi = pr->builtins[ind])
|
||||
|| !(proc = bi->proc)) {
|
||||
bi = PR_FindBuiltinNum (pr, -func->first_statement);
|
||||
if (!bi || !(proc = bi->proc)) {
|
||||
Sys_DPrintf ("WARNING: Bad builtin call number: %s = #%d\n",
|
||||
bi_name, ind);
|
||||
proc = bi_no_function;
|
||||
|
|
|
@ -53,21 +53,16 @@ static __attribute__ ((unused)) const char rcsid[] =
|
|||
static void
|
||||
call_function (progs_t *pr, func_t func)
|
||||
{
|
||||
dfunction_t *newf;
|
||||
dfunction_t *f;
|
||||
|
||||
if (!func)
|
||||
PR_RunError (pr, "NULL function");
|
||||
newf = pr->pr_functions + func;
|
||||
if (newf->first_statement < 0) {
|
||||
f = pr->pr_functions + func;
|
||||
if (f->first_statement < 0) {
|
||||
// negative statements are built in functions
|
||||
int i = -newf->first_statement;
|
||||
|
||||
if (i >= pr->numbuiltins || !pr->builtins[i]
|
||||
|| !pr->builtins[i]->proc)
|
||||
PR_RunError (pr, "Bad builtin call number");
|
||||
pr->builtins[i]->proc (pr);
|
||||
((bfunction_t *) f)->func (pr);
|
||||
} else {
|
||||
PR_EnterFunction (pr, newf);
|
||||
PR_EnterFunction (pr, f);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -919,79 +914,73 @@ pr__c_Object__conformsToProtocol_ (progs_t *pr)
|
|||
|
||||
//====================================================================
|
||||
|
||||
static struct {
|
||||
const char *name;
|
||||
void (*func)(progs_t *pr);
|
||||
} obj_methods [] = {
|
||||
{"__obj_exec_class", pr___obj_exec_class},
|
||||
static builtin_t obj_methods [] = {
|
||||
{"__obj_exec_class", pr___obj_exec_class, -1},
|
||||
|
||||
{"obj_error", pr_obj_error},
|
||||
{"obj_verror", pr_obj_verror},
|
||||
{"obj_set_error_handler", pr_obj_set_error_handler},
|
||||
{"obj_msg_lookup", pr_obj_msg_lookup},
|
||||
{"obj_msg_lookup_super", pr_obj_msg_lookup_super},
|
||||
{"obj_msg_sendv", pr_obj_msg_sendv},
|
||||
{"obj_malloc", pr_obj_malloc},
|
||||
{"obj_atomic_malloc", pr_obj_atomic_malloc},
|
||||
{"obj_valloc", pr_obj_valloc},
|
||||
{"obj_realloc", pr_obj_realloc},
|
||||
{"obj_calloc", pr_obj_calloc},
|
||||
{"obj_free", pr_obj_free},
|
||||
{"obj_get_uninstalled_dtable", pr_obj_get_uninstalled_dtable},
|
||||
{"obj_msgSend", pr_obj_msgSend},
|
||||
{"obj_msgSend_super", pr_obj_msgSend_super},
|
||||
{"obj_error", pr_obj_error, -1},
|
||||
{"obj_verror", pr_obj_verror, -1},
|
||||
{"obj_set_error_handler", pr_obj_set_error_handler, -1},
|
||||
{"obj_msg_lookup", pr_obj_msg_lookup, -1},
|
||||
{"obj_msg_lookup_super", pr_obj_msg_lookup_super, -1},
|
||||
{"obj_msg_sendv", pr_obj_msg_sendv, -1},
|
||||
{"obj_malloc", pr_obj_malloc, -1},
|
||||
{"obj_atomic_malloc", pr_obj_atomic_malloc, -1},
|
||||
{"obj_valloc", pr_obj_valloc, -1},
|
||||
{"obj_realloc", pr_obj_realloc, -1},
|
||||
{"obj_calloc", pr_obj_calloc, -1},
|
||||
{"obj_free", pr_obj_free, -1},
|
||||
{"obj_get_uninstalled_dtable", pr_obj_get_uninstalled_dtable, -1},
|
||||
{"obj_msgSend", pr_obj_msgSend, -1},
|
||||
{"obj_msgSend_super", pr_obj_msgSend_super, -1},
|
||||
|
||||
{"obj_get_class", pr_obj_get_class, -1},
|
||||
{"obj_lookup_class", pr_obj_lookup_class, -1},
|
||||
{"obj_next_class", pr_obj_next_class, -1},
|
||||
|
||||
{"obj_get_class", pr_obj_get_class},
|
||||
{"obj_lookup_class", pr_obj_lookup_class},
|
||||
{"obj_next_class", pr_obj_next_class},
|
||||
{"sel_get_name", pr_sel_get_name, -1},
|
||||
{"sel_get_type", pr_sel_get_type, -1},
|
||||
{"sel_get_uid", pr_sel_get_uid, -1},
|
||||
{"sel_register_name", pr_sel_register_name, -1},
|
||||
{"sel_is_mapped", pr_sel_is_mapped, -1},
|
||||
|
||||
{"sel_get_name", pr_sel_get_name},
|
||||
{"sel_get_type", pr_sel_get_type},
|
||||
{"sel_get_uid", pr_sel_get_uid},
|
||||
{"sel_register_name", pr_sel_register_name},
|
||||
{"sel_is_mapped", pr_sel_is_mapped},
|
||||
{"class_get_class_method", pr_class_get_class_method, -1},
|
||||
{"class_get_instance_method", pr_class_get_instance_method, -1},
|
||||
{"class_pose_as", pr_class_pose_as, -1},
|
||||
{"class_create_instance", pr_class_create_instance, -1},
|
||||
{"class_get_class_name", pr_class_get_class_name, -1},
|
||||
{"class_get_instance_size", pr_class_get_instance_size, -1},
|
||||
{"class_get_meta_class", pr_class_get_meta_class, -1},
|
||||
{"class_get_super_class", pr_class_get_super_class, -1},
|
||||
{"class_get_version", pr_class_get_version, -1},
|
||||
{"class_is_class", pr_class_is_class, -1},
|
||||
{"class_is_meta_class", pr_class_is_meta_class, -1},
|
||||
{"class_set_version", pr_class_set_version, -1},
|
||||
{"class_get_gc_object_type", pr_class_get_gc_object_type, -1},
|
||||
{"class_ivar_set_gcinvisible", pr_class_ivar_set_gcinvisible, -1},
|
||||
|
||||
{"class_get_class_method", pr_class_get_class_method},
|
||||
{"class_get_instance_method", pr_class_get_instance_method},
|
||||
{"class_pose_as", pr_class_pose_as},
|
||||
{"class_create_instance", pr_class_create_instance},
|
||||
{"class_get_class_name", pr_class_get_class_name},
|
||||
{"class_get_instance_size", pr_class_get_instance_size},
|
||||
{"class_get_meta_class", pr_class_get_meta_class},
|
||||
{"class_get_super_class", pr_class_get_super_class},
|
||||
{"class_get_version", pr_class_get_version},
|
||||
{"class_is_class", pr_class_is_class},
|
||||
{"class_is_meta_class", pr_class_is_meta_class},
|
||||
{"class_set_version", pr_class_set_version},
|
||||
{"class_get_gc_object_type", pr_class_get_gc_object_type},
|
||||
{"class_ivar_set_gcinvisible", pr_class_ivar_set_gcinvisible},
|
||||
{"method_get_imp", pr_method_get_imp, -1},
|
||||
{"get_imp", pr_get_imp, -1},
|
||||
|
||||
{"method_get_imp", pr_method_get_imp},
|
||||
{"get_imp", pr_get_imp},
|
||||
{"object_copy", pr_object_copy, -1},
|
||||
{"object_dispose", pr_object_dispose, -1},
|
||||
{"object_get_class", pr_object_get_class, -1},
|
||||
{"object_get_class_name", pr_object_get_class_name, -1},
|
||||
{"object_get_meta_class", pr_object_get_meta_class, -1},
|
||||
{"object_get_super_class", pr_object_get_super_class, -1},
|
||||
{"object_is_class", pr_object_is_class, -1},
|
||||
{"object_is_instance", pr_object_is_instance, -1},
|
||||
{"object_is_meta_class", pr_object_is_meta_class, -1},
|
||||
|
||||
{"object_copy", pr_object_copy},
|
||||
{"object_dispose", pr_object_dispose},
|
||||
{"object_get_class", pr_object_get_class},
|
||||
{"object_get_class_name", pr_object_get_class_name},
|
||||
{"object_get_meta_class", pr_object_get_meta_class},
|
||||
{"object_get_super_class", pr_object_get_super_class},
|
||||
{"object_is_class", pr_object_is_class},
|
||||
{"object_is_instance", pr_object_is_instance},
|
||||
{"object_is_meta_class", pr_object_is_meta_class},
|
||||
|
||||
{"_i_Object__hash", pr__i_Object__hash},
|
||||
{"_i_Object_error_error_", pr__i_Object_error_error_},
|
||||
{"_c_Object__conformsToProtocol_", pr__c_Object__conformsToProtocol_},
|
||||
{"_i_Object__hash", pr__i_Object__hash, -1},
|
||||
{"_i_Object_error_error_", pr__i_Object_error_error_, -1},
|
||||
{"_c_Object__conformsToProtocol_", pr__c_Object__conformsToProtocol_, -1},
|
||||
{0}
|
||||
};
|
||||
|
||||
void
|
||||
PR_Obj_Progs_Init (progs_t *pr)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < sizeof (obj_methods) / sizeof (obj_methods[0]); i++) {
|
||||
PR_AddBuiltin (pr, obj_methods[i].name, obj_methods[i].func, -1);
|
||||
}
|
||||
PR_RegisterBuiltins (pr, obj_methods);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue