pr_obj.h: add the structure for static instances rua_obj.c: add support for +initialize test.r: add some test code for +initialize main.c: don't need to initialize the hunk any more and fix a buffer overflow

This is an imperfect revision of history.
This commit is contained in:
Bill Currie 2004-11-02 05:12:00 +00:00 committed by Jeff Teunissen
parent 96b65ba63c
commit 8e2f392d2d
4 changed files with 65 additions and 10 deletions

View file

@ -145,6 +145,14 @@ typedef struct pr_ivar_list_s {
} pr_ivar_list_t;
typedef struct pr_ivar_s pr_ivar_t;
typedef struct pr_static_instances_s {
// one per staticly instanced class per module (eg, 3 instances of Object
// will produce one of these structs with 3 pointers to those instances in
// instances[]
string_t class_name;
pointer_t instances[1]; // null terminated array of pr_id_t
} pr_static_instances_t;
typedef struct pr_symtab_s {
int sel_ref_cnt;
pointer_t refs; // pr_sel_t

View file

@ -298,7 +298,53 @@ obj_find_message (progs_t *pr, pr_class_t *class, pr_sel_t *selector)
return 0;
}
static pr_method_t *
static void
obj_send_initialize (progs_t *pr, pr_class_t *class)
{
pr_method_list_t *method_list;
pr_method_t *method;
pr_sel_t *sel;
pr_class_t *class_pointer;
pr_sel_t *selector = sel_register_name (pr, "initialize");
int i;
if (PR_CLS_ISINITIALIZED (class))
return;
class_pointer = &G_STRUCT (pr, pr_class_t, class->class_pointer);
PR_CLS_SETINITIALIZED (class);
PR_CLS_SETINITIALIZED (class_pointer);
if (class->super_class)
obj_send_initialize (pr, &G_STRUCT (pr, pr_class_t,
class->super_class));
method_list = &G_STRUCT (pr, pr_method_list_t, class_pointer->methods);
while (method_list) {
for (i = 0, method = method_list->method_list;
i < method_list->method_count; i++, method++) {
sel = &G_STRUCT (pr, pr_sel_t, method->method_name);
if (sel->sel_id == selector->sel_id) {
int size = pr->pr_param_size * MAX_PARMS;
pr_type_t *params = alloca (size * sizeof (pr_type_t));
memcpy (params, *pr->pr_params, size * sizeof (pr_type_t));
PR_ExecuteProgram (pr, method->method_imp);
memcpy (*pr->pr_params, params, size * sizeof (pr_type_t));
return;
}
}
method_list = &G_STRUCT (pr, pr_method_list_t,
method_list->method_next);
}
}
static func_t
get_imp (progs_t *pr, pr_class_t *class, pr_sel_t *sel)
{
pr_method_t *method = obj_find_message (pr, class, sel);
return method ? method->method_imp : 0;
}
static func_t
obj_msg_lookup (progs_t *pr, pr_id_t *receiver, pr_sel_t *op)
{
pr_class_t *class;
@ -308,7 +354,7 @@ obj_msg_lookup (progs_t *pr, pr_id_t *receiver, pr_sel_t *op)
return obj_find_message (pr, class, op);
}
static pr_method_t *
static func_t
obj_msg_lookup_super (progs_t *pr, pr_super_t *super, pr_sel_t *op)
{
pr_class_t *class;
@ -317,7 +363,7 @@ obj_msg_lookup_super (progs_t *pr, pr_super_t *super, pr_sel_t *op)
return 0;
class = &G_STRUCT (pr, pr_class_t, super->class);
return obj_find_message (pr, class, op);
return get_imp (pr, class, op);
}
static void

View file

@ -53,8 +53,6 @@ static edict_t *edicts;
static int num_edicts;
static int reserved_edicts;
static progs_t pr;
static void *membase;
static int memsize = 16*1024*1024;
static QFile *
open_file (const char *path, int *len)
@ -74,7 +72,7 @@ load_file (progs_t *pr, const char *name)
{
QFile *file;
int size;
void *sym;
char *sym;
file = open_file (name, &size);
if (!file) {
@ -83,7 +81,8 @@ load_file (progs_t *pr, const char *name)
return 0;
}
}
sym = malloc (size);
sym = malloc (size + 1);
sym[size] = 0;
Qread (file, sym, size);
return sym;
}
@ -109,9 +108,6 @@ init_qf (void)
Sys_Init_Cvars ();
Cmd_Init ();
membase = malloc (memsize);
Memory_Init (membase, memsize);
Cvar_Get ("pr_debug", "1", 0, 0, 0);
Cvar_Get ("pr_boundscheck", "0", 0, 0, 0);

View file

@ -5,6 +5,11 @@
@implementation Foo
+ (void) initialize
{
print ("+initialize\n");
}
-run
{
print ("Hello world\n");