mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-30 04:30:43 +00:00
Add support for checkfunction, which is a builtin that searches for
another builtin by name, and returns it. Soon I'll change all our new builtins to by allocated dynamically, as well as changing the number checkfunction uses, and happily break everything that uses them :D
This commit is contained in:
parent
0f56fea4e3
commit
c218ede288
5 changed files with 32 additions and 18 deletions
|
@ -595,6 +595,13 @@ PR_ExecuteProgram (progs_t * pr, func_t fnum)
|
|||
pr->pr_argc = st->op - OP_CALL0;
|
||||
if (!OPA.func_var)
|
||||
PR_RunError (pr, "NULL function");
|
||||
if (OPA.func_var < 0) { // dynamic builtin
|
||||
int i = -OPA.func_var;
|
||||
if (i >= pr->numbuiltins || !pr->builtins[i].proc)
|
||||
PR_RunError (pr, "Bad builtin call number");
|
||||
pr->builtins[i].proc (pr);
|
||||
break;
|
||||
}
|
||||
newf = &pr->pr_functions[OPA.func_var];
|
||||
if (newf->first_statement < 0) {
|
||||
// negative statements are built in functions
|
||||
|
|
|
@ -2006,7 +2006,7 @@ PF_checkfunction (progs_t *pr)
|
|||
|
||||
for (i = 0; i < pr->numbuiltins; i++) {
|
||||
if (pr->builtins[i].name && strequal (pr->builtins[i].name, name)) {
|
||||
G_FUNCTION (pr, OFS_RETURN) = i;
|
||||
G_FUNCTION (pr, OFS_RETURN) = -i;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -549,6 +549,7 @@ typedef struct {
|
|||
int warn_error; // treat warnings as errors
|
||||
int quiet; // not so much chatter
|
||||
int debug; // produce debug info
|
||||
int undefined_function_warning; // print a warning when a function isn't defined
|
||||
} options_t;
|
||||
|
||||
extern options_t options;
|
||||
|
|
|
@ -151,6 +151,7 @@ static keyword_t keywords[] = {
|
|||
{"entity", TYPE, &type_entity },
|
||||
{"quaternion", TYPE, &type_quaternion},
|
||||
{"integer", TYPE, &type_integer },
|
||||
{"function", TYPE, &type_function },
|
||||
{"local", LOCAL, 0 },
|
||||
{"return", RETURN, 0 },
|
||||
{"while", WHILE, 0 },
|
||||
|
|
|
@ -706,16 +706,16 @@ PR_FinishCompilation (void)
|
|||
expr_t e;
|
||||
|
||||
// check to make sure all functions prototyped have code
|
||||
for (d = pr.def_head.def_next; d; d = d->def_next) {
|
||||
if (d->type->type == ev_func && !d->scope) { // function args ok
|
||||
// f = G_FUNCTION(d->ofs);
|
||||
// if (!f || (!f->code && !f->builtin))
|
||||
if (!d->initialized) {
|
||||
printf ("function %s was not defined\n", d->name);
|
||||
errors = true;
|
||||
if (options.undefined_function_warning)
|
||||
for (d = pr.def_head.def_next; d; d = d->def_next) {
|
||||
if (d->type->type == ev_func && !d->scope) { // function args ok
|
||||
// f = G_FUNCTION(d->ofs);
|
||||
// if (!f || (!f->code && !f->builtin))
|
||||
if (!d->initialized) {
|
||||
warning (0, "function %s was not defined\n", d->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (errors)
|
||||
return !errors;
|
||||
|
@ -920,15 +920,16 @@ main (int argc, char **argv)
|
|||
if (CheckParm ("-h") || CheckParm ("--help")) {
|
||||
printf ("%s - A compiler for the QuakeC language\n", argv[0]);
|
||||
printf ("Usage: %s [options]\n", argv[0]);
|
||||
printf ("\
|
||||
Options: \n\
|
||||
-s, --source <dir> look for progs.src in directory <dir>\n\
|
||||
-h, --help display this help and exit\n\
|
||||
-V, --version output version information and exit\n\
|
||||
--cow allow assignment to initialized globals\n\
|
||||
--id only support id (progs version 6) features\n\
|
||||
--warn=error treat warnings as errors\n\
|
||||
");
|
||||
printf (
|
||||
"Options: \n"
|
||||
" -s, --source <dir> look for progs.src in directory <dir>\n"
|
||||
" -h, --help display this help and exit\n"
|
||||
" -V, --version output version information and exit\n"
|
||||
" --cow allow assignment to initialized globals\n"
|
||||
" --id only support id (progs version 6) features\n"
|
||||
" --warn=error treat warnings as errors\n"
|
||||
" --undefined-function-warning warn when a function isn't defined\n"
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -976,6 +977,10 @@ Options: \n\
|
|||
options.warn_error = 1;
|
||||
}
|
||||
|
||||
if (CheckParm ("--undefined-function-warning")) {
|
||||
options.undefined_function_warning = 1;
|
||||
}
|
||||
|
||||
if (strcmp (sourcedir, ".")) {
|
||||
printf ("Source directory: %s\n", sourcedir);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue