mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
start working in the obj runtime. any and all functions named ".ctor" will
be run in the order found.
This commit is contained in:
parent
9f06f89d57
commit
9820c5d45a
5 changed files with 207 additions and 2 deletions
|
@ -136,6 +136,7 @@ int NUM_FOR_BAD_EDICT(progs_t *pr, edict_t *e);
|
|||
#define G_VECTOR(p,o) G_var (p, o, vector)
|
||||
#define G_STRING(p,o) PR_GetString (p, G_var (p, o, string))
|
||||
#define G_FUNCTION(p,o) G_var (p, o, func)
|
||||
#define G_STRUCT(p,t,o) (*(t *)&(p)->pr_globals[o])
|
||||
|
||||
#define RETURN_STRING(p, s) ((p)->pr_globals[OFS_RETURN].integer_var = PR_SetString((p), s))
|
||||
#define RETURN_EDICT(p, e) ((p)->pr_globals[OFS_RETURN].integer_var = EDICT_TO_PROG(p, e))
|
||||
|
@ -181,6 +182,12 @@ builtin_t *PR_FindBuiltin (progs_t *pr, const char *name);
|
|||
int PR_RelocateBuiltins (progs_t *pr);
|
||||
int PR_ResolveGlobals (progs_t *pr);
|
||||
|
||||
//
|
||||
// PR Obj stuff
|
||||
//
|
||||
void PR_Obj_Progs_Init (progs_t *pr);
|
||||
void PR_InitRuntime (progs_t *pr);
|
||||
|
||||
//
|
||||
// PR Strings stuff
|
||||
//
|
||||
|
@ -322,6 +329,11 @@ struct progs_s {
|
|||
pr_resource_t *resources;
|
||||
struct hashtab_s *resource_hash;
|
||||
|
||||
// obj info
|
||||
struct hashtab_s *classes;
|
||||
struct hashtab_s *categories;
|
||||
struct hashtab_s *protocols;
|
||||
|
||||
// debug info
|
||||
char *debugfile;
|
||||
struct pr_debug_header_s *debug;
|
||||
|
|
|
@ -378,6 +378,8 @@ Menu_Init (void)
|
|||
PR_AddBuiltin (&menu_pr_state, "Menu_Quit", bi_Menu_Quit, -1);
|
||||
PR_AddBuiltin (&menu_pr_state, "Menu_GetIndex", bi_Menu_GetIndex, -1);
|
||||
|
||||
PR_Obj_Progs_Init (&menu_pr_state);
|
||||
|
||||
Cbuf_Progs_Init (&menu_pr_state);
|
||||
Cmd_Progs_Init (&menu_pr_state);
|
||||
Cvar_Progs_Init (&menu_pr_state);
|
||||
|
@ -432,6 +434,7 @@ Menu_Load (void)
|
|||
Con_SetOrMask (0x00);
|
||||
return;
|
||||
}
|
||||
PR_InitRuntime (&menu_pr_state);
|
||||
PR_ExecuteProgram (&menu_pr_state, menu_init);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,5 +6,5 @@ lib_LTLIBRARIES= libQFgamecode.la
|
|||
|
||||
libQFgamecode_la_LDFLAGS= -version-info 1:0:0
|
||||
libQFgamecode_la_SOURCES= \
|
||||
pr_builtins.c pr_edict.c pr_debug.c pr_exec.c pr_load.c pr_opcode.c \
|
||||
pr_resolve.c pr_resource.c pr_strings.c pr_zone.c
|
||||
pr_builtins.c pr_edict.c pr_debug.c pr_exec.c pr_load.c pr_obj.c \
|
||||
pr_opcode.c pr_resolve.c pr_resource.c pr_strings.c pr_zone.c
|
||||
|
|
|
@ -271,6 +271,8 @@ PR_LoadProgs (progs_t *pr, const char *progsname, int edicts, int zone)
|
|||
PR_LoadDebug (pr);
|
||||
|
||||
PR_Check_Opcodes (pr);
|
||||
|
||||
PR_InitRuntime (pr);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
188
libs/gamecode/engine/pr_obj.c
Normal file
188
libs/gamecode/engine/pr_obj.c
Normal file
|
@ -0,0 +1,188 @@
|
|||
/*
|
||||
pr_obj.c
|
||||
|
||||
Progs Obj runtime support
|
||||
|
||||
Copyright (C) 2001 Bill Currie
|
||||
|
||||
Author: Bill Currie <bill@taniwha.org>
|
||||
Date: 2002/7/21
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to:
|
||||
|
||||
Free Software Foundation, Inc.
|
||||
59 Temple Place - Suite 330
|
||||
Boston, MA 02111-1307, USA
|
||||
|
||||
*/
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include "QF/cvar.h"
|
||||
#include "QF/hash.h"
|
||||
#include "QF/pr_obj.h"
|
||||
#include "QF/progs.h"
|
||||
#include "QF/sys.h"
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
static const char *
|
||||
class_get_key (void *c, void *pr)
|
||||
{
|
||||
return PR_GetString ((progs_t *)pr, ((pr_class_t *)c)->name);
|
||||
}
|
||||
|
||||
static void
|
||||
pr_obj_msgSend (progs_t *pr)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
pr_obj_msgSend_super (progs_t *pr)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
dump_ivars (progs_t *pr, pointer_t _ivars)
|
||||
{
|
||||
pr_ivar_list_t *ivars;
|
||||
int i;
|
||||
|
||||
if (!_ivars)
|
||||
return;
|
||||
ivars = &G_STRUCT (pr, pr_ivar_list_t, _ivars);
|
||||
for (i = 0; i < ivars->ivar_count; i++) {
|
||||
Sys_Printf (" %s %s %d\n",
|
||||
PR_GetString (pr, ivars->ivar_list[i].ivar_name),
|
||||
PR_GetString (pr, ivars->ivar_list[i].ivar_type),
|
||||
ivars->ivar_list[i].ivar_offset);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pr___obj_exec_class (progs_t *pr)
|
||||
{
|
||||
pr_module_t *module;
|
||||
pr_symtab_t *symtab;
|
||||
pointer_t *ptr;
|
||||
int i;
|
||||
//int d = developer->int_val;
|
||||
pr_class_t *object_class;
|
||||
pointer_t object_ptr;
|
||||
|
||||
if (!G_INT (pr, OFS_PARM0))
|
||||
return;
|
||||
module = &G_STRUCT (pr, pr_module_t, G_INT (pr, OFS_PARM0));
|
||||
if (!module->symtab)
|
||||
return;
|
||||
//developer->int_val = 1;
|
||||
symtab = &G_STRUCT (pr, pr_symtab_t, module->symtab);
|
||||
Sys_DPrintf ("Initializing %s module with %d classes and %d categories\n",
|
||||
PR_GetString (pr, module->name),
|
||||
symtab->cls_def_cnt, symtab->cat_def_cnt);
|
||||
ptr = symtab->defs;
|
||||
for (i = 0; i < symtab->cls_def_cnt; i++) {
|
||||
pr_class_t *class = &G_STRUCT (pr, pr_class_t, *ptr);
|
||||
pr_class_t *meta = &G_STRUCT (pr, pr_class_t, class->class_pointer);
|
||||
Sys_DPrintf ("Class %s @ %d\n", PR_GetString (pr, class->name), *ptr);
|
||||
Sys_DPrintf (" class pointer: %d\n", class->class_pointer);
|
||||
Sys_DPrintf (" super class: %s\n",
|
||||
PR_GetString (pr, class->super_class));
|
||||
Sys_DPrintf (" instance variables: %d @ %d\n", class->instance_size,
|
||||
class->ivars);
|
||||
if (developer->int_val)
|
||||
dump_ivars (pr, class->ivars);
|
||||
Sys_DPrintf (" instance methods: %d\n", class->methods);
|
||||
Sys_DPrintf (" protocols: %d\n", class->protocols);
|
||||
|
||||
Sys_DPrintf (" class methods: %d\n", meta->methods);
|
||||
Sys_DPrintf (" instance variables: %d @ %d\n", meta->instance_size,
|
||||
meta->ivars);
|
||||
if (developer->int_val)
|
||||
dump_ivars (pr, meta->ivars);
|
||||
|
||||
Hash_Add (pr->classes, class);
|
||||
ptr++;
|
||||
}
|
||||
for (i = 0; i < symtab->cat_def_cnt; i++) {
|
||||
pr_category_t *category = &G_STRUCT (pr, pr_category_t, *ptr);
|
||||
Sys_DPrintf ("Category %s (%s) @ %d\n",
|
||||
PR_GetString (pr, category->class_name),
|
||||
PR_GetString (pr, category->category_name), *ptr);
|
||||
Sys_DPrintf (" instance methods: %d\n", category->instance_methods);
|
||||
Sys_DPrintf (" class methods: %d\n", category->class_methods);
|
||||
Sys_DPrintf (" protocols: %d\n", category->protocols);
|
||||
ptr++;
|
||||
}
|
||||
|
||||
object_class = Hash_Find (pr->classes, "Object");
|
||||
if (object_class && !object_class->super_class)
|
||||
object_ptr = (pr_type_t *)object_class - pr->pr_globals;
|
||||
else
|
||||
PR_Error (pr, "root class Object not found");
|
||||
|
||||
ptr = symtab->defs;
|
||||
for (i = 0; i < symtab->cls_def_cnt; i++) {
|
||||
pr_class_t *class = &G_STRUCT (pr, pr_class_t, *ptr);
|
||||
pr_class_t *meta = &G_STRUCT (pr, pr_class_t, class->class_pointer);
|
||||
pr_type_t *val;
|
||||
|
||||
meta->class_pointer = object_ptr;
|
||||
if (class->super_class) {
|
||||
val = Hash_Find (pr->classes, PR_GetString (pr,
|
||||
class->super_class));
|
||||
meta->super_class = class->super_class = val - pr->pr_globals;
|
||||
}
|
||||
Sys_DPrintf (" %d %d %d\n", meta->class_pointer, meta->super_class,
|
||||
class->super_class);
|
||||
|
||||
ptr++;
|
||||
}
|
||||
for (i = 0; i < symtab->cat_def_cnt; i++) {
|
||||
//pr_category_t *category = &G_STRUCT (pr, pr_category_t, *ptr);
|
||||
ptr++;
|
||||
}
|
||||
|
||||
//developer->int_val = d;
|
||||
}
|
||||
|
||||
void
|
||||
PR_Obj_Progs_Init (progs_t *pr)
|
||||
{
|
||||
PR_AddBuiltin (pr, "obj_msgSend", pr_obj_msgSend, -1);
|
||||
PR_AddBuiltin (pr, "obj_msgSend_super", pr_obj_msgSend_super, -1);
|
||||
PR_AddBuiltin (pr, "__obj_exec_class", pr___obj_exec_class, -1);
|
||||
}
|
||||
|
||||
void
|
||||
PR_InitRuntime (progs_t *pr)
|
||||
{
|
||||
int fnum;
|
||||
|
||||
if (!pr->classes)
|
||||
pr->classes = Hash_NewTable (1021, class_get_key, 0, pr);
|
||||
else
|
||||
Hash_FlushTable (pr->classes);
|
||||
for (fnum = 0; fnum < pr->progs->numfunctions; fnum++) {
|
||||
if (strequal (PR_GetString (pr, pr->pr_functions[fnum].s_name),
|
||||
".ctor")) {
|
||||
PR_ExecuteProgram (pr, fnum);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue