diff --git a/configure.ac b/configure.ac index 067cd723c..350325963 100644 --- a/configure.ac +++ b/configure.ac @@ -2033,7 +2033,7 @@ QF_DEPS(QFPROGS, ) QF_DEPS(QWAQ, [], - [$(top_builddir)/libs/gamecode/engine/libQFgamecode.la $(top_builddir)/libs/util/libQFutil.la], + [$(top_builddir)/libs/ruamoko/libQFruamoko.la $(top_builddir)/libs/gamecode/engine/libQFgamecode.la $(top_builddir)/libs/util/libQFutil.la], [$(WIN32_LIBS)], ) QF_DEPS(CARNE, diff --git a/include/QF/progs.h b/include/QF/progs.h index 3a6f4210d..f4078dc8a 100644 --- a/include/QF/progs.h +++ b/include/QF/progs.h @@ -235,14 +235,9 @@ int PR_ResolveGlobals (progs_t *pr); typedef int pr_load_func_t (progs_t *); void PR_AddLoadFunc (progs_t *pr, pr_load_func_t *func); +void PR_AddLoadFinishFunc (progs_t *pr, pr_load_func_t *func); int PR_RunLoadFuncs (progs_t *pr); -// -// PR Obj stuff -// -void PR_Obj_Progs_Init (progs_t *pr); -int PR_InitRuntime (progs_t *pr); - // // PR Strings stuff // @@ -346,6 +341,11 @@ struct progs_s { int max_load_funcs; pr_load_func_t **load_funcs; + // cleared each load + int num_load_finish_funcs; + int max_load_finish_funcs; + pr_load_func_t **load_finish_funcs; + struct dstring_mem_s *ds_mem; strref_t *free_string_refs; strref_t *static_strings; diff --git a/include/rua_internal.h b/include/rua_internal.h index 3e2055b21..4be1f0a4f 100644 --- a/include/rua_internal.h +++ b/include/rua_internal.h @@ -48,6 +48,8 @@ void RUA_File_Init (struct progs_s *pr, int secure); void RUA_Hash_Init (struct progs_s *pr, int secure); +void RUA_Obj_Init (struct progs_s *pr, int secure); + void RUA_Plist_Init (struct progs_s *pr, int secure); void RUA_String_Init (struct progs_s *pr, int secure); diff --git a/libs/console/menu.c b/libs/console/menu.c index 93699c398..9e9816a37 100644 --- a/libs/console/menu.c +++ b/libs/console/menu.c @@ -449,8 +449,6 @@ Menu_Init (void) PR_RegisterBuiltins (&menu_pr_state, builtins); - PR_Obj_Progs_Init (&menu_pr_state); - RUA_Init (&menu_pr_state, 1); InputLine_Progs_Init (&menu_pr_state); diff --git a/libs/gamecode/engine/Makefile.am b/libs/gamecode/engine/Makefile.am index ce2b634de..6c7559fa4 100644 --- a/libs/gamecode/engine/Makefile.am +++ b/libs/gamecode/engine/Makefile.am @@ -8,4 +8,4 @@ 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_parse.c \ - pr_obj.c pr_opcode.c pr_resolve.c pr_resource.c pr_strings.c pr_zone.c + pr_opcode.c pr_resolve.c pr_resource.c pr_strings.c pr_zone.c diff --git a/libs/gamecode/engine/pr_load.c b/libs/gamecode/engine/pr_load.c index 37036df69..92268e0e8 100644 --- a/libs/gamecode/engine/pr_load.c +++ b/libs/gamecode/engine/pr_load.c @@ -280,6 +280,20 @@ PR_AddLoadFunc (progs_t *pr, int (*func)(progs_t *)) pr->load_funcs[pr->num_load_funcs++] = func; } +void +PR_AddLoadFinishFunc (progs_t *pr, int (*func)(progs_t *)) +{ + if (pr->num_load_finish_funcs == pr->max_load_finish_funcs) { + int n; + pr->max_load_finish_funcs += 8; + n = pr->max_load_finish_funcs; + pr->load_finish_funcs = realloc (pr->load_finish_funcs, + n * sizeof (pr_load_func_t *)); + SYS_CHECKMEM (pr->load_finish_funcs); + } + pr->load_finish_funcs[pr->num_load_finish_funcs++] = func; +} + static int (*load_funcs[])(progs_t *) = { PR_RelocateBuiltins, PR_ResolveGlobals, @@ -288,19 +302,41 @@ static int (*load_funcs[])(progs_t *) = { PR_LoadDebug, }; +static int +pr_run_ctors (progs_t *pr) +{ + int fnum; + dfunction_t *func; + + for (fnum = 0; fnum < pr->progs->numfunctions; fnum++) { + func = pr->pr_functions + fnum; + if (strequal (PR_GetString (pr, func->s_name), ".ctor")) + PR_ExecuteProgram (pr, fnum); + } + return 1; +} + int PR_RunLoadFuncs (progs_t *pr) { int i; for (i = 0; i < sizeof (load_funcs) / sizeof (load_funcs[0]); i++) - if (!load_funcs[i](pr)) + if (!load_funcs[i] (pr)) return 0; for (i = 0; i < pr->num_load_funcs; i++) - if (!pr->load_funcs[i](pr)) + if (!pr->load_funcs[i] (pr)) return 0; - return PR_InitRuntime (pr); + + if (!pr_run_ctors (pr)) + return 0; + + while (pr->num_load_finish_funcs) + if (!pr->load_finish_funcs[--pr->num_load_finish_funcs] (pr)) + return 0; + + return 1; } /* diff --git a/libs/ruamoko/Makefile.am b/libs/ruamoko/Makefile.am index 7f21a515d..f002de032 100644 --- a/libs/ruamoko/Makefile.am +++ b/libs/ruamoko/Makefile.am @@ -8,4 +8,4 @@ lib_LTLIBRARIES= libQFruamoko.la libQFruamoko_la_LDFLAGS= -version-info 1:0:0 libQFruamoko_la_SOURCES= \ rua_cbuf.c rua_cmd.c rua_cvar.c rua_file.c rua_hash.c rua_init.c \ - rua_plist.c rua_qfile.c rua_qfs.c rua_string.c + rua_obj.c rua_plist.c rua_qfile.c rua_qfs.c rua_string.c diff --git a/libs/ruamoko/rua_init.c b/libs/ruamoko/rua_init.c index fee428255..b0135c2a3 100644 --- a/libs/ruamoko/rua_init.c +++ b/libs/ruamoko/rua_init.c @@ -37,6 +37,8 @@ static __attribute__ ((unused)) const char rcsid[] = #include "rua_internal.h" static void (*init_funcs[])(progs_t *, int) = { + RUA_Obj_Init, // done early (for the heck of it at this stage) + RUA_Cbuf_Init, RUA_Cmd_Init, RUA_Cvar_Init, diff --git a/libs/gamecode/engine/pr_obj.c b/libs/ruamoko/rua_obj.c similarity index 82% rename from libs/gamecode/engine/pr_obj.c rename to libs/ruamoko/rua_obj.c index a4b78703a..b8067c631 100644 --- a/libs/gamecode/engine/pr_obj.c +++ b/libs/ruamoko/rua_obj.c @@ -1,5 +1,5 @@ /* - pr_obj.c + rua_obj.c Progs Obj runtime support @@ -49,6 +49,7 @@ static __attribute__ ((unused)) const char rcsid[] = #include "QF/sys.h" #include "compat.h" +#include "rua_internal.h" static void call_function (progs_t *pr, func_t func) @@ -206,7 +207,7 @@ finish_category (progs_t *pr, pr_category_t *category) } static void -pr___obj_exec_class (progs_t *pr) +rua___obj_exec_class (progs_t *pr) { pr_module_t *module = &P_STRUCT (pr, pr_module_t, 0); pr_symtab_t *symtab; @@ -334,7 +335,7 @@ obj_verror (progs_t *pr, pr_id_t *object, int code, const char *fmt, int count, } static void -pr_obj_error (progs_t *pr) +rua_obj_error (progs_t *pr) { pr_id_t *object = &P_STRUCT (pr, pr_id_t, 0); int code = P_INT (pr, 1); @@ -346,7 +347,7 @@ pr_obj_error (progs_t *pr) } static void -pr_obj_verror (progs_t *pr) +rua_obj_verror (progs_t *pr) { pr_id_t *object = &P_STRUCT (pr, pr_id_t, 0); int code = P_INT (pr, 1); @@ -358,7 +359,7 @@ pr_obj_verror (progs_t *pr) } static void -pr_obj_set_error_handler (progs_t *pr) +rua_obj_set_error_handler (progs_t *pr) { //func_t func = P_INT (pr, 0); //arglist @@ -367,7 +368,7 @@ pr_obj_set_error_handler (progs_t *pr) } static void -pr_obj_msg_lookup (progs_t *pr) +rua_obj_msg_lookup (progs_t *pr) { pr_id_t *receiver = &P_STRUCT (pr, pr_id_t, 0); pr_sel_t *op = &P_STRUCT (pr, pr_sel_t, 1); @@ -376,7 +377,7 @@ pr_obj_msg_lookup (progs_t *pr) } static void -pr_obj_msg_lookup_super (progs_t *pr) +rua_obj_msg_lookup_super (progs_t *pr) { pr_super_t *super = &P_STRUCT (pr, pr_super_t, 0); pr_sel_t *_cmd = &P_STRUCT (pr, pr_sel_t, 1); @@ -385,7 +386,7 @@ pr_obj_msg_lookup_super (progs_t *pr) } static void -pr_obj_msg_sendv (progs_t *pr) +rua_obj_msg_sendv (progs_t *pr) { pr_id_t *receiver = &P_STRUCT (pr, pr_id_t, 0); pr_sel_t *op = &P_STRUCT (pr, pr_sel_t, 1); @@ -404,7 +405,7 @@ pr_obj_msg_sendv (progs_t *pr) } static void -pr_obj_malloc (progs_t *pr) +rua_obj_malloc (progs_t *pr) { int size = P_INT (pr, 0) * sizeof (pr_type_t); void *mem = PR_Zone_Malloc (pr, size); @@ -413,7 +414,7 @@ pr_obj_malloc (progs_t *pr) } static void -pr_obj_atomic_malloc (progs_t *pr) +rua_obj_atomic_malloc (progs_t *pr) { int size = P_INT (pr, 0) * sizeof (pr_type_t); void *mem = PR_Zone_Malloc (pr, size); @@ -422,7 +423,7 @@ pr_obj_atomic_malloc (progs_t *pr) } static void -pr_obj_valloc (progs_t *pr) +rua_obj_valloc (progs_t *pr) { int size = P_INT (pr, 0) * sizeof (pr_type_t); void *mem = PR_Zone_Malloc (pr, size); @@ -431,7 +432,7 @@ pr_obj_valloc (progs_t *pr) } static void -pr_obj_realloc (progs_t *pr) +rua_obj_realloc (progs_t *pr) { void *mem = (void*)P_GPOINTER (pr, 0); int size = P_INT (pr, 1) * sizeof (pr_type_t); @@ -441,7 +442,7 @@ pr_obj_realloc (progs_t *pr) } static void -pr_obj_calloc (progs_t *pr) +rua_obj_calloc (progs_t *pr) { int size = P_INT (pr, 0) * sizeof (pr_type_t); void *mem = PR_Zone_Malloc (pr, size); @@ -451,7 +452,7 @@ pr_obj_calloc (progs_t *pr) } static void -pr_obj_free (progs_t *pr) +rua_obj_free (progs_t *pr) { void *mem = (void*)P_GPOINTER (pr, 0); @@ -459,14 +460,14 @@ pr_obj_free (progs_t *pr) } static void -pr_obj_get_uninstalled_dtable (progs_t *pr) +rua_obj_get_uninstalled_dtable (progs_t *pr) { //XXX PR_RunError (pr, "%s, not implemented", __FUNCTION__); } static void -pr_obj_msgSend (progs_t *pr) +rua_obj_msgSend (progs_t *pr) { pr_id_t *self = &P_STRUCT (pr, pr_id_t, 0); pr_sel_t *_cmd = &P_STRUCT (pr, pr_sel_t, 1); @@ -488,7 +489,7 @@ pr_obj_msgSend (progs_t *pr) } static void -pr_obj_msgSend_super (progs_t *pr) +rua_obj_msgSend_super (progs_t *pr) { pr_super_t *super = &P_STRUCT (pr, pr_super_t, 0); pr_sel_t *_cmd = &P_STRUCT (pr, pr_sel_t, 1); @@ -506,7 +507,7 @@ pr_obj_msgSend_super (progs_t *pr) } static void -pr_obj_get_class (progs_t *pr) +rua_obj_get_class (progs_t *pr) { const char *name = P_GSTRING (pr, 0); pr_class_t *class; @@ -518,7 +519,7 @@ pr_obj_get_class (progs_t *pr) } static void -pr_obj_lookup_class (progs_t *pr) +rua_obj_lookup_class (progs_t *pr) { const char *name = P_GSTRING (pr, 0); pr_class_t *class; @@ -528,7 +529,7 @@ pr_obj_lookup_class (progs_t *pr) } static void -pr_obj_next_class (progs_t *pr) +rua_obj_next_class (progs_t *pr) { //XXX PR_RunError (pr, "%s, not implemented", __FUNCTION__); @@ -537,21 +538,21 @@ pr_obj_next_class (progs_t *pr) //==================================================================== static void -pr_sel_get_name (progs_t *pr) +rua_sel_get_name (progs_t *pr) { pr_sel_t *sel = &P_STRUCT (pr, pr_sel_t, 0); R_INT (pr) = sel->sel_id; } static void -pr_sel_get_type (progs_t *pr) +rua_sel_get_type (progs_t *pr) { pr_sel_t *sel = &P_STRUCT (pr, pr_sel_t, 0); R_INT (pr) = sel->sel_types; } static void -pr_sel_get_uid (progs_t *pr) +rua_sel_get_uid (progs_t *pr) { const char *name = P_GSTRING (pr, 0); pr_sel_t *sel = Hash_Find (pr->selectors, name); @@ -559,7 +560,7 @@ pr_sel_get_uid (progs_t *pr) } static void -pr_sel_register_name (progs_t *pr) +rua_sel_register_name (progs_t *pr) { //const char *name = P_GSTRING (pr, 0); //XXX @@ -567,7 +568,7 @@ pr_sel_register_name (progs_t *pr) } static void -pr_sel_is_mapped (progs_t *pr) +rua_sel_is_mapped (progs_t *pr) { //pr_sel_t *sel = &P_STRUCT (pr, pr_sel_t, 0); //XXX @@ -577,7 +578,7 @@ pr_sel_is_mapped (progs_t *pr) //==================================================================== static void -pr_class_get_class_method (progs_t *pr) +rua_class_get_class_method (progs_t *pr) { pr_class_t *class = &P_STRUCT (pr, pr_class_t, 0); pr_sel_t *aSel = &P_STRUCT (pr, pr_sel_t, 1); @@ -588,7 +589,7 @@ pr_class_get_class_method (progs_t *pr) } static void -pr_class_get_instance_method (progs_t *pr) +rua_class_get_instance_method (progs_t *pr) { pr_class_t *class = &P_STRUCT (pr, pr_class_t, 0); pr_sel_t *aSel = &P_STRUCT (pr, pr_sel_t, 1); @@ -599,7 +600,7 @@ pr_class_get_instance_method (progs_t *pr) #define CLASSOF(x) (&G_STRUCT (pr, pr_class_t, (x)->class_pointer)) static void -pr_class_pose_as (progs_t *pr) +rua_class_pose_as (progs_t *pr) { pr_class_t *impostor = &P_STRUCT (pr, pr_class_t, 0); pr_class_t *superclass = &P_STRUCT (pr, pr_class_t, 1); @@ -644,7 +645,7 @@ class_create_instance (progs_t *pr, pr_class_t *class) } static void -pr_class_create_instance (progs_t *pr) +rua_class_create_instance (progs_t *pr) { pr_class_t *class = &P_STRUCT (pr, pr_class_t, 0); pr_id_t *id = class_create_instance (pr, class); @@ -653,7 +654,7 @@ pr_class_create_instance (progs_t *pr) } static void -pr_class_get_class_name (progs_t *pr) +rua_class_get_class_name (progs_t *pr) { pr_class_t *class = &P_STRUCT (pr, pr_class_t, 0); R_INT (pr) = PR_CLS_ISCLASS (class) ? class->name @@ -661,49 +662,49 @@ pr_class_get_class_name (progs_t *pr) } static void -pr_class_get_instance_size (progs_t *pr) +rua_class_get_instance_size (progs_t *pr) { pr_class_t *class = &P_STRUCT (pr, pr_class_t, 0); R_INT (pr) = PR_CLS_ISCLASS (class) ? class->instance_size : 0; } static void -pr_class_get_meta_class (progs_t *pr) +rua_class_get_meta_class (progs_t *pr) { pr_class_t *class = &P_STRUCT (pr, pr_class_t, 0); R_INT (pr) = PR_CLS_ISCLASS (class) ? class->class_pointer : 0; } static void -pr_class_get_super_class (progs_t *pr) +rua_class_get_super_class (progs_t *pr) { pr_class_t *class = &P_STRUCT (pr, pr_class_t, 0); R_INT (pr) = PR_CLS_ISCLASS (class) ? class->super_class : 0; } static void -pr_class_get_version (progs_t *pr) +rua_class_get_version (progs_t *pr) { pr_class_t *class = &P_STRUCT (pr, pr_class_t, 0); R_INT (pr) = PR_CLS_ISCLASS (class) ? class->version : -1; } static void -pr_class_is_class (progs_t *pr) +rua_class_is_class (progs_t *pr) { pr_class_t *class = &P_STRUCT (pr, pr_class_t, 0); R_INT (pr) = PR_CLS_ISCLASS (class); } static void -pr_class_is_meta_class (progs_t *pr) +rua_class_is_meta_class (progs_t *pr) { pr_class_t *class = &P_STRUCT (pr, pr_class_t, 0); R_INT (pr) = PR_CLS_ISMETA (class); } static void -pr_class_set_version (progs_t *pr) +rua_class_set_version (progs_t *pr) { pr_class_t *class = &P_STRUCT (pr, pr_class_t, 0); if (PR_CLS_ISCLASS (class)) @@ -711,14 +712,14 @@ pr_class_set_version (progs_t *pr) } static void -pr_class_get_gc_object_type (progs_t *pr) +rua_class_get_gc_object_type (progs_t *pr) { pr_class_t *class = &P_STRUCT (pr, pr_class_t, 0); R_INT (pr) = PR_CLS_ISCLASS (class) ? class->gc_object_type : 0; } static void -pr_class_ivar_set_gcinvisible (progs_t *pr) +rua_class_ivar_set_gcinvisible (progs_t *pr) { //pr_class_t *impostor = &P_STRUCT (pr, pr_class_t, 0); //const char *ivarname = P_GSTRING (pr, 1); @@ -730,7 +731,7 @@ pr_class_ivar_set_gcinvisible (progs_t *pr) //==================================================================== static void -pr_method_get_imp (progs_t *pr) +rua_method_get_imp (progs_t *pr) { pr_method_t *method = &P_STRUCT (pr, pr_method_t, 0); @@ -738,7 +739,7 @@ pr_method_get_imp (progs_t *pr) } static void -pr_get_imp (progs_t *pr) +rua_get_imp (progs_t *pr) { //pr_class_t *class = &P_STRUCT (pr, pr_class_t, 0); //pr_sel_t *sel = &P_STRUCT (pr, pr_sel_t, 1); @@ -749,14 +750,14 @@ pr_get_imp (progs_t *pr) //==================================================================== static void -pr_object_dispose (progs_t *pr) +rua_object_dispose (progs_t *pr) { pr_id_t *object = &P_STRUCT (pr, pr_id_t, 0); PR_Zone_Free (pr, object); } static void -pr_object_copy (progs_t *pr) +rua_object_copy (progs_t *pr) { pr_id_t *object = &P_STRUCT (pr, pr_id_t, 0); pr_class_t *class = &G_STRUCT (pr, pr_class_t, object->class_pointer); @@ -768,7 +769,7 @@ pr_object_copy (progs_t *pr) } static void -pr_object_get_class (progs_t *pr) +rua_object_get_class (progs_t *pr) { pr_id_t *object = &P_STRUCT (pr, pr_id_t, 0); pr_class_t *class; @@ -788,7 +789,7 @@ pr_object_get_class (progs_t *pr) } static void -pr_object_get_super_class (progs_t *pr) +rua_object_get_super_class (progs_t *pr) { pr_id_t *object = &P_STRUCT (pr, pr_id_t, 0); pr_class_t *class; @@ -808,7 +809,7 @@ pr_object_get_super_class (progs_t *pr) } static void -pr_object_get_meta_class (progs_t *pr) +rua_object_get_meta_class (progs_t *pr) { pr_id_t *object = &P_STRUCT (pr, pr_id_t, 0); pr_class_t *class; @@ -828,7 +829,7 @@ pr_object_get_meta_class (progs_t *pr) } static void -pr_object_get_class_name (progs_t *pr) +rua_object_get_class_name (progs_t *pr) { pr_id_t *object = &P_STRUCT (pr, pr_id_t, 0); pr_class_t *class; @@ -848,7 +849,7 @@ pr_object_get_class_name (progs_t *pr) } static void -pr_object_is_class (progs_t *pr) +rua_object_is_class (progs_t *pr) { pr_id_t *object = &P_STRUCT (pr, pr_id_t, 0); @@ -860,7 +861,7 @@ pr_object_is_class (progs_t *pr) } static void -pr_object_is_instance (progs_t *pr) +rua_object_is_instance (progs_t *pr) { pr_id_t *object = &P_STRUCT (pr, pr_id_t, 0); @@ -868,7 +869,7 @@ pr_object_is_instance (progs_t *pr) } static void -pr_object_is_meta_class (progs_t *pr) +rua_object_is_meta_class (progs_t *pr) { pr_id_t *object = &P_STRUCT (pr, pr_id_t, 0); @@ -882,13 +883,13 @@ pr_object_is_meta_class (progs_t *pr) //==================================================================== static void -pr__i_Object__hash (progs_t *pr) +rua__i_Object__hash (progs_t *pr) { R_INT (pr) = P_INT (pr, 0); } static void -pr__i_Object_error_error_ (progs_t *pr) +rua__i_Object_error_error_ (progs_t *pr) { pr_id_t *self = &P_STRUCT (pr, pr_id_t, 0); const char *fmt = P_GSTRING (pr, 2); @@ -903,7 +904,7 @@ pr__i_Object_error_error_ (progs_t *pr) } static void -pr__c_Object__conformsToProtocol_ (progs_t *pr) +rua__c_Object__conformsToProtocol_ (progs_t *pr) { //pr_id_t *object = &P_STRUCT (pr, pr_id_t, 0); //pr_protocol_t *proto = &P_STRUCT (pr, pr_protocol_t, 2); @@ -915,107 +916,74 @@ pr__c_Object__conformsToProtocol_ (progs_t *pr) //==================================================================== static builtin_t obj_methods [] = { - {"__obj_exec_class", pr___obj_exec_class, -1}, + {"__obj_exec_class", rua___obj_exec_class, -1}, - {"obj_error", pr_obj_error, -1}, - {"obj_verror", pr_obj_verror, -1}, - {"obj_set_error_handler", pr_obj_set_error_handler, -1}, - {"obj_msg_lookup", pr_obj_msg_lookup, -1}, - {"obj_msg_lookup_super", pr_obj_msg_lookup_super, -1}, - {"obj_msg_sendv", pr_obj_msg_sendv, -1}, - {"obj_malloc", pr_obj_malloc, -1}, - {"obj_atomic_malloc", pr_obj_atomic_malloc, -1}, - {"obj_valloc", pr_obj_valloc, -1}, - {"obj_realloc", pr_obj_realloc, -1}, - {"obj_calloc", pr_obj_calloc, -1}, - {"obj_free", pr_obj_free, -1}, - {"obj_get_uninstalled_dtable", pr_obj_get_uninstalled_dtable, -1}, - {"obj_msgSend", pr_obj_msgSend, -1}, - {"obj_msgSend_super", pr_obj_msgSend_super, -1}, + {"obj_error", rua_obj_error, -1}, + {"obj_verror", rua_obj_verror, -1}, + {"obj_set_error_handler", rua_obj_set_error_handler, -1}, + {"obj_msg_lookup", rua_obj_msg_lookup, -1}, + {"obj_msg_lookup_super", rua_obj_msg_lookup_super, -1}, + {"obj_msg_sendv", rua_obj_msg_sendv, -1}, + {"obj_malloc", rua_obj_malloc, -1}, + {"obj_atomic_malloc", rua_obj_atomic_malloc, -1}, + {"obj_valloc", rua_obj_valloc, -1}, + {"obj_realloc", rua_obj_realloc, -1}, + {"obj_calloc", rua_obj_calloc, -1}, + {"obj_free", rua_obj_free, -1}, + {"obj_get_uninstalled_dtable", rua_obj_get_uninstalled_dtable, -1}, + {"obj_msgSend", rua_obj_msgSend, -1}, + {"obj_msgSend_super", rua_obj_msgSend_super, -1}, - {"obj_get_class", pr_obj_get_class, -1}, - {"obj_lookup_class", pr_obj_lookup_class, -1}, - {"obj_next_class", pr_obj_next_class, -1}, + {"obj_get_class", rua_obj_get_class, -1}, + {"obj_lookup_class", rua_obj_lookup_class, -1}, + {"obj_next_class", rua_obj_next_class, -1}, - {"sel_get_name", pr_sel_get_name, -1}, - {"sel_get_type", pr_sel_get_type, -1}, - {"sel_get_uid", pr_sel_get_uid, -1}, - {"sel_register_name", pr_sel_register_name, -1}, - {"sel_is_mapped", pr_sel_is_mapped, -1}, + {"sel_get_name", rua_sel_get_name, -1}, + {"sel_get_type", rua_sel_get_type, -1}, + {"sel_get_uid", rua_sel_get_uid, -1}, + {"sel_register_name", rua_sel_register_name, -1}, + {"sel_is_mapped", rua_sel_is_mapped, -1}, - {"class_get_class_method", pr_class_get_class_method, -1}, - {"class_get_instance_method", pr_class_get_instance_method, -1}, - {"class_pose_as", pr_class_pose_as, -1}, - {"class_create_instance", pr_class_create_instance, -1}, - {"class_get_class_name", pr_class_get_class_name, -1}, - {"class_get_instance_size", pr_class_get_instance_size, -1}, - {"class_get_meta_class", pr_class_get_meta_class, -1}, - {"class_get_super_class", pr_class_get_super_class, -1}, - {"class_get_version", pr_class_get_version, -1}, - {"class_is_class", pr_class_is_class, -1}, - {"class_is_meta_class", pr_class_is_meta_class, -1}, - {"class_set_version", pr_class_set_version, -1}, - {"class_get_gc_object_type", pr_class_get_gc_object_type, -1}, - {"class_ivar_set_gcinvisible", pr_class_ivar_set_gcinvisible, -1}, + {"class_get_class_method", rua_class_get_class_method, -1}, + {"class_get_instance_method", rua_class_get_instance_method, -1}, + {"class_pose_as", rua_class_pose_as, -1}, + {"class_create_instance", rua_class_create_instance, -1}, + {"class_get_class_name", rua_class_get_class_name, -1}, + {"class_get_instance_size", rua_class_get_instance_size, -1}, + {"class_get_meta_class", rua_class_get_meta_class, -1}, + {"class_get_super_class", rua_class_get_super_class, -1}, + {"class_get_version", rua_class_get_version, -1}, + {"class_is_class", rua_class_is_class, -1}, + {"class_is_meta_class", rua_class_is_meta_class, -1}, + {"class_set_version", rua_class_set_version, -1}, + {"class_get_gc_object_type", rua_class_get_gc_object_type, -1}, + {"class_ivar_set_gcinvisible", rua_class_ivar_set_gcinvisible, -1}, - {"method_get_imp", pr_method_get_imp, -1}, - {"get_imp", pr_get_imp, -1}, + {"method_get_imp", rua_method_get_imp, -1}, + {"get_imp", rua_get_imp, -1}, - {"object_copy", pr_object_copy, -1}, - {"object_dispose", pr_object_dispose, -1}, - {"object_get_class", pr_object_get_class, -1}, - {"object_get_class_name", pr_object_get_class_name, -1}, - {"object_get_meta_class", pr_object_get_meta_class, -1}, - {"object_get_super_class", pr_object_get_super_class, -1}, - {"object_is_class", pr_object_is_class, -1}, - {"object_is_instance", pr_object_is_instance, -1}, - {"object_is_meta_class", pr_object_is_meta_class, -1}, + {"object_copy", rua_object_copy, -1}, + {"object_dispose", rua_object_dispose, -1}, + {"object_get_class", rua_object_get_class, -1}, + {"object_get_class_name", rua_object_get_class_name, -1}, + {"object_get_meta_class", rua_object_get_meta_class, -1}, + {"object_get_super_class", rua_object_get_super_class, -1}, + {"object_is_class", rua_object_is_class, -1}, + {"object_is_instance", rua_object_is_instance, -1}, + {"object_is_meta_class", rua_object_is_meta_class, -1}, - {"_i_Object__hash", pr__i_Object__hash, -1}, - {"_i_Object_error_error_", pr__i_Object_error_error_, -1}, - {"_c_Object__conformsToProtocol_", pr__c_Object__conformsToProtocol_, -1}, + {"_i_Object__hash", rua__i_Object__hash, -1}, + {"_i_Object_error_error_", rua__i_Object_error_error_, -1}, + {"_c_Object__conformsToProtocol_", rua__c_Object__conformsToProtocol_, -1}, {0} }; -void -PR_Obj_Progs_Init (progs_t *pr) +static int +rua_init_finish (progs_t *pr) { - PR_RegisterBuiltins (pr, obj_methods); -} - -int -PR_InitRuntime (progs_t *pr) -{ - int fnum; pr_class_t **class_list, **class; pr_category_t **category_list, **category; - if (!pr->selectors) - pr->selectors = Hash_NewTable (1021, selector_get_key, 0, pr); - else - Hash_FlushTable (pr->selectors); - - if (!pr->classes) - pr->classes = Hash_NewTable (1021, class_get_key, 0, pr); - else - Hash_FlushTable (pr->classes); - - if (!pr->categories) { - pr->categories = Hash_NewTable (1021, 0, 0, pr); - Hash_SetHashCompare (pr->categories, - category_get_hash, category_compare); - } else { - Hash_FlushTable (pr->categories); - } - - pr->fields.this = ED_GetFieldIndex (pr, ".this"); - for (fnum = 0; fnum < pr->progs->numfunctions; fnum++) { - if (strequal (PR_GetString (pr, pr->pr_functions[fnum].s_name), - ".ctor")) { - PR_ExecuteProgram (pr, fnum); - } - } - class_list = (pr_class_t **) Hash_GetList (pr->classes); if (*class_list) { pr_class_t *object_class; @@ -1039,3 +1007,38 @@ PR_InitRuntime (progs_t *pr) free (category_list); return 1; } + +static int +rua_init_runtime (progs_t *pr) +{ + if (!pr->selectors) + pr->selectors = Hash_NewTable (1021, selector_get_key, 0, pr); + else + Hash_FlushTable (pr->selectors); + + if (!pr->classes) + pr->classes = Hash_NewTable (1021, class_get_key, 0, pr); + else + Hash_FlushTable (pr->classes); + + if (!pr->categories) { + pr->categories = Hash_NewTable (1021, 0, 0, pr); + Hash_SetHashCompare (pr->categories, + category_get_hash, category_compare); + } else { + Hash_FlushTable (pr->categories); + } + + pr->fields.this = ED_GetFieldIndex (pr, ".this"); + + PR_AddLoadFinishFunc (pr, rua_init_finish); + return 1; +} + +void +RUA_Obj_Init (progs_t *pr, int secure) +{ + PR_RegisterBuiltins (pr, obj_methods); + + PR_AddLoadFunc (pr, rua_init_runtime); +} diff --git a/nq/source/sv_pr_cmds.c b/nq/source/sv_pr_cmds.c index 9c376095d..73b3727ae 100644 --- a/nq/source/sv_pr_cmds.c +++ b/nq/source/sv_pr_cmds.c @@ -1412,7 +1412,6 @@ static builtin_t builtins[] = { void SV_PR_Cmds_Init () { - PR_Obj_Progs_Init (&sv_pr_state); RUA_Init (&sv_pr_state, 1); PR_Cmds_Init (&sv_pr_state); diff --git a/qw/source/sv_pr_cmds.c b/qw/source/sv_pr_cmds.c index ed427a678..faf0ae376 100644 --- a/qw/source/sv_pr_cmds.c +++ b/qw/source/sv_pr_cmds.c @@ -2008,7 +2008,6 @@ SV_PR_Cmds_Init () { builtin_t *bi; - PR_Obj_Progs_Init (&sv_pr_state); RUA_Init (&sv_pr_state, 1); PR_Cmds_Init (&sv_pr_state); diff --git a/tools/qwaq/main.c b/tools/qwaq/main.c index e86f13155..2e11b9c6a 100644 --- a/tools/qwaq/main.c +++ b/tools/qwaq/main.c @@ -40,6 +40,7 @@ static __attribute__ ((unused)) const char rcsid[] = #include #include #include +#include "QF/ruamoko.h" #include #include "QF/va.h" #include @@ -123,7 +124,7 @@ init_qf (void) PR_Init_Cvars (); PR_Init (); - PR_Obj_Progs_Init (&pr); + RUA_Init (&pr, 0); BI_Init (&pr); }