mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-18 15:01:41 +00:00
make a common call function and fix pr_trace such that it autoclears only when the execution session it's set in is exited
This is an imperfect revision of history.
This commit is contained in:
parent
201252c1c0
commit
780fb41858
5 changed files with 64 additions and 64 deletions
|
@ -330,6 +330,7 @@ static void
|
||||||
PF_traceon (progs_t *pr)
|
PF_traceon (progs_t *pr)
|
||||||
{
|
{
|
||||||
pr->pr_trace = true;
|
pr->pr_trace = true;
|
||||||
|
pr->pr_trace_depth = pr->pr_depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -112,12 +112,15 @@ PR_PopFrame (progs_t *pr)
|
||||||
pr->pr_xtstr = frame->tstr;
|
pr->pr_xtstr = frame->tstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/** Setup the stackframe prior to calling a progs function. Saves all local
|
||||||
PR_EnterFunction
|
data the called function will trample on and copies the parameters used
|
||||||
|
by the function into the function's local data space.
|
||||||
Returns the new program statement counter
|
\param pr pointer to progs_t VM struct
|
||||||
|
\param f pointer to the descriptor for the called function
|
||||||
|
\note Passing a descriptor for a builtin function will result in
|
||||||
|
undefined behavior.
|
||||||
*/
|
*/
|
||||||
void
|
static void
|
||||||
PR_EnterFunction (progs_t *pr, dfunction_t *f)
|
PR_EnterFunction (progs_t *pr, dfunction_t *f)
|
||||||
{
|
{
|
||||||
int i, j, c, o;
|
int i, j, c, o;
|
||||||
|
@ -242,6 +245,24 @@ signal_hook (int sig, void *data)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
PR_CallFunction (progs_t *pr, func_t fnum)
|
||||||
|
{
|
||||||
|
dfunction_t *f;
|
||||||
|
|
||||||
|
if (!fnum)
|
||||||
|
PR_RunError (pr, "NULL function");
|
||||||
|
f = pr->pr_functions + fnum;
|
||||||
|
if (f->first_statement < 0) {
|
||||||
|
// negative statements are built in functions
|
||||||
|
((bfunction_t *) f)->func (pr);
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
PR_EnterFunction (pr, f);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
PR_ExecuteProgram
|
PR_ExecuteProgram
|
||||||
|
|
||||||
|
@ -252,31 +273,23 @@ PR_ExecuteProgram (progs_t * pr, func_t fnum)
|
||||||
{
|
{
|
||||||
int exitdepth, profile, startprofile;
|
int exitdepth, profile, startprofile;
|
||||||
unsigned int pointer;
|
unsigned int pointer;
|
||||||
dfunction_t *f;
|
|
||||||
dstatement_t *st;
|
dstatement_t *st;
|
||||||
edict_t *ed;
|
edict_t *ed;
|
||||||
pr_type_t *ptr;
|
pr_type_t *ptr;
|
||||||
|
|
||||||
if (!fnum || fnum >= pr->progs->numfunctions) {
|
|
||||||
if (*pr->globals.self)
|
|
||||||
ED_Print (pr, PROG_TO_EDICT (pr, *pr->globals.self));
|
|
||||||
PR_RunError (pr, "PR_ExecuteProgram: NULL function");
|
|
||||||
}
|
|
||||||
|
|
||||||
f = &pr->pr_functions[fnum];
|
|
||||||
//Sys_Printf("%s:\n", PR_GetString(pr,f->s_name));
|
|
||||||
|
|
||||||
pr->pr_trace = false;
|
|
||||||
|
|
||||||
// make a stack frame
|
// make a stack frame
|
||||||
exitdepth = pr->pr_depth;
|
exitdepth = pr->pr_depth;
|
||||||
|
|
||||||
PR_EnterFunction (pr, f);
|
|
||||||
st = pr->pr_statements + pr->pr_xstatement;
|
|
||||||
startprofile = profile = 0;
|
startprofile = profile = 0;
|
||||||
|
|
||||||
Sys_PushSignalHook (signal_hook, pr);
|
Sys_PushSignalHook (signal_hook, pr);
|
||||||
|
|
||||||
|
if (!PR_CallFunction (pr, fnum)) {
|
||||||
|
// called a builtin instead of progs code
|
||||||
|
Sys_PopSignalHook ();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
st = pr->pr_statements + pr->pr_xstatement;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
pr_type_t *op_a, *op_b, *op_c;
|
pr_type_t *op_a, *op_b, *op_c;
|
||||||
|
|
||||||
|
@ -771,15 +784,7 @@ PR_ExecuteProgram (progs_t * pr, func_t fnum)
|
||||||
pr->pr_xfunction->profile += profile - startprofile;
|
pr->pr_xfunction->profile += profile - startprofile;
|
||||||
startprofile = profile;
|
startprofile = profile;
|
||||||
pr->pr_argc = st->op - OP_CALL0;
|
pr->pr_argc = st->op - OP_CALL0;
|
||||||
if (!OPA.func_var)
|
PR_CallFunction (pr, OPA.func_var);
|
||||||
PR_RunError (pr, "NULL function");
|
|
||||||
f = &pr->pr_functions[OPA.func_var];
|
|
||||||
// negative statements are built in functions
|
|
||||||
if (f->first_statement < 0) {
|
|
||||||
((bfunction_t *) f)->func (pr);
|
|
||||||
} else {
|
|
||||||
PR_EnterFunction (pr, f);
|
|
||||||
}
|
|
||||||
st = pr->pr_statements + pr->pr_xstatement;
|
st = pr->pr_statements + pr->pr_xstatement;
|
||||||
break;
|
break;
|
||||||
case OP_DONE:
|
case OP_DONE:
|
||||||
|
@ -795,6 +800,8 @@ PR_ExecuteProgram (progs_t * pr, func_t fnum)
|
||||||
PR_LeaveFunction (pr);
|
PR_LeaveFunction (pr);
|
||||||
st = pr->pr_statements + pr->pr_xstatement;
|
st = pr->pr_statements + pr->pr_xstatement;
|
||||||
if (pr->pr_depth == exitdepth) {
|
if (pr->pr_depth == exitdepth) {
|
||||||
|
if (pr->pr_trace && pr->pr_depth <= pr->pr_trace_depth)
|
||||||
|
pr->pr_trace = false;
|
||||||
Sys_PopSignalHook ();
|
Sys_PopSignalHook ();
|
||||||
return; // all done
|
return; // all done
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,18 +52,9 @@ static __attribute__ ((unused)) const char rcsid[] =
|
||||||
#include "rua_internal.h"
|
#include "rua_internal.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
call_function (progs_t *pr, func_t func)
|
|
||||||
{
|
{
|
||||||
dfunction_t *f;
|
|
||||||
|
|
||||||
if (!func)
|
|
||||||
PR_RunError (pr, "NULL function");
|
|
||||||
f = pr->pr_functions + func;
|
|
||||||
if (f->first_statement < 0) {
|
|
||||||
// negative statements are built in functions
|
|
||||||
((bfunction_t *) f)->func (pr);
|
|
||||||
} else {
|
} else {
|
||||||
PR_EnterFunction (pr, f);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -418,8 +409,8 @@ rua_obj_msg_lookup (progs_t *pr)
|
||||||
{
|
{
|
||||||
pr_id_t *receiver = &P_STRUCT (pr, pr_id_t, 0);
|
pr_id_t *receiver = &P_STRUCT (pr, pr_id_t, 0);
|
||||||
pr_sel_t *op = &P_STRUCT (pr, pr_sel_t, 1);
|
pr_sel_t *op = &P_STRUCT (pr, pr_sel_t, 1);
|
||||||
pr_method_t *method = obj_msg_lookup (pr, receiver, op);
|
|
||||||
R_INT (pr) = method ? method->method_imp : 0;
|
R_INT (pr) = obj_msg_lookup (pr, receiver, op);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -427,8 +418,8 @@ rua_obj_msg_lookup_super (progs_t *pr)
|
||||||
{
|
{
|
||||||
pr_super_t *super = &P_STRUCT (pr, pr_super_t, 0);
|
pr_super_t *super = &P_STRUCT (pr, pr_super_t, 0);
|
||||||
pr_sel_t *_cmd = &P_STRUCT (pr, pr_sel_t, 1);
|
pr_sel_t *_cmd = &P_STRUCT (pr, pr_sel_t, 1);
|
||||||
pr_method_t *method = obj_msg_lookup_super (pr, super, _cmd);
|
|
||||||
R_INT (pr) = method ? method->method_imp : 0;
|
R_INT (pr) = obj_msg_lookup_super (pr, super, _cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -436,18 +427,19 @@ rua_obj_msg_sendv (progs_t *pr)
|
||||||
{
|
{
|
||||||
pr_id_t *receiver = &P_STRUCT (pr, pr_id_t, 0);
|
pr_id_t *receiver = &P_STRUCT (pr, pr_id_t, 0);
|
||||||
pr_sel_t *op = &P_STRUCT (pr, pr_sel_t, 1);
|
pr_sel_t *op = &P_STRUCT (pr, pr_sel_t, 1);
|
||||||
pr_va_list_t args = P_STRUCT (pr, pr_va_list_t, 2);
|
pr_va_list_t *args = (pr_va_list_t *) &P_POINTER (pr, 2);
|
||||||
pr_method_t *method = obj_msg_lookup (pr, receiver, op);
|
pr_type_t *params = G_GPOINTER (pr, args->list);
|
||||||
|
int count = args->count;
|
||||||
|
func_t imp = obj_msg_lookup (pr, receiver, op);
|
||||||
|
|
||||||
if (!method)
|
if (!imp)
|
||||||
PR_RunError (pr, "%s does not respond to %s",
|
PR_RunError (pr, "%s does not respond to %s",
|
||||||
PR_GetString (pr, object_get_class_name (pr, receiver)),
|
PR_GetString (pr, object_get_class_name (pr, receiver)),
|
||||||
PR_GetString (pr, op->sel_id));
|
PR_GetString (pr, pr->selector_names[op->sel_id]));
|
||||||
if (args.count > 6)
|
if (count > 6)
|
||||||
args.count = 6;
|
count = 6;
|
||||||
memcpy (pr->pr_params[2], G_GPOINTER (pr, args.list),
|
memcpy (pr->pr_params[2], params, count * 4 * pr->pr_param_size);
|
||||||
args.count * 4 * pr->pr_param_size);
|
PR_CallFunction (pr, imp);
|
||||||
call_function (pr, method->method_imp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -517,7 +509,7 @@ rua_obj_msgSend (progs_t *pr)
|
||||||
{
|
{
|
||||||
pr_id_t *self = &P_STRUCT (pr, pr_id_t, 0);
|
pr_id_t *self = &P_STRUCT (pr, pr_id_t, 0);
|
||||||
pr_sel_t *_cmd = &P_STRUCT (pr, pr_sel_t, 1);
|
pr_sel_t *_cmd = &P_STRUCT (pr, pr_sel_t, 1);
|
||||||
pr_method_t *method;
|
func_t imp;
|
||||||
|
|
||||||
if (!self) {
|
if (!self) {
|
||||||
R_INT (pr) = R_INT (pr);
|
R_INT (pr) = R_INT (pr);
|
||||||
|
@ -525,13 +517,13 @@ rua_obj_msgSend (progs_t *pr)
|
||||||
}
|
}
|
||||||
if (!_cmd)
|
if (!_cmd)
|
||||||
PR_RunError (pr, "null selector");
|
PR_RunError (pr, "null selector");
|
||||||
method = obj_msg_lookup (pr, self, _cmd);
|
imp = obj_msg_lookup (pr, self, _cmd);
|
||||||
if (!method)
|
if (!imp)
|
||||||
PR_RunError (pr, "%s does not respond to %s",
|
PR_RunError (pr, "%s does not respond to %s",
|
||||||
PR_GetString (pr, object_get_class_name (pr, self)),
|
PR_GetString (pr, object_get_class_name (pr, self)),
|
||||||
PR_GetString (pr, _cmd->sel_id));
|
PR_GetString (pr, pr->selector_names[_cmd->sel_id]));
|
||||||
|
|
||||||
call_function (pr, method->method_imp);
|
PR_CallFunction (pr, imp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -539,17 +531,17 @@ rua_obj_msgSend_super (progs_t *pr)
|
||||||
{
|
{
|
||||||
pr_super_t *super = &P_STRUCT (pr, pr_super_t, 0);
|
pr_super_t *super = &P_STRUCT (pr, pr_super_t, 0);
|
||||||
pr_sel_t *_cmd = &P_STRUCT (pr, pr_sel_t, 1);
|
pr_sel_t *_cmd = &P_STRUCT (pr, pr_sel_t, 1);
|
||||||
pr_method_t *method;
|
func_t imp;
|
||||||
|
|
||||||
method = obj_msg_lookup_super (pr, super, _cmd);
|
imp = obj_msg_lookup_super (pr, super, _cmd);
|
||||||
if (!method) {
|
if (!imp) {
|
||||||
pr_id_t *self = &G_STRUCT (pr, pr_id_t, super->self);
|
pr_id_t *self = &G_STRUCT (pr, pr_id_t, super->self);
|
||||||
PR_RunError (pr, "%s does not respond to %s",
|
PR_RunError (pr, "%s does not respond to %s",
|
||||||
PR_GetString (pr, object_get_class_name (pr, self)),
|
PR_GetString (pr, object_get_class_name (pr, self)),
|
||||||
PR_GetString (pr, _cmd->sel_id));
|
PR_GetString (pr, pr->selector_names[_cmd->sel_id]));
|
||||||
}
|
}
|
||||||
P_POINTER (pr, 0) = super->self;
|
P_POINTER (pr, 0) = super->self;
|
||||||
call_function (pr, method->method_imp);
|
PR_CallFunction (pr, imp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -127,6 +127,7 @@ static void
|
||||||
bi_traceon (progs_t *pr)
|
bi_traceon (progs_t *pr)
|
||||||
{
|
{
|
||||||
pr->pr_trace = true;
|
pr->pr_trace = true;
|
||||||
|
pr->pr_trace_depth = pr->pr_depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
void (string str) print = #1;
|
void (string str) print = #1;
|
||||||
void () garbage_collect = #2;
|
|
||||||
integer () errno = #3;
|
integer () errno = #3;
|
||||||
string (integer err) strerror = #4;
|
string (integer err) strerror = #4;
|
||||||
integer (...) open = #5; // string path, float flags[, float mode]
|
integer (...) open = #5; // string path, float flags[, float mode]
|
||||||
|
|
Loading…
Reference in a new issue