2004-07-16 02:26:21 -04:00
|
|
|
#include "factor.h"
|
|
|
|
|
2004-12-10 21:46:42 -05:00
|
|
|
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);
|
2004-11-27 22:26:05 -05:00
|
|
|
sbuf->string = tag_object(string(capacity,'\0'));
|
2004-07-16 02:26:21 -04:00
|
|
|
return sbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_sbuf(void)
|
|
|
|
{
|
2004-10-12 23:49:43 -04:00
|
|
|
maybe_garbage_collection();
|
2004-08-12 17:36:36 -04:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2004-12-10 21:46:42 -05:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2004-12-10 21:46:42 -05: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
|
|
|
}
|