\usepackage{alltt}
\usepackage{times}
\usepackage{tabularx}
-\usepackage{epstopdf}
\usepackage{epsfig}
-\usepackage{epsf}
\usepackage{amssymb}
+\usepackage{epstopdf}
\pagestyle{headings}
]
unit-test
-[ "05" ] [ "5" 2 CHAR: 0 pad ] unit-test
-[ "666" ] [ "666" 2 CHAR: 0 pad ] unit-test
+[ "05" ] [ "5" 2 CHAR: 0 pad-left ] unit-test
+[ "666" ] [ "666" 2 CHAR: 0 pad-left ] unit-test
[ 1 "" nth ] unit-test-fails
[ -6 "hello" nth ] unit-test-fails
void primitive_alien(void)
{
void* ptr = (void*)unbox_signed_cell();
- maybe_garbage_collection();
+ maybe_gc(sizeof(ALIEN));
box_alien(ptr);
}
CELL alien;
CELL displacement;
DISPLACED_ALIEN* d;
- maybe_garbage_collection();
+ maybe_gc(sizeof(DISPLACED_ALIEN));
alien = dpop();
displacement = unbox_unsigned_cell();
d = allot_object(DISPLACED_ALIEN_TYPE,sizeof(DISPLACED_ALIEN));
if(capacity < 0)
general_error(ERROR_NEGATIVE_ARRAY_SIZE,tag_fixnum(capacity));
- array = allot_object(type,sizeof(F_ARRAY) + capacity * CELLS);
+ array = allot_object(type,array_size(capacity));
array->capacity = tag_fixnum(capacity);
return array;
}
void primitive_array(void)
{
- maybe_garbage_collection();
- dpush(tag_object(array(ARRAY_TYPE,to_fixnum(dpop()),F)));
+ CELL size = to_fixnum(dpop());
+ maybe_gc(array_size(size));
+ dpush(tag_object(array(ARRAY_TYPE,size,F)));
}
void primitive_tuple(void)
{
- maybe_garbage_collection();
- dpush(tag_object(array(TUPLE_TYPE,to_fixnum(dpop()),F)));
+ CELL size = to_fixnum(dpop());
+ maybe_gc(array_size(size));
+ dpush(tag_object(array(TUPLE_TYPE,size,F)));
}
void primitive_byte_array(void)
{
- maybe_garbage_collection();
- dpush(tag_object(array(BYTE_ARRAY_TYPE,to_fixnum(dpop()),0)));
+ CELL size = to_fixnum(dpop());
+ maybe_gc(array_size(size));
+ dpush(tag_object(array(BYTE_ARRAY_TYPE,size,0)));
}
/* see note about fill in array() */
void primitive_resize_array(void)
{
F_ARRAY* array; CELL capacity;
- maybe_garbage_collection();
+ maybe_gc(0);
array = untag_array_fast(dpop());
capacity = to_fixnum(dpop());
dpush(tag_object(resize_array(array,capacity,F)));
return (F_ARRAY*)UNTAG(tagged);
}
+INLINE CELL array_size(CELL size)
+{
+ return align8(sizeof(F_ARRAY) + size * CELLS);
+}
+
F_ARRAY* allot_array(CELL type, CELL capacity);
F_ARRAY* array(CELL type, CELL capacity, CELL fill);
void primitive_to_bignum(void)
{
- maybe_garbage_collection();
+ maybe_gc(0);
drepl(tag_bignum(to_bignum(dpeek())));
}
#define GC_AND_POP_BIGNUMS(x,y) \
F_ARRAY *x, *y; \
- maybe_garbage_collection(); \
+ maybe_gc(0); \
y = untag_bignum_fast(dpop()); \
x = untag_bignum_fast(dpop());
{
F_FIXNUM y;
F_ARRAY* x;
- maybe_garbage_collection();
+ maybe_gc(0);
y = to_fixnum(dpop());
x = to_bignum(dpop());
dpush(tag_bignum(s48_bignum_arithmetic_shift(x,y)));
void primitive_bignum_not(void)
{
- maybe_garbage_collection();
+ maybe_gc(0);
drepl(tag_bignum(s48_bignum_bitwise_not(
untag_bignum_fast(dpeek()))));
}
CELL real, imaginary;
F_CONS* complex;
- maybe_garbage_collection();
+ maybe_gc(sizeof(F_CONS));
imaginary = dpop();
real = dpop();
void primitive_cons(void)
{
CELL car, cdr;
- maybe_garbage_collection();
+ maybe_gc(sizeof(F_CONS));
cdr = dpop();
car = dpop();
dpush(cons(car,cdr));
DLL* dll;
F_STRING* path;
- maybe_garbage_collection();
+ maybe_gc(sizeof(DLL));
path = untag_string(dpop());
dll = allot_object(DLL_TYPE,sizeof(DLL));
CELL dll;
F_STRING* sym;
- maybe_garbage_collection();
+ maybe_gc(0);
dll = dpop();
sym = untag_string(dpop());
void primitive_dlclose(void)
{
- maybe_garbage_collection();
ffi_dlclose(untag_dll(dpop()));
}
#include "factor.h"
-void foobar(int x, int y, int z, int t)
-{
- printf("%d\n",x);
- printf("%d\n",y);
- printf("%d\n",z);
- printf("%d\n",t);
-}
-
double to_float(CELL tagged)
{
F_RATIO* r;
void primitive_to_float(void)
{
- maybe_garbage_collection();
+ maybe_gc(sizeof(F_FLOAT));
drepl(tag_float(to_float(dpeek())));
}
char *c_str, *end;
double f;
- maybe_garbage_collection();
+ maybe_gc(sizeof(F_FLOAT));
str = untag_string(dpeek());
c_str = to_c_string(str);
{
char tmp[33];
- maybe_garbage_collection();
+ maybe_gc(sizeof(F_FLOAT));
snprintf(tmp,32,"%.16g",to_float(dpop()));
tmp[32] = '\0';
#define GC_AND_POP_FLOATS(x,y) \
double x, y; \
- maybe_garbage_collection(); \
+ maybe_gc(sizeof(F_FLOAT)); \
y = untag_float_fast(dpop()); \
x = untag_float_fast(dpop());
void primitive_facos(void)
{
- maybe_garbage_collection();
+ maybe_gc(sizeof(F_FLOAT));
drepl(tag_float(acos(to_float(dpeek()))));
}
void primitive_fasin(void)
{
- maybe_garbage_collection();
+ maybe_gc(sizeof(F_FLOAT));
drepl(tag_float(asin(to_float(dpeek()))));
}
void primitive_fatan(void)
{
- maybe_garbage_collection();
+ maybe_gc(sizeof(F_FLOAT));
drepl(tag_float(atan(to_float(dpeek()))));
}
void primitive_fatan2(void)
{
double x, y;
- maybe_garbage_collection();
+ maybe_gc(sizeof(F_FLOAT));
y = to_float(dpop());
x = to_float(dpop());
dpush(tag_float(atan2(x,y)));
void primitive_fcos(void)
{
- maybe_garbage_collection();
+ maybe_gc(sizeof(F_FLOAT));
drepl(tag_float(cos(to_float(dpeek()))));
}
void primitive_fexp(void)
{
- maybe_garbage_collection();
+ maybe_gc(sizeof(F_FLOAT));
drepl(tag_float(exp(to_float(dpeek()))));
}
void primitive_fcosh(void)
{
- maybe_garbage_collection();
+ maybe_gc(sizeof(F_FLOAT));
drepl(tag_float(cosh(to_float(dpeek()))));
}
void primitive_flog(void)
{
- maybe_garbage_collection();
+ maybe_gc(sizeof(F_FLOAT));
drepl(tag_float(log(to_float(dpeek()))));
}
void primitive_fpow(void)
{
double x, y;
- maybe_garbage_collection();
+ maybe_gc(sizeof(F_FLOAT));
y = to_float(dpop());
x = to_float(dpop());
dpush(tag_float(pow(x,y)));
void primitive_fsin(void)
{
- maybe_garbage_collection();
+ maybe_gc(sizeof(F_FLOAT));
drepl(tag_float(sin(to_float(dpeek()))));
}
void primitive_fsinh(void)
{
- maybe_garbage_collection();
+ maybe_gc(sizeof(F_FLOAT));
drepl(tag_float(sinh(to_float(dpeek()))));
}
void primitive_fsqrt(void)
{
- maybe_garbage_collection();
+ maybe_gc(sizeof(F_FLOAT));
drepl(tag_float(sqrt(to_float(dpeek()))));
}
/* WARNING: only call this from a context where all local variables
are also reachable via the GC roots. */
-void maybe_garbage_collection(void)
+void maybe_gc(CELL size)
{
- if(nursery.here > nursery.alarm)
+ if(nursery.here + size > nursery.alarm)
{
CELL gen = NURSERY;
while(gen < TENURED)
void primitive_gc_time(void)
{
- maybe_garbage_collection();
+ maybe_gc(0);
dpush(tag_bignum(s48_long_long_to_bignum(gc_time)));
}
CELL collect_next(CELL scan);
void garbage_collection(CELL gen);
void primitive_gc(void);
-void maybe_garbage_collection(void);
+void maybe_gc(CELL size);
void primitive_gc_time(void);
void primitive_hashtable(void)
{
- maybe_garbage_collection();
+ maybe_gc(0);
drepl(tag_object(hashtable(to_fixnum(dpeek()))));
}
{
char *path, *mode;
FILE* file;
- maybe_garbage_collection();
+ maybe_gc(0);
mode = unbox_c_string();
path = unbox_c_string();
file = fopen(path,mode);
FILE* file;
char line[FACTOR_LINE_LEN];
- maybe_garbage_collection();
+ maybe_gc(0);
file = (FILE*)unbox_alien();
if(fgets(line,FACTOR_LINE_LEN,file) == NULL)
{
FILE* file;
F_STRING* text;
- maybe_garbage_collection();
+ maybe_gc(0);
file = (FILE*)unbox_alien();
text = untag_string(dpop());
if(fwrite(to_c_string_unchecked(text),1,
case TUPLE_TYPE:
case BIGNUM_TYPE:
case BYTE_ARRAY_TYPE:
- size = align8(sizeof(F_ARRAY) +
- array_capacity((F_ARRAY*)(pointer)) * CELLS);
+ size = array_size(array_capacity((F_ARRAY*)(pointer)));
break;
case HASHTABLE_TYPE:
size = sizeof(F_HASHTABLE);
size = sizeof(F_VECTOR);
break;
case STRING_TYPE:
- size = SSIZE(pointer);
+ size = string_size(string_capacity((F_STRING*)(pointer)));
break;
case SBUF_TYPE:
size = sizeof(F_SBUF);
{
char *name, *value;
- maybe_garbage_collection();
+ maybe_gc(0);
name = unbox_c_string();
value = getenv(name);
void primitive_millis(void)
{
- maybe_garbage_collection();
+ maybe_gc(0);
dpush(tag_bignum(s48_long_long_to_bignum(current_millis())));
}
void primitive_random_int(void)
{
- maybe_garbage_collection();
+ maybe_gc(0);
dpush(tag_bignum(s48_long_to_bignum(rand())));
}
CELL numerator, denominator;
F_RATIO* ratio;
- maybe_garbage_collection();
+ maybe_gc(0);
denominator = dpop();
numerator = dpop();
original = get(rel->offset);
/* to_c_string can fill up the heap */
- maybe_garbage_collection();
+ maybe_gc(0);
new_value = compute_code_rel(rel,original);
if(REL_RELATIVE(rel))
void primitive_sbuf(void)
{
- maybe_garbage_collection();
- drepl(tag_object(sbuf(to_fixnum(dpeek()))));
+ CELL size = to_fixnum(dpeek());
+ maybe_gc(sizeof(F_SBUF) + string_size(size));
+ drepl(tag_object(sbuf(size)));
}
void primitive_sbuf_to_string(void)
void primitive_datastack(void)
{
- maybe_garbage_collection();
+ maybe_gc(0);
dpush(tag_object(stack_to_vector(ds_bot,ds)));
}
void primitive_callstack(void)
{
- maybe_garbage_collection();
+ maybe_gc(0);
dpush(tag_object(stack_to_vector(cs_bot,cs)));
}
void primitive_resize_string(void)
{
F_STRING* string; CELL capacity;
- maybe_garbage_collection();
+ maybe_gc(0);
string = untag_string_fast(dpop());
capacity = to_fixnum(dpop());
dpush(tag_object(resize_string(string,capacity,F)));
return untag_fixnum_fast(str->length);
}
-#define SSIZE(pointer) align8(sizeof(F_STRING) + \
- (string_capacity((F_STRING*)(pointer)) + 1) * CHARS)
+INLINE CELL string_size(CELL size)
+{
+ return align8(sizeof(F_STRING) + (size + 1) * CHARS);
+}
F_STRING* allot_string(CELL capacity);
F_STRING* string(CELL capacity, CELL fill);
void ffi_dlclose(DLL *dll)
{
- if(dlclose(dll->dll) != NULL)
+ if(dlclose(dll->dll))
{
general_error(ERROR_FFI,tag_object(
from_c_string(dlerror())));
struct stat sb;
F_STRING* path;
- maybe_garbage_collection();
+ maybe_gc(0);
path = untag_string(dpop());
if(stat(to_c_string(path),&sb) < 0)
DIR* dir;
CELL result = F;
- maybe_garbage_collection();
+ maybe_gc(0);
path = untag_string(dpop());
dir = opendir(to_c_string(path));
void primitive_cwd(void)
{
char wd[MAXPATHLEN];
- maybe_garbage_collection();
+ maybe_gc(0);
if(getcwd(wd,MAXPATHLEN) == NULL)
io_error();
box_c_string(wd);
void primitive_cd(void)
{
- maybe_garbage_collection();
+ maybe_gc(0);
chdir(unbox_c_string());
}
void primitive_vector(void)
{
- maybe_garbage_collection();
- drepl(tag_object(vector(to_fixnum(dpeek()))));
+ CELL size = to_fixnum(dpeek());
+ maybe_gc(array_size(size) + sizeof(F_VECTOR));
+ drepl(tag_object(vector(size)));
}
void fixup_vector(F_VECTOR* vector)
F_STRING *path;
WIN32_FILE_ATTRIBUTE_DATA st;
- maybe_garbage_collection();
+ maybe_gc(0);
path = untag_string(dpop());
if(!GetFileAttributesEx(to_c_string(path), GetFileExInfoStandard, &st))
WIN32_FIND_DATA find_data;
CELL result = F;
- maybe_garbage_collection();
+ maybe_gc(0);
path = untag_string(dpop());
if (INVALID_HANDLE_VALUE != (dir = FindFirstFile(".\\*", &find_data)))
{
char buf[MAX_PATH];
- maybe_garbage_collection();
+ maybe_gc(0);
if(!GetCurrentDirectory(MAX_PATH, buf))
io_error();
void primitive_cd(void)
{
- maybe_garbage_collection();
+ maybe_gc(0);
SetCurrentDirectory(unbox_c_string());
}
\ No newline at end of file
{
F_WORD* word;
- maybe_garbage_collection();
+ maybe_gc(sizeof(F_WORD));
word = allot_object(WORD_TYPE,sizeof(F_WORD));
word->hashcode = tag_fixnum((CELL)word); /* initial address */