mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 04:42:32 +00:00
pr_comp.h:
add OP_ADD_S. WARNING!!! this /will/ move. progs.h: add prototype for PR_PrintStatement pr_edict.c: add OP_ADD_S support in the progs checker pr_exec.c: implement OP_ADD_S tools/qfcc/include/.gitignore: add config.h.in qfcc.h: nuke PR_NameImmediate and change PR_ParseImmediate's prototype (see pr_imm.c) pr_comp.c: add ADD_S, adjust for PR_ParseImmediate's prototype, make PR_ParseExpression work with non-sequential opcodes (slow, will work on that next). Fix up initialised global parsing. pr_imm.c: nuke PR_NameImmediate. didn't work well and wasn't such a good idea anyway. PR_ParseImmediate now accepts a def_t * arg. if null, will allocate a new global def, otherwise it will initialize the def passed in. qwaq/main.c: sports some debugging code (dumps info about the progs it's running) qwaq/main.qc: better ADD_S testing
This commit is contained in:
parent
0ca5fc0c67
commit
09118bc01e
10 changed files with 73 additions and 60 deletions
|
@ -126,7 +126,9 @@ enum {
|
||||||
OP_OR,
|
OP_OR,
|
||||||
|
|
||||||
OP_BITAND,
|
OP_BITAND,
|
||||||
OP_BITOR
|
OP_BITOR,
|
||||||
|
|
||||||
|
OP_ADD_S,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,7 @@ typedef struct progs_s progs_t;
|
||||||
void PR_Init (void);
|
void PR_Init (void);
|
||||||
void PR_Init_Cvars (void);
|
void PR_Init_Cvars (void);
|
||||||
|
|
||||||
|
void PR_PrintStatement (progs_t * pr, dstatement_t *s);
|
||||||
void PR_ExecuteProgram (progs_t *pr, func_t fnum);
|
void PR_ExecuteProgram (progs_t *pr, func_t fnum);
|
||||||
void PR_LoadProgs (progs_t *pr, char *progsname);
|
void PR_LoadProgs (progs_t *pr, char *progsname);
|
||||||
void PR_LoadStrings (progs_t *pr);
|
void PR_LoadStrings (progs_t *pr);
|
||||||
|
|
|
@ -1158,6 +1158,7 @@ PR_LoadProgs (progs_t * pr, char *progsname)
|
||||||
case OP_DIV_F:
|
case OP_DIV_F:
|
||||||
case OP_BITAND:
|
case OP_BITAND:
|
||||||
case OP_BITOR:
|
case OP_BITOR:
|
||||||
|
case OP_ADD_S:
|
||||||
case OP_GE:
|
case OP_GE:
|
||||||
case OP_LE:
|
case OP_LE:
|
||||||
case OP_GT:
|
case OP_GT:
|
||||||
|
|
|
@ -38,11 +38,13 @@
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include "compat.h"
|
|
||||||
#include "QF/console.h"
|
#include "QF/console.h"
|
||||||
#include "QF/cvar.h"
|
#include "QF/cvar.h"
|
||||||
#include "QF/progs.h"
|
#include "QF/progs.h"
|
||||||
#include "QF/sys.h"
|
#include "QF/sys.h"
|
||||||
|
#include "QF/zone.h"
|
||||||
|
|
||||||
|
#include "compat.h"
|
||||||
|
|
||||||
char *pr_opnames[] = {
|
char *pr_opnames[] = {
|
||||||
"DONE",
|
"DONE",
|
||||||
|
@ -129,7 +131,9 @@ char *pr_opnames[] = {
|
||||||
"OR",
|
"OR",
|
||||||
|
|
||||||
"BITAND",
|
"BITAND",
|
||||||
"BITOR"
|
"BITOR",
|
||||||
|
|
||||||
|
"ADD_S",
|
||||||
};
|
};
|
||||||
|
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
|
@ -391,6 +395,18 @@ PR_ExecuteProgram (progs_t * pr, func_t fnum)
|
||||||
E_OPC->vector[1] = E_OPA->vector[1] + E_OPB->vector[1];
|
E_OPC->vector[1] = E_OPA->vector[1] + E_OPB->vector[1];
|
||||||
E_OPC->vector[2] = E_OPA->vector[2] + E_OPB->vector[2];
|
E_OPC->vector[2] = E_OPA->vector[2] + E_OPB->vector[2];
|
||||||
break;
|
break;
|
||||||
|
case OP_ADD_S:
|
||||||
|
{
|
||||||
|
char *a = PR_GetString (pr, E_OPA->string);
|
||||||
|
char *b = PR_GetString (pr, E_OPB->string);
|
||||||
|
int lena = strlen (a);
|
||||||
|
int size = lena + strlen (b) + 1;
|
||||||
|
char *c = Hunk_TempAlloc (size);
|
||||||
|
strcpy (c, a);
|
||||||
|
strcpy (c + lena, b);
|
||||||
|
E_OPC->string = PR_SetString (pr, c);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case OP_SUB_F:
|
case OP_SUB_F:
|
||||||
E_OPC->_float = E_OPA->_float - E_OPB->_float;
|
E_OPC->_float = E_OPA->_float - E_OPB->_float;
|
||||||
break;
|
break;
|
||||||
|
|
1
tools/qfcc/include/.gitignore
vendored
1
tools/qfcc/include/.gitignore
vendored
|
@ -1,3 +1,4 @@
|
||||||
|
config.h.in
|
||||||
stamp-h.in
|
stamp-h.in
|
||||||
Makefile.in
|
Makefile.in
|
||||||
Makefile
|
Makefile
|
||||||
|
|
|
@ -356,8 +356,7 @@ void PR_Lex (void);
|
||||||
|
|
||||||
type_t *PR_ParseType (void);
|
type_t *PR_ParseType (void);
|
||||||
char *PR_ParseName (void);
|
char *PR_ParseName (void);
|
||||||
def_t *PR_ParseImmediate (void);
|
def_t *PR_ParseImmediate (def_t *def);
|
||||||
void PR_NameImmediate (def_t *def);
|
|
||||||
|
|
||||||
qboolean PR_Check (token_type_t type, char *string);
|
qboolean PR_Check (token_type_t type, char *string);
|
||||||
void PR_Expect (token_type_t type, char *string);
|
void PR_Expect (token_type_t type, char *string);
|
||||||
|
|
|
@ -131,6 +131,8 @@ opcode_t pr_opcodes[] = {
|
||||||
{"&", "BITAND", 2, false, &def_float, &def_float, &def_float},
|
{"&", "BITAND", 2, false, &def_float, &def_float, &def_float},
|
||||||
{"|", "BITOR", 2, false, &def_float, &def_float, &def_float},
|
{"|", "BITOR", 2, false, &def_float, &def_float, &def_float},
|
||||||
|
|
||||||
|
{"+", "ADD_S", 3, false, &def_string, &def_string, &def_string},
|
||||||
|
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -340,7 +342,7 @@ PR_ParseValue (void)
|
||||||
|
|
||||||
// if the token is an immediate, allocate a constant for it
|
// if the token is an immediate, allocate a constant for it
|
||||||
if (pr_token_type == tt_immediate)
|
if (pr_token_type == tt_immediate)
|
||||||
return PR_ParseImmediate ();
|
return PR_ParseImmediate (0);
|
||||||
|
|
||||||
name = PR_ParseName ();
|
name = PR_ParseName ();
|
||||||
|
|
||||||
|
@ -446,9 +448,10 @@ PR_Expression (int priority)
|
||||||
oldop = op;
|
oldop = op;
|
||||||
while (type_a != op->type_a->type->type
|
while (type_a != op->type_a->type->type
|
||||||
|| type_b != op->type_b->type->type
|
|| type_b != op->type_b->type->type
|
||||||
|| (type_c != ev_void && type_c != op->type_c->type->type)) {
|
|| (type_c != ev_void && type_c != op->type_c->type->type)
|
||||||
|
|| strcmp (op->name, oldop->name)) {
|
||||||
op++;
|
op++;
|
||||||
if (!op->name || strcmp (op->name, oldop->name))
|
if (!op->name)// || strcmp (op->name, oldop->name))
|
||||||
PR_ParseError ("type mismatch for %s", oldop->name);
|
PR_ParseError ("type mismatch for %s", oldop->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -594,7 +597,7 @@ PR_ParseState (void)
|
||||||
if (pr_token_type != tt_immediate || pr_immediate_type != &type_float)
|
if (pr_token_type != tt_immediate || pr_immediate_type != &type_float)
|
||||||
PR_ParseError ("state frame must be a number");
|
PR_ParseError ("state frame must be a number");
|
||||||
|
|
||||||
s1 = PR_ParseImmediate ();
|
s1 = PR_ParseImmediate (0);
|
||||||
|
|
||||||
PR_Expect (tt_punct, ",");
|
PR_Expect (tt_punct, ",");
|
||||||
|
|
||||||
|
@ -727,11 +730,7 @@ PR_ParseDefs (void)
|
||||||
PR_ParseError ("wrong immediate type for %s", name);
|
PR_ParseError ("wrong immediate type for %s", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
def->initialized = 1;
|
def = PR_ParseImmediate (def);
|
||||||
memcpy (pr_globals + def->ofs, &pr_immediate,
|
|
||||||
4 * type_size[pr_immediate_type->type]);
|
|
||||||
PR_NameImmediate (def);
|
|
||||||
PR_Lex ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (PR_Check (tt_punct, ","));
|
} while (PR_Check (tt_punct, ","));
|
||||||
|
|
|
@ -60,7 +60,7 @@ vector_imm_get_key (void *_def, void *unused)
|
||||||
Looks for a preexisting constant
|
Looks for a preexisting constant
|
||||||
*/
|
*/
|
||||||
def_t *
|
def_t *
|
||||||
PR_ParseImmediate (void)
|
PR_ParseImmediate (def_t *def)
|
||||||
{
|
{
|
||||||
def_t *cn = 0;
|
def_t *cn = 0;
|
||||||
char rep[60];
|
char rep[60];
|
||||||
|
@ -100,13 +100,16 @@ PR_ParseImmediate (void)
|
||||||
|
|
||||||
// allocate a new one
|
// allocate a new one
|
||||||
// always share immediates
|
// always share immediates
|
||||||
|
if (def) {
|
||||||
|
cn = def;
|
||||||
|
} else {
|
||||||
cn = PR_NewDef (pr_immediate_type, "IMMEDIATE", 0);
|
cn = PR_NewDef (pr_immediate_type, "IMMEDIATE", 0);
|
||||||
cn->initialized = 1;
|
|
||||||
|
|
||||||
// copy the immediate to the global area
|
|
||||||
cn->ofs = numpr_globals;
|
cn->ofs = numpr_globals;
|
||||||
pr_global_defs[cn->ofs] = cn;
|
pr_global_defs[cn->ofs] = cn;
|
||||||
numpr_globals += type_size[pr_immediate_type->type];
|
numpr_globals += type_size[pr_immediate_type->type];
|
||||||
|
}
|
||||||
|
cn->initialized = 1;
|
||||||
|
// copy the immediate to the global area
|
||||||
if (pr_immediate_type == &type_string)
|
if (pr_immediate_type == &type_string)
|
||||||
pr_immediate.string = CopyString (pr_immediate_string);
|
pr_immediate.string = CopyString (pr_immediate_string);
|
||||||
|
|
||||||
|
@ -119,42 +122,3 @@ PR_ParseImmediate (void)
|
||||||
|
|
||||||
return cn;
|
return cn;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
PR_NameImmediate (def_t *def)
|
|
||||||
{
|
|
||||||
char rep[60];
|
|
||||||
def_t *cn;
|
|
||||||
hashtab_t *tab;
|
|
||||||
|
|
||||||
if (!string_imm_defs) {
|
|
||||||
string_imm_defs = Hash_NewTable (16381, string_imm_get_key, 0, 0);
|
|
||||||
float_imm_defs = Hash_NewTable (16381, float_imm_get_key, 0, 0);
|
|
||||||
vector_imm_defs = Hash_NewTable (16381, vector_imm_get_key, 0, 0);
|
|
||||||
}
|
|
||||||
if (def->type == &type_string) {
|
|
||||||
cn = Hash_Find (string_imm_defs, string_imm_get_key (def, 0));
|
|
||||||
tab = string_imm_defs;
|
|
||||||
} else if (def->type == &type_float) {
|
|
||||||
strcpy (rep, float_imm_get_key (def, 0));
|
|
||||||
cn = Hash_Find (float_imm_defs, rep);
|
|
||||||
tab = float_imm_defs;
|
|
||||||
} else if (def->type == &type_vector) {
|
|
||||||
strcpy (rep, vector_imm_get_key (def, 0));
|
|
||||||
cn = Hash_Find (vector_imm_defs, rep);
|
|
||||||
tab = vector_imm_defs;
|
|
||||||
} else {
|
|
||||||
PR_ParseError ("weird immediate type");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
if (cn) {
|
|
||||||
if (strcmp (cn->name, "IMMEDIATE") != 0) {
|
|
||||||
free cn->name;
|
|
||||||
cn->name = strdup (def->name);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
Hash_Add (tab, def);
|
|
||||||
}
|
|
||||||
|
|
|
@ -12,12 +12,15 @@ int memsize = 16*1024*1024;
|
||||||
|
|
||||||
void BI_Init (progs_t *progs);
|
void BI_Init (progs_t *progs);
|
||||||
|
|
||||||
|
extern char *type_name[];
|
||||||
|
|
||||||
int
|
int
|
||||||
main ()
|
main ()
|
||||||
{
|
{
|
||||||
func_t main_func;
|
func_t main_func;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
int len;
|
int len;
|
||||||
|
int i;
|
||||||
|
|
||||||
Cvar_Init_Hash ();
|
Cvar_Init_Hash ();
|
||||||
Cmd_Init_Hash ();
|
Cmd_Init_Hash ();
|
||||||
|
@ -44,6 +47,31 @@ main ()
|
||||||
}
|
}
|
||||||
if (!progs.progs)
|
if (!progs.progs)
|
||||||
Sys_Error ("couldn't load %s\n", "qwaq.dat");
|
Sys_Error ("couldn't load %s\n", "qwaq.dat");
|
||||||
|
for (i = 0; i < progs.progs->numstatements; i++)
|
||||||
|
PR_PrintStatement (&progs, &progs.pr_statements[i]);
|
||||||
|
printf ("\n");
|
||||||
|
for (i = 0; i < progs.progs->numfunctions; i++) {
|
||||||
|
dfunction_t *func = &progs.pr_functions[i];
|
||||||
|
int j;
|
||||||
|
|
||||||
|
printf ("%d %d %d %d %s %s %d", func->first_statement, func->parm_start, func->locals, func->profile, PR_GetString (&progs, func->s_name), PR_GetString (&progs, func->s_file), func->numparms);
|
||||||
|
for (j = 0; j < func->numparms; j++)
|
||||||
|
printf (" %d", func->parm_size[j]);
|
||||||
|
printf ("\n");
|
||||||
|
}
|
||||||
|
printf ("\n");
|
||||||
|
for (i = 0; i < progs.progs->numglobaldefs; i++) {
|
||||||
|
ddef_t *def = &progs.pr_globaldefs[i];
|
||||||
|
|
||||||
|
printf ("%s %d %d %s\n", type_name[def->type & ~DEF_SAVEGLOBAL], (def->type & DEF_SAVEGLOBAL) != 0, def->ofs, PR_GetString (&progs, def->s_name));
|
||||||
|
}
|
||||||
|
printf ("\n");
|
||||||
|
for (i = 0; i < progs.progs->numfielddefs; i++) {
|
||||||
|
ddef_t *def = &progs.pr_fielddefs[i];
|
||||||
|
|
||||||
|
printf ("%s %d %d %s\n", type_name[def->type & ~DEF_SAVEGLOBAL], (def->type & DEF_SAVEGLOBAL) != 0, def->ofs, PR_GetString (&progs, def->s_name));
|
||||||
|
}
|
||||||
|
printf ("\n");
|
||||||
main_func = PR_GetFunctionIndex (&progs, "main");
|
main_func = PR_GetFunctionIndex (&progs, "main");
|
||||||
PR_ExecuteProgram (&progs, main_func);
|
PR_ExecuteProgram (&progs, main_func);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
|
string hello = "hello";
|
||||||
|
string world = "world";
|
||||||
float () main =
|
float () main =
|
||||||
{
|
{
|
||||||
print ("hello world\n");
|
print (hello + " " + world + "\n");
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue