qse/ase/stx/object.c

60 lines
1.7 KiB
C
Raw Normal View History

2005-05-06 17:18:29 +00:00
/*
2005-05-08 11:16:07 +00:00
* $Id: object.c,v 1.4 2005-05-08 11:16:07 bacon Exp $
2005-05-06 17:18:29 +00:00
*/
#include <xp/stx/object.h>
2005-05-08 07:39:51 +00:00
#include <xp/stx/memory.h>
2005-05-06 17:18:29 +00:00
/* n: number of instance variables */
2005-05-08 11:16:07 +00:00
xp_stx_word_t xp_stx_alloc_object (xp_stx_t* stx, xp_stx_word_t n)
2005-05-06 17:18:29 +00:00
{
2005-05-08 10:31:25 +00:00
xp_stx_word_t idx;
2005-05-06 17:18:29 +00:00
2005-05-08 10:31:25 +00:00
/* bytes to allocidxed =
2005-05-06 17:18:29 +00:00
* number of instance variables * word_size
*/
2005-05-08 10:31:25 +00:00
idx = xp_stx_memory_alloc (&stx->memory,
n * xp_sizeof(xp_stx_word_t) + xp_sizeof(xp_stx_object_t));
if (idx >= stx->memory.capacity) return idx; /* failed */
2005-05-08 07:39:51 +00:00
2005-05-08 10:31:25 +00:00
XP_STX_OBJECT_CLASS(&stx->memory,idx) = stx->nil;
XP_STX_OBJECT_ACCESS(&stx->memory,idx) = ((n << 2) | 0x00);
while (n--) XP_STX_OBJECT_AT(&stx->memory,idx,n) = stx->nil;
2005-05-06 17:18:29 +00:00
2005-05-08 10:31:25 +00:00
return idx;
2005-05-06 17:18:29 +00:00
}
2005-05-08 07:39:51 +00:00
/* n: number of bytes */
2005-05-08 11:16:07 +00:00
xp_stx_word_t xp_stx_alloc_byte_object (xp_stx_t* stx, xp_stx_word_t n)
2005-05-06 17:18:29 +00:00
{
2005-05-08 10:31:25 +00:00
xp_stx_word_t idx;
2005-05-06 17:18:29 +00:00
2005-05-08 10:31:25 +00:00
idx = xp_stx_memory_alloc (
&stx->memory, n + xp_sizeof(xp_stx_object_t));
if (idx >= stx->memory.capacity) return idx; /* failed */
2005-05-08 07:39:51 +00:00
2005-05-08 10:31:25 +00:00
XP_STX_OBJECT_CLASS(&stx->memory,idx) = stx->nil;
XP_STX_OBJECT_ACCESS(&stx->memory,idx) = ((n << 2) | 0x01);
while (n--) XP_STX_OBJECT_BYTEAT(&stx->memory,idx,n) = 0;
2005-05-06 17:18:29 +00:00
2005-05-08 10:31:25 +00:00
return idx;
2005-05-06 17:18:29 +00:00
}
2005-05-08 07:39:51 +00:00
/* n: length of the string */
xp_stx_word_t xp_stx_alloc_string_object (
xp_stx_t* stx, xp_stx_char_t* str, xp_stx_word_t n)
2005-05-06 17:18:29 +00:00
{
2005-05-08 10:31:25 +00:00
xp_stx_word_t idx;
2005-05-06 17:18:29 +00:00
2005-05-08 10:31:25 +00:00
idx = xp_stx_memory_alloc (&stx->memory,
(n + 1) * xp_sizeof(xp_stx_char_t) + xp_sizeof(xp_stx_object_t));
if (idx >= stx->memory.capacity) return idx; /* failed */
2005-05-06 17:18:29 +00:00
2005-05-08 10:31:25 +00:00
XP_STX_OBJECT_CLASS(&stx->memory,idx) = stx->nil;
XP_STX_OBJECT_ACCESS(&stx->memory,idx) = ((n << 2) | 0x02);
XP_STX_OBJECT_CHARAT(&stx->memory,idx,n) = XP_STX_CHAR('\0');
while (n--) XP_STX_OBJECT_CHARAT(&stx->memory,idx,n) = str[n];
2005-05-06 17:18:29 +00:00
2005-05-08 10:31:25 +00:00
return idx;
2005-05-06 17:18:29 +00:00
}