stand alone qc interpreter. So I'm on some serious qwaq :) (actuallly, its

main purpose is language extention testing)
This commit is contained in:
Bill Currie 2001-06-01 21:57:59 +00:00
parent e699f6e888
commit 8a23ae0a48
7 changed files with 131 additions and 0 deletions

7
tools/qwaq/.gitignore vendored Normal file
View file

@ -0,0 +1,7 @@
*.la
*.lo
.deps
.libs
.vimrc
Makefile
Makefile.in

26
tools/qwaq/Makefile Normal file
View file

@ -0,0 +1,26 @@
EXE=qctest
MAKEDEPS=$(CC) -MM $(CPPFLAGS) $< | sed -e 's/$*\.o:*/$*\.o $@:/g' > $@
CFLAGS+=-Wall -Werror -g -O2
CPPFLAGS+=
LIBS=
vpath %.a
SRC=main.c builtins.c
%.d: %.c
$(MAKEDEPS)
OBJ=$(patsubst %,%.o,$(basename $(SRC)))
DEP=$(patsubst %.o,%.d,$(OBJ))
all: $(EXE)
$(EXE): $(OBJ) $(LIBS)
$(CC) $(LDFLAGS) -o $@ $^ -lQFgamecode -lQFutil
clean:
rm -f $(EXE) *.o *.d core *.dat progdefs.h
-include $(DEP)

31
tools/qwaq/builtins.c Normal file
View file

@ -0,0 +1,31 @@
#include <QF/progs.h>
#define RETURN_EDICT(p, e) ((p)->pr_globals[OFS_RETURN].int_var = EDICT_TO_PROG(p, e))
#define RETURN_STRING(p, s) ((p)->pr_globals[OFS_RETURN].int_var = PR_SetString((p), s))
void
bi_fixme (progs_t *pr)
{
PR_Error (pr, "unimplemented function\n");
}
void
bi_print (progs_t *pr)
{
char *str;
str = G_STRING (pr, (OFS_PARM0));
fprintf (stdout, "%s", str);
}
builtin_t builtins[] = {
bi_fixme,
bi_print,
};
void
BI_Init (progs_t *progs)
{
progs->builtins = builtins;
progs->numbuiltins = sizeof (builtins) / sizeof (builtins[0]);
}

8
tools/qwaq/defs.qc Normal file
View file

@ -0,0 +1,8 @@
void (string str) print = #1;
float time;
entity self;
.float nextthink;
.float think;
.float frame;

50
tools/qwaq/main.c Normal file
View file

@ -0,0 +1,50 @@
#include <stdlib.h>
#include <QF/cmd.h>
#include <QF/cvar.h>
#include <QF/progs.h>
#include <QF/sys.h>
#include <QF/zone.h>
progs_t progs;
void *membase;
int memsize = 16*1024*1024;
void BI_Init (progs_t *progs);
int
main ()
{
func_t main_func;
FILE *f;
int len;
Cvar_Init_Hash ();
Cmd_Init_Hash ();
membase = malloc (memsize);
Memory_Init (membase, memsize);
Cvar_Init ();
Cbuf_Init ();
Cmd_Init ();
PR_Init_Cvars ();
PR_Init ();
BI_Init (&progs);
f = fopen ("qctest.dat", "rb");
if (f) {
fseek (f, 0, SEEK_END);
len = ftell (f);
fseek (f, 0, SEEK_SET);
progs.progs = Hunk_AllocName (len, "qctest.dat");
fread (progs.progs, 1, len, f);
fclose (f);
if (progs.progs)
PR_LoadProgs (&progs, 0);
}
if (!progs.progs)
Sys_Error ("couldn't load %s\n", "qctest.dat");
main_func = PR_GetFunctionIndex (&progs, "main");
PR_ExecuteProgram (&progs, main_func);
return 0;
}

4
tools/qwaq/main.qc Normal file
View file

@ -0,0 +1,4 @@
float () main =
{
print ("hello world\n");
};

5
tools/qwaq/progs.src Normal file
View file

@ -0,0 +1,5 @@
qctest.dat
defs.qc
main.qc