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"
|
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/pr_obj.h"
|
|
|
|
#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"
|
|
|
|
|
|
|
|
#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__))
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
func_t *imp;
|
|
|
|
} dtable_t;
|
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
typedef struct probj_resources_s {
|
|
|
|
progs_t *pr;
|
|
|
|
unsigned selector_index;
|
|
|
|
unsigned selector_index_max;
|
|
|
|
obj_list **selector_sels;
|
|
|
|
string_t *selector_names;
|
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;
|
2020-03-09 09:11:36 +00:00
|
|
|
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;
|
|
|
|
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;
|
|
|
|
} 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 *obj_list_free_list;
|
|
|
|
|
|
|
|
static obj_list *
|
|
|
|
obj_list_new (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
obj_list *l;
|
|
|
|
|
|
|
|
if (!obj_list_free_list) {
|
|
|
|
obj_list_free_list = calloc (128, sizeof (obj_list));
|
|
|
|
for (i = 0; i < 127; i++)
|
|
|
|
obj_list_free_list[i].next = &obj_list_free_list[i + 1];
|
|
|
|
}
|
|
|
|
l = obj_list_free_list;
|
|
|
|
obj_list_free_list = l->next;
|
|
|
|
l->next = 0;
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2002-10-15 18:53:33 +00:00
|
|
|
static void
|
2004-11-11 00:34:00 +00:00
|
|
|
obj_list_free (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)
|
|
|
|
;
|
|
|
|
e->next = obj_list_free_list;
|
|
|
|
obj_list_free_list = l;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline obj_list *
|
|
|
|
list_cons (void *data, obj_list *next)
|
|
|
|
{
|
|
|
|
obj_list *l = obj_list_new ();
|
|
|
|
l->data = data;
|
|
|
|
l->next = next;
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
list_remove (obj_list **list)
|
|
|
|
{
|
|
|
|
if ((*list)->next) {
|
|
|
|
obj_list *l = *list;
|
|
|
|
*list = (*list)->next;
|
|
|
|
l->next = 0;
|
|
|
|
obj_list_free (l);
|
2002-10-15 18:53:33 +00:00
|
|
|
} else {
|
2004-11-11 00:34:00 +00:00
|
|
|
obj_list_free (*list);
|
|
|
|
*list = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct class_tree {
|
|
|
|
pr_class_t *class;
|
|
|
|
obj_list *subclasses;
|
|
|
|
} class_tree;
|
|
|
|
|
|
|
|
class_tree *class_tree_free_list;
|
|
|
|
|
|
|
|
static class_tree *
|
|
|
|
class_tree_new (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
class_tree *t;
|
|
|
|
|
|
|
|
if (!class_tree_free_list) {
|
|
|
|
class_tree_free_list = calloc (128, sizeof (class_tree));
|
|
|
|
for (i = 0; i < 127; i++) {
|
|
|
|
class_tree *x = &class_tree_free_list[i];
|
|
|
|
x->subclasses = (obj_list *) (x + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
t = class_tree_free_list;
|
|
|
|
class_tree_free_list = (class_tree *) t->subclasses;
|
|
|
|
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;
|
|
|
|
tree = prev = class_tree_new ();
|
|
|
|
prev->class = bottom;
|
|
|
|
while (superclass != upper) {
|
|
|
|
tree = class_tree_new ();
|
|
|
|
tree->class = superclass;
|
|
|
|
tree->subclasses = list_cons (prev, tree->subclasses);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
node = class_tree_new ();
|
|
|
|
node->class = class;
|
|
|
|
tree->subclasses = list_cons (node, tree->subclasses);
|
|
|
|
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);
|
|
|
|
tree->subclasses = list_cons (new_tree, tree->subclasses);
|
|
|
|
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);
|
|
|
|
probj->class_tree_list = list_cons (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
|
|
|
{
|
|
|
|
tree->subclasses = (obj_list *) class_tree_free_list;
|
|
|
|
class_tree_free_list = tree;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static 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
|
2020-02-25 14:14:18 +00:00
|
|
|
finish_class (probj_t *probj, pr_class_t *class, pointer_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 {
|
|
|
|
pointer_t *ml = &meta->methods;
|
|
|
|
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,
|
|
|
|
size * sizeof (string_t));
|
|
|
|
for (i = probj->selector_index_max; i < size; i++) {
|
|
|
|
probj->selector_sels[i] = 0;
|
|
|
|
probj->selector_names[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;
|
|
|
|
}
|
|
|
|
if (!sel)
|
|
|
|
sel = PR_Zone_Malloc (pr, sizeof (pr_sel_t));
|
|
|
|
|
|
|
|
sel->sel_id = index;
|
|
|
|
sel->sel_types = PR_SetString (pr, types);
|
|
|
|
|
|
|
|
l = obj_list_new ();
|
|
|
|
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
|
|
|
|
|
|
|
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"))) {
|
|
|
|
probj->unclaimed_proto_list = list_cons (protos,
|
|
|
|
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)) {
|
|
|
|
list_remove (&probj->unresolved_classes);
|
|
|
|
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);
|
2020-02-25 14:14:18 +00:00
|
|
|
list_remove (&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);
|
|
|
|
obj_list_free (probj->module_list);
|
|
|
|
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;
|
2011-01-10 00:21:42 +00:00
|
|
|
int dev = developer->int_val;
|
|
|
|
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);
|
2021-03-29 10:58:00 +00:00
|
|
|
if (developer->int_val & 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;
|
|
|
|
dtable->imp = calloc (dtable->size, sizeof (func_t));
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2004-11-02 05:12:00 +00:00
|
|
|
static 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
|
|
|
{
|
2020-03-09 09:11:36 +00:00
|
|
|
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;
|
|
|
|
func_t imp = 0;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2004-11-02 05:12:00 +00:00
|
|
|
static 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
|
|
|
}
|
|
|
|
|
2004-11-02 05:12:00 +00:00
|
|
|
static 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
|
|
|
dstring_t *dstr = dstring_newstr ();
|
|
|
|
|
2012-12-16 04:19:31 +00:00
|
|
|
PR_Sprintf (pr, dstr, "obj_verror", fmt, count, args);
|
2020-03-31 04:56:40 +00:00
|
|
|
PR_RunError (pr, "%s: %s", PR_GetString (pr, class->name), dstr->str);
|
2004-01-05 01:41:20 +00:00
|
|
|
}
|
|
|
|
|
2011-01-10 00:21:42 +00:00
|
|
|
static void
|
2020-02-25 14:14:18 +00:00
|
|
|
dump_ivars (probj_t *probj, pointer_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;
|
|
|
|
pointer_t *ptr;
|
|
|
|
pointer_t *inst;
|
|
|
|
|
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) {
|
|
|
|
list_remove (cell);
|
|
|
|
} else {
|
|
|
|
cell = &(*cell)->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-11 00:34:00 +00:00
|
|
|
static void
|
|
|
|
rua___obj_exec_class (progs_t *pr)
|
|
|
|
{
|
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;
|
|
|
|
pointer_t *ptr;
|
|
|
|
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
|
|
|
|
2020-02-25 14:14:18 +00:00
|
|
|
probj->module_list = list_cons (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);
|
2021-03-29 10:58:00 +00:00
|
|
|
if (developer->int_val & 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);
|
2021-03-29 10:58:00 +00:00
|
|
|
if (developer->int_val & 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))
|
|
|
|
probj->unresolved_classes = list_cons (class,
|
|
|
|
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
|
|
|
|
= list_cons (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
|
|
|
|
= list_cons (&G_STRUCT (pr, pointer_t, *ptr),
|
|
|
|
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) {
|
|
|
|
list_remove (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);
|
2004-11-11 00:34:00 +00:00
|
|
|
list_remove (cell);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
rua___obj_forward (progs_t *pr)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
pr_class_t *class =&G_STRUCT (pr, pr_class_t, obj->class_pointer);
|
|
|
|
func_t imp;
|
|
|
|
|
|
|
|
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
|
|
|
|
// args is full param list
|
|
|
|
//FIXME oh for a stack
|
2020-03-09 18:09:21 +00:00
|
|
|
size_t parm_size = pr->pr_param_size * sizeof(pr_type_t);
|
|
|
|
size_t size = pr->pr_argc * parm_size;
|
2020-03-09 13:20:11 +00:00
|
|
|
string_t args_block = PR_AllocTempBlock (pr, size);
|
|
|
|
|
|
|
|
int argc = pr->pr_argc;
|
|
|
|
__auto_type 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));
|
2020-03-09 18:09:21 +00:00
|
|
|
memcpy (argv + 8, &P_INT (pr, 2), (argc - 2) * parm_size);
|
2020-03-09 13:20:11 +00:00
|
|
|
|
|
|
|
PR_RESET_PARAMS (pr);
|
|
|
|
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);
|
2020-03-09 14:38:27 +00:00
|
|
|
PR_PushTempString (pr, args_block);
|
2020-03-09 11:41:17 +00:00
|
|
|
PR_CallFunction (pr, imp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//FIXME ditto
|
|
|
|
err_sel = sel_register_typed_name (probj, "doesNotRecognize:", "", 0);
|
|
|
|
if (obj_reponds_to (probj, obj, err_sel)) {
|
|
|
|
imp = get_imp (probj, class, err_sel);
|
|
|
|
PR_RESET_PARAMS (pr);
|
|
|
|
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);
|
2020-03-12 10:32:09 +00:00
|
|
|
pr->pr_argc = 3;
|
2020-03-09 11:41:17 +00:00
|
|
|
PR_CallFunction (pr, imp);
|
|
|
|
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]));
|
|
|
|
|
|
|
|
//FIXME ditto
|
|
|
|
err_sel = sel_register_typed_name (probj, "error:", "", 0);
|
|
|
|
if (obj_reponds_to (probj, obj, err_sel)) {
|
|
|
|
imp = get_imp (probj, class, err_sel);
|
|
|
|
PR_RESET_PARAMS (pr);
|
|
|
|
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);
|
2020-03-12 10:32:09 +00:00
|
|
|
pr->pr_argc = 3;
|
2020-03-09 11:41:17 +00:00
|
|
|
PR_CallFunction (pr, imp);
|
|
|
|
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
|
|
|
|
rua___obj_responds_to (progs_t *pr)
|
|
|
|
{
|
|
|
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_obj_error (progs_t *pr)
|
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
|
|
|
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_obj_verror (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_obj_set_error_handler (progs_t *pr)
|
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
|
|
|
//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
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_obj_msg_lookup (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_obj_msg_lookup_super (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_obj_msg_sendv (progs_t *pr)
|
2002-05-22 17:32:44 +00:00
|
|
|
{
|
2020-02-25 14:14:18 +00:00
|
|
|
probj_t *probj = pr->pr_objective_resources;
|
2020-03-09 17:56:37 +00:00
|
|
|
pointer_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);
|
2020-03-09 17:56:37 +00:00
|
|
|
pointer_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);
|
2020-02-25 14:14:18 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
if (count < 2 || count > MAX_PARMS) {
|
|
|
|
PR_RunError (pr, "bad args count in obj_msg_sendv: %d", count);
|
|
|
|
}
|
|
|
|
if (pr_boundscheck->int_val) {
|
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
|
|
|
}
|
|
|
|
|
|
|
|
pr->pr_argc = count;
|
|
|
|
// skip over the first two parameters because receiver and op will
|
|
|
|
// replace them
|
|
|
|
count -= 2;
|
|
|
|
params += 2 * pr->pr_param_size;
|
|
|
|
PR_RESET_PARAMS (pr);
|
|
|
|
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);
|
|
|
|
}
|
2004-11-07 03:00:00 +00:00
|
|
|
PR_CallFunction (pr, imp);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
2012-11-08 11:24:25 +00:00
|
|
|
static void
|
|
|
|
rua_obj_increment_retaincount (progs_t *pr)
|
|
|
|
{
|
|
|
|
pr_type_t *obj = &P_STRUCT (pr, pr_type_t, 0);
|
|
|
|
R_INT (pr) = ++(*--obj).integer_var;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rua_obj_decrement_retaincount (progs_t *pr)
|
|
|
|
{
|
|
|
|
pr_type_t *obj = &P_STRUCT (pr, pr_type_t, 0);
|
|
|
|
R_INT (pr) = --(*--obj).integer_var;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rua_obj_get_retaincount (progs_t *pr)
|
|
|
|
{
|
|
|
|
pr_type_t *obj = &P_STRUCT (pr, pr_type_t, 0);
|
|
|
|
R_INT (pr) = (*--obj).integer_var;
|
|
|
|
}
|
|
|
|
|
2002-05-22 17:32:44 +00:00
|
|
|
static void
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_obj_malloc (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_obj_atomic_malloc (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_obj_valloc (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_obj_realloc (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_obj_calloc (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_obj_free (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_obj_get_uninstalled_dtable (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_obj_msgSend (progs_t *pr)
|
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);
|
2004-11-07 03:00:00 +00:00
|
|
|
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;
|
|
|
|
}
|
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
|
|
|
|
2004-11-07 03:00:00 +00:00
|
|
|
PR_CallFunction (pr, imp);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_obj_msgSend_super (progs_t *pr)
|
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);
|
2004-11-07 03:00:00 +00:00
|
|
|
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
|
|
|
}
|
2005-06-12 09:54:01 +00:00
|
|
|
pr->pr_params[0] = pr->pr_real_params[0];
|
2003-05-15 05:58:31 +00:00
|
|
|
P_POINTER (pr, 0) = super->self;
|
2004-11-07 03:00:00 +00:00
|
|
|
PR_CallFunction (pr, imp);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_obj_get_class (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_obj_lookup_class (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_obj_next_class (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_sel_get_name (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_sel_get_type (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_sel_get_uid (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_sel_register_name (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_sel_is_mapped (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_class_get_class_method (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_class_get_instance_method (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_class_pose_as (progs_t *pr)
|
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);
|
|
|
|
pointer_t *subclass;
|
|
|
|
|
|
|
|
subclass = &superclass->subclass_list;
|
|
|
|
while (*subclass) {
|
|
|
|
pr_class_t *sub = &P_STRUCT (pr, pr_class_t, *subclass);
|
|
|
|
pointer_t nextSub = sub->sibling_class;
|
|
|
|
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)
|
|
|
|
{
|
2012-11-08 11:24:25 +00:00
|
|
|
int size = (class->instance_size + 1) * sizeof (pr_type_t);
|
|
|
|
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);
|
|
|
|
id = (pr_id_t *) (mem + 1);
|
|
|
|
id->class_pointer = PR_SetPointer (pr, class);
|
|
|
|
}
|
2002-05-22 17:32:44 +00:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_class_create_instance (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_class_get_class_name (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_class_get_instance_size (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_class_get_meta_class (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_class_get_super_class (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_class_get_version (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_class_is_class (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_class_is_meta_class (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_class_set_version (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_class_get_gc_object_type (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_class_ivar_set_gcinvisible (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_method_get_imp (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_get_imp (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_object_dispose (progs_t *pr)
|
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;
|
|
|
|
PR_Zone_Free (pr, mem - 1);
|
2002-05-22 17:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_object_copy (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_object_get_class (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_object_get_super_class (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_object_get_meta_class (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_object_get_class_name (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_object_is_class (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_object_is_instance (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua_object_is_meta_class (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua__i_Object__hash (progs_t *pr)
|
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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua__i_Object_error_error_ (progs_t *pr)
|
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);
|
|
|
|
dstring_t *dstr = dstring_new ();
|
|
|
|
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
|
|
|
|
2004-01-05 01:41:20 +00:00
|
|
|
dsprintf (dstr, "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);
|
|
|
|
obj_verror (probj, self, 0, dstr->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
|
2004-01-16 08:02:31 +00:00
|
|
|
rua__c_Object__conformsToProtocol_ (progs_t *pr)
|
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
|
|
|
|
rua_PR_FindGlobal (progs_t *pr)
|
|
|
|
{
|
|
|
|
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
|
|
|
//====================================================================
|
|
|
|
|
2004-01-06 05:51:09 +00:00
|
|
|
static builtin_t obj_methods [] = {
|
2004-01-16 08:02:31 +00:00
|
|
|
{"__obj_exec_class", rua___obj_exec_class, -1},
|
2020-03-09 10:09:08 +00:00
|
|
|
{"__obj_forward", rua___obj_forward, -1},
|
2020-03-09 15:07:01 +00:00
|
|
|
{"__obj_responds_to", rua___obj_responds_to, -1},
|
2004-01-16 08:02:31 +00:00
|
|
|
|
|
|
|
{"obj_error", rua_obj_error, -1},
|
|
|
|
{"obj_verror", rua_obj_verror, -1},
|
|
|
|
{"obj_set_error_handler", rua_obj_set_error_handler, -1},
|
|
|
|
{"obj_msg_lookup", rua_obj_msg_lookup, -1},
|
|
|
|
{"obj_msg_lookup_super", rua_obj_msg_lookup_super, -1},
|
|
|
|
{"obj_msg_sendv", rua_obj_msg_sendv, -1},
|
2012-11-08 11:24:25 +00:00
|
|
|
{"obj_increment_retaincount", rua_obj_increment_retaincount, -1},
|
|
|
|
{"obj_decrement_retaincount", rua_obj_decrement_retaincount, -1},
|
|
|
|
{"obj_get_retaincount", rua_obj_get_retaincount, -1},
|
2004-01-16 08:02:31 +00:00
|
|
|
{"obj_malloc", rua_obj_malloc, -1},
|
|
|
|
{"obj_atomic_malloc", rua_obj_atomic_malloc, -1},
|
|
|
|
{"obj_valloc", rua_obj_valloc, -1},
|
|
|
|
{"obj_realloc", rua_obj_realloc, -1},
|
|
|
|
{"obj_calloc", rua_obj_calloc, -1},
|
|
|
|
{"obj_free", rua_obj_free, -1},
|
|
|
|
{"obj_get_uninstalled_dtable", rua_obj_get_uninstalled_dtable, -1},
|
|
|
|
{"obj_msgSend", rua_obj_msgSend, -1},
|
|
|
|
{"obj_msgSend_super", rua_obj_msgSend_super, -1},
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2004-01-16 08:02:31 +00:00
|
|
|
{"obj_get_class", rua_obj_get_class, -1},
|
|
|
|
{"obj_lookup_class", rua_obj_lookup_class, -1},
|
|
|
|
{"obj_next_class", rua_obj_next_class, -1},
|
|
|
|
|
|
|
|
{"sel_get_name", rua_sel_get_name, -1},
|
|
|
|
{"sel_get_type", rua_sel_get_type, -1},
|
|
|
|
{"sel_get_uid", rua_sel_get_uid, -1},
|
|
|
|
{"sel_register_name", rua_sel_register_name, -1},
|
|
|
|
{"sel_is_mapped", rua_sel_is_mapped, -1},
|
|
|
|
|
|
|
|
{"class_get_class_method", rua_class_get_class_method, -1},
|
|
|
|
{"class_get_instance_method", rua_class_get_instance_method, -1},
|
|
|
|
{"class_pose_as", rua_class_pose_as, -1},
|
|
|
|
{"class_create_instance", rua_class_create_instance, -1},
|
|
|
|
{"class_get_class_name", rua_class_get_class_name, -1},
|
|
|
|
{"class_get_instance_size", rua_class_get_instance_size, -1},
|
|
|
|
{"class_get_meta_class", rua_class_get_meta_class, -1},
|
|
|
|
{"class_get_super_class", rua_class_get_super_class, -1},
|
|
|
|
{"class_get_version", rua_class_get_version, -1},
|
|
|
|
{"class_is_class", rua_class_is_class, -1},
|
|
|
|
{"class_is_meta_class", rua_class_is_meta_class, -1},
|
|
|
|
{"class_set_version", rua_class_set_version, -1},
|
|
|
|
{"class_get_gc_object_type", rua_class_get_gc_object_type, -1},
|
|
|
|
{"class_ivar_set_gcinvisible", rua_class_ivar_set_gcinvisible, -1},
|
|
|
|
|
|
|
|
{"method_get_imp", rua_method_get_imp, -1},
|
|
|
|
{"get_imp", rua_get_imp, -1},
|
|
|
|
|
|
|
|
{"object_copy", rua_object_copy, -1},
|
|
|
|
{"object_dispose", rua_object_dispose, -1},
|
|
|
|
{"object_get_class", rua_object_get_class, -1},
|
|
|
|
{"object_get_class_name", rua_object_get_class_name, -1},
|
|
|
|
{"object_get_meta_class", rua_object_get_meta_class, -1},
|
|
|
|
{"object_get_super_class", rua_object_get_super_class, -1},
|
|
|
|
{"object_is_class", rua_object_is_class, -1},
|
|
|
|
{"object_is_instance", rua_object_is_instance, -1},
|
|
|
|
{"object_is_meta_class", rua_object_is_meta_class, -1},
|
|
|
|
|
|
|
|
{"_i_Object__hash", rua__i_Object__hash, -1},
|
|
|
|
{"_i_Object_error_error_", rua__i_Object_error_error_, -1},
|
|
|
|
{"_c_Object__conformsToProtocol_", rua__c_Object__conformsToProtocol_, -1},
|
2012-11-15 04:40:11 +00:00
|
|
|
|
|
|
|
{"PR_FindGlobal", rua_PR_FindGlobal, -1},//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;
|
|
|
|
pointer_t object_ptr;
|
|
|
|
|
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;
|
|
|
|
for (i = 0; i < probj->selector_index_max; i++) {
|
|
|
|
obj_list_free (probj->selector_sels[i]);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
pr->hashlink_freelist);
|
|
|
|
probj->classes = Hash_NewTable (1021, class_get_key, 0, probj,
|
|
|
|
pr->hashlink_freelist);
|
|
|
|
probj->protocols = Hash_NewTable (1021, protocol_get_key, 0, probj,
|
|
|
|
pr->hashlink_freelist);
|
|
|
|
probj->load_methods = Hash_NewTable (1021, 0, 0, probj,
|
|
|
|
pr->hashlink_freelist);
|
2020-03-09 11:41:17 +00:00
|
|
|
probj->msg = dstring_newstr();
|
2020-03-09 09:09:03 +00:00
|
|
|
Hash_SetHashCompare (probj->load_methods, load_methods_get_hash,
|
|
|
|
load_methods_compare);
|
2020-02-25 14:14:18 +00:00
|
|
|
|
|
|
|
PR_Resources_Register (pr, "RUA_ObjectiveQuakeC", probj, rua_obj_cleanup);
|
|
|
|
|
2004-01-16 08:02:31 +00:00
|
|
|
PR_RegisterBuiltins (pr, obj_methods);
|
|
|
|
|
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
|
|
|
|
|
|
|
func_t
|
|
|
|
RUA_Obj_msg_lookup (progs_t *pr, pointer_t _self, pointer_t __cmd)
|
|
|
|
{
|
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);
|
|
|
|
func_t imp;
|
|
|
|
|
|
|
|
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
|
|
|
|
RUA_obj_increment_retaincount (progs_t *pr)
|
|
|
|
{
|
|
|
|
rua_obj_increment_retaincount (pr);
|
|
|
|
return R_INT (pr);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
RUA_obj_decrement_retaincount (progs_t *pr)
|
|
|
|
{
|
|
|
|
rua_obj_decrement_retaincount (pr);
|
|
|
|
return R_INT (pr);
|
|
|
|
}
|