qse/ase/stx/class.c

51 lines
1.4 KiB
C
Raw Normal View History

2005-05-22 15:03:20 +00:00
/*
2005-05-29 16:51:16 +00:00
* $Id: class.c,v 1.8 2005-05-29 16:51:16 bacon Exp $
2005-05-22 15:03:20 +00:00
*/
#include <xp/stx/class.h>
#include <xp/stx/symbol.h>
#include <xp/stx/object.h>
#include <xp/stx/hash.h>
#include <xp/stx/misc.h>
xp_stx_word_t xp_stx_new_class (xp_stx_t* stx, const xp_stx_char_t* name)
{
xp_stx_word_t meta, class;
2005-05-24 03:28:31 +00:00
xp_stx_word_t class_name;
2005-05-22 15:03:20 +00:00
2005-05-24 03:28:31 +00:00
meta = xp_stx_alloc_word_object (stx, XP_STX_METACLASS_SIZE);
2005-05-22 15:03:20 +00:00
XP_STX_CLASS(stx,meta) = stx->class_metaclass;
2005-05-25 16:44:05 +00:00
/* the spec of the metaclass must be the spec of its
* instance. so the XP_STX_CLASS_SIZE is set */
2005-05-29 16:51:16 +00:00
XP_STX_WORDAT(stx,meta,XP_STX_METACLASS_SPEC) =
2005-05-25 16:44:05 +00:00
XP_STX_TO_SMALLINT((XP_STX_CLASS_SIZE << 1) | 0x00);
2005-05-22 15:03:20 +00:00
2005-05-25 16:44:05 +00:00
/* the spec of the class is set later in __create_builtin_classes */
2005-05-22 15:03:20 +00:00
class = xp_stx_alloc_word_object (stx, XP_STX_CLASS_SIZE);
XP_STX_CLASS(stx,class) = meta;
class_name = xp_stx_new_symbol (stx, name);
2005-05-29 16:51:16 +00:00
XP_STX_WORDAT(stx,class,XP_STX_CLASS_NAME) = class_name;
2005-05-22 15:03:20 +00:00
xp_stx_hash_insert (stx, stx->smalltalk,
xp_stx_hash_char_object(stx, class_name),
class_name, class);
return class;
}
xp_stx_word_t xp_stx_lookup_class (xp_stx_t* stx, const xp_stx_char_t* name)
{
2005-05-22 16:26:58 +00:00
xp_stx_word_t link, meta, value;
2005-05-22 15:03:20 +00:00
link = xp_stx_hash_lookup_symbol (stx, stx->smalltalk, name);
if (link == stx->nil) return stx->nil;
2005-05-29 16:51:16 +00:00
value = XP_STX_WORDAT(stx,link,XP_STX_PAIRLINK_VALUE);
2005-05-22 16:26:58 +00:00
meta = XP_STX_CLASS(stx,value);
if (XP_STX_CLASS(stx,meta) != stx->class_metaclass) return stx->nil;
2005-05-22 15:24:57 +00:00
return value;
2005-05-22 15:03:20 +00:00
}