diff --git a/include/QF/pr_comp.h b/include/QF/pr_comp.h index f4d8c077b..aa66e5f6a 100644 --- a/include/QF/pr_comp.h +++ b/include/QF/pr_comp.h @@ -126,7 +126,9 @@ enum { OP_OR, OP_BITAND, - OP_BITOR + OP_BITOR, + + OP_ADD_S, }; diff --git a/include/QF/progs.h b/include/QF/progs.h index 5382ffe36..8b058c027 100644 --- a/include/QF/progs.h +++ b/include/QF/progs.h @@ -77,6 +77,7 @@ typedef struct progs_s progs_t; void PR_Init (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_LoadProgs (progs_t *pr, char *progsname); void PR_LoadStrings (progs_t *pr); diff --git a/libs/gamecode/pr_edict.c b/libs/gamecode/pr_edict.c index d56bc259a..f1a4c56b1 100644 --- a/libs/gamecode/pr_edict.c +++ b/libs/gamecode/pr_edict.c @@ -1158,6 +1158,7 @@ PR_LoadProgs (progs_t * pr, char *progsname) case OP_DIV_F: case OP_BITAND: case OP_BITOR: + case OP_ADD_S: case OP_GE: case OP_LE: case OP_GT: diff --git a/libs/gamecode/pr_exec.c b/libs/gamecode/pr_exec.c index 60857d97f..075e054c3 100644 --- a/libs/gamecode/pr_exec.c +++ b/libs/gamecode/pr_exec.c @@ -38,11 +38,13 @@ #include -#include "compat.h" #include "QF/console.h" #include "QF/cvar.h" #include "QF/progs.h" #include "QF/sys.h" +#include "QF/zone.h" + +#include "compat.h" char *pr_opnames[] = { "DONE", @@ -129,7 +131,9 @@ char *pr_opnames[] = { "OR", "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[2] = E_OPA->vector[2] + E_OPB->vector[2]; 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: E_OPC->_float = E_OPA->_float - E_OPB->_float; break; diff --git a/tools/qfcc/include/.gitignore b/tools/qfcc/include/.gitignore index 6e00d28a1..06f852dd4 100644 --- a/tools/qfcc/include/.gitignore +++ b/tools/qfcc/include/.gitignore @@ -1,3 +1,4 @@ +config.h.in stamp-h.in Makefile.in Makefile diff --git a/tools/qfcc/include/qfcc.h b/tools/qfcc/include/qfcc.h index 1726aef9a..731e16cbc 100644 --- a/tools/qfcc/include/qfcc.h +++ b/tools/qfcc/include/qfcc.h @@ -356,8 +356,7 @@ void PR_Lex (void); type_t *PR_ParseType (void); char *PR_ParseName (void); -def_t *PR_ParseImmediate (void); -void PR_NameImmediate (def_t *def); +def_t *PR_ParseImmediate (def_t *def); qboolean PR_Check (token_type_t type, char *string); void PR_Expect (token_type_t type, char *string); diff --git a/tools/qfcc/source/pr_comp.c b/tools/qfcc/source/pr_comp.c index 166960177..0c813b5c2 100644 --- a/tools/qfcc/source/pr_comp.c +++ b/tools/qfcc/source/pr_comp.c @@ -131,6 +131,8 @@ opcode_t pr_opcodes[] = { {"&", "BITAND", 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} }; @@ -340,7 +342,7 @@ PR_ParseValue (void) // if the token is an immediate, allocate a constant for it if (pr_token_type == tt_immediate) - return PR_ParseImmediate (); + return PR_ParseImmediate (0); name = PR_ParseName (); @@ -446,9 +448,10 @@ PR_Expression (int priority) oldop = op; while (type_a != op->type_a->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++; - if (!op->name || strcmp (op->name, oldop->name)) + if (!op->name)// || strcmp (op->name, 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) PR_ParseError ("state frame must be a number"); - s1 = PR_ParseImmediate (); + s1 = PR_ParseImmediate (0); PR_Expect (tt_punct, ","); @@ -727,11 +730,7 @@ PR_ParseDefs (void) PR_ParseError ("wrong immediate type for %s", name); } - def->initialized = 1; - memcpy (pr_globals + def->ofs, &pr_immediate, - 4 * type_size[pr_immediate_type->type]); - PR_NameImmediate (def); - PR_Lex (); + def = PR_ParseImmediate (def); } } while (PR_Check (tt_punct, ",")); diff --git a/tools/qfcc/source/pr_imm.c b/tools/qfcc/source/pr_imm.c index 943497d3c..a05e4f01f 100644 --- a/tools/qfcc/source/pr_imm.c +++ b/tools/qfcc/source/pr_imm.c @@ -60,7 +60,7 @@ vector_imm_get_key (void *_def, void *unused) Looks for a preexisting constant */ def_t * -PR_ParseImmediate (void) +PR_ParseImmediate (def_t *def) { def_t *cn = 0; char rep[60]; @@ -100,13 +100,16 @@ PR_ParseImmediate (void) // allocate a new one // always share immediates - cn = PR_NewDef (pr_immediate_type, "IMMEDIATE", 0); + if (def) { + cn = def; + } else { + cn = PR_NewDef (pr_immediate_type, "IMMEDIATE", 0); + cn->ofs = numpr_globals; + pr_global_defs[cn->ofs] = cn; + numpr_globals += type_size[pr_immediate_type->type]; + } cn->initialized = 1; - // copy the immediate to the global area - cn->ofs = numpr_globals; - pr_global_defs[cn->ofs] = cn; - numpr_globals += type_size[pr_immediate_type->type]; if (pr_immediate_type == &type_string) pr_immediate.string = CopyString (pr_immediate_string); @@ -119,42 +122,3 @@ PR_ParseImmediate (void) 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); -} diff --git a/tools/qwaq/main.c b/tools/qwaq/main.c index 1bf75c692..08d20a32e 100644 --- a/tools/qwaq/main.c +++ b/tools/qwaq/main.c @@ -12,12 +12,15 @@ int memsize = 16*1024*1024; void BI_Init (progs_t *progs); +extern char *type_name[]; + int main () { func_t main_func; FILE *f; int len; + int i; Cvar_Init_Hash (); Cmd_Init_Hash (); @@ -44,6 +47,31 @@ main () } if (!progs.progs) 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"); PR_ExecuteProgram (&progs, main_func); return 0; diff --git a/tools/qwaq/main.qc b/tools/qwaq/main.qc index e010b3c76..f2bca7e49 100644 --- a/tools/qwaq/main.qc +++ b/tools/qwaq/main.qc @@ -1,4 +1,6 @@ +string hello = "hello"; +string world = "world"; float () main = { - print ("hello world\n"); + print (hello + " " + world + "\n"); };