2002-05-21 21:29:49 +00:00
|
|
|
/*
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_obj.c
|
2002-05-21 21:29:49 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2002-05-21 22:13:05 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
2002-05-21 21:29:49 +00:00
|
|
|
|
2011-08-25 13:35:20 +00:00
|
|
|
#if defined(_WIN32) && defined(HAVE_MALLOC_H)
|
2007-03-22 23:20:57 +00:00
|
|
|
#include <malloc.h>
|
|
|
|
#endif
|
|
|
|
|
2013-01-22 05:09:41 +00:00
|
|
|
#include "qfalloca.h"
|
|
|
|
|
2002-05-21 21:29:49 +00:00
|
|
|
#include "QF/cvar.h"
|
2023-03-05 08:20:04 +00:00
|
|
|
#include "QF/darray.h"
|
2004-01-05 01:41:20 +00:00
|
|
|
#include "QF/dstring.h"
|
2002-05-21 21:29:49 +00:00
|
|
|
#include "QF/hash.h"
|
2011-12-24 01:04:33 +00:00
|
|
|
#include "QF/mathlib.h"
|
2002-05-21 21:29:49 +00:00
|
|
|
#include "QF/progs.h"
|
2011-03-30 11:19:31 +00:00
|
|
|
#include "QF/ruamoko.h"
|
2002-05-21 21:29:49 +00:00
|
|
|
#include "QF/sys.h"
|
|
|
|
|
2022-01-08 15:26:52 +00:00
|
|
|
#include "QF/progs/pr_obj.h"
|
2022-02-05 05:24:12 +00:00
|
|
|
#include "QF/progs/pr_type.h"
|
2022-01-08 15:26:52 +00:00
|
|
|
|
2002-05-21 21:29:49 +00:00
|
|
|
#include "compat.h"
|
2004-01-16 08:02:31 +00:00
|
|
|
#include "rua_internal.h"
|
2002-05-21 21:29:49 +00:00
|
|
|
|
2020-03-09 09:11:36 +00:00
|
|
|
#define always_inline inline __attribute__((__always_inline__))
|
|
|
|
|
2022-02-05 04:01:44 +00:00
|
|
|
/* Macros to help with setting up to call a function, and cleaning up
|
|
|
|
* afterwards. The problem is that PR_CallFunction saves the CURRENT stack
|
|
|
|
* pointer, which has been adjusted by PR_SetupParams in order to push
|
|
|
|
* the function arguments.
|
|
|
|
*
|
|
|
|
* RUA_CALL_BEGIN and RUA_CALL_END must be used in pairs and this is enforced
|
|
|
|
* by the unbalanced {}s in the macros.
|
|
|
|
*/
|
|
|
|
#define RUA_CALL_BEGIN(pr, argc) \
|
|
|
|
{ \
|
|
|
|
pr_ptr_t saved_stack = 0; \
|
|
|
|
int call_depth = (pr)->pr_depth; \
|
|
|
|
if ((pr)->globals.stack) { \
|
|
|
|
saved_stack = *(pr)->globals.stack; \
|
|
|
|
} \
|
|
|
|
PR_SetupParams (pr, argc, 1); \
|
|
|
|
(pr)->pr_argc = argc;
|
|
|
|
|
|
|
|
#define RUA_CALL_END(pr, imp) \
|
|
|
|
if (PR_CallFunction ((pr), (imp), (pr)->pr_return)) { \
|
|
|
|
/* the call is to a progs function so a frame was pushed, */ \
|
|
|
|
/* ensure the stack pointer is restored on return */ \
|
|
|
|
/* if there's no stack, then the following is effectively a */ \
|
|
|
|
/* noop */ \
|
|
|
|
(pr)->pr_stack[call_depth].stack_ptr = saved_stack; \
|
|
|
|
} else if ((pr)->globals.stack) { \
|
|
|
|
/* the call was to a builtin, restore the stack */ \
|
|
|
|
*(pr)->globals.stack = saved_stack; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2022-02-11 16:52:35 +00:00
|
|
|
// number of selectors to allocate at once (to minimize memory waste)
|
|
|
|
#define SELECTOR_BLOCK 64
|
|
|
|
|
2006-11-30 22:52:36 +00:00
|
|
|
typedef struct obj_list_s {
|
|
|
|
struct obj_list_s *next;
|
2004-11-11 00:34:00 +00:00
|
|
|
void *data;
|
|
|
|
} obj_list;
|
|
|
|
|
2023-03-05 08:20:04 +00:00
|
|
|
typedef struct listset_s DARRAY_TYPE (obj_list *) listset_t;
|
|
|
|
|
2020-03-09 09:11:36 +00:00
|
|
|
typedef struct dtable_s {
|
2021-09-25 06:42:54 +00:00
|
|
|
struct dtable_s *next;
|
|
|
|
struct dtable_s **prev;
|
2020-03-09 09:11:36 +00:00
|
|
|
size_t size;
|
2022-01-18 06:32:43 +00:00
|
|
|
pr_func_t *imp;
|
2020-03-09 09:11:36 +00:00
|
|
|
} dtable_t;
|
|
|
|
|
2023-03-05 08:20:04 +00:00
|
|
|
typedef struct class_tree {
|
|
|
|
pr_class_t *class;
|
|
|
|
obj_list *subclasses;
|
|
|
|
} class_tree;
|
|
|
|
|
|
|
|
typedef struct treeset_s DARRAY_TYPE (class_tree *) treeset_t;
|
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
typedef struct probj_resources_s {
|
|
|
|
progs_t *pr;
|
|
|
|
unsigned selector_index;
|
|
|
|
unsigned selector_index_max;
|
2022-02-11 16:52:35 +00:00
|
|
|
pr_sel_t *selector_block;
|
|
|
|
int available_selectors;
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_list **selector_sels;
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_string_t *selector_names;
|
2022-02-05 05:24:12 +00:00
|
|
|
pr_int_t *selector_argc;
|
2020-03-09 09:11:36 +00:00
|
|
|
PR_RESMAP (dtable_t) dtables;
|
2021-09-25 06:42:54 +00:00
|
|
|
dtable_t *dtable_list;
|
2022-01-18 06:32:43 +00:00
|
|
|
pr_func_t obj_forward;
|
2020-03-09 11:41:17 +00:00
|
|
|
pr_sel_t *forward_selector;
|
|
|
|
dstring_t *msg;
|
2020-02-25 14:14:18 +00:00
|
|
|
hashtab_t *selector_hash;
|
|
|
|
hashtab_t *classes;
|
2020-03-02 06:20:34 +00:00
|
|
|
hashtab_t *protocols;
|
2020-02-25 14:14:18 +00:00
|
|
|
hashtab_t *load_methods;
|
2023-03-05 08:20:04 +00:00
|
|
|
listset_t obj_list_sets;
|
2022-05-12 09:23:32 +00:00
|
|
|
obj_list *obj_list_free_list;
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_list *unresolved_classes;
|
|
|
|
obj_list *unclaimed_categories;
|
2020-03-02 04:02:29 +00:00
|
|
|
obj_list *uninitialized_statics;
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_list *unclaimed_proto_list;
|
|
|
|
obj_list *module_list;
|
|
|
|
obj_list *class_tree_list;
|
2023-03-05 08:20:04 +00:00
|
|
|
|
|
|
|
class_tree *class_tree_free_list;
|
|
|
|
treeset_t class_tree_sets;
|
2020-02-25 14:14:18 +00:00
|
|
|
} probj_t;
|
|
|
|
|
2020-03-09 09:11:36 +00:00
|
|
|
static dtable_t *
|
|
|
|
dtable_new (probj_t *probj)
|
|
|
|
{
|
2021-09-25 06:42:54 +00:00
|
|
|
dtable_t *dtable = PR_RESNEW (probj->dtables);
|
|
|
|
dtable->next = probj->dtable_list;
|
|
|
|
dtable->prev = &probj->dtable_list;
|
|
|
|
if (probj->dtable_list) {
|
|
|
|
probj->dtable_list->prev = &dtable->next;
|
|
|
|
}
|
|
|
|
probj->dtable_list = dtable;
|
|
|
|
return dtable;
|
2020-03-09 09:11:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dtable_reset (probj_t *probj)
|
|
|
|
{
|
2021-03-21 12:26:36 +00:00
|
|
|
PR_RESRESET (probj->dtables);
|
2021-12-29 15:21:29 +00:00
|
|
|
probj->dtable_list = 0;
|
2020-03-09 09:11:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline dtable_t *
|
|
|
|
dtable_get (probj_t *probj, int index)
|
|
|
|
{
|
2021-03-21 12:26:36 +00:00
|
|
|
return PR_RESGET (probj->dtables, index);
|
2020-03-09 09:11:36 +00:00
|
|
|
}
|
|
|
|
|
2020-12-20 17:12:51 +00:00
|
|
|
static inline int __attribute__((pure))
|
2020-03-09 09:11:36 +00:00
|
|
|
dtable_index (probj_t *probj, dtable_t *dtable)
|
|
|
|
{
|
2021-03-21 12:26:36 +00:00
|
|
|
return PR_RESINDEX (probj->dtables, dtable);
|
2020-03-09 09:11:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static always_inline dtable_t * __attribute__((pure))
|
|
|
|
get_dtable (probj_t *probj, const char *name, int index)
|
|
|
|
{
|
|
|
|
dtable_t *dtable = dtable_get (probj, index);
|
|
|
|
|
|
|
|
if (!dtable) {
|
|
|
|
PR_RunError (probj->pr, "invalid dtable index in %s", name);
|
|
|
|
}
|
|
|
|
return dtable;
|
|
|
|
}
|
|
|
|
|
2004-11-11 00:34:00 +00:00
|
|
|
static obj_list *
|
2022-05-12 09:23:32 +00:00
|
|
|
obj_list_new (probj_t *probj)
|
2004-11-11 00:34:00 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
obj_list *l;
|
|
|
|
|
2022-05-12 09:23:32 +00:00
|
|
|
if (!probj->obj_list_free_list) {
|
|
|
|
probj->obj_list_free_list = calloc (128, sizeof (obj_list));
|
2023-03-05 08:20:04 +00:00
|
|
|
for (i = 0; i < 127; i++) {
|
|
|
|
__auto_type next = &probj->obj_list_free_list[i + 1];
|
|
|
|
probj->obj_list_free_list[i].next = next;
|
|
|
|
}
|
|
|
|
DARRAY_APPEND (&probj->obj_list_sets, probj->obj_list_free_list);
|
2004-11-11 00:34:00 +00:00
|
|
|
}
|
2022-05-12 09:23:32 +00:00
|
|
|
l = probj->obj_list_free_list;
|
|
|
|
probj->obj_list_free_list = l->next;
|
2004-11-11 00:34:00 +00:00
|
|
|
l->next = 0;
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2002-10-15 18:53:33 +00:00
|
|
|
static void
|
2022-05-12 09:23:32 +00:00
|
|
|
obj_list_free (probj_t *probj, obj_list *l)
|
2002-10-15 18:53:33 +00:00
|
|
|
{
|
2004-11-11 00:34:00 +00:00
|
|
|
obj_list *e;
|
2002-10-15 18:53:33 +00:00
|
|
|
|
2004-11-11 00:34:00 +00:00
|
|
|
if (!l)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (e = l; e->next; e = e->next)
|
|
|
|
;
|
2022-05-12 09:23:32 +00:00
|
|
|
e->next = probj->obj_list_free_list;
|
|
|
|
probj->obj_list_free_list = l;
|
2004-11-11 00:34:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline obj_list *
|
2022-05-12 09:23:32 +00:00
|
|
|
list_cons (probj_t *probj, void *data, obj_list *next)
|
2004-11-11 00:34:00 +00:00
|
|
|
{
|
2022-05-12 09:23:32 +00:00
|
|
|
obj_list *l = obj_list_new (probj);
|
2004-11-11 00:34:00 +00:00
|
|
|
l->data = data;
|
|
|
|
l->next = next;
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2022-05-12 09:23:32 +00:00
|
|
|
list_remove (probj_t *probj, obj_list **list)
|
2004-11-11 00:34:00 +00:00
|
|
|
{
|
|
|
|
if ((*list)->next) {
|
|
|
|
obj_list *l = *list;
|
|
|
|
*list = (*list)->next;
|
|
|
|
l->next = 0;
|
2022-05-12 09:23:32 +00:00
|
|
|
obj_list_free (probj, l);
|
2002-10-15 18:53:33 +00:00
|
|
|
} else {
|
2022-05-12 09:23:32 +00:00
|
|
|
obj_list_free (probj, *list);
|
2004-11-11 00:34:00 +00:00
|
|
|
*list = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static class_tree *
|
2023-03-05 08:20:04 +00:00
|
|
|
class_tree_new (probj_t *probj)
|
2004-11-11 00:34:00 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
class_tree *t;
|
|
|
|
|
2023-03-05 08:20:04 +00:00
|
|
|
if (!probj->class_tree_free_list) {
|
|
|
|
probj->class_tree_free_list = calloc (128, sizeof (class_tree));
|
2004-11-11 00:34:00 +00:00
|
|
|
for (i = 0; i < 127; i++) {
|
2023-03-05 08:20:04 +00:00
|
|
|
class_tree *x = &probj->class_tree_free_list[i];
|
2004-11-11 00:34:00 +00:00
|
|
|
x->subclasses = (obj_list *) (x + 1);
|
|
|
|
}
|
2023-03-05 08:20:04 +00:00
|
|
|
DARRAY_APPEND (&probj->class_tree_sets, probj->class_tree_free_list);
|
2004-11-11 00:34:00 +00:00
|
|
|
}
|
2023-03-05 08:20:04 +00:00
|
|
|
t = probj->class_tree_free_list;
|
|
|
|
probj->class_tree_free_list = (class_tree *) t->subclasses;
|
2004-11-11 00:34:00 +00:00
|
|
|
t->subclasses = 0;
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2020-02-25 14:14:18 +00:00
|
|
|
class_is_subclass_of_class (probj_t *probj, pr_class_t *class,
|
2004-11-11 00:34:00 +00:00
|
|
|
pr_class_t *superclass)
|
|
|
|
{
|
|
|
|
while (class) {
|
|
|
|
if (class == superclass)
|
|
|
|
return 1;
|
|
|
|
if (!class->super_class)
|
|
|
|
break;
|
2020-02-25 14:14:18 +00:00
|
|
|
class = Hash_Find (probj->classes,
|
|
|
|
PR_GetString (probj->pr, class->super_class));
|
2004-11-11 00:34:00 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static class_tree *
|
2020-02-25 14:14:18 +00:00
|
|
|
create_tree_of_subclasses_inherited_from (probj_t *probj, pr_class_t *bottom,
|
2004-11-11 00:34:00 +00:00
|
|
|
pr_class_t *upper)
|
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
progs_t *pr = probj->pr;
|
2004-11-11 00:34:00 +00:00
|
|
|
const char *super_class = PR_GetString (pr, bottom->super_class);
|
|
|
|
pr_class_t *superclass;
|
|
|
|
class_tree *tree, *prev;
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
superclass = bottom->super_class ? Hash_Find (probj->classes, super_class)
|
2004-11-11 00:34:00 +00:00
|
|
|
: 0;
|
2023-03-05 08:20:04 +00:00
|
|
|
tree = prev = class_tree_new (probj);
|
2004-11-11 00:34:00 +00:00
|
|
|
prev->class = bottom;
|
|
|
|
while (superclass != upper) {
|
2023-03-05 08:20:04 +00:00
|
|
|
tree = class_tree_new (probj);
|
2004-11-11 00:34:00 +00:00
|
|
|
tree->class = superclass;
|
2022-05-12 09:23:32 +00:00
|
|
|
tree->subclasses = list_cons (probj, prev, tree->subclasses);
|
2004-11-11 00:34:00 +00:00
|
|
|
super_class = PR_GetString (pr, superclass->super_class);
|
2020-02-25 14:14:18 +00:00
|
|
|
superclass = (superclass->super_class ? Hash_Find (probj->classes,
|
2004-11-11 00:34:00 +00:00
|
|
|
super_class)
|
|
|
|
: 0);
|
|
|
|
prev = tree;
|
|
|
|
}
|
|
|
|
return tree;
|
|
|
|
}
|
|
|
|
|
|
|
|
static class_tree *
|
2020-02-25 14:14:18 +00:00
|
|
|
_obj_tree_insert_class (probj_t *probj, class_tree *tree, pr_class_t *class)
|
2004-11-11 00:34:00 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
progs_t *pr = probj->pr;
|
2004-11-11 00:34:00 +00:00
|
|
|
obj_list *subclasses;
|
|
|
|
class_tree *new_tree;
|
|
|
|
|
|
|
|
if (!tree)
|
2020-02-25 14:14:18 +00:00
|
|
|
return create_tree_of_subclasses_inherited_from (probj, class, 0);
|
2004-11-11 00:34:00 +00:00
|
|
|
if (class == tree->class)
|
|
|
|
return tree;
|
2020-02-25 14:14:18 +00:00
|
|
|
if ((class->super_class ? Hash_Find (probj->classes,
|
2004-11-11 00:34:00 +00:00
|
|
|
PR_GetString (pr,
|
|
|
|
class->super_class))
|
|
|
|
: 0) == tree->class) {
|
|
|
|
obj_list *list = tree->subclasses;
|
|
|
|
class_tree *node;
|
|
|
|
|
|
|
|
while (list) {
|
|
|
|
if (((class_tree *) list->data)->class == class)
|
|
|
|
return tree;
|
|
|
|
list = list->next;
|
|
|
|
}
|
2023-03-05 08:20:04 +00:00
|
|
|
node = class_tree_new (probj);
|
2004-11-11 00:34:00 +00:00
|
|
|
node->class = class;
|
2022-05-12 09:23:32 +00:00
|
|
|
tree->subclasses = list_cons (probj, node, tree->subclasses);
|
2004-11-11 00:34:00 +00:00
|
|
|
return tree;
|
|
|
|
}
|
2020-02-25 14:14:18 +00:00
|
|
|
if (!class_is_subclass_of_class (probj, class, tree->class))
|
2004-11-11 00:34:00 +00:00
|
|
|
return 0;
|
|
|
|
for (subclasses = tree->subclasses; subclasses;
|
|
|
|
subclasses = subclasses->next) {
|
|
|
|
pr_class_t *aclass = ((class_tree *)subclasses->data)->class;
|
2020-02-25 14:14:18 +00:00
|
|
|
if (class_is_subclass_of_class (probj, class, aclass)) {
|
|
|
|
subclasses->data = _obj_tree_insert_class (probj, subclasses->data,
|
2004-11-11 00:34:00 +00:00
|
|
|
class);
|
|
|
|
return tree;
|
|
|
|
}
|
|
|
|
}
|
2020-02-25 14:14:18 +00:00
|
|
|
new_tree = create_tree_of_subclasses_inherited_from (probj, class,
|
2004-11-11 00:34:00 +00:00
|
|
|
tree->class);
|
2022-05-12 09:23:32 +00:00
|
|
|
tree->subclasses = list_cons (probj, new_tree, tree->subclasses);
|
2004-11-11 00:34:00 +00:00
|
|
|
return tree;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_tree_insert_class (probj_t *probj, pr_class_t *class)
|
2004-11-11 00:34:00 +00:00
|
|
|
{
|
|
|
|
obj_list *list_node;
|
|
|
|
class_tree *tree;
|
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
list_node = probj->class_tree_list;
|
2004-11-11 00:34:00 +00:00
|
|
|
while (list_node) {
|
2020-02-25 14:14:18 +00:00
|
|
|
tree = _obj_tree_insert_class (probj, list_node->data, class);
|
2004-11-11 00:34:00 +00:00
|
|
|
if (tree) {
|
|
|
|
list_node->data = tree;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
list_node = list_node->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!list_node) {
|
2020-02-25 14:14:18 +00:00
|
|
|
tree = _obj_tree_insert_class (probj, 0, class);
|
2022-05-12 09:23:32 +00:00
|
|
|
probj->class_tree_list = list_cons (probj, tree,
|
|
|
|
probj->class_tree_list);
|
2002-10-15 18:53:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-11 00:34:00 +00:00
|
|
|
static void
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_create_classes_tree (probj_t *probj, pr_module_t *module)
|
2004-11-11 00:34:00 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
progs_t *pr = probj->pr;
|
2004-11-11 00:34:00 +00:00
|
|
|
pr_symtab_t *symtab = &G_STRUCT (pr, pr_symtab_t, module->symtab);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < symtab->cls_def_cnt; i++) {
|
|
|
|
pr_class_t *class = &G_STRUCT (pr, pr_class_t, symtab->defs[i]);
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_tree_insert_class (probj, class);
|
2004-11-11 00:34:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_destroy_class_tree_node (probj_t *probj, class_tree *tree, int level)
|
2004-11-11 00:34:00 +00:00
|
|
|
{
|
2023-03-05 08:20:04 +00:00
|
|
|
tree->subclasses = (obj_list *) probj->class_tree_free_list;
|
|
|
|
probj->class_tree_free_list = tree;
|
2004-11-11 00:34:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_preorder_traverse (probj_t *probj, class_tree *tree, int level,
|
|
|
|
void (*func) (probj_t *, class_tree *, int))
|
2004-11-11 00:34:00 +00:00
|
|
|
{
|
|
|
|
obj_list *node;
|
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
func (probj, tree, level);
|
2004-11-11 00:34:00 +00:00
|
|
|
for (node = tree->subclasses; node; node = node->next)
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_preorder_traverse (probj, node->data, level + 1, func);
|
2004-11-11 00:34:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_postorder_traverse (probj_t *probj, class_tree *tree, int level,
|
|
|
|
void (*func) (probj_t *, class_tree *, int))
|
2004-11-11 00:34:00 +00:00
|
|
|
{
|
|
|
|
obj_list *node;
|
|
|
|
|
|
|
|
for (node = tree->subclasses; node; node = node->next)
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_postorder_traverse (probj, node->data, level + 1, func);
|
|
|
|
func (probj, tree, level);
|
2004-11-11 00:34:00 +00:00
|
|
|
}
|
|
|
|
|
2003-08-23 22:16:42 +00:00
|
|
|
static const char *
|
2020-02-25 14:14:18 +00:00
|
|
|
selector_get_key (const void *s, void *_probj)
|
2003-08-23 22:16:42 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
__auto_type probj = (probj_t *) _probj;
|
|
|
|
return PR_GetString (probj->pr, probj->selector_names[(intptr_t) s]);
|
2003-08-23 22:16:42 +00:00
|
|
|
}
|
|
|
|
|
2002-05-22 17:32:44 +00:00
|
|
|
static const char *
|
2020-02-25 14:14:18 +00:00
|
|
|
class_get_key (const void *c, void *_probj)
|
2002-05-21 21:29:49 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
__auto_type probj = (probj_t *) _probj;
|
|
|
|
return PR_GetString (probj->pr, ((pr_class_t *)c)->name);
|
2002-05-21 21:29:49 +00:00
|
|
|
}
|
|
|
|
|
2020-03-02 06:20:34 +00:00
|
|
|
static const char *
|
|
|
|
protocol_get_key (const void *p, void *_probj)
|
|
|
|
{
|
|
|
|
__auto_type probj = (probj_t *) _probj;
|
|
|
|
return PR_GetString (probj->pr, ((pr_protocol_t *)p)->protocol_name);
|
|
|
|
}
|
|
|
|
|
2007-04-04 07:48:14 +00:00
|
|
|
static uintptr_t
|
2020-02-25 14:14:18 +00:00
|
|
|
load_methods_get_hash (const void *m, void *_probj)
|
2002-11-14 20:42:48 +00:00
|
|
|
{
|
2007-04-04 07:48:14 +00:00
|
|
|
return (uintptr_t) m;
|
2002-11-14 20:42:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2020-02-25 14:14:18 +00:00
|
|
|
load_methods_compare (const void *m1, const void *m2, void *_probj)
|
2002-11-14 20:42:48 +00:00
|
|
|
{
|
2004-11-11 00:34:00 +00:00
|
|
|
return m1 == m2;
|
2002-11-14 20:42:48 +00:00
|
|
|
}
|
|
|
|
|
2004-11-10 05:37:00 +00:00
|
|
|
static inline int
|
|
|
|
sel_eq (pr_sel_t *s1, pr_sel_t *s2)
|
2002-05-21 21:29:49 +00:00
|
|
|
{
|
2004-11-10 05:37:00 +00:00
|
|
|
if (!s1 || !s2)
|
|
|
|
return s1 == s2;
|
|
|
|
return s1->sel_id == s2->sel_id;
|
2002-05-21 21:29:49 +00:00
|
|
|
}
|
|
|
|
|
2004-01-05 01:41:20 +00:00
|
|
|
static int
|
2020-02-25 14:14:18 +00:00
|
|
|
object_is_instance (probj_t *probj, pr_id_t *object)
|
2004-01-05 01:41:20 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
progs_t *pr = probj->pr;
|
2004-01-05 01:41:20 +00:00
|
|
|
pr_class_t *class;
|
|
|
|
|
|
|
|
if (object) {
|
|
|
|
class = &G_STRUCT (pr, pr_class_t, object->class_pointer);
|
|
|
|
return PR_CLS_ISCLASS (class);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-01-18 03:11:14 +00:00
|
|
|
static pr_string_t
|
2020-02-25 14:14:18 +00:00
|
|
|
object_get_class_name (probj_t *probj, pr_id_t *object)
|
2002-05-22 19:02:26 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
progs_t *pr = probj->pr;
|
2002-05-22 19:02:26 +00:00
|
|
|
pr_class_t *class;
|
|
|
|
|
|
|
|
if (object) {
|
|
|
|
class = &G_STRUCT (pr, pr_class_t, object->class_pointer);
|
|
|
|
if (PR_CLS_ISCLASS (class)) {
|
2002-05-22 22:35:37 +00:00
|
|
|
R_INT (pr) = class->name;
|
2002-05-22 19:02:26 +00:00
|
|
|
return class->name;
|
|
|
|
}
|
|
|
|
if (PR_CLS_ISMETA (class)) {
|
2002-05-22 22:35:37 +00:00
|
|
|
R_INT (pr) = ((pr_class_t *)object)->name;
|
2002-05-22 19:02:26 +00:00
|
|
|
return ((pr_class_t *)object)->name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_SetString (pr, "Nil");
|
|
|
|
}
|
|
|
|
|
2002-05-22 17:32:44 +00:00
|
|
|
//====================================================================
|
|
|
|
|
2002-08-16 22:53:37 +00:00
|
|
|
static void
|
2022-01-18 03:11:14 +00:00
|
|
|
finish_class (probj_t *probj, pr_class_t *class, pr_ptr_t object_ptr)
|
2002-08-16 22:53:37 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
progs_t *pr = probj->pr;
|
2002-08-16 22:53:37 +00:00
|
|
|
pr_class_t *meta = &G_STRUCT (pr, pr_class_t, class->class_pointer);
|
|
|
|
pr_class_t *val;
|
|
|
|
|
|
|
|
meta->class_pointer = object_ptr;
|
|
|
|
if (class->super_class) {
|
2003-03-13 18:45:45 +00:00
|
|
|
const char *super_class = PR_GetString (pr, class->super_class);
|
|
|
|
const char *class_name = PR_GetString (pr, class->name);
|
2020-02-25 14:14:18 +00:00
|
|
|
val = Hash_Find (probj->classes, super_class);
|
2003-03-13 18:45:45 +00:00
|
|
|
if (!val)
|
|
|
|
PR_Error (pr, "broken class %s: super class %s not found",
|
|
|
|
class_name, super_class);
|
2002-08-16 22:53:37 +00:00
|
|
|
meta->super_class = val->class_pointer;
|
2004-11-05 11:49:00 +00:00
|
|
|
class->super_class = PR_SetPointer (pr, val);
|
2002-08-16 22:53:37 +00:00
|
|
|
} else {
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_ptr_t *ml = &meta->methods;
|
2002-08-16 22:53:37 +00:00
|
|
|
while (*ml)
|
|
|
|
ml = &G_STRUCT (pr, pr_method_list_t, *ml).method_next;
|
|
|
|
*ml = class->methods;
|
|
|
|
}
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_rua_obj, " %x %x %x\n", meta->class_pointer,
|
2010-11-23 05:09:30 +00:00
|
|
|
meta->super_class, class->super_class);
|
2002-08-16 22:53:37 +00:00
|
|
|
}
|
|
|
|
|
2004-11-10 05:37:00 +00:00
|
|
|
//====================================================================
|
|
|
|
|
|
|
|
static int
|
2020-02-25 14:14:18 +00:00
|
|
|
add_sel_name (probj_t *probj, const char *name)
|
2004-11-10 05:37:00 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
int ind = ++probj->selector_index;
|
2004-11-10 05:37:00 +00:00
|
|
|
int size, i;
|
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
if (probj->selector_index >= probj->selector_index_max) {
|
|
|
|
size = probj->selector_index_max + 128;
|
|
|
|
probj->selector_sels = realloc (probj->selector_sels,
|
|
|
|
size * sizeof (obj_list *));
|
|
|
|
probj->selector_names = realloc (probj->selector_names,
|
2022-01-18 03:11:14 +00:00
|
|
|
size * sizeof (pr_string_t));
|
2022-02-05 05:24:12 +00:00
|
|
|
probj->selector_argc = realloc (probj->selector_argc,
|
|
|
|
size * sizeof (pr_int_t));
|
2020-02-25 14:14:18 +00:00
|
|
|
for (i = probj->selector_index_max; i < size; i++) {
|
|
|
|
probj->selector_sels[i] = 0;
|
|
|
|
probj->selector_names[i] = 0;
|
2022-02-05 05:24:12 +00:00
|
|
|
probj->selector_argc[i] = 0;
|
2004-11-10 05:37:00 +00:00
|
|
|
}
|
2020-02-25 14:14:18 +00:00
|
|
|
probj->selector_index_max = size;
|
2004-11-10 05:37:00 +00:00
|
|
|
}
|
2020-02-25 14:14:18 +00:00
|
|
|
probj->selector_names[ind] = PR_SetString (probj->pr, name);
|
2004-11-10 05:37:00 +00:00
|
|
|
return ind;
|
|
|
|
}
|
|
|
|
|
|
|
|
static pr_sel_t *
|
2020-02-25 14:14:18 +00:00
|
|
|
sel_register_typed_name (probj_t *probj, const char *name, const char *types,
|
2004-11-10 05:37:00 +00:00
|
|
|
pr_sel_t *sel)
|
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
progs_t *pr = probj->pr;
|
2007-04-04 07:48:14 +00:00
|
|
|
intptr_t index;
|
2005-01-02 14:23:20 +00:00
|
|
|
int is_new = 0;
|
2004-11-10 05:37:00 +00:00
|
|
|
obj_list *l;
|
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
index = (intptr_t) Hash_Find (probj->selector_hash, name);
|
2004-11-10 05:37:00 +00:00
|
|
|
if (index) {
|
2020-02-25 14:14:18 +00:00
|
|
|
for (l = probj->selector_sels[index]; l; l = l->next) {
|
2004-11-10 05:37:00 +00:00
|
|
|
pr_sel_t *s = l->data;
|
|
|
|
if (!types || !s->sel_types) {
|
|
|
|
if (!s->sel_types && !types) {
|
|
|
|
if (sel) {
|
|
|
|
sel->sel_id = index;
|
2011-01-10 00:21:42 +00:00
|
|
|
goto done;
|
2004-11-10 05:37:00 +00:00
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
} else if (strcmp (PR_GetString (pr, s->sel_types), types) == 0) {
|
|
|
|
if (sel) {
|
|
|
|
sel->sel_id = index;
|
2011-01-10 00:21:42 +00:00
|
|
|
goto done;
|
2004-11-10 05:37:00 +00:00
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_rua_obj, " Registering SEL %s %s\n",
|
2020-03-09 11:41:17 +00:00
|
|
|
name, types);
|
2020-02-25 14:14:18 +00:00
|
|
|
index = add_sel_name (probj, name);
|
2004-11-10 05:37:00 +00:00
|
|
|
is_new = 1;
|
|
|
|
}
|
2022-02-11 16:52:35 +00:00
|
|
|
if (!sel) {
|
|
|
|
if (!probj->available_selectors) {
|
|
|
|
probj->available_selectors = SELECTOR_BLOCK;
|
|
|
|
sel = PR_Zone_Malloc (pr, SELECTOR_BLOCK*sizeof (pr_sel_t));
|
|
|
|
probj->selector_block = sel;
|
|
|
|
}
|
|
|
|
sel = &probj->selector_block[--probj->available_selectors];
|
|
|
|
}
|
2004-11-10 05:37:00 +00:00
|
|
|
|
|
|
|
sel->sel_id = index;
|
|
|
|
sel->sel_types = PR_SetString (pr, types);
|
|
|
|
|
2022-05-12 09:23:32 +00:00
|
|
|
l = obj_list_new (probj);
|
2004-11-10 05:37:00 +00:00
|
|
|
l->data = sel;
|
2020-02-25 14:14:18 +00:00
|
|
|
l->next = probj->selector_sels[index];
|
|
|
|
probj->selector_sels[index] = l;
|
2004-11-10 05:37:00 +00:00
|
|
|
|
2022-02-05 05:24:12 +00:00
|
|
|
if (sel->sel_types && pr->type_encodings) {
|
|
|
|
const char *enc = PR_GetString (pr, sel->sel_types);
|
|
|
|
__auto_type type = (qfot_type_t *) Hash_Find (pr->type_hash, enc);
|
|
|
|
if (type->meta != ty_basic || type->type != ev_func) {
|
|
|
|
PR_RunError (pr, "selector type encoing is not a function");
|
|
|
|
}
|
|
|
|
probj->selector_argc[index] = type->func.num_params;
|
|
|
|
}
|
|
|
|
|
2004-11-10 05:37:00 +00:00
|
|
|
if (is_new)
|
2020-02-25 14:14:18 +00:00
|
|
|
Hash_Add (probj->selector_hash, (void *) index);
|
2011-01-10 00:21:42 +00:00
|
|
|
done:
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_rua_obj, " %d @ %x\n",
|
2011-01-10 00:21:42 +00:00
|
|
|
sel->sel_id, PR_SetPointer (pr, sel));
|
2004-11-10 05:37:00 +00:00
|
|
|
return sel;
|
|
|
|
}
|
|
|
|
|
|
|
|
static pr_sel_t *
|
2020-02-25 14:14:18 +00:00
|
|
|
sel_register_name (probj_t *probj, const char *name)
|
2004-11-10 05:37:00 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
return sel_register_typed_name (probj, name, "", 0);
|
2004-11-10 05:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-03-02 06:20:34 +00:00
|
|
|
obj_register_selectors_from_description_list (probj_t *probj,
|
|
|
|
pr_method_description_list_t *method_list)
|
|
|
|
{
|
|
|
|
progs_t *pr = probj->pr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!method_list) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (i = 0; i < method_list->count; i++) {
|
|
|
|
pr_method_description_t *method = &method_list->list[i];
|
|
|
|
const char *name = PR_GetString (pr, method->name);
|
|
|
|
const char *types = PR_GetString (pr, method->types);
|
|
|
|
pr_sel_t *sel = sel_register_typed_name (probj, name, types, 0);
|
|
|
|
method->name = PR_SetPointer (pr, sel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
obj_register_selectors_from_list (probj_t *probj,
|
|
|
|
pr_method_list_t *method_list)
|
2004-11-10 05:37:00 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
progs_t *pr = probj->pr;
|
2004-11-10 05:37:00 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < method_list->method_count; i++) {
|
|
|
|
pr_method_t *method = &method_list->method_list[i];
|
|
|
|
const char *name = PR_GetString (pr, method->method_name);
|
|
|
|
const char *types = PR_GetString (pr, method->method_types);
|
2020-02-25 14:14:18 +00:00
|
|
|
pr_sel_t *sel = sel_register_typed_name (probj, name, types, 0);
|
2004-11-10 05:37:00 +00:00
|
|
|
method->method_name = PR_SetPointer (pr, sel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_register_selectors_from_class (probj_t *probj, pr_class_t *class)
|
2004-11-10 05:37:00 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
progs_t *pr = probj->pr;
|
2004-11-10 05:37:00 +00:00
|
|
|
pr_method_list_t *method_list = &G_STRUCT (pr, pr_method_list_t,
|
|
|
|
class->methods);
|
|
|
|
while (method_list) {
|
2020-03-02 06:20:34 +00:00
|
|
|
obj_register_selectors_from_list (probj, method_list);
|
2004-11-10 05:37:00 +00:00
|
|
|
method_list = &G_STRUCT (pr, pr_method_list_t,
|
|
|
|
method_list->method_next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-02 04:02:29 +00:00
|
|
|
static void obj_init_protocols (probj_t *probj, pr_protocol_list_t *protos);
|
|
|
|
|
|
|
|
static void
|
|
|
|
obj_init_protocol (probj_t *probj, pr_class_t *proto_class,
|
|
|
|
pr_protocol_t *proto)
|
|
|
|
{
|
|
|
|
progs_t *pr = probj->pr;
|
|
|
|
|
|
|
|
if (!proto->class_pointer) {
|
2020-03-02 06:20:34 +00:00
|
|
|
const char *protocol_name = PR_GetString (pr, proto->protocol_name);
|
2020-03-02 04:02:29 +00:00
|
|
|
proto->class_pointer = PR_SetPointer (pr, proto_class);
|
2020-03-02 06:20:34 +00:00
|
|
|
obj_register_selectors_from_description_list (probj,
|
|
|
|
&G_STRUCT (pr, pr_method_description_list_t,
|
|
|
|
proto->instance_methods));
|
|
|
|
obj_register_selectors_from_description_list (probj,
|
|
|
|
&G_STRUCT (pr, pr_method_description_list_t,
|
|
|
|
proto->class_methods));
|
|
|
|
if (!Hash_Find (probj->protocols, protocol_name)) {
|
|
|
|
Hash_Add (probj->protocols, proto);
|
|
|
|
}
|
2020-03-02 04:02:29 +00:00
|
|
|
obj_init_protocols (probj, &G_STRUCT (pr, pr_protocol_list_t,
|
|
|
|
proto->protocol_list));
|
|
|
|
} else {
|
|
|
|
if (proto->class_pointer != PR_SetPointer (pr, proto_class))
|
|
|
|
PR_RunError (pr, "protocol broken");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-10 05:37:00 +00:00
|
|
|
static void
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_init_protocols (probj_t *probj, pr_protocol_list_t *protos)
|
2004-11-10 05:37:00 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
progs_t *pr = probj->pr;
|
2004-11-10 05:37:00 +00:00
|
|
|
pr_class_t *proto_class;
|
|
|
|
pr_protocol_t *proto;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!protos)
|
|
|
|
return;
|
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
if (!(proto_class = Hash_Find (probj->classes, "Protocol"))) {
|
2022-05-12 09:23:32 +00:00
|
|
|
probj->unclaimed_proto_list = list_cons (probj, protos,
|
2020-02-25 14:14:18 +00:00
|
|
|
probj->unclaimed_proto_list);
|
2004-11-10 05:37:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < protos->count; i++) {
|
|
|
|
proto = &G_STRUCT (pr, pr_protocol_t, protos->list[i]);
|
2020-03-02 04:02:29 +00:00
|
|
|
obj_init_protocol (probj, proto_class, proto);
|
2004-11-10 05:37:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-14 20:42:48 +00:00
|
|
|
static void
|
2020-02-25 14:14:18 +00:00
|
|
|
class_add_method_list (probj_t *probj, pr_class_t *class,
|
|
|
|
pr_method_list_t *list)
|
2004-11-10 05:37:00 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
progs_t *pr = probj->pr;
|
2004-11-10 05:37:00 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < list->method_count; i++) {
|
|
|
|
pr_method_t *method = &list->method_list[i];
|
|
|
|
if (method->method_name) {
|
|
|
|
const char *name = PR_GetString (pr, method->method_name);
|
|
|
|
const char *types = PR_GetString (pr, method->method_types);
|
2020-02-25 14:14:18 +00:00
|
|
|
pr_sel_t *sel = sel_register_typed_name (probj, name, types, 0);
|
2004-11-10 05:37:00 +00:00
|
|
|
method->method_name = PR_SetPointer (pr, sel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
list->method_next = class->methods;
|
|
|
|
class->methods = PR_SetPointer (pr, list);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_class_add_protocols (probj_t *probj, pr_class_t *class,
|
2004-11-10 05:37:00 +00:00
|
|
|
pr_protocol_list_t *protos)
|
|
|
|
{
|
|
|
|
if (!protos)
|
|
|
|
return;
|
|
|
|
|
|
|
|
protos->next = class->protocols;
|
|
|
|
class->protocols = protos->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-25 14:14:18 +00:00
|
|
|
finish_category (probj_t *probj, pr_category_t *category, pr_class_t *class)
|
2002-11-14 20:42:48 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
progs_t *pr = probj->pr;
|
2002-11-14 20:42:48 +00:00
|
|
|
pr_method_list_t *method_list;
|
2004-11-10 05:37:00 +00:00
|
|
|
pr_protocol_list_t *protocol_list;
|
2002-11-14 20:42:48 +00:00
|
|
|
|
|
|
|
if (category->instance_methods) {
|
|
|
|
method_list = &G_STRUCT (pr, pr_method_list_t,
|
|
|
|
category->instance_methods);
|
2020-02-25 14:14:18 +00:00
|
|
|
class_add_method_list (probj, class, method_list);
|
2002-11-14 20:42:48 +00:00
|
|
|
}
|
|
|
|
if (category->class_methods) {
|
|
|
|
pr_class_t *meta = &G_STRUCT (pr, pr_class_t, class->class_pointer);
|
|
|
|
method_list = &G_STRUCT (pr, pr_method_list_t,
|
|
|
|
category->class_methods);
|
2020-02-25 14:14:18 +00:00
|
|
|
class_add_method_list (probj, meta, method_list);
|
2004-11-10 05:37:00 +00:00
|
|
|
}
|
|
|
|
if (category->protocols) {
|
|
|
|
protocol_list = &G_STRUCT (pr, pr_protocol_list_t,
|
|
|
|
category->protocols);
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_init_protocols (probj, protocol_list);
|
|
|
|
obj_class_add_protocols (probj, class, protocol_list);
|
2002-11-14 20:42:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-21 21:29:49 +00:00
|
|
|
static void
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_send_message_in_list (probj_t *probj, pr_method_list_t *method_list,
|
2004-11-10 05:37:00 +00:00
|
|
|
pr_class_t *class, pr_sel_t *op)
|
2002-05-21 21:29:49 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
progs_t *pr = probj->pr;
|
2002-08-16 22:53:37 +00:00
|
|
|
int i;
|
2002-05-21 21:29:49 +00:00
|
|
|
|
2004-11-10 05:37:00 +00:00
|
|
|
if (!method_list)
|
2002-05-22 22:35:37 +00:00
|
|
|
return;
|
2004-11-10 05:37:00 +00:00
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_send_message_in_list (probj, &G_STRUCT (pr, pr_method_list_t,
|
|
|
|
method_list->method_next),
|
2004-11-10 05:37:00 +00:00
|
|
|
class, op);
|
|
|
|
|
|
|
|
for (i = 0; i < method_list->method_count; i++) {
|
|
|
|
pr_method_t *mth = &method_list->method_list[i];
|
|
|
|
if (mth->method_name && sel_eq (&G_STRUCT (pr, pr_sel_t,
|
|
|
|
mth->method_name), op)
|
2020-02-25 14:14:18 +00:00
|
|
|
&& !Hash_FindElement (probj->load_methods,
|
|
|
|
(void *) (intptr_t) mth->method_imp)) {
|
|
|
|
Hash_AddElement (probj->load_methods,
|
|
|
|
(void *) (intptr_t) mth->method_imp);
|
|
|
|
//FIXME need to wrap in save/restore params?
|
2004-11-10 05:37:00 +00:00
|
|
|
PR_ExecuteProgram (pr, mth->method_imp);
|
|
|
|
break;
|
|
|
|
}
|
2003-08-23 06:15:19 +00:00
|
|
|
}
|
2004-11-10 05:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-25 14:14:18 +00:00
|
|
|
send_load (probj_t *probj, class_tree *tree, int level)
|
2004-11-10 05:37:00 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
progs_t *pr = probj->pr;
|
|
|
|
pr_sel_t *load_sel = sel_register_name (probj, "load");
|
2004-11-10 05:37:00 +00:00
|
|
|
pr_class_t *class = tree->class;
|
|
|
|
pr_class_t *meta = &G_STRUCT (pr, pr_class_t, class->class_pointer);
|
|
|
|
pr_method_list_t *method_list = &G_STRUCT (pr, pr_method_list_t,
|
|
|
|
meta->methods);
|
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_send_message_in_list (probj, method_list, class, load_sel);
|
2004-11-10 05:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_send_load (probj_t *probj)
|
2004-11-10 05:37:00 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
progs_t *pr = probj->pr;
|
2004-11-10 05:37:00 +00:00
|
|
|
obj_list *m;
|
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
if (probj->unresolved_classes) {
|
|
|
|
pr_class_t *class = probj->unresolved_classes->data;
|
2004-11-10 05:37:00 +00:00
|
|
|
const char *super_class = PR_GetString (pr, class->super_class);
|
2020-02-25 14:14:18 +00:00
|
|
|
while (Hash_Find (probj->classes, super_class)) {
|
2022-05-12 09:23:32 +00:00
|
|
|
list_remove (probj, &probj->unresolved_classes);
|
2020-02-25 14:14:18 +00:00
|
|
|
if (probj->unresolved_classes) {
|
|
|
|
class = probj->unresolved_classes->data;
|
2004-11-10 05:37:00 +00:00
|
|
|
super_class = PR_GetString (pr, class->super_class);
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-02-25 14:14:18 +00:00
|
|
|
if (probj->unresolved_classes)
|
2004-11-10 05:37:00 +00:00
|
|
|
return;
|
2002-05-21 21:29:49 +00:00
|
|
|
}
|
2004-11-10 05:37:00 +00:00
|
|
|
|
|
|
|
//XXX constant string stuff here (see init.c in libobjc source)
|
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
for (m = probj->module_list; m; m = m->next)
|
|
|
|
obj_create_classes_tree (probj, m->data);
|
|
|
|
while (probj->class_tree_list) {
|
|
|
|
obj_preorder_traverse (probj, probj->class_tree_list->data, 0,
|
|
|
|
send_load);
|
|
|
|
obj_postorder_traverse (probj, probj->class_tree_list->data, 0,
|
2006-11-30 22:52:36 +00:00
|
|
|
obj_destroy_class_tree_node);
|
2022-05-12 09:23:32 +00:00
|
|
|
list_remove (probj, &probj->class_tree_list);
|
2002-05-21 21:29:49 +00:00
|
|
|
}
|
2004-11-10 05:37:00 +00:00
|
|
|
//XXX callback
|
2020-02-25 14:14:18 +00:00
|
|
|
//for (m = probj->module_list; m; m = m->next)
|
|
|
|
// obj_create_classes_tree (probj, m->data);
|
2022-05-12 09:23:32 +00:00
|
|
|
obj_list_free (probj, probj->module_list);
|
2020-02-25 14:14:18 +00:00
|
|
|
probj->module_list = 0;
|
2002-05-21 21:29:49 +00:00
|
|
|
}
|
|
|
|
|
2003-08-23 22:16:42 +00:00
|
|
|
static pr_method_t *
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_find_message (probj_t *probj, pr_class_t *class, pr_sel_t *selector)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
progs_t *pr = probj->pr;
|
2002-05-22 17:32:44 +00:00
|
|
|
pr_class_t *c = class;
|
|
|
|
pr_method_list_t *method_list;
|
|
|
|
pr_method_t *method;
|
2004-11-10 05:37:00 +00:00
|
|
|
pr_sel_t *sel;
|
2002-05-22 17:32:44 +00:00
|
|
|
int i;
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
int dev = developer;
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_string_t *names;
|
2002-05-22 17:32:44 +00:00
|
|
|
|
2021-03-29 10:58:00 +00:00
|
|
|
if (dev & SYS_rua_msg) {
|
2020-02-25 14:14:18 +00:00
|
|
|
names = probj->selector_names;
|
2011-01-10 00:21:42 +00:00
|
|
|
Sys_Printf ("Searching for %s\n",
|
|
|
|
PR_GetString (pr, names[selector->sel_id]));
|
|
|
|
}
|
2002-05-22 17:32:44 +00:00
|
|
|
while (c) {
|
2021-03-29 10:58:00 +00:00
|
|
|
if (dev & SYS_rua_msg)
|
2011-01-10 00:21:42 +00:00
|
|
|
Sys_Printf ("Checking class %s @ %x\n",
|
|
|
|
PR_GetString (pr, c->name),
|
|
|
|
PR_SetPointer (pr, c));
|
2002-05-31 06:01:47 +00:00
|
|
|
method_list = &G_STRUCT (pr, pr_method_list_t, c->methods);
|
|
|
|
while (method_list) {
|
2021-03-29 10:58:00 +00:00
|
|
|
if (dev & SYS_rua_msg) {
|
2011-01-10 00:21:42 +00:00
|
|
|
Sys_Printf ("method list %x\n",
|
|
|
|
PR_SetPointer (pr, method_list));
|
|
|
|
}
|
2002-05-22 17:32:44 +00:00
|
|
|
for (i = 0, method = method_list->method_list;
|
2002-05-31 06:01:47 +00:00
|
|
|
i < method_list->method_count; i++, method++) {
|
2004-11-10 05:37:00 +00:00
|
|
|
sel = &G_STRUCT (pr, pr_sel_t, method->method_name);
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (developer & SYS_rua_msg) {
|
2020-02-25 14:14:18 +00:00
|
|
|
names = probj->selector_names;
|
2011-01-10 00:21:42 +00:00
|
|
|
Sys_Printf (" %s\n",
|
|
|
|
PR_GetString (pr, names[sel->sel_id]));
|
|
|
|
}
|
2012-12-16 04:19:31 +00:00
|
|
|
if (sel->sel_id == selector->sel_id) {
|
2021-03-29 10:58:00 +00:00
|
|
|
if (dev & SYS_rua_msg) {
|
2020-02-25 14:14:18 +00:00
|
|
|
names = probj->selector_names;
|
2012-12-16 04:19:31 +00:00
|
|
|
Sys_Printf ("found %s: %x\n",
|
|
|
|
PR_GetString (pr, names[selector->sel_id]),
|
|
|
|
method->method_imp);
|
|
|
|
}
|
2003-08-23 22:16:42 +00:00
|
|
|
return method;
|
2012-12-16 04:19:31 +00:00
|
|
|
}
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
2002-05-31 06:01:47 +00:00
|
|
|
method_list = &G_STRUCT (pr, pr_method_list_t,
|
|
|
|
method_list->method_next);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
c = c->super_class ? &G_STRUCT (pr, pr_class_t, c->super_class) : 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-11-02 05:12:00 +00:00
|
|
|
static void
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_send_initialize (probj_t *probj, pr_class_t *class)
|
2004-11-02 05:12:00 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
progs_t *pr = probj->pr;
|
2004-11-02 05:12:00 +00:00
|
|
|
pr_method_list_t *method_list;
|
|
|
|
pr_method_t *method;
|
|
|
|
pr_sel_t *sel;
|
|
|
|
pr_class_t *class_pointer;
|
2020-02-25 14:14:18 +00:00
|
|
|
pr_sel_t *selector = sel_register_name (probj, "initialize");
|
2004-11-02 05:12:00 +00:00
|
|
|
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)
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_send_initialize (probj, &G_STRUCT (pr, pr_class_t,
|
|
|
|
class->super_class));
|
2004-11-02 05:12:00 +00:00
|
|
|
|
|
|
|
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) {
|
2007-06-09 13:44:06 +00:00
|
|
|
PR_PushFrame (pr);
|
2020-02-25 05:30:26 +00:00
|
|
|
__auto_type params = PR_SaveParams (pr);
|
2007-06-09 13:44:06 +00:00
|
|
|
// param 0 is known to be the class pointer
|
|
|
|
P_POINTER (pr, 1) = method->method_name;
|
|
|
|
// pr->pr_argc is known to be 2
|
2004-11-02 05:12:00 +00:00
|
|
|
PR_ExecuteProgram (pr, method->method_imp);
|
2020-02-25 05:30:26 +00:00
|
|
|
PR_RestoreParams (pr, params);
|
2007-06-09 13:44:06 +00:00
|
|
|
PR_PopFrame (pr);
|
2004-11-02 05:12:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
method_list = &G_STRUCT (pr, pr_method_list_t,
|
|
|
|
method_list->method_next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-09 09:11:36 +00:00
|
|
|
static void
|
|
|
|
obj_install_methods_in_dtable (probj_t *probj, pr_class_t *class,
|
|
|
|
pr_method_list_t *method_list)
|
|
|
|
{
|
|
|
|
progs_t *pr = probj->pr;
|
|
|
|
dtable_t *dtable;
|
|
|
|
|
|
|
|
if (!method_list) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (method_list->method_next) {
|
|
|
|
obj_install_methods_in_dtable (probj, class,
|
|
|
|
&G_STRUCT (pr, pr_method_list_t,
|
|
|
|
method_list->method_next));
|
|
|
|
}
|
|
|
|
|
|
|
|
dtable = get_dtable (probj, __FUNCTION__, class->dtable);
|
|
|
|
for (int i = 0; i < method_list->method_count; i++) {
|
|
|
|
pr_method_t *method = &method_list->method_list[i];
|
|
|
|
pr_sel_t *sel = &G_STRUCT (pr, pr_sel_t, method->method_name);
|
|
|
|
if (sel->sel_id < dtable->size) {
|
|
|
|
dtable->imp[sel->sel_id] = method->method_imp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
obj_install_dispatch_table_for_class (probj_t *probj, pr_class_t *class)
|
|
|
|
{
|
|
|
|
progs_t *pr = probj->pr;
|
|
|
|
pr_class_t *super = &G_STRUCT (pr, pr_class_t, class->super_class);
|
|
|
|
dtable_t *dtable;
|
|
|
|
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_rua_obj, " install dispatch for class %s %x %d\n",
|
2020-03-09 09:11:36 +00:00
|
|
|
PR_GetString (pr, class->name),
|
|
|
|
class->methods,
|
|
|
|
PR_CLS_ISMETA(class));
|
|
|
|
|
|
|
|
if (super && !super->dtable) {
|
|
|
|
obj_install_dispatch_table_for_class (probj, super);
|
|
|
|
}
|
|
|
|
|
|
|
|
dtable = dtable_new (probj);
|
|
|
|
class->dtable = dtable_index (probj, dtable);
|
|
|
|
dtable->size = probj->selector_index + 1;
|
2022-01-18 06:32:43 +00:00
|
|
|
dtable->imp = calloc (dtable->size, sizeof (pr_func_t));
|
2020-03-09 09:11:36 +00:00
|
|
|
if (super) {
|
|
|
|
dtable_t *super_dtable = get_dtable (probj, __FUNCTION__,
|
|
|
|
super->dtable);
|
|
|
|
memcpy (dtable->imp, super_dtable->imp,
|
|
|
|
super_dtable->size * sizeof (*dtable->imp));
|
|
|
|
}
|
|
|
|
obj_install_methods_in_dtable (probj, class,
|
|
|
|
&G_STRUCT (pr, pr_method_list_t,
|
|
|
|
class->methods));
|
|
|
|
}
|
|
|
|
|
2020-03-09 11:41:17 +00:00
|
|
|
static inline dtable_t *
|
|
|
|
obj_check_dtable_installed (probj_t *probj, pr_class_t *class)
|
|
|
|
{
|
|
|
|
if (!class->dtable) {
|
|
|
|
obj_install_dispatch_table_for_class (probj, class);
|
|
|
|
}
|
|
|
|
return get_dtable (probj, __FUNCTION__, class->dtable);
|
|
|
|
}
|
|
|
|
|
2022-01-18 06:32:43 +00:00
|
|
|
static pr_func_t
|
2020-02-25 14:14:18 +00:00
|
|
|
get_imp (probj_t *probj, pr_class_t *class, pr_sel_t *sel)
|
2004-11-02 05:12:00 +00:00
|
|
|
{
|
2022-01-18 06:32:43 +00:00
|
|
|
pr_func_t imp = 0;
|
2004-11-02 05:12:00 +00:00
|
|
|
|
2020-03-09 09:11:36 +00:00
|
|
|
if (class->dtable) {
|
|
|
|
dtable_t *dtable = get_dtable (probj, __FUNCTION__, class->dtable);
|
|
|
|
if (sel->sel_id < dtable->size) {
|
|
|
|
imp = dtable->imp[sel->sel_id];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!imp) {
|
|
|
|
if (!class->dtable) {
|
|
|
|
obj_install_dispatch_table_for_class (probj, class);
|
|
|
|
imp = get_imp (probj, class, sel);
|
|
|
|
} else {
|
|
|
|
imp = probj->obj_forward;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return imp;
|
2004-11-02 05:12:00 +00:00
|
|
|
}
|
|
|
|
|
2020-03-09 11:41:17 +00:00
|
|
|
static int
|
|
|
|
obj_reponds_to (probj_t *probj, pr_id_t *obj, pr_sel_t *sel)
|
|
|
|
{
|
|
|
|
progs_t *pr = probj->pr;
|
|
|
|
pr_class_t *class;
|
|
|
|
dtable_t *dtable;
|
2022-01-18 06:32:43 +00:00
|
|
|
pr_func_t imp = 0;
|
2020-03-09 11:41:17 +00:00
|
|
|
|
|
|
|
class = &G_STRUCT (pr, pr_class_t, obj->class_pointer);
|
|
|
|
dtable = obj_check_dtable_installed (probj, class);
|
|
|
|
|
|
|
|
if (sel->sel_id < dtable->size) {
|
|
|
|
imp = dtable->imp[sel->sel_id];
|
|
|
|
}
|
|
|
|
return imp != 0;
|
|
|
|
}
|
|
|
|
|
2022-01-18 06:32:43 +00:00
|
|
|
static pr_func_t
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_msg_lookup (probj_t *probj, pr_id_t *receiver, pr_sel_t *op)
|
2002-05-22 19:02:26 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
progs_t *pr = probj->pr;
|
2002-05-22 19:02:26 +00:00
|
|
|
pr_class_t *class;
|
|
|
|
if (!receiver)
|
|
|
|
return 0;
|
|
|
|
class = &G_STRUCT (pr, pr_class_t, receiver->class_pointer);
|
2004-11-11 00:34:00 +00:00
|
|
|
if (PR_CLS_ISCLASS (class)) {
|
|
|
|
if (!PR_CLS_ISINITIALIZED (class))
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_send_initialize (probj, class);
|
2004-11-11 00:34:00 +00:00
|
|
|
} else if (PR_CLS_ISMETA (class)
|
|
|
|
&& PR_CLS_ISCLASS ((pr_class_t *) receiver)) {
|
|
|
|
if (!PR_CLS_ISINITIALIZED ((pr_class_t *) receiver))
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_send_initialize (probj, (pr_class_t *) receiver);
|
2004-11-11 00:34:00 +00:00
|
|
|
}
|
2020-02-25 14:14:18 +00:00
|
|
|
return get_imp (probj, class, op);
|
2002-05-22 19:02:26 +00:00
|
|
|
}
|
|
|
|
|
2022-01-18 06:32:43 +00:00
|
|
|
static pr_func_t
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_msg_lookup_super (probj_t *probj, pr_super_t *super, pr_sel_t *op)
|
2002-05-22 19:02:26 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
progs_t *pr = probj->pr;
|
2002-05-22 19:02:26 +00:00
|
|
|
pr_class_t *class;
|
2003-05-15 05:58:31 +00:00
|
|
|
|
|
|
|
if (!super->self)
|
2002-05-22 19:02:26 +00:00
|
|
|
return 0;
|
2003-05-15 05:58:31 +00:00
|
|
|
|
|
|
|
class = &G_STRUCT (pr, pr_class_t, super->class);
|
2020-02-25 14:14:18 +00:00
|
|
|
return get_imp (probj, class, op);
|
2002-05-22 19:02:26 +00:00
|
|
|
}
|
|
|
|
|
2004-01-05 01:41:20 +00:00
|
|
|
static void
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_verror (probj_t *probj, pr_id_t *object, int code, const char *fmt, int count,
|
2012-12-16 04:19:31 +00:00
|
|
|
pr_type_t **args)
|
2004-01-05 01:41:20 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
progs_t *pr = probj->pr;
|
2020-03-31 04:56:40 +00:00
|
|
|
__auto_type class = &G_STRUCT (pr, pr_class_t, object->class_pointer);
|
2004-01-05 01:41:20 +00:00
|
|
|
|
2022-05-12 09:23:32 +00:00
|
|
|
PR_Sprintf (pr, probj->msg, "obj_verror", fmt, count, args);
|
|
|
|
PR_RunError (pr, "%s: %s", PR_GetString (pr, class->name), probj->msg->str);
|
2004-01-05 01:41:20 +00:00
|
|
|
}
|
|
|
|
|
2011-01-10 00:21:42 +00:00
|
|
|
static void
|
2022-01-18 03:11:14 +00:00
|
|
|
dump_ivars (probj_t *probj, pr_ptr_t _ivars)
|
2011-01-10 00:21:42 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
progs_t *pr = probj->pr;
|
2011-01-10 00:21:42 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-02 04:02:29 +00:00
|
|
|
static void
|
|
|
|
obj_init_statics (probj_t *probj)
|
|
|
|
{
|
|
|
|
progs_t *pr = probj->pr;
|
|
|
|
obj_list **cell = &probj->uninitialized_statics;
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_ptr_t *ptr;
|
|
|
|
pr_ptr_t *inst;
|
2020-03-02 04:02:29 +00:00
|
|
|
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_rua_obj, "Initializing statics\n");
|
2020-03-02 04:02:29 +00:00
|
|
|
while (*cell) {
|
|
|
|
int initialized = 1;
|
|
|
|
|
|
|
|
for (ptr = (*cell)->data; *ptr; ptr++) {
|
|
|
|
__auto_type statics = &G_STRUCT (pr, pr_static_instances_t, *ptr);
|
|
|
|
const char *class_name = PR_GetString (pr, statics->class_name);
|
|
|
|
pr_class_t *class = Hash_Find (probj->classes, class_name);
|
|
|
|
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_rua_obj, " %s %p\n", class_name, class);
|
2020-03-02 04:02:29 +00:00
|
|
|
if (!class) {
|
|
|
|
initialized = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp (class_name, "Protocol") == 0) {
|
|
|
|
// protocols are special
|
|
|
|
for (inst = statics->instances; *inst; inst++) {
|
|
|
|
obj_init_protocol (probj, class,
|
|
|
|
&G_STRUCT (pr, pr_protocol_t, *inst));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (inst = statics->instances; *inst; inst++) {
|
|
|
|
pr_id_t *id = &G_STRUCT (pr, pr_id_t, *inst);
|
|
|
|
id->class_pointer = PR_SetPointer (pr, class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (initialized) {
|
2022-05-12 09:23:32 +00:00
|
|
|
list_remove (probj, cell);
|
2020-03-02 04:02:29 +00:00
|
|
|
} else {
|
|
|
|
cell = &(*cell)->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-11 00:34:00 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua___obj_exec_class (progs_t *pr, void *data)
|
2004-11-11 00:34:00 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
probj_t *probj = pr->pr_objective_resources;
|
2004-11-11 00:34:00 +00:00
|
|
|
pr_module_t *module = &P_STRUCT (pr, pr_module_t, 0);
|
|
|
|
pr_symtab_t *symtab;
|
|
|
|
pr_sel_t *sel;
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_ptr_t *ptr;
|
2004-11-11 00:34:00 +00:00
|
|
|
int i;
|
|
|
|
obj_list **cell;
|
|
|
|
|
|
|
|
if (!module)
|
|
|
|
return;
|
|
|
|
symtab = &G_STRUCT (pr, pr_symtab_t, module->symtab);
|
|
|
|
if (!symtab)
|
|
|
|
return;
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_rua_obj, "Initializing %s module\n"
|
2011-01-10 00:21:42 +00:00
|
|
|
"symtab @ %x : %d selector%s @ %x, "
|
2020-03-02 04:02:29 +00:00
|
|
|
"%d class%s and %d categor%s\n"
|
|
|
|
"static instance lists: %s\n",
|
2011-01-10 00:21:42 +00:00
|
|
|
PR_GetString (pr, module->name), module->symtab,
|
|
|
|
symtab->sel_ref_cnt, symtab->sel_ref_cnt == 1 ? "" : "s",
|
|
|
|
symtab->refs,
|
|
|
|
symtab->cls_def_cnt, symtab->cls_def_cnt == 1 ? "" : "es",
|
|
|
|
symtab->cat_def_cnt,
|
2020-03-02 04:02:29 +00:00
|
|
|
symtab->cat_def_cnt == 1 ? "y" : "ies",
|
|
|
|
symtab->defs[symtab->cls_def_cnt
|
|
|
|
+ symtab->cat_def_cnt] ? "yes" : "no");
|
2004-11-11 00:34:00 +00:00
|
|
|
|
2022-05-12 09:23:32 +00:00
|
|
|
probj->module_list = list_cons (probj, module, probj->module_list);
|
2004-11-11 00:34:00 +00:00
|
|
|
|
|
|
|
sel = &G_STRUCT (pr, pr_sel_t, symtab->refs);
|
|
|
|
for (i = 0; i < symtab->sel_ref_cnt; i++) {
|
|
|
|
const char *name, *types;
|
|
|
|
name = PR_GetString (pr, sel->sel_id);
|
|
|
|
types = PR_GetString (pr, sel->sel_types);
|
2020-02-25 14:14:18 +00:00
|
|
|
sel_register_typed_name (probj, name, types, sel);
|
2004-11-11 00:34:00 +00:00
|
|
|
sel++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr = symtab->defs;
|
|
|
|
for (i = 0; i < symtab->cls_def_cnt; i++, ptr++) {
|
|
|
|
pr_class_t *class = &G_STRUCT (pr, pr_class_t, *ptr);
|
|
|
|
pr_class_t *meta = &G_STRUCT (pr, pr_class_t, class->class_pointer);
|
|
|
|
const char *super_class = PR_GetString (pr, class->super_class);
|
|
|
|
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_rua_obj, "Class %s @ %x\n",
|
2011-01-10 00:21:42 +00:00
|
|
|
PR_GetString (pr, class->name), *ptr);
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_rua_obj, " class pointer: %x\n",
|
2011-01-10 00:21:42 +00:00
|
|
|
class->class_pointer);
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_rua_obj, " super class: %s\n",
|
2011-01-10 00:21:42 +00:00
|
|
|
PR_GetString (pr, class->super_class));
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_rua_obj, " instance variables: %d @ %x\n",
|
2011-01-10 00:21:42 +00:00
|
|
|
class->instance_size,
|
|
|
|
class->ivars);
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (developer & SYS_rua_obj)
|
2020-02-25 14:14:18 +00:00
|
|
|
dump_ivars (probj, class->ivars);
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_rua_obj, " instance methods: %x\n",
|
2011-01-10 00:21:42 +00:00
|
|
|
class->methods);
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_rua_obj, " protocols: %x\n", class->protocols);
|
2011-01-10 00:21:42 +00:00
|
|
|
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_rua_obj, " class methods: %x\n", meta->methods);
|
|
|
|
Sys_MaskPrintf (SYS_rua_obj, " instance variables: %d @ %x\n",
|
2011-01-10 00:21:42 +00:00
|
|
|
meta->instance_size,
|
|
|
|
meta->ivars);
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (developer & SYS_rua_obj)
|
2020-02-25 14:14:18 +00:00
|
|
|
dump_ivars (probj, meta->ivars);
|
2011-01-10 00:21:42 +00:00
|
|
|
|
2004-11-11 00:34:00 +00:00
|
|
|
class->subclass_list = 0;
|
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
Hash_Add (probj->classes, class);
|
2004-11-11 00:34:00 +00:00
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_register_selectors_from_class (probj, class);
|
|
|
|
obj_register_selectors_from_class (probj, meta);
|
2004-11-11 00:34:00 +00:00
|
|
|
|
|
|
|
if (class->protocols) {
|
|
|
|
pr_protocol_list_t *protocol_list;
|
|
|
|
protocol_list = &G_STRUCT (pr, pr_protocol_list_t,
|
|
|
|
class->protocols);
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_init_protocols (probj, protocol_list);
|
2004-11-11 00:34:00 +00:00
|
|
|
}
|
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
if (class->super_class && !Hash_Find (probj->classes, super_class))
|
2022-05-12 09:23:32 +00:00
|
|
|
probj->unresolved_classes = list_cons (probj, class,
|
2020-02-25 14:14:18 +00:00
|
|
|
probj->unresolved_classes);
|
2004-11-11 00:34:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < symtab->cat_def_cnt; i++, ptr++) {
|
|
|
|
pr_category_t *category = &G_STRUCT (pr, pr_category_t, *ptr);
|
|
|
|
const char *class_name = PR_GetString (pr, category->class_name);
|
2020-02-25 14:14:18 +00:00
|
|
|
pr_class_t *class = Hash_Find (probj->classes, class_name);
|
2004-11-11 00:34:00 +00:00
|
|
|
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_rua_obj, "Category %s (%s) @ %x\n",
|
2011-01-10 00:21:42 +00:00
|
|
|
PR_GetString (pr, category->class_name),
|
|
|
|
PR_GetString (pr, category->category_name), *ptr);
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_rua_obj, " instance methods: %x\n",
|
2011-01-10 00:21:42 +00:00
|
|
|
category->instance_methods);
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_rua_obj, " class methods: %x\n",
|
2011-01-10 00:21:42 +00:00
|
|
|
category->class_methods);
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_rua_obj, " protocols: %x\n",
|
2011-01-10 00:21:42 +00:00
|
|
|
category->protocols);
|
|
|
|
|
2004-11-11 00:34:00 +00:00
|
|
|
if (class) {
|
2020-02-25 14:14:18 +00:00
|
|
|
finish_category (probj, category, class);
|
2004-11-11 00:34:00 +00:00
|
|
|
} else {
|
2020-02-25 14:14:18 +00:00
|
|
|
probj->unclaimed_categories
|
2022-05-12 09:23:32 +00:00
|
|
|
= list_cons (probj, category, probj->unclaimed_categories);
|
2004-11-11 00:34:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-02 04:02:29 +00:00
|
|
|
if (*ptr) {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_rua_obj, "Static instances lists: %x\n", *ptr);
|
2020-03-02 04:02:29 +00:00
|
|
|
probj->uninitialized_statics
|
2022-05-12 09:23:32 +00:00
|
|
|
= list_cons (probj, &G_STRUCT (pr, pr_ptr_t, *ptr),
|
2020-03-02 04:02:29 +00:00
|
|
|
probj->uninitialized_statics);
|
|
|
|
}
|
|
|
|
if (probj->uninitialized_statics) {
|
|
|
|
obj_init_statics (probj);
|
|
|
|
}
|
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
for (cell = &probj->unclaimed_categories; *cell; ) {
|
2004-11-11 00:34:00 +00:00
|
|
|
pr_category_t *category = (*cell)->data;
|
|
|
|
const char *class_name = PR_GetString (pr, category->class_name);
|
2020-02-25 14:14:18 +00:00
|
|
|
pr_class_t *class = Hash_Find (probj->classes, class_name);
|
2004-11-11 00:34:00 +00:00
|
|
|
|
|
|
|
if (class) {
|
2022-05-12 09:23:32 +00:00
|
|
|
list_remove (probj, cell);
|
2020-02-25 14:14:18 +00:00
|
|
|
finish_category (probj, category, class);
|
2004-11-11 00:34:00 +00:00
|
|
|
} else {
|
|
|
|
cell = &(*cell)->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
if (probj->unclaimed_proto_list
|
|
|
|
&& Hash_Find (probj->classes, "Protocol")) {
|
|
|
|
for (cell = &probj->unclaimed_proto_list; *cell; ) {
|
|
|
|
obj_init_protocols (probj, (*cell)->data);
|
2022-05-12 09:23:32 +00:00
|
|
|
list_remove (probj, cell);
|
2004-11-11 00:34:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_rua_obj, "Finished initializing %s module\n",
|
2011-01-10 00:21:42 +00:00
|
|
|
PR_GetString (pr, module->name));
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_send_load (probj);
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_rua_obj, "Leaving %s module init\n",
|
2011-01-10 00:21:42 +00:00
|
|
|
PR_GetString (pr, module->name));
|
2004-11-11 00:34:00 +00:00
|
|
|
}
|
|
|
|
|
2020-03-09 10:09:08 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua___obj_forward (progs_t *pr, void *data)
|
2020-03-09 10:09:08 +00:00
|
|
|
{
|
|
|
|
probj_t *probj = pr->pr_objective_resources;
|
2020-03-09 11:41:17 +00:00
|
|
|
pr_id_t *obj = &P_STRUCT (pr, pr_id_t, 0);
|
|
|
|
pr_sel_t *sel = &P_STRUCT (pr, pr_sel_t, 1);
|
|
|
|
pr_sel_t *fwd_sel = probj->forward_selector;
|
|
|
|
pr_sel_t *err_sel;
|
2022-09-09 04:51:42 +00:00
|
|
|
pr_class_t *class = &G_STRUCT (pr, pr_class_t, obj->class_pointer);
|
2022-01-18 06:32:43 +00:00
|
|
|
pr_func_t imp;
|
2020-03-09 11:41:17 +00:00
|
|
|
|
|
|
|
if (!fwd_sel) {
|
|
|
|
//FIXME sel_register_typed_name is really not the way to go about
|
|
|
|
//looking for a selector by name
|
|
|
|
fwd_sel = sel_register_typed_name (probj, "forward::", "", 0);
|
|
|
|
probj->forward_selector = fwd_sel;
|
|
|
|
}
|
|
|
|
if (obj_reponds_to (probj, obj, fwd_sel)) {
|
|
|
|
imp = get_imp (probj, class, fwd_sel);
|
2020-03-09 13:20:11 +00:00
|
|
|
// forward:(SEL) sel :(@va_list) args
|
2022-02-05 04:01:44 +00:00
|
|
|
// args is full param list as a va_list
|
|
|
|
pr_string_t args_block = 0;
|
|
|
|
int argc;
|
|
|
|
pr_type_t *argv;
|
|
|
|
if (pr->globals.stack) {
|
|
|
|
argv = pr->pr_params[0];
|
2022-02-05 05:24:12 +00:00
|
|
|
argc = probj->selector_argc[sel->sel_id];
|
|
|
|
if (argc < 0) {
|
|
|
|
// -ve values indicate varargs functions and is the ones
|
|
|
|
// complement of the number of real parameters before the
|
|
|
|
// ellipsis. However, Ruamoko ISA progs pass va_list through
|
|
|
|
// ... so in the end, a -ve value indicates the total number
|
|
|
|
// of arguments (including va_list) passed to the function.
|
|
|
|
argc = -argc;
|
|
|
|
}
|
2022-02-05 04:01:44 +00:00
|
|
|
} else {
|
|
|
|
size_t parm_size = pr->pr_param_size * sizeof(pr_type_t);
|
|
|
|
size_t size = pr->pr_argc * parm_size;
|
|
|
|
args_block = PR_AllocTempBlock (pr, size);
|
|
|
|
|
|
|
|
argc = pr->pr_argc;
|
|
|
|
argv = (pr_type_t *) PR_GetString (pr, args_block);
|
|
|
|
// can't memcpy all params because 0 and 1 could be anywhere
|
|
|
|
memcpy (argv + 0, &P_INT (pr, 0), 4 * sizeof (pr_type_t));
|
|
|
|
memcpy (argv + 4, &P_INT (pr, 1), 4 * sizeof (pr_type_t));
|
|
|
|
memcpy (argv + 8, &P_INT (pr, 2), (argc - 2) * parm_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
RUA_CALL_BEGIN (pr, 4);
|
2020-03-09 13:20:11 +00:00
|
|
|
P_POINTER (pr, 0) = PR_SetPointer (pr, obj);
|
|
|
|
P_POINTER (pr, 1) = PR_SetPointer (pr, fwd_sel);
|
|
|
|
P_POINTER (pr, 2) = PR_SetPointer (pr, sel);
|
|
|
|
P_PACKED (pr, pr_va_list_t, 3).count = argc;
|
|
|
|
P_PACKED (pr, pr_va_list_t, 3).list = PR_SetPointer (pr, argv);
|
2022-02-05 04:01:44 +00:00
|
|
|
if (args_block) {
|
|
|
|
PR_PushTempString (pr, args_block);
|
|
|
|
}
|
|
|
|
RUA_CALL_END (pr, imp);
|
2020-03-09 11:41:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
err_sel = sel_register_typed_name (probj, "doesNotRecognize:", "", 0);
|
|
|
|
if (obj_reponds_to (probj, obj, err_sel)) {
|
2022-02-05 04:01:44 +00:00
|
|
|
RUA_CALL_BEGIN (pr, 3)
|
2020-03-09 11:41:17 +00:00
|
|
|
P_POINTER (pr, 0) = PR_SetPointer (pr, obj);
|
|
|
|
P_POINTER (pr, 1) = PR_SetPointer (pr, err_sel);
|
|
|
|
P_POINTER (pr, 2) = PR_SetPointer (pr, sel);
|
2022-02-05 04:01:44 +00:00
|
|
|
RUA_CALL_END (pr, get_imp (probj, class, err_sel))
|
2020-03-09 11:41:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dsprintf (probj->msg, "(%s) %s does not recognize %s",
|
|
|
|
PR_CLS_ISMETA (class) ? "class" : "instance",
|
|
|
|
PR_GetString (pr, class->name),
|
|
|
|
PR_GetString (pr, probj->selector_names[sel->sel_id]));
|
|
|
|
|
|
|
|
err_sel = sel_register_typed_name (probj, "error:", "", 0);
|
|
|
|
if (obj_reponds_to (probj, obj, err_sel)) {
|
2022-02-05 04:01:44 +00:00
|
|
|
RUA_CALL_BEGIN (pr, 3)
|
2020-03-09 11:41:17 +00:00
|
|
|
P_POINTER (pr, 0) = PR_SetPointer (pr, obj);
|
|
|
|
P_POINTER (pr, 1) = PR_SetPointer (pr, err_sel);
|
|
|
|
P_POINTER (pr, 2) = PR_SetTempString (pr, probj->msg->str);
|
2022-02-05 04:01:44 +00:00
|
|
|
RUA_CALL_END (pr, get_imp (probj, class, err_sel))
|
2020-03-09 11:41:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_RunError (pr, "%s", probj->msg->str);
|
2020-03-09 10:09:08 +00:00
|
|
|
}
|
|
|
|
|
2020-03-09 15:07:01 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua___obj_responds_to (progs_t *pr, void *data)
|
2020-03-09 15:07:01 +00:00
|
|
|
{
|
|
|
|
probj_t *probj = pr->pr_objective_resources;
|
|
|
|
pr_id_t *obj = &P_STRUCT (pr, pr_id_t, 0);
|
|
|
|
pr_sel_t *sel = &P_STRUCT (pr, pr_sel_t, 1);
|
|
|
|
|
|
|
|
R_INT (pr) = obj_reponds_to (probj, obj, sel);
|
|
|
|
}
|
|
|
|
|
2002-05-22 17:32:44 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_obj_error (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
probj_t *probj = pr->pr_objective_resources;
|
2004-01-05 01:41:20 +00:00
|
|
|
pr_id_t *object = &P_STRUCT (pr, pr_id_t, 0);
|
|
|
|
int code = P_INT (pr, 1);
|
|
|
|
const char *fmt = P_GSTRING (pr, 2);
|
|
|
|
int count = pr->pr_argc - 3;
|
2012-12-16 04:19:31 +00:00
|
|
|
pr_type_t **args = &pr->pr_params[3];
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2023-03-05 08:20:04 +00:00
|
|
|
if (pr->progs->version == PROG_VERSION) {
|
|
|
|
__auto_type va_list = &P_PACKED (pr, pr_va_list_t, 3);
|
|
|
|
count = va_list->count;
|
|
|
|
if (count) {
|
|
|
|
args = alloca (count * sizeof (pr_type_t *));
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
args[i] = &pr->pr_globals[va_list->list + i * 4];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
args = 0;
|
|
|
|
}
|
|
|
|
}
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_verror (probj, object, code, fmt, count, args);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_obj_verror (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
probj_t *probj = pr->pr_objective_resources;
|
2004-01-05 01:41:20 +00:00
|
|
|
pr_id_t *object = &P_STRUCT (pr, pr_id_t, 0);
|
|
|
|
int code = P_INT (pr, 1);
|
|
|
|
const char *fmt = P_GSTRING (pr, 2);
|
|
|
|
pr_va_list_t *val = (pr_va_list_t *) pr->pr_params[3];
|
2012-12-16 04:19:31 +00:00
|
|
|
pr_type_t *params = &G_STRUCT (pr, pr_type_t, val->list);
|
|
|
|
pr_type_t **args = alloca (val->count * sizeof (pr_type_t *));
|
|
|
|
int i;
|
2004-01-05 01:41:20 +00:00
|
|
|
|
2012-12-16 04:19:31 +00:00
|
|
|
for (i = 0; i < val->count; i++)
|
|
|
|
args[i] = params + i * pr->pr_param_size;
|
2020-02-25 14:14:18 +00:00
|
|
|
obj_verror (probj, object, code, fmt, val->count, args);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_obj_set_error_handler (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
//probj_t *probj = pr->pr_objective_resources;
|
2022-01-18 06:32:43 +00:00
|
|
|
//pr_func_t func = P_INT (pr, 0);
|
2002-05-22 19:02:26 +00:00
|
|
|
//arglist
|
2002-05-22 17:32:44 +00:00
|
|
|
//XXX
|
2002-05-22 19:02:26 +00:00
|
|
|
PR_RunError (pr, "%s, not implemented", __FUNCTION__);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
2022-09-09 04:51:42 +00:00
|
|
|
static const char *
|
|
|
|
rua_at_handler (progs_t *pr, pr_ptr_t at_param, void *_probj)
|
|
|
|
{
|
|
|
|
probj_t *probj = _probj;
|
|
|
|
pr_id_t *obj = &G_STRUCT (pr, pr_id_t, at_param);
|
|
|
|
pr_class_t *class = &G_STRUCT (pr, pr_class_t, obj->class_pointer);
|
|
|
|
//FIXME sel_register_typed_name is really not the way to go about
|
|
|
|
//looking for a selector by name
|
|
|
|
pr_sel_t *describe_sel=sel_register_typed_name (probj, "describe", "", 0);
|
|
|
|
pr_func_t imp = get_imp (probj, class, describe_sel);
|
|
|
|
|
|
|
|
PR_PushFrame (pr);
|
|
|
|
PR_RESET_PARAMS (pr);
|
|
|
|
P_POINTER (pr, 0) = at_param;
|
|
|
|
P_POINTER (pr, 1) = PR_SetPointer (pr, describe_sel);
|
|
|
|
pr->pr_argc = 2;
|
|
|
|
PR_ExecuteProgram (pr, imp);
|
|
|
|
PR_PopFrame (pr);
|
|
|
|
//FIXME the lifetime of the string may be a problem
|
|
|
|
return PR_GetString (pr, R_STRING (pr));
|
|
|
|
}
|
|
|
|
|
2002-05-22 17:32:44 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_obj_msg_lookup (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
probj_t *probj = pr->pr_objective_resources;
|
2002-05-22 22:35:37 +00:00
|
|
|
pr_id_t *receiver = &P_STRUCT (pr, pr_id_t, 0);
|
|
|
|
pr_sel_t *op = &P_STRUCT (pr, pr_sel_t, 1);
|
2004-11-07 03:00:00 +00:00
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
R_INT (pr) = obj_msg_lookup (probj, receiver, op);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_obj_msg_lookup_super (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
probj_t *probj = pr->pr_objective_resources;
|
2003-05-15 05:58:31 +00:00
|
|
|
pr_super_t *super = &P_STRUCT (pr, pr_super_t, 0);
|
|
|
|
pr_sel_t *_cmd = &P_STRUCT (pr, pr_sel_t, 1);
|
2004-11-07 03:00:00 +00:00
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
R_INT (pr) = obj_msg_lookup_super (probj, super, _cmd);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_obj_msg_sendv (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
probj_t *probj = pr->pr_objective_resources;
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_ptr_t obj = P_POINTER (pr, 0);
|
2002-10-16 22:17:26 +00:00
|
|
|
pr_id_t *receiver = &P_STRUCT (pr, pr_id_t, 0);
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_ptr_t sel = P_POINTER (pr, 1);
|
2002-10-16 22:17:26 +00:00
|
|
|
pr_sel_t *op = &P_STRUCT (pr, pr_sel_t, 1);
|
2022-01-18 06:32:43 +00:00
|
|
|
pr_func_t imp = obj_msg_lookup (probj, receiver, op);
|
2002-10-16 22:17:26 +00:00
|
|
|
|
2020-03-09 17:56:37 +00:00
|
|
|
__auto_type args = &P_PACKED (pr, pr_va_list_t, 2);
|
|
|
|
int count = args->count;
|
|
|
|
pr_type_t *params = G_GPOINTER (pr, args->list);
|
|
|
|
|
2022-01-23 05:17:25 +00:00
|
|
|
if (count < 2 || count > PR_MAX_PARAMS) {
|
2020-03-09 17:56:37 +00:00
|
|
|
PR_RunError (pr, "bad args count in obj_msg_sendv: %d", count);
|
|
|
|
}
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (pr_boundscheck) {
|
2010-01-13 06:36:16 +00:00
|
|
|
PR_BoundsCheckSize (pr, args->list, count * pr->pr_param_size);
|
2020-03-09 17:56:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!imp) {
|
2002-10-16 22:17:26 +00:00
|
|
|
PR_RunError (pr, "%s does not respond to %s",
|
2020-02-25 14:14:18 +00:00
|
|
|
PR_GetString (pr, object_get_class_name (probj, receiver)),
|
|
|
|
PR_GetString (pr, probj->selector_names[op->sel_id]));
|
2020-03-09 17:56:37 +00:00
|
|
|
}
|
|
|
|
|
2022-02-05 04:01:44 +00:00
|
|
|
RUA_CALL_BEGIN (pr, count)
|
2020-03-09 17:56:37 +00:00
|
|
|
// skip over the first two parameters because receiver and op will
|
|
|
|
// replace them
|
|
|
|
count -= 2;
|
|
|
|
params += 2 * pr->pr_param_size;
|
2022-02-05 04:01:44 +00:00
|
|
|
|
2020-03-09 17:56:37 +00:00
|
|
|
P_POINTER (pr, 0) = obj;
|
|
|
|
P_POINTER (pr, 1) = sel;
|
|
|
|
if (count) {
|
|
|
|
memcpy (&P_INT (pr, 2), params,
|
|
|
|
count * sizeof (pr_type_t) * pr->pr_param_size);
|
|
|
|
}
|
2022-02-05 04:01:44 +00:00
|
|
|
RUA_CALL_END (pr, imp)
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
2022-04-26 06:10:00 +00:00
|
|
|
#define RETAIN_COUNT(obj) PR_PTR (int, &(obj)[-1])
|
|
|
|
|
2012-11-08 11:24:25 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_obj_increment_retaincount (progs_t *pr, void *data)
|
2012-11-08 11:24:25 +00:00
|
|
|
{
|
|
|
|
pr_type_t *obj = &P_STRUCT (pr, pr_type_t, 0);
|
2022-04-26 06:10:00 +00:00
|
|
|
R_INT (pr) = ++RETAIN_COUNT (obj);
|
2012-11-08 11:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_obj_decrement_retaincount (progs_t *pr, void *data)
|
2012-11-08 11:24:25 +00:00
|
|
|
{
|
|
|
|
pr_type_t *obj = &P_STRUCT (pr, pr_type_t, 0);
|
2022-04-26 06:10:00 +00:00
|
|
|
R_INT (pr) = --RETAIN_COUNT (obj);
|
2012-11-08 11:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_obj_get_retaincount (progs_t *pr, void *data)
|
2012-11-08 11:24:25 +00:00
|
|
|
{
|
|
|
|
pr_type_t *obj = &P_STRUCT (pr, pr_type_t, 0);
|
2022-04-26 06:10:00 +00:00
|
|
|
R_INT (pr) = RETAIN_COUNT (obj);
|
2012-11-08 11:24:25 +00:00
|
|
|
}
|
|
|
|
|
2002-05-22 17:32:44 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_obj_malloc (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2002-05-22 22:35:37 +00:00
|
|
|
int size = P_INT (pr, 0) * sizeof (pr_type_t);
|
2002-05-22 19:02:26 +00:00
|
|
|
void *mem = PR_Zone_Malloc (pr, size);
|
|
|
|
|
2004-11-05 11:49:00 +00:00
|
|
|
RETURN_POINTER (pr, mem);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_obj_atomic_malloc (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2002-05-22 22:35:37 +00:00
|
|
|
int size = P_INT (pr, 0) * sizeof (pr_type_t);
|
2002-05-22 19:02:26 +00:00
|
|
|
void *mem = PR_Zone_Malloc (pr, size);
|
|
|
|
|
2004-11-05 11:49:00 +00:00
|
|
|
RETURN_POINTER (pr, mem);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_obj_valloc (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2002-05-22 22:35:37 +00:00
|
|
|
int size = P_INT (pr, 0) * sizeof (pr_type_t);
|
2002-05-22 19:02:26 +00:00
|
|
|
void *mem = PR_Zone_Malloc (pr, size);
|
|
|
|
|
2004-11-05 11:49:00 +00:00
|
|
|
RETURN_POINTER (pr, mem);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_obj_realloc (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2003-04-22 18:20:15 +00:00
|
|
|
void *mem = (void*)P_GPOINTER (pr, 0);
|
2002-05-29 20:58:53 +00:00
|
|
|
int size = P_INT (pr, 1) * sizeof (pr_type_t);
|
|
|
|
|
|
|
|
mem = PR_Zone_Realloc (pr, mem, size);
|
2004-11-05 11:49:00 +00:00
|
|
|
RETURN_POINTER (pr, mem);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_obj_calloc (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2020-04-02 10:29:54 +00:00
|
|
|
int size = P_INT (pr, 0) * P_INT (pr, 1) * sizeof (pr_type_t);
|
2002-05-22 19:02:26 +00:00
|
|
|
void *mem = PR_Zone_Malloc (pr, size);
|
|
|
|
|
|
|
|
memset (mem, 0, size);
|
2004-11-05 11:49:00 +00:00
|
|
|
RETURN_POINTER (pr, mem);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_obj_free (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2003-04-22 18:20:15 +00:00
|
|
|
void *mem = (void*)P_GPOINTER (pr, 0);
|
2002-05-22 19:02:26 +00:00
|
|
|
|
|
|
|
PR_Zone_Free (pr, mem);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_obj_get_uninstalled_dtable (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
//probj_t *probj = pr->pr_objective_resources;
|
2002-05-22 17:32:44 +00:00
|
|
|
//XXX
|
2002-05-22 19:02:26 +00:00
|
|
|
PR_RunError (pr, "%s, not implemented", __FUNCTION__);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_obj_msgSend (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
probj_t *probj = pr->pr_objective_resources;
|
2002-05-22 22:35:37 +00:00
|
|
|
pr_id_t *self = &P_STRUCT (pr, pr_id_t, 0);
|
|
|
|
pr_sel_t *_cmd = &P_STRUCT (pr, pr_sel_t, 1);
|
2022-01-18 06:32:43 +00:00
|
|
|
pr_func_t imp;
|
2002-05-22 17:32:44 +00:00
|
|
|
|
2002-05-22 19:02:26 +00:00
|
|
|
if (!self) {
|
2012-12-16 04:39:59 +00:00
|
|
|
R_INT (pr) = P_INT (pr, 0);
|
2002-05-22 17:32:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-01-31 05:03:36 +00:00
|
|
|
if (P_UINT (pr, 0) >= pr->globals_size) {
|
|
|
|
PR_RunError (pr, "invalid self: %x", P_UINT (pr, 0));
|
|
|
|
}
|
2002-05-22 19:02:26 +00:00
|
|
|
if (!_cmd)
|
2002-05-22 17:32:44 +00:00
|
|
|
PR_RunError (pr, "null selector");
|
2020-02-25 14:14:18 +00:00
|
|
|
imp = obj_msg_lookup (probj, self, _cmd);
|
2004-11-07 03:00:00 +00:00
|
|
|
if (!imp)
|
2002-05-22 17:32:44 +00:00
|
|
|
PR_RunError (pr, "%s does not respond to %s",
|
2020-02-25 14:14:18 +00:00
|
|
|
PR_GetString (pr, object_get_class_name (probj, self)),
|
|
|
|
PR_GetString (pr, probj->selector_names[_cmd->sel_id]));
|
2002-10-15 18:53:33 +00:00
|
|
|
|
2022-01-17 10:12:28 +00:00
|
|
|
PR_CallFunction (pr, imp, pr->pr_return);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_obj_msgSend_super (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
probj_t *probj = pr->pr_objective_resources;
|
2003-05-15 05:58:31 +00:00
|
|
|
pr_super_t *super = &P_STRUCT (pr, pr_super_t, 0);
|
2002-05-22 22:35:37 +00:00
|
|
|
pr_sel_t *_cmd = &P_STRUCT (pr, pr_sel_t, 1);
|
2022-01-18 06:32:43 +00:00
|
|
|
pr_func_t imp;
|
2002-05-22 17:32:44 +00:00
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
imp = obj_msg_lookup_super (probj, super, _cmd);
|
2004-11-07 03:00:00 +00:00
|
|
|
if (!imp) {
|
2003-05-15 05:58:31 +00:00
|
|
|
pr_id_t *self = &G_STRUCT (pr, pr_id_t, super->self);
|
2002-05-22 17:32:44 +00:00
|
|
|
PR_RunError (pr, "%s does not respond to %s",
|
2020-02-25 14:14:18 +00:00
|
|
|
PR_GetString (pr, object_get_class_name (probj, self)),
|
|
|
|
PR_GetString (pr, probj->selector_names[_cmd->sel_id]));
|
2003-05-15 05:58:31 +00:00
|
|
|
}
|
2022-01-31 10:04:18 +00:00
|
|
|
if (pr->progs->version < PROG_VERSION) {
|
|
|
|
pr->pr_params[0] = pr->pr_real_params[0];
|
|
|
|
}
|
2003-05-15 05:58:31 +00:00
|
|
|
P_POINTER (pr, 0) = super->self;
|
2022-01-17 10:12:28 +00:00
|
|
|
PR_CallFunction (pr, imp, pr->pr_return);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_obj_get_class (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
probj_t *probj = pr->pr_objective_resources;
|
2003-04-22 18:20:15 +00:00
|
|
|
const char *name = P_GSTRING (pr, 0);
|
2002-05-22 19:02:26 +00:00
|
|
|
pr_class_t *class;
|
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
class = Hash_Find (probj->classes, name);
|
2002-05-22 19:02:26 +00:00
|
|
|
if (!class)
|
|
|
|
PR_RunError (pr, "could not find class %s", name);
|
2004-11-05 11:49:00 +00:00
|
|
|
RETURN_POINTER (pr, class);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_obj_lookup_class (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
probj_t *probj = pr->pr_objective_resources;
|
2003-04-22 18:20:15 +00:00
|
|
|
const char *name = P_GSTRING (pr, 0);
|
2002-05-22 19:02:26 +00:00
|
|
|
pr_class_t *class;
|
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
class = Hash_Find (probj->classes, name);
|
2004-11-05 11:49:00 +00:00
|
|
|
RETURN_POINTER (pr, class);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_obj_next_class (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
//probj_t *probj = pr->pr_objective_resources;
|
2002-05-22 17:32:44 +00:00
|
|
|
//XXX
|
2002-05-22 19:02:26 +00:00
|
|
|
PR_RunError (pr, "%s, not implemented", __FUNCTION__);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//====================================================================
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_sel_get_name (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
probj_t *probj = pr->pr_objective_resources;
|
2002-05-22 22:35:37 +00:00
|
|
|
pr_sel_t *sel = &P_STRUCT (pr, pr_sel_t, 0);
|
2004-11-10 05:37:00 +00:00
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
if (sel->sel_id > 0 && sel->sel_id <= probj->selector_index)
|
|
|
|
R_STRING (pr) = probj->selector_names[sel->sel_id];
|
2004-11-10 05:37:00 +00:00
|
|
|
else
|
|
|
|
R_STRING (pr) = 0;
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_sel_get_type (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2002-05-22 22:35:37 +00:00
|
|
|
pr_sel_t *sel = &P_STRUCT (pr, pr_sel_t, 0);
|
2004-11-10 05:37:00 +00:00
|
|
|
|
2002-05-22 22:35:37 +00:00
|
|
|
R_INT (pr) = sel->sel_types;
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_sel_get_uid (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
probj_t *probj = pr->pr_objective_resources;
|
2003-08-23 22:16:42 +00:00
|
|
|
const char *name = P_GSTRING (pr, 0);
|
2004-11-10 05:37:00 +00:00
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
RETURN_POINTER (pr, sel_register_typed_name (probj, name, "", 0));
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_sel_register_name (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
probj_t *probj = pr->pr_objective_resources;
|
2004-11-10 05:37:00 +00:00
|
|
|
const char *name = P_GSTRING (pr, 0);
|
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
RETURN_POINTER (pr, sel_register_typed_name (probj, name, "", 0));
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_sel_is_mapped (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
probj_t *probj = pr->pr_objective_resources;
|
2004-11-10 05:37:00 +00:00
|
|
|
// FIXME might correspond to a string
|
|
|
|
pr_sel_t *sel = &P_STRUCT (pr, pr_sel_t, 0);
|
2020-02-25 14:14:18 +00:00
|
|
|
R_INT (pr) = sel->sel_id > 0 && sel->sel_id <= probj->selector_index;
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//====================================================================
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_class_get_class_method (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
probj_t *probj = pr->pr_objective_resources;
|
2003-08-24 03:44:12 +00:00
|
|
|
pr_class_t *class = &P_STRUCT (pr, pr_class_t, 0);
|
|
|
|
pr_sel_t *aSel = &P_STRUCT (pr, pr_sel_t, 1);
|
2003-08-25 01:47:05 +00:00
|
|
|
pr_method_t *method;
|
2003-08-24 03:44:12 +00:00
|
|
|
class = &G_STRUCT (pr, pr_class_t, class->class_pointer);
|
2020-02-25 14:14:18 +00:00
|
|
|
method = obj_find_message (probj, class, aSel);
|
2003-08-24 03:44:12 +00:00
|
|
|
RETURN_POINTER (pr, method);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_class_get_instance_method (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
probj_t *probj = pr->pr_objective_resources;
|
2003-08-23 22:16:42 +00:00
|
|
|
pr_class_t *class = &P_STRUCT (pr, pr_class_t, 0);
|
|
|
|
pr_sel_t *aSel = &P_STRUCT (pr, pr_sel_t, 1);
|
2020-02-25 14:14:18 +00:00
|
|
|
pr_method_t *method = obj_find_message (probj, class, aSel);
|
2003-08-23 22:16:42 +00:00
|
|
|
RETURN_POINTER (pr, method);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
2003-08-24 03:44:12 +00:00
|
|
|
#define CLASSOF(x) (&G_STRUCT (pr, pr_class_t, (x)->class_pointer))
|
|
|
|
|
2002-05-22 17:32:44 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_class_pose_as (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2003-08-24 03:44:12 +00:00
|
|
|
pr_class_t *impostor = &P_STRUCT (pr, pr_class_t, 0);
|
|
|
|
pr_class_t *superclass = &P_STRUCT (pr, pr_class_t, 1);
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_ptr_t *subclass;
|
2003-08-24 03:44:12 +00:00
|
|
|
|
|
|
|
subclass = &superclass->subclass_list;
|
|
|
|
while (*subclass) {
|
|
|
|
pr_class_t *sub = &P_STRUCT (pr, pr_class_t, *subclass);
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_ptr_t nextSub = sub->sibling_class;
|
2003-08-24 03:44:12 +00:00
|
|
|
if (sub != impostor) {
|
|
|
|
sub->sibling_class = impostor->subclass_list;
|
|
|
|
sub->super_class = P_POINTER (pr, 0); // impostor
|
|
|
|
impostor->subclass_list = *subclass; // sub
|
|
|
|
CLASSOF (sub)->sibling_class = CLASSOF (impostor)->sibling_class;
|
|
|
|
CLASSOF (sub)->super_class = impostor->class_pointer;
|
|
|
|
CLASSOF (impostor)->subclass_list = sub->class_pointer;
|
|
|
|
}
|
|
|
|
*subclass = nextSub;
|
|
|
|
}
|
|
|
|
superclass->subclass_list = P_POINTER (pr, 0); // impostor
|
|
|
|
CLASSOF (superclass)->subclass_list = impostor->class_pointer;
|
|
|
|
|
|
|
|
impostor->sibling_class = 0;
|
|
|
|
CLASSOF (impostor)->sibling_class = 0;
|
|
|
|
|
|
|
|
//XXX how much do I need to do here?!?
|
|
|
|
//class_table_replace (super_class, impostor);
|
|
|
|
R_INT (pr) = P_POINTER (pr, 0); // impostor
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
2003-08-24 03:44:12 +00:00
|
|
|
#undef CLASSOF
|
2002-05-22 17:32:44 +00:00
|
|
|
|
2003-08-11 06:05:07 +00:00
|
|
|
static inline pr_id_t *
|
2002-05-22 17:32:44 +00:00
|
|
|
class_create_instance (progs_t *pr, pr_class_t *class)
|
|
|
|
{
|
2022-06-04 16:08:45 +00:00
|
|
|
int size = class->instance_size * sizeof (pr_type_t);
|
2012-11-08 11:24:25 +00:00
|
|
|
pr_type_t *mem;
|
2021-01-13 06:24:50 +00:00
|
|
|
pr_id_t *id = 0;
|
2002-05-22 17:32:44 +00:00
|
|
|
|
2020-03-31 07:03:54 +00:00
|
|
|
mem = PR_Zone_TagMalloc (pr, size, class->name);
|
2021-01-13 06:24:50 +00:00
|
|
|
if (mem) {
|
|
|
|
memset (mem, 0, size);
|
2022-06-04 16:08:45 +00:00
|
|
|
id = (pr_id_t *) mem;
|
2021-01-13 06:24:50 +00:00
|
|
|
id->class_pointer = PR_SetPointer (pr, class);
|
|
|
|
}
|
2002-05-22 17:32:44 +00:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_class_create_instance (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2002-05-22 22:35:37 +00:00
|
|
|
pr_class_t *class = &P_STRUCT (pr, pr_class_t, 0);
|
2002-05-22 17:32:44 +00:00
|
|
|
pr_id_t *id = class_create_instance (pr, class);
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2004-11-05 11:49:00 +00:00
|
|
|
RETURN_POINTER (pr, id);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
2002-05-21 23:39:21 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_class_get_class_name (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2002-05-22 22:35:37 +00:00
|
|
|
pr_class_t *class = &P_STRUCT (pr, pr_class_t, 0);
|
|
|
|
R_INT (pr) = PR_CLS_ISCLASS (class) ? class->name
|
2002-07-13 03:41:33 +00:00
|
|
|
: PR_SetString (pr, "Nil");
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_class_get_instance_size (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2002-05-22 22:35:37 +00:00
|
|
|
pr_class_t *class = &P_STRUCT (pr, pr_class_t, 0);
|
|
|
|
R_INT (pr) = PR_CLS_ISCLASS (class) ? class->instance_size : 0;
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_class_get_meta_class (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2002-05-22 22:35:37 +00:00
|
|
|
pr_class_t *class = &P_STRUCT (pr, pr_class_t, 0);
|
|
|
|
R_INT (pr) = PR_CLS_ISCLASS (class) ? class->class_pointer : 0;
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_class_get_super_class (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2002-05-22 22:35:37 +00:00
|
|
|
pr_class_t *class = &P_STRUCT (pr, pr_class_t, 0);
|
|
|
|
R_INT (pr) = PR_CLS_ISCLASS (class) ? class->super_class : 0;
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_class_get_version (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2002-05-22 22:35:37 +00:00
|
|
|
pr_class_t *class = &P_STRUCT (pr, pr_class_t, 0);
|
|
|
|
R_INT (pr) = PR_CLS_ISCLASS (class) ? class->version : -1;
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_class_is_class (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2002-05-22 22:35:37 +00:00
|
|
|
pr_class_t *class = &P_STRUCT (pr, pr_class_t, 0);
|
|
|
|
R_INT (pr) = PR_CLS_ISCLASS (class);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_class_is_meta_class (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2002-05-22 22:35:37 +00:00
|
|
|
pr_class_t *class = &P_STRUCT (pr, pr_class_t, 0);
|
|
|
|
R_INT (pr) = PR_CLS_ISMETA (class);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_class_set_version (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2002-05-22 22:35:37 +00:00
|
|
|
pr_class_t *class = &P_STRUCT (pr, pr_class_t, 0);
|
2002-05-22 17:32:44 +00:00
|
|
|
if (PR_CLS_ISCLASS (class))
|
2002-05-22 22:35:37 +00:00
|
|
|
class->version = P_INT (pr, 1);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_class_get_gc_object_type (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2002-05-22 22:35:37 +00:00
|
|
|
pr_class_t *class = &P_STRUCT (pr, pr_class_t, 0);
|
|
|
|
R_INT (pr) = PR_CLS_ISCLASS (class) ? class->gc_object_type : 0;
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_class_ivar_set_gcinvisible (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
//probj_t *probj = pr->pr_objective_resources;
|
2003-08-24 03:44:12 +00:00
|
|
|
//pr_class_t *impostor = &P_STRUCT (pr, pr_class_t, 0);
|
2003-04-22 18:20:15 +00:00
|
|
|
//const char *ivarname = P_GSTRING (pr, 1);
|
2002-05-22 22:35:37 +00:00
|
|
|
//int gcInvisible = P_INT (pr, 2);
|
2002-05-22 17:32:44 +00:00
|
|
|
//XXX
|
2002-05-22 19:02:26 +00:00
|
|
|
PR_RunError (pr, "%s, not implemented", __FUNCTION__);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//====================================================================
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_method_get_imp (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2002-05-22 22:35:37 +00:00
|
|
|
pr_method_t *method = &P_STRUCT (pr, pr_method_t, 0);
|
2002-05-22 19:02:26 +00:00
|
|
|
|
2020-03-26 05:13:05 +00:00
|
|
|
R_INT (pr) = method ? method->method_imp : 0;
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_get_imp (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
probj_t *probj = pr->pr_objective_resources;
|
2004-11-11 00:34:00 +00:00
|
|
|
pr_class_t *class = &P_STRUCT (pr, pr_class_t, 0);
|
|
|
|
pr_sel_t *sel = &P_STRUCT (pr, pr_sel_t, 1);
|
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
R_INT (pr) = get_imp (probj, class, sel);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//====================================================================
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_object_dispose (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2002-05-22 22:35:37 +00:00
|
|
|
pr_id_t *object = &P_STRUCT (pr, pr_id_t, 0);
|
2012-11-08 11:24:25 +00:00
|
|
|
pr_type_t *mem = (pr_type_t *) object;
|
2022-06-04 16:08:45 +00:00
|
|
|
PR_Zone_Free (pr, mem);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_object_copy (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2002-05-22 22:35:37 +00:00
|
|
|
pr_id_t *object = &P_STRUCT (pr, pr_id_t, 0);
|
2002-05-22 17:32:44 +00:00
|
|
|
pr_class_t *class = &G_STRUCT (pr, pr_class_t, object->class_pointer);
|
|
|
|
pr_id_t *id;
|
|
|
|
|
|
|
|
id = class_create_instance (pr, class);
|
2021-01-13 06:24:50 +00:00
|
|
|
if (id) {
|
|
|
|
memcpy (id, object, sizeof (pr_type_t) * class->instance_size);
|
|
|
|
// copy the retain count
|
|
|
|
((pr_type_t *) id)[-1] = ((pr_type_t *) object)[-1];
|
|
|
|
}
|
2004-11-05 11:49:00 +00:00
|
|
|
RETURN_POINTER (pr, id);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_object_get_class (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2002-05-22 22:35:37 +00:00
|
|
|
pr_id_t *object = &P_STRUCT (pr, pr_id_t, 0);
|
2002-05-22 17:32:44 +00:00
|
|
|
pr_class_t *class;
|
|
|
|
|
2002-05-22 22:35:37 +00:00
|
|
|
if (object) {
|
2002-05-22 17:32:44 +00:00
|
|
|
class = &G_STRUCT (pr, pr_class_t, object->class_pointer);
|
|
|
|
if (PR_CLS_ISCLASS (class)) {
|
2004-11-05 11:49:00 +00:00
|
|
|
RETURN_POINTER (pr, class);
|
2002-05-22 17:32:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (PR_CLS_ISMETA (class)) {
|
2002-05-22 22:35:37 +00:00
|
|
|
R_INT (pr) = P_INT (pr, 0);
|
2002-05-22 17:32:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2002-05-22 22:35:37 +00:00
|
|
|
R_INT (pr) = 0;
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_object_get_super_class (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2002-05-22 22:35:37 +00:00
|
|
|
pr_id_t *object = &P_STRUCT (pr, pr_id_t, 0);
|
2002-05-22 17:32:44 +00:00
|
|
|
pr_class_t *class;
|
|
|
|
|
2002-05-22 22:35:37 +00:00
|
|
|
if (object) {
|
2002-05-22 17:32:44 +00:00
|
|
|
class = &G_STRUCT (pr, pr_class_t, object->class_pointer);
|
|
|
|
if (PR_CLS_ISCLASS (class)) {
|
2002-05-22 22:35:37 +00:00
|
|
|
R_INT (pr) = class->super_class;
|
2002-05-22 17:32:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (PR_CLS_ISMETA (class)) {
|
2002-05-22 22:35:37 +00:00
|
|
|
R_INT (pr) = ((pr_class_t *)object)->super_class;
|
2002-05-22 17:32:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2002-05-22 22:35:37 +00:00
|
|
|
R_INT (pr) = 0;
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_object_get_meta_class (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2002-05-22 22:35:37 +00:00
|
|
|
pr_id_t *object = &P_STRUCT (pr, pr_id_t, 0);
|
2002-05-22 17:32:44 +00:00
|
|
|
pr_class_t *class;
|
|
|
|
|
2002-05-22 22:35:37 +00:00
|
|
|
if (object) {
|
2002-05-22 17:32:44 +00:00
|
|
|
class = &G_STRUCT (pr, pr_class_t, object->class_pointer);
|
|
|
|
if (PR_CLS_ISCLASS (class)) {
|
2002-05-22 22:35:37 +00:00
|
|
|
R_INT (pr) = class->class_pointer;
|
2002-05-22 17:32:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (PR_CLS_ISMETA (class)) {
|
2002-05-22 22:35:37 +00:00
|
|
|
R_INT (pr) = ((pr_class_t *)object)->class_pointer;
|
2002-05-22 17:32:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2002-05-22 22:35:37 +00:00
|
|
|
R_INT (pr) = 0;
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_object_get_class_name (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
probj_t *probj = pr->pr_objective_resources;
|
2002-05-22 22:35:37 +00:00
|
|
|
pr_id_t *object = &P_STRUCT (pr, pr_id_t, 0);
|
2002-05-22 17:32:44 +00:00
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
R_STRING (pr) = object_get_class_name (probj, object);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_object_is_class (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2002-05-22 22:35:37 +00:00
|
|
|
pr_id_t *object = &P_STRUCT (pr, pr_id_t, 0);
|
2002-05-22 17:32:44 +00:00
|
|
|
|
2002-05-22 22:35:37 +00:00
|
|
|
if (object) {
|
|
|
|
R_INT (pr) = PR_CLS_ISCLASS ((pr_class_t*)object);
|
2002-05-22 17:32:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-05-22 22:35:37 +00:00
|
|
|
R_INT (pr) = 0;
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_object_is_instance (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
probj_t *probj = pr->pr_objective_resources;
|
2002-05-22 22:35:37 +00:00
|
|
|
pr_id_t *object = &P_STRUCT (pr, pr_id_t, 0);
|
2002-05-22 17:32:44 +00:00
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
R_INT (pr) = object_is_instance (probj, object);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_object_is_meta_class (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2002-05-22 22:35:37 +00:00
|
|
|
pr_id_t *object = &P_STRUCT (pr, pr_id_t, 0);
|
2002-05-22 17:32:44 +00:00
|
|
|
|
2002-05-22 22:35:37 +00:00
|
|
|
if (object) {
|
|
|
|
R_INT (pr) = PR_CLS_ISMETA ((pr_class_t*)object);
|
2002-05-22 17:32:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-05-22 22:35:37 +00:00
|
|
|
R_INT (pr) = 0;
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//====================================================================
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua__i_Object__hash (progs_t *pr, void *data)
|
2002-05-21 23:39:21 +00:00
|
|
|
{
|
2002-05-22 22:35:37 +00:00
|
|
|
R_INT (pr) = P_INT (pr, 0);
|
2002-05-21 23:39:21 +00:00
|
|
|
}
|
|
|
|
|
2002-05-22 17:32:44 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua__i_Object_error_error_ (progs_t *pr, void *data)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
probj_t *probj = pr->pr_objective_resources;
|
2004-01-05 01:41:20 +00:00
|
|
|
pr_id_t *self = &P_STRUCT (pr, pr_id_t, 0);
|
|
|
|
const char *fmt = P_GSTRING (pr, 2);
|
|
|
|
int count = pr->pr_argc - 3;
|
2012-12-16 04:19:31 +00:00
|
|
|
pr_type_t **args = &pr->pr_params[3];
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2023-03-05 08:20:04 +00:00
|
|
|
if (pr->progs->version == PROG_VERSION) {
|
|
|
|
__auto_type va_list = &P_PACKED (pr, pr_va_list_t, 3);
|
|
|
|
count = va_list->count;
|
|
|
|
if (count) {
|
|
|
|
args = alloca (count * sizeof (pr_type_t *));
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
args[i] = &pr->pr_globals[va_list->list + i * 4];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
args = 0;
|
|
|
|
}
|
|
|
|
}
|
2022-05-12 09:23:32 +00:00
|
|
|
dsprintf (probj->msg, "error: %s (%s)\n%s",
|
2020-02-25 14:14:18 +00:00
|
|
|
PR_GetString (pr, object_get_class_name (probj, self)),
|
|
|
|
object_is_instance (probj, self) ? "instance" : "class", fmt);
|
2022-05-12 09:23:32 +00:00
|
|
|
obj_verror (probj, self, 0, probj->msg->str, count, args);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
2020-03-02 06:21:10 +00:00
|
|
|
static int
|
|
|
|
obj_protocol_conformsToProtocol (probj_t *probj, pr_protocol_t *proto,
|
|
|
|
pr_protocol_t *protocol)
|
|
|
|
{
|
|
|
|
progs_t *pr = probj->pr;
|
|
|
|
|
|
|
|
pr_protocol_list_t *proto_list;
|
|
|
|
|
|
|
|
if (!proto || !protocol) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (proto == protocol) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (proto->protocol_name == protocol->protocol_name
|
|
|
|
|| strcmp (PR_GetString (pr, proto->protocol_name),
|
|
|
|
PR_GetString (pr, protocol->protocol_name)) == 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
proto_list = &G_STRUCT (pr, pr_protocol_list_t, proto->protocol_list);
|
|
|
|
while (proto_list) {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_rua_obj, "%x %x %d\n",
|
2020-03-02 06:21:10 +00:00
|
|
|
PR_SetPointer (pr, proto_list), proto_list->next,
|
|
|
|
proto_list->count);
|
|
|
|
for (int i = 0; i < proto_list->count; i++) {
|
|
|
|
proto = &G_STRUCT (pr, pr_protocol_t, proto_list->list[i]);
|
|
|
|
if (proto == protocol
|
|
|
|
|| obj_protocol_conformsToProtocol (probj, proto, protocol)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_list = &G_STRUCT (pr, pr_protocol_list_t, proto_list->next);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-07-30 17:44:38 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua__c_Object__conformsToProtocol_ (progs_t *pr, void *data)
|
2003-07-30 17:44:38 +00:00
|
|
|
{
|
2020-03-02 06:21:10 +00:00
|
|
|
probj_t *probj = pr->pr_objective_resources;
|
|
|
|
// class points to _OBJ_CLASS_foo, and class->class_pointer points to
|
|
|
|
// _OBJ_METACLASS_foo
|
|
|
|
pr_class_t *class = &P_STRUCT (pr, pr_class_t, 0);
|
|
|
|
// protocol->class_pointer must point to _OBJ_CLASS_Protocol (ie, if
|
|
|
|
// protocol is not actually a protocol, then the class cannot conform
|
|
|
|
// to it)
|
|
|
|
pr_protocol_t *protocol = &P_STRUCT (pr, pr_protocol_t, 2);
|
|
|
|
pr_protocol_list_t *proto_list;
|
|
|
|
|
|
|
|
if (!class || !protocol) {
|
|
|
|
goto not_conforms;
|
|
|
|
}
|
|
|
|
if (protocol->class_pointer != PR_SetPointer (pr,
|
|
|
|
Hash_Find (probj->classes,
|
|
|
|
"Protocol"))) {
|
|
|
|
goto not_conforms;
|
|
|
|
}
|
|
|
|
proto_list = &G_STRUCT (pr, pr_protocol_list_t, class->protocols);
|
|
|
|
while (proto_list) {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_rua_obj, "%x %x %d\n",
|
2020-03-02 06:21:10 +00:00
|
|
|
PR_SetPointer (pr, proto_list), proto_list->next,
|
|
|
|
proto_list->count);
|
|
|
|
for (int i = 0; i < proto_list->count; i++) {
|
|
|
|
__auto_type proto = &G_STRUCT (pr, pr_protocol_t,
|
|
|
|
proto_list->list[i]);
|
|
|
|
if (proto == protocol
|
|
|
|
|| obj_protocol_conformsToProtocol (probj, proto, protocol)) {
|
|
|
|
goto conforms;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_list = &G_STRUCT (pr, pr_protocol_list_t, proto_list->next);
|
|
|
|
}
|
|
|
|
not_conforms:
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_rua_obj, "does not conform\n");
|
2020-03-02 06:21:10 +00:00
|
|
|
R_INT (pr) = 0;
|
|
|
|
return;
|
|
|
|
conforms:
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_rua_obj, "conforms\n");
|
2020-03-02 06:21:10 +00:00
|
|
|
R_INT (pr) = 1;
|
|
|
|
return;
|
2003-07-30 17:44:38 +00:00
|
|
|
}
|
|
|
|
|
2012-11-15 04:40:11 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_PR_FindGlobal (progs_t *pr, void *data)
|
2012-11-15 04:40:11 +00:00
|
|
|
{
|
|
|
|
const char *name = P_GSTRING (pr, 0);
|
2020-02-22 13:33:44 +00:00
|
|
|
pr_def_t *def;
|
2012-11-15 04:40:11 +00:00
|
|
|
|
|
|
|
R_POINTER (pr) = 0;
|
|
|
|
def = PR_FindGlobal (pr, name);
|
|
|
|
if (def)
|
2020-03-02 04:00:33 +00:00
|
|
|
R_POINTER (pr) = def->ofs;
|
2012-11-15 04:40:11 +00:00
|
|
|
}
|
|
|
|
|
2002-05-22 17:32:44 +00:00
|
|
|
//====================================================================
|
|
|
|
|
2022-01-23 12:54:03 +00:00
|
|
|
#define bi(x,np,params...) {#x, rua_##x, -1, np, {params}}
|
|
|
|
#define p(type) PR_PARAM(type)
|
|
|
|
#define P(a, s) { .size = (s), .alignment = BITOP_LOG2 (a), }
|
2004-01-06 05:51:09 +00:00
|
|
|
static builtin_t obj_methods [] = {
|
2022-01-23 12:54:03 +00:00
|
|
|
bi(__obj_exec_class, 1, p(ptr)),
|
|
|
|
bi(__obj_forward, -3, p(ptr), p(ptr)),
|
|
|
|
bi(__obj_responds_to, 2, p(ptr), p(ptr)),
|
|
|
|
|
|
|
|
bi(obj_error, -4, p(ptr), p(int), p(string)),
|
|
|
|
bi(obj_verror, 4, p(ptr), p(int), p(string), P(1, 2)),
|
|
|
|
bi(obj_set_error_handler, 1, p(func)),
|
|
|
|
bi(obj_msg_lookup, 2, p(ptr), p(ptr)),
|
|
|
|
bi(obj_msg_lookup_super, 2, p(ptr), p(ptr)),
|
|
|
|
bi(obj_msg_sendv, 3, p(ptr), p(ptr), P(1, 2)),
|
|
|
|
bi(obj_increment_retaincount, 1, p(ptr)),
|
|
|
|
bi(obj_decrement_retaincount, 1, p(ptr)),
|
|
|
|
bi(obj_get_retaincount, 1, p(ptr)),
|
|
|
|
bi(obj_malloc, 1, p(int)),
|
|
|
|
bi(obj_atomic_malloc, 1, p(int)),
|
|
|
|
bi(obj_valloc, 1, p(int)),
|
|
|
|
bi(obj_realloc, 2, p(ptr), p(int)),
|
|
|
|
bi(obj_calloc, 2, p(int), p(int)),
|
|
|
|
bi(obj_free, 1, p(ptr)),
|
|
|
|
bi(obj_get_uninstalled_dtable, 0),
|
|
|
|
bi(obj_msgSend, 2, p(ptr), p(ptr)),//magic
|
|
|
|
bi(obj_msgSend_super, 2, p(ptr), p(ptr)),//magic
|
|
|
|
|
|
|
|
bi(obj_get_class, 1, p(string)),
|
|
|
|
bi(obj_lookup_class, 1, p(string)),
|
|
|
|
bi(obj_next_class, 1, p(ptr)),
|
|
|
|
|
|
|
|
bi(sel_get_name, 1, p(ptr)),
|
|
|
|
bi(sel_get_type, 1, p(ptr)),
|
|
|
|
bi(sel_get_uid, 1, p(string)),
|
|
|
|
bi(sel_register_name, 1, p(string)),
|
|
|
|
bi(sel_is_mapped, 1, p(ptr)),
|
|
|
|
|
|
|
|
bi(class_get_class_method, 2, p(ptr), p(ptr)),
|
|
|
|
bi(class_get_instance_method, 2, p(ptr), p(ptr)),
|
|
|
|
bi(class_pose_as, 2, p(ptr), p(ptr)),
|
|
|
|
bi(class_create_instance, 1, p(ptr)),
|
|
|
|
bi(class_get_class_name, 1, p(ptr)),
|
|
|
|
bi(class_get_instance_size, 1, p(ptr)),
|
|
|
|
bi(class_get_meta_class, 1, p(ptr)),
|
|
|
|
bi(class_get_super_class, 1, p(ptr)),
|
|
|
|
bi(class_get_version, 1, p(ptr)),
|
|
|
|
bi(class_is_class, 1, p(ptr)),
|
|
|
|
bi(class_is_meta_class, 1, p(ptr)),
|
|
|
|
bi(class_set_version, 2, p(ptr), p(int)),
|
|
|
|
bi(class_get_gc_object_type, 1, p(ptr)),
|
|
|
|
bi(class_ivar_set_gcinvisible, 3, p(ptr), p(string), p(int)),
|
|
|
|
|
|
|
|
bi(method_get_imp, 1, p(ptr)),
|
|
|
|
bi(get_imp, 1, p(ptr), p(ptr)),
|
|
|
|
|
|
|
|
bi(object_copy, 1, p(ptr)),
|
|
|
|
bi(object_dispose, 1, p(ptr)),
|
|
|
|
bi(object_get_class, 1, p(ptr)),
|
|
|
|
bi(object_get_class_name, 1, p(ptr)),
|
|
|
|
bi(object_get_meta_class, 1, p(ptr)),
|
|
|
|
bi(object_get_super_class, 1, p(ptr)),
|
|
|
|
bi(object_is_class, 1, p(ptr)),
|
|
|
|
bi(object_is_instance, 1, p(ptr)),
|
|
|
|
bi(object_is_meta_class, 1, p(ptr)),
|
|
|
|
|
|
|
|
bi(_i_Object__hash, 2, p(ptr), p(ptr)),
|
|
|
|
bi(_i_Object_error_error_, -4, p(ptr), p(ptr), p(string)),
|
|
|
|
bi(_c_Object__conformsToProtocol_, 3, p(ptr), p(ptr), p(ptr)),
|
|
|
|
|
|
|
|
bi(PR_FindGlobal, 1, p(string)),//FIXME
|
2004-01-06 05:51:09 +00:00
|
|
|
{0}
|
2002-05-22 17:32:44 +00:00
|
|
|
};
|
|
|
|
|
2004-01-16 08:02:31 +00:00
|
|
|
static int
|
|
|
|
rua_init_finish (progs_t *pr)
|
2002-05-21 21:29:49 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
probj_t *probj = pr->pr_objective_resources;
|
2002-11-15 14:56:57 +00:00
|
|
|
pr_class_t **class_list, **class;
|
2002-05-21 21:29:49 +00:00
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
class_list = (pr_class_t **) Hash_GetList (probj->classes);
|
2002-08-16 22:53:37 +00:00
|
|
|
if (*class_list) {
|
|
|
|
pr_class_t *object_class;
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_ptr_t object_ptr;
|
2002-08-16 22:53:37 +00:00
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
object_class = Hash_Find (probj->classes, "Object");
|
2002-08-16 22:53:37 +00:00
|
|
|
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");
|
|
|
|
for (class = class_list; *class; class++)
|
2020-02-25 14:14:18 +00:00
|
|
|
finish_class (probj, *class, object_ptr);
|
2002-08-16 22:53:37 +00:00
|
|
|
}
|
|
|
|
free (class_list);
|
2002-11-14 20:42:48 +00:00
|
|
|
|
2003-11-20 07:46:56 +00:00
|
|
|
return 1;
|
2002-05-21 21:29:49 +00:00
|
|
|
}
|
2004-01-16 08:02:31 +00:00
|
|
|
|
|
|
|
static int
|
2020-02-25 14:14:18 +00:00
|
|
|
rua_obj_init_runtime (progs_t *pr)
|
2004-01-16 08:02:31 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
probj_t *probj = pr->pr_objective_resources;
|
2020-02-22 13:33:44 +00:00
|
|
|
pr_def_t *def;
|
2020-03-09 09:11:36 +00:00
|
|
|
dfunction_t *obj_forward;
|
2020-03-09 09:09:03 +00:00
|
|
|
|
|
|
|
if ((def = PR_FindField (pr, ".this")))
|
|
|
|
pr->fields.this = def->ofs;
|
|
|
|
|
2020-03-09 09:11:36 +00:00
|
|
|
probj->obj_forward = 0;
|
|
|
|
if ((obj_forward = PR_FindFunction (pr, "__obj_forward"))) {
|
|
|
|
probj->obj_forward = (intptr_t) (obj_forward - pr->pr_functions);
|
|
|
|
}
|
|
|
|
|
2020-03-09 09:09:03 +00:00
|
|
|
PR_AddLoadFinishFunc (pr, rua_init_finish);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rua_obj_cleanup (progs_t *pr, void *data)
|
|
|
|
{
|
2012-12-21 12:53:13 +00:00
|
|
|
unsigned i;
|
2004-11-10 05:37:00 +00:00
|
|
|
|
2020-03-09 09:09:03 +00:00
|
|
|
__auto_type probj = (probj_t *) data;
|
|
|
|
pr->pr_objective_resources = probj;
|
|
|
|
|
|
|
|
Hash_FlushTable (probj->selector_hash);
|
2020-02-25 14:14:18 +00:00
|
|
|
probj->selector_index = 0;
|
2022-02-11 16:52:35 +00:00
|
|
|
probj->available_selectors = 0;
|
|
|
|
probj->selector_block = 0;
|
2020-02-25 14:14:18 +00:00
|
|
|
for (i = 0; i < probj->selector_index_max; i++) {
|
2022-05-12 09:23:32 +00:00
|
|
|
obj_list_free (probj, probj->selector_sels[i]);
|
2020-02-25 14:14:18 +00:00
|
|
|
probj->selector_sels[i] = 0;
|
|
|
|
probj->selector_names[i] = 0;
|
2004-11-10 05:37:00 +00:00
|
|
|
}
|
2004-01-16 08:02:31 +00:00
|
|
|
|
2021-09-25 06:42:54 +00:00
|
|
|
for (dtable_t *dtable = probj->dtable_list; dtable;
|
|
|
|
dtable = dtable->next) {
|
2020-03-09 09:09:03 +00:00
|
|
|
free (dtable->imp);
|
2004-01-16 08:02:31 +00:00
|
|
|
}
|
2020-03-09 09:09:03 +00:00
|
|
|
dtable_reset (probj);
|
2004-01-16 08:02:31 +00:00
|
|
|
|
2020-03-09 09:09:03 +00:00
|
|
|
Hash_FlushTable (probj->classes);
|
|
|
|
Hash_FlushTable (probj->protocols);
|
|
|
|
Hash_FlushTable (probj->load_methods);
|
2020-02-25 14:14:18 +00:00
|
|
|
probj->unresolved_classes = 0;
|
|
|
|
probj->unclaimed_categories = 0;
|
|
|
|
probj->unclaimed_proto_list = 0;
|
|
|
|
probj->module_list = 0;
|
|
|
|
probj->class_tree_list = 0;
|
|
|
|
}
|
|
|
|
|
2022-05-12 09:23:32 +00:00
|
|
|
static void
|
|
|
|
rua_obj_destroy (progs_t *pr, void *_res)
|
|
|
|
{
|
|
|
|
probj_t *probj = _res;
|
|
|
|
|
|
|
|
dstring_delete (probj->msg);
|
|
|
|
Hash_DelTable (probj->selector_hash);
|
|
|
|
Hash_DelTable (probj->classes);
|
|
|
|
Hash_DelTable (probj->protocols);
|
|
|
|
Hash_DelTable (probj->load_methods);
|
2023-03-03 10:36:28 +00:00
|
|
|
|
2023-03-03 13:07:27 +00:00
|
|
|
free (probj->selector_sels);
|
|
|
|
free (probj->selector_names);
|
|
|
|
free (probj->selector_argc);
|
|
|
|
|
2023-03-05 08:20:04 +00:00
|
|
|
for (size_t i = 0; i < probj->obj_list_sets.size; i++) {
|
|
|
|
free (probj->obj_list_sets.a[i]);
|
|
|
|
}
|
|
|
|
DARRAY_CLEAR (&probj->obj_list_sets);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < probj->class_tree_sets.size; i++) {
|
|
|
|
free (probj->class_tree_sets.a[i]);
|
|
|
|
}
|
|
|
|
DARRAY_CLEAR (&probj->class_tree_sets);
|
2023-03-03 13:07:27 +00:00
|
|
|
|
|
|
|
PR_RESDELMAP (probj->dtables);
|
|
|
|
|
2023-03-03 10:36:28 +00:00
|
|
|
free (probj);
|
2022-05-12 09:23:32 +00:00
|
|
|
}
|
|
|
|
|
2004-01-16 08:02:31 +00:00
|
|
|
void
|
|
|
|
RUA_Obj_Init (progs_t *pr, int secure)
|
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
probj_t *probj = calloc (1, sizeof (*probj));
|
2020-03-09 09:09:03 +00:00
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
probj->pr = pr;
|
2020-03-25 06:43:16 +00:00
|
|
|
probj->selector_hash = Hash_NewTable (1021, selector_get_key, 0, probj,
|
2022-05-12 08:54:23 +00:00
|
|
|
pr->hashctx);
|
|
|
|
probj->classes = Hash_NewTable (1021, class_get_key, 0, probj, pr->hashctx);
|
2020-03-25 06:43:16 +00:00
|
|
|
probj->protocols = Hash_NewTable (1021, protocol_get_key, 0, probj,
|
2022-05-12 08:54:23 +00:00
|
|
|
pr->hashctx);
|
|
|
|
probj->load_methods = Hash_NewTable (1021, 0, 0, probj, pr->hashctx);
|
2020-03-09 09:09:03 +00:00
|
|
|
Hash_SetHashCompare (probj->load_methods, load_methods_get_hash,
|
|
|
|
load_methods_compare);
|
2023-03-05 08:20:04 +00:00
|
|
|
probj->msg = dstring_newstr();
|
|
|
|
DARRAY_INIT (&probj->obj_list_sets, 32);
|
|
|
|
DARRAY_INIT (&probj->class_tree_sets, 32);
|
2020-02-25 14:14:18 +00:00
|
|
|
|
2022-09-09 04:51:42 +00:00
|
|
|
PR_Sprintf_SetAtHandler (pr, rua_at_handler, probj);
|
|
|
|
|
2022-05-12 09:23:32 +00:00
|
|
|
PR_Resources_Register (pr, "RUA_ObjectiveQuakeC", probj, rua_obj_cleanup,
|
|
|
|
rua_obj_destroy);
|
2022-01-23 15:20:05 +00:00
|
|
|
PR_RegisterBuiltins (pr, obj_methods, probj);
|
2004-01-16 08:02:31 +00:00
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
PR_AddLoadFunc (pr, rua_obj_init_runtime);
|
2004-01-16 08:02:31 +00:00
|
|
|
}
|
2011-03-30 11:19:31 +00:00
|
|
|
|
2022-01-18 06:32:43 +00:00
|
|
|
pr_func_t
|
2022-01-18 03:11:14 +00:00
|
|
|
RUA_Obj_msg_lookup (progs_t *pr, pr_ptr_t _self, pr_ptr_t __cmd)
|
2011-03-30 11:19:31 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
probj_t *probj = pr->pr_objective_resources;
|
2011-03-30 11:19:31 +00:00
|
|
|
pr_id_t *self = &G_STRUCT (pr, pr_id_t, _self);
|
|
|
|
pr_sel_t *_cmd = &G_STRUCT (pr, pr_sel_t, __cmd);
|
2022-01-18 06:32:43 +00:00
|
|
|
pr_func_t imp;
|
2011-03-30 11:19:31 +00:00
|
|
|
|
|
|
|
if (!self)
|
|
|
|
return 0;
|
|
|
|
if (!_cmd)
|
|
|
|
PR_RunError (pr, "null selector");
|
2020-02-25 14:14:18 +00:00
|
|
|
imp = obj_msg_lookup (probj, self, _cmd);
|
2011-03-30 11:19:31 +00:00
|
|
|
if (!imp)
|
|
|
|
PR_RunError (pr, "%s does not respond to %s",
|
2020-02-25 14:14:18 +00:00
|
|
|
PR_GetString (pr, object_get_class_name (probj, self)),
|
|
|
|
PR_GetString (pr, probj->selector_names[_cmd->sel_id]));
|
2011-03-30 11:19:31 +00:00
|
|
|
|
|
|
|
return imp;
|
|
|
|
}
|
2020-03-30 07:49:57 +00:00
|
|
|
|
|
|
|
int
|
2022-02-14 03:28:38 +00:00
|
|
|
RUA_obj_increment_retaincount (progs_t *pr, void *data)
|
2020-03-30 07:49:57 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_obj_increment_retaincount (pr, data);
|
2020-03-30 07:49:57 +00:00
|
|
|
return R_INT (pr);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2022-02-14 03:28:38 +00:00
|
|
|
RUA_obj_decrement_retaincount (progs_t *pr, void *data)
|
2020-03-30 07:49:57 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
rua_obj_decrement_retaincount (pr, data);
|
2020-03-30 07:49:57 +00:00
|
|
|
return R_INT (pr);
|
|
|
|
}
|