factor/native/sbuf.c

45 lines
877 B
C
Raw Normal View History

2004-07-16 02:26:21 -04:00
#include "factor.h"
F_SBUF* sbuf(F_FIXNUM capacity)
2004-07-16 02:26:21 -04:00
{
2004-12-25 02:55:03 -05:00
F_SBUF* sbuf;
if(capacity < 0)
general_error(ERROR_NEGATIVE_ARRAY_SIZE,tag_fixnum(capacity));
sbuf = allot_object(SBUF_TYPE,sizeof(F_SBUF));
2005-05-05 22:30:58 -04:00
sbuf->top = tag_fixnum(0);
sbuf->string = tag_object(string(capacity,'\0'));
2004-07-16 02:26:21 -04:00
return sbuf;
}
void primitive_sbuf(void)
{
maybe_garbage_collection();
drepl(tag_object(sbuf(to_fixnum(dpeek()))));
2004-07-16 02:26:21 -04:00
}
2005-05-18 16:26:22 -04:00
void primitive_sbuf_to_string(void)
{
F_STRING* result;
F_SBUF* sbuf = untag_sbuf(dpeek());
F_STRING* string = untag_string(sbuf->string);
CELL length = untag_fixnum_fast(sbuf->top);
result = allot_string(length);
memcpy(result + 1,
(void*)((CELL)(string + 1)),
CHARS * length);
rehash_string(result);
drepl(tag_object(result));
}
void fixup_sbuf(F_SBUF* sbuf)
2004-07-16 02:26:21 -04:00
{
2004-12-25 02:55:03 -05:00
data_fixup(&sbuf->string);
2004-07-16 02:26:21 -04:00
}
void collect_sbuf(F_SBUF* sbuf)
2004-07-16 02:26:21 -04:00
{
2005-05-12 01:02:39 -04:00
copy_handle(&sbuf->string);
2004-07-16 02:26:21 -04:00
}