diff --git a/include/QF/pr_obj.h b/include/QF/pr_obj.h index 243892d6b..e6b431057 100644 --- a/include/QF/pr_obj.h +++ b/include/QF/pr_obj.h @@ -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 diff --git a/libs/ruamoko/rua_obj.c b/libs/ruamoko/rua_obj.c index b8067c631..8c9862569 100644 --- a/libs/ruamoko/rua_obj.c +++ b/libs/ruamoko/rua_obj.c @@ -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 diff --git a/tools/qwaq/main.c b/tools/qwaq/main.c index 2e11b9c6a..5ace4d7f9 100644 --- a/tools/qwaq/main.c +++ b/tools/qwaq/main.c @@ -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); diff --git a/tools/qwaq/test.r b/tools/qwaq/test.r index ad343c37e..44b420ddd 100644 --- a/tools/qwaq/test.r +++ b/tools/qwaq/test.r @@ -5,6 +5,11 @@ @implementation Foo ++ (void) initialize +{ + print ("+initialize\n"); +} + -run { print ("Hello world\n");