case FIXNUM_TYPE:
return tagged == 0;
case BIGNUM_TYPE:
- return BIGNUM_ZERO_P((ARRAY*)UNTAG(tagged));
+ return BIGNUM_ZERO_P((F_ARRAY*)UNTAG(tagged));
case FLOAT_TYPE:
- return ((FLOAT*)UNTAG(tagged))->n == 0.0;
+ return ((F_FLOAT*)UNTAG(tagged))->n == 0.0;
case RATIO_TYPE:
case COMPLEX_TYPE:
return false;
case FIXNUM_TYPE:
return tagged == tag_fixnum(1);
case BIGNUM_TYPE:
- return BIGNUM_ONE_P((ARRAY*)UNTAG(tagged),0);
+ return BIGNUM_ONE_P((F_ARRAY*)UNTAG(tagged),0);
case FLOAT_TYPE:
- return ((FLOAT*)UNTAG(tagged))->n == 1.0;
+ return ((F_FLOAT*)UNTAG(tagged))->n == 1.0;
case RATIO_TYPE:
case COMPLEX_TYPE:
return false;
#include "factor.h"
/* untagged */
-ARRAY* allot_array(CELL type, FIXNUM capacity)
+F_ARRAY* allot_array(CELL type, F_FIXNUM capacity)
{
- ARRAY* array;
+ F_ARRAY* array;
if(capacity < 0)
general_error(ERROR_NEGATIVE_ARRAY_SIZE,tag_fixnum(capacity));
- array = allot_object(type,sizeof(ARRAY) + capacity * CELLS);
+ array = allot_object(type,sizeof(F_ARRAY) + capacity * CELLS);
array->capacity = capacity;
return array;
}
/* untagged */
-ARRAY* array(FIXNUM capacity, CELL fill)
+F_ARRAY* array(F_FIXNUM capacity, CELL fill)
{
int i;
- ARRAY* array = allot_array(ARRAY_TYPE, capacity);
+ F_ARRAY* array = allot_array(ARRAY_TYPE, capacity);
for(i = 0; i < capacity; i++)
put(AREF(array,i),fill);
return array;
}
-ARRAY* grow_array(ARRAY* array, FIXNUM capacity, CELL fill)
+F_ARRAY* grow_array(F_ARRAY* array, F_FIXNUM capacity, CELL fill)
{
/* later on, do an optimization: if end of array is here, just grow */
int i;
- ARRAY* new_array = allot_array(untag_header(array->header),capacity);
+ F_ARRAY* new_array = allot_array(untag_header(array->header),capacity);
memcpy(new_array + 1,array + 1,array->capacity * CELLS);
return new_array;
}
-ARRAY* shrink_array(ARRAY* array, FIXNUM capacity)
+F_ARRAY* shrink_array(F_ARRAY* array, F_FIXNUM capacity)
{
- ARRAY* new_array = allot_array(untag_header(array->header),capacity);
+ F_ARRAY* new_array = allot_array(untag_header(array->header),capacity);
memcpy(new_array + 1,array + 1,capacity * CELLS);
return new_array;
}
-void fixup_array(ARRAY* array)
+void fixup_array(F_ARRAY* array)
{
int i = 0;
for(i = 0; i < array->capacity; i++)
fixup((void*)AREF(array,i));
}
-void collect_array(ARRAY* array)
+void collect_array(F_ARRAY* array)
{
int i = 0;
for(i = 0; i < array->capacity; i++)
CELL header;
/* untagged */
CELL capacity;
-} ARRAY;
+} F_ARRAY;
-INLINE ARRAY* untag_array(CELL tagged)
+INLINE F_ARRAY* untag_array(CELL tagged)
{
/* type_check(ARRAY_TYPE,tagged); */
- return (ARRAY*)UNTAG(tagged); /* FIXME */
+ return (F_ARRAY*)UNTAG(tagged); /* FIXME */
}
-ARRAY* allot_array(CELL type, FIXNUM capacity);
-ARRAY* array(FIXNUM capacity, CELL fill);
-ARRAY* grow_array(ARRAY* array, FIXNUM capacity, CELL fill);
-ARRAY* shrink_array(ARRAY* array, FIXNUM capacity);
+F_ARRAY* allot_array(CELL type, F_FIXNUM capacity);
+F_ARRAY* array(F_FIXNUM capacity, CELL fill);
+F_ARRAY* grow_array(F_ARRAY* array, F_FIXNUM capacity, CELL fill);
+F_ARRAY* shrink_array(F_ARRAY* array, F_FIXNUM capacity);
-#define AREF(array,index) ((CELL)(array) + sizeof(ARRAY) + (index) * CELLS)
+#define AREF(array,index) ((CELL)(array) + sizeof(F_ARRAY) + (index) * CELLS)
-#define ASIZE(pointer) align8(sizeof(ARRAY) + \
- ((ARRAY*)(pointer))->capacity * CELLS)
+#define ASIZE(pointer) align8(sizeof(F_ARRAY) + \
+ ((F_ARRAY*)(pointer))->capacity * CELLS)
/* untagged & unchecked */
-INLINE CELL array_nth(ARRAY* array, CELL index)
+INLINE CELL array_nth(F_ARRAY* array, CELL index)
{
return get(AREF(array,index));
}
/* untagged & unchecked */
-INLINE void set_array_nth(ARRAY* array, CELL index, CELL value)
+INLINE void set_array_nth(F_ARRAY* array, CELL index, CELL value)
{
put(AREF(array,index),value);
}
-void fixup_array(ARRAY* array);
-void collect_array(ARRAY* array);
+void fixup_array(F_ARRAY* array);
+void collect_array(F_ARRAY* array);
#include "factor.h"
-FIXNUM to_integer(CELL x)
+F_FIXNUM to_integer(CELL x)
{
switch(type_of(x))
{
}
/* FFI calls this */
-void box_integer(FIXNUM integer)
+void box_integer(F_FIXNUM integer)
{
dpush(tag_integer(integer));
}
}
/* FFI calls this */
-FIXNUM unbox_integer(void)
+F_FIXNUM unbox_integer(void)
{
return to_integer(dpop());
}
return to_integer(dpop());
}
-ARRAY* to_bignum(CELL tagged)
+F_ARRAY* to_bignum(CELL tagged)
{
- RATIO* r;
- ARRAY* x;
- ARRAY* y;
- FLOAT* f;
+ F_RATIO* r;
+ F_ARRAY* x;
+ F_ARRAY* y;
+ F_FLOAT* f;
switch(type_of(tagged))
{
case FIXNUM_TYPE:
return s48_long_to_bignum(untag_fixnum_fast(tagged));
case BIGNUM_TYPE:
- return (ARRAY*)UNTAG(tagged);
+ return (F_ARRAY*)UNTAG(tagged);
case RATIO_TYPE:
- r = (RATIO*)UNTAG(tagged);
+ r = (F_RATIO*)UNTAG(tagged);
x = to_bignum(r->numerator);
y = to_bignum(r->denominator);
return s48_bignum_quotient(x,y);
case FLOAT_TYPE:
- f = (FLOAT*)UNTAG(tagged);
+ f = (F_FLOAT*)UNTAG(tagged);
return s48_double_to_bignum(f->n);
default:
type_error(BIGNUM_TYPE,tagged);
void primitive_bignum_eq(void)
{
- ARRAY* y = to_bignum(dpop());
- ARRAY* x = to_bignum(dpop());
+ F_ARRAY* y = to_bignum(dpop());
+ F_ARRAY* x = to_bignum(dpop());
box_boolean(s48_bignum_equal_p(x,y));
}
#define GC_AND_POP_BIGNUMS(x,y) \
- ARRAY *x, *y; \
+ F_ARRAY *x, *y; \
maybe_garbage_collection(); \
y = to_bignum(dpop()); \
x = to_bignum(dpop());
void primitive_bignum_divmod(void)
{
- ARRAY *q, *r;
+ F_ARRAY *q, *r;
GC_AND_POP_BIGNUMS(x,y);
s48_bignum_divide(x,y,&q,&r);
dpush(tag_object(q));
void primitive_bignum_shift(void)
{
- FIXNUM y;
- ARRAY* x;
+ F_FIXNUM y;
+ F_ARRAY* x;
maybe_garbage_collection();
y = to_fixnum(dpop());
x = to_bignum(dpop());
void primitive_bignum_less(void)
{
- ARRAY* y = to_bignum(dpop());
- ARRAY* x = to_bignum(dpop());
+ F_ARRAY* y = to_bignum(dpop());
+ F_ARRAY* x = to_bignum(dpop());
box_boolean(s48_bignum_compare(x,y) == bignum_comparison_less);
}
void primitive_bignum_lesseq(void)
{
- ARRAY* y = to_bignum(dpop());
- ARRAY* x = to_bignum(dpop());
+ F_ARRAY* y = to_bignum(dpop());
+ F_ARRAY* x = to_bignum(dpop());
switch(s48_bignum_compare(x,y))
{
void primitive_bignum_greater(void)
{
- ARRAY* y = to_bignum(dpop());
- ARRAY* x = to_bignum(dpop());
+ F_ARRAY* y = to_bignum(dpop());
+ F_ARRAY* x = to_bignum(dpop());
box_boolean(s48_bignum_compare(x,y) == bignum_comparison_greater);
}
void primitive_bignum_greatereq(void)
{
- ARRAY* y = to_bignum(dpop());
- ARRAY* x = to_bignum(dpop());
+ F_ARRAY* y = to_bignum(dpop());
+ F_ARRAY* x = to_bignum(dpop());
switch(s48_bignum_compare(x,y))
{
CELL bignum_pos_one;
CELL bignum_neg_one;
-INLINE ARRAY* untag_bignum(CELL tagged)
+INLINE F_ARRAY* untag_bignum(CELL tagged)
{
type_check(BIGNUM_TYPE,tagged);
- return (ARRAY*)UNTAG(tagged);
+ return (F_ARRAY*)UNTAG(tagged);
}
-FIXNUM to_integer(CELL x);
-void box_integer(FIXNUM integer);
+F_FIXNUM to_integer(CELL x);
+void box_integer(F_FIXNUM integer);
void box_cell(CELL cell);
-FIXNUM unbox_integer(void);
+F_FIXNUM unbox_integer(void);
CELL unbox_cell(void);
-ARRAY* to_bignum(CELL tagged);
+F_ARRAY* to_bignum(CELL tagged);
void primitive_to_bignum(void);
void primitive_bignum_eq(void);
void primitive_bignum_add(void);
void copy_bignum_constants(void);
CELL three_test(void* x, unsigned char r, unsigned char g, unsigned char b);
-INLINE CELL tag_integer(FIXNUM x)
+INLINE CELL tag_integer(F_FIXNUM x)
{
if(x < FIXNUM_MIN || x > FIXNUM_MAX)
return tag_object(s48_long_to_bignum(x));
dpush(real);
else
{
- COMPLEX* complex = allot(sizeof(COMPLEX));
+ F_COMPLEX* complex = allot(sizeof(F_COMPLEX));
complex->real = real;
complex->imaginary = imaginary;
dpush(tag_complex(complex));
typedef struct {
CELL real;
CELL imaginary;
-} COMPLEX;
+} F_COMPLEX;
-INLINE COMPLEX* untag_complex(CELL tagged)
+INLINE F_COMPLEX* untag_complex(CELL tagged)
{
type_check(COMPLEX_TYPE,tagged);
- return (COMPLEX*)UNTAG(tagged);
+ return (F_COMPLEX*)UNTAG(tagged);
}
-INLINE CELL tag_complex(COMPLEX* complex)
+INLINE CELL tag_complex(F_COMPLEX* complex)
{
return RETAG(complex,COMPLEX_TYPE);
}
CELL cons(CELL car, CELL cdr)
{
- CONS* cons = allot(sizeof(CONS));
+ F_CONS* cons = allot(sizeof(F_CONS));
cons->car = car;
cons->cdr = cdr;
return tag_cons(cons);
typedef struct {
CELL car;
CELL cdr;
-} CONS;
+} F_CONS;
-INLINE CONS* untag_cons(CELL tagged)
+INLINE F_CONS* untag_cons(CELL tagged)
{
type_check(CONS_TYPE,tagged);
- return (CONS*)UNTAG(tagged);
+ return (F_CONS*)UNTAG(tagged);
}
-INLINE CELL tag_cons(CONS* cons)
+INLINE CELL tag_cons(F_CONS* cons)
{
return RETAG(cons,CONS_TYPE);
}
general_error(ERROR_TYPE,c);
}
-void range_error(CELL tagged, FIXNUM index, CELL max)
+void range_error(CELL tagged, F_FIXNUM index, CELL max)
{
CELL c = cons(tagged,cons(tag_integer(index),cons(tag_cell(max),F)));
general_error(ERROR_RANGE,c);
void signal_error(int signal);
void type_error(CELL type, CELL tagged);
void primitive_throw(void);
-void range_error(CELL tagged, FIXNUM index, CELL max);
+void range_error(CELL tagged, F_FIXNUM index, CELL max);
#define FIXNUM_MAX (LONG_MAX >> TAG_BITS)
#define FIXNUM_MIN (LONG_MIN >> TAG_BITS)
-#define FIXNUM long int /* unboxed */
+#define F_FIXNUM long int /* unboxed */
#define WORD_SIZE (CELLS*8)
#define HALF_WORD_SIZE (CELLS*4)
INLINE CELL alien_pointer(void)
{
- FIXNUM offset = unbox_integer();
+ F_FIXNUM offset = unbox_integer();
ALIEN* alien = untag_alien(dpop());
CELL ptr = alien->ptr;
#ifdef FFI
CELL length = unbox_integer();
ALIEN* alien;
- STRING* local;
+ F_STRING* local;
maybe_garbage_collection();
alien = allot_object(ALIEN_TYPE,sizeof(ALIEN));
local = string(length / CHARS,'\0');
- alien->ptr = (CELL)local + sizeof(STRING);
+ alien->ptr = (CELL)local + sizeof(F_STRING);
alien->local = true;
dpush(tag_object(alien));
#else
{
if(alien->local && alien->ptr != NULL)
{
- STRING* ptr = (STRING*)(alien->ptr - sizeof(STRING));
+ F_STRING* ptr = (F_STRING*)(alien->ptr - sizeof(F_STRING));
ptr = copy_untagged_object(ptr,SSIZE(ptr));
- alien->ptr = (CELL)ptr + sizeof(STRING);
+ alien->ptr = (CELL)ptr + sizeof(F_STRING);
}
}
void primitive_stat(void)
{
struct stat sb;
- STRING* path;
+ F_STRING* path;
maybe_garbage_collection();
void primitive_read_dir(void)
{
- STRING* path;
+ F_STRING* path;
DIR* dir;
CELL result = F;
#include "factor.h"
-FIXNUM to_fixnum(CELL tagged)
+F_FIXNUM to_fixnum(CELL tagged)
{
- RATIO* r;
- ARRAY* x;
- ARRAY* y;
- FLOAT* f;
+ F_RATIO* r;
+ F_ARRAY* x;
+ F_ARRAY* y;
+ F_FLOAT* f;
switch(type_of(tagged))
{
case FIXNUM_TYPE:
return untag_fixnum_fast(tagged);
case BIGNUM_TYPE:
- return (FIXNUM)s48_bignum_to_long((ARRAY*)UNTAG(tagged));
+ return (F_FIXNUM)s48_bignum_to_long((F_ARRAY*)UNTAG(tagged));
case RATIO_TYPE:
- r = (RATIO*)UNTAG(tagged);
+ r = (F_RATIO*)UNTAG(tagged);
x = to_bignum(r->numerator);
y = to_bignum(r->denominator);
return to_fixnum(tag_object(s48_bignum_quotient(x,y)));
case FLOAT_TYPE:
- f = (FLOAT*)UNTAG(tagged);
- return (FIXNUM)f->n;
+ f = (F_FLOAT*)UNTAG(tagged);
+ return (F_FIXNUM)f->n;
default:
type_error(FIXNUM_TYPE,tagged);
return -1; /* can't happen */
void primitive_fixnum_eq(void)
{
- FIXNUM y = untag_fixnum_fast(dpop());
- FIXNUM x = untag_fixnum_fast(dpop());
+ F_FIXNUM y = untag_fixnum_fast(dpop());
+ F_FIXNUM x = untag_fixnum_fast(dpop());
box_boolean(x == y);
}
void primitive_fixnum_add(void)
{
- FIXNUM y = untag_fixnum_fast(dpop());
- FIXNUM x = untag_fixnum_fast(dpop());
+ F_FIXNUM y = untag_fixnum_fast(dpop());
+ F_FIXNUM x = untag_fixnum_fast(dpop());
box_integer(x + y);
}
void primitive_fixnum_subtract(void)
{
- FIXNUM y = untag_fixnum_fast(dpop());
- FIXNUM x = untag_fixnum_fast(dpop());
+ F_FIXNUM y = untag_fixnum_fast(dpop());
+ F_FIXNUM x = untag_fixnum_fast(dpop());
box_integer(x - y);
}
*/
void primitive_fixnum_multiply(void)
{
- FIXNUM y = untag_fixnum_fast(dpop());
- FIXNUM x = untag_fixnum_fast(dpop());
+ F_FIXNUM y = untag_fixnum_fast(dpop());
+ F_FIXNUM x = untag_fixnum_fast(dpop());
if(x == 0 || y == 0)
dpush(tag_fixnum(0));
else
{
- FIXNUM prod = x * y;
+ F_FIXNUM prod = x * y;
/* if this is not equal, we have overflow */
if(prod / x == y)
box_integer(prod);
void primitive_fixnum_divint(void)
{
- FIXNUM y = untag_fixnum_fast(dpop());
- FIXNUM x = untag_fixnum_fast(dpop());
+ F_FIXNUM y = untag_fixnum_fast(dpop());
+ F_FIXNUM x = untag_fixnum_fast(dpop());
box_integer(x / y);
}
void primitive_fixnum_divfloat(void)
{
- FIXNUM y = untag_fixnum_fast(dpop());
- FIXNUM x = untag_fixnum_fast(dpop());
+ F_FIXNUM y = untag_fixnum_fast(dpop());
+ F_FIXNUM x = untag_fixnum_fast(dpop());
dpush(tag_object(make_float((double)x / (double)y)));
}
void primitive_fixnum_divmod(void)
{
- FIXNUM y = untag_fixnum_fast(dpop());
- FIXNUM x = untag_fixnum_fast(dpop());
+ F_FIXNUM y = untag_fixnum_fast(dpop());
+ F_FIXNUM x = untag_fixnum_fast(dpop());
box_integer(x / y);
box_integer(x % y);
}
void primitive_fixnum_mod(void)
{
- FIXNUM y = untag_fixnum_fast(dpop());
- FIXNUM x = untag_fixnum_fast(dpop());
+ F_FIXNUM y = untag_fixnum_fast(dpop());
+ F_FIXNUM x = untag_fixnum_fast(dpop());
dpush(tag_fixnum(x % y));
}
void primitive_fixnum_and(void)
{
- FIXNUM y = untag_fixnum_fast(dpop());
- FIXNUM x = untag_fixnum_fast(dpop());
+ F_FIXNUM y = untag_fixnum_fast(dpop());
+ F_FIXNUM x = untag_fixnum_fast(dpop());
dpush(tag_fixnum(x & y));
}
void primitive_fixnum_or(void)
{
- FIXNUM y = untag_fixnum_fast(dpop());
- FIXNUM x = untag_fixnum_fast(dpop());
+ F_FIXNUM y = untag_fixnum_fast(dpop());
+ F_FIXNUM x = untag_fixnum_fast(dpop());
dpush(tag_fixnum(x | y));
}
void primitive_fixnum_xor(void)
{
- FIXNUM y = untag_fixnum_fast(dpop());
- FIXNUM x = untag_fixnum_fast(dpop());
+ F_FIXNUM y = untag_fixnum_fast(dpop());
+ F_FIXNUM x = untag_fixnum_fast(dpop());
dpush(tag_fixnum(x ^ y));
}
*/
void primitive_fixnum_shift(void)
{
- FIXNUM y = untag_fixnum_fast(dpop());
- FIXNUM x = untag_fixnum_fast(dpop());
+ F_FIXNUM y = untag_fixnum_fast(dpop());
+ F_FIXNUM x = untag_fixnum_fast(dpop());
if(y < 0)
{
}
else if(y < WORD_SIZE - TAG_BITS)
{
- FIXNUM mask = (1 << (WORD_SIZE - 1 - TAG_BITS - y));
+ F_FIXNUM mask = (1 << (WORD_SIZE - 1 - TAG_BITS - y));
if(x > 0)
mask = -mask;
void primitive_fixnum_less(void)
{
- FIXNUM y = untag_fixnum_fast(dpop());
- FIXNUM x = untag_fixnum_fast(dpop());
+ F_FIXNUM y = untag_fixnum_fast(dpop());
+ F_FIXNUM x = untag_fixnum_fast(dpop());
box_boolean(x < y);
}
void primitive_fixnum_lesseq(void)
{
- FIXNUM y = untag_fixnum_fast(dpop());
- FIXNUM x = untag_fixnum_fast(dpop());
+ F_FIXNUM y = untag_fixnum_fast(dpop());
+ F_FIXNUM x = untag_fixnum_fast(dpop());
box_boolean(x <= y);
}
void primitive_fixnum_greater(void)
{
- FIXNUM y = untag_fixnum_fast(dpop());
- FIXNUM x = untag_fixnum_fast(dpop());
+ F_FIXNUM y = untag_fixnum_fast(dpop());
+ F_FIXNUM x = untag_fixnum_fast(dpop());
box_boolean(x > y);
}
void primitive_fixnum_greatereq(void)
{
- FIXNUM y = untag_fixnum_fast(dpop());
- FIXNUM x = untag_fixnum_fast(dpop());
+ F_FIXNUM y = untag_fixnum_fast(dpop());
+ F_FIXNUM x = untag_fixnum_fast(dpop());
box_boolean(x >= y);
}
-INLINE FIXNUM untag_fixnum_fast(CELL tagged)
+INLINE F_FIXNUM untag_fixnum_fast(CELL tagged)
{
- return ((FIXNUM)tagged) >> TAG_BITS;
+ return ((F_FIXNUM)tagged) >> TAG_BITS;
}
-INLINE CELL tag_fixnum(FIXNUM untagged)
+INLINE CELL tag_fixnum(F_FIXNUM untagged)
{
return RETAG(untagged << TAG_BITS,FIXNUM_TYPE);
}
-FIXNUM to_fixnum(CELL tagged);
+F_FIXNUM to_fixnum(CELL tagged);
void primitive_to_fixnum(void);
void primitive_fixnum_eq(void);
double to_float(CELL tagged)
{
- RATIO* r;
+ F_RATIO* r;
double x;
double y;
case FIXNUM_TYPE:
return (double)untag_fixnum_fast(tagged);
case BIGNUM_TYPE:
- return s48_bignum_to_double((ARRAY*)UNTAG(tagged));
+ return s48_bignum_to_double((F_ARRAY*)UNTAG(tagged));
case RATIO_TYPE:
- r = (RATIO*)UNTAG(tagged);
+ r = (F_RATIO*)UNTAG(tagged);
x = to_float(r->numerator);
y = to_float(r->denominator);
return x / y;
case FLOAT_TYPE:
- return ((FLOAT*)UNTAG(tagged))->n;
+ return ((F_FLOAT*)UNTAG(tagged))->n;
default:
type_error(FLOAT_TYPE,tagged);
return 0.0; /* can't happen */
void primitive_str_to_float(void)
{
- STRING* str;
+ F_STRING* str;
char *c_str, *end;
double f;
typedef struct {
CELL header;
double n;
-} FLOAT;
+} F_FLOAT;
-INLINE FLOAT* make_float(double n)
+INLINE F_FLOAT* make_float(double n)
{
- FLOAT* flo = allot_object(FLOAT_TYPE,sizeof(FLOAT));
+ F_FLOAT* flo = allot_object(FLOAT_TYPE,sizeof(F_FLOAT));
flo->n = n;
return flo;
}
INLINE double untag_float_fast(CELL tagged)
{
- return ((FLOAT*)UNTAG(tagged))->n;
+ return ((F_FLOAT*)UNTAG(tagged))->n;
}
INLINE double untag_float(CELL tagged)
switch(untag_header(get(scan)))
{
case WORD_TYPE:
- collect_word((WORD*)scan);
+ collect_word((F_WORD*)scan);
break;
case ARRAY_TYPE:
- collect_array((ARRAY*)scan);
+ collect_array((F_ARRAY*)scan);
break;
case VECTOR_TYPE:
- collect_vector((VECTOR*)scan);
+ collect_vector((F_VECTOR*)scan);
break;
case SBUF_TYPE:
- collect_sbuf((SBUF*)scan);
+ collect_sbuf((F_SBUF*)scan);
break;
case PORT_TYPE:
- collect_port((PORT*)scan);
+ collect_port((F_PORT*)scan);
break;
}
void primitive_save_image(void)
{
- STRING* filename = untag_string(dpop());
+ F_STRING* filename = untag_string(dpop());
save_image(to_c_string(filename));
}
}
void remove_io_task(
- PORT* port,
+ F_PORT* port,
IO_TASK* io_tasks,
int* fd_count)
{
*fd_count = *fd_count - 1;
}
-bool perform_copy_from_io_task(PORT* port, PORT* other_port)
+bool perform_copy_from_io_task(F_PORT* port, F_PORT* other_port)
{
if(port->buf_fill == 0)
{
return false;
}
-bool perform_copy_to_io_task(PORT* port, PORT* other_port)
+bool perform_copy_to_io_task(F_PORT* port, F_PORT* other_port)
{
bool success = perform_write_io_task(port);
/* only return 'true' if the COPY_FROM task is done also. */
CELL pop_io_task_callback(
IO_TASK_TYPE type,
- PORT* port,
+ F_PORT* port,
IO_TASK* io_tasks,
int* fd_count)
{
int fd = port->fd;
- CONS* callbacks = untag_cons(io_tasks[fd].callbacks);
+ F_CONS* callbacks = untag_cons(io_tasks[fd].callbacks);
CELL callback = callbacks->car;
if(callbacks->cdr == F)
remove_io_task(port,io_tasks,fd_count);
CELL perform_io_task(IO_TASK* io_task, IO_TASK* io_tasks, int* fd_count)
{
bool success;
- PORT* port = untag_port(io_task->port);
+ F_PORT* port = untag_port(io_task->port);
switch(io_task->type)
{
if(typep(PORT_TYPE,io_task.port))
{
- PORT* port = untag_port(io_task.port);
+ F_PORT* port = untag_port(io_task.port);
if(port->closed)
{
return pop_io_task_callback(
void primitive_close(void)
{
/* This does not flush. */
- PORT* port = untag_port(dpop());
+ F_PORT* port = untag_port(dpop());
close(port->fd);
port->closed = true;
}
IO_TASK* io_tasks,
int* fd_count);
void remove_io_task(
- PORT* port,
+ F_PORT* port,
IO_TASK* io_tasks,
int* fd_count);
-void remove_io_tasks(PORT* port);
-bool perform_copy_from_io_task(PORT* port, PORT* other_port);
-bool perform_copy_to_io_task(PORT* port, PORT* other_port);
+void remove_io_tasks(F_PORT* port);
+bool perform_copy_from_io_task(F_PORT* port, F_PORT* other_port);
+bool perform_copy_to_io_task(F_PORT* port, F_PORT* other_port);
void primitive_add_copy_io_task(void);
CELL pop_io_task_callback(
IO_TASK_TYPE type,
- PORT* port,
+ F_PORT* port,
IO_TASK* io_tasks,
int* fd_count);
bool set_up_fd_set(fd_set* fdset, int fd_count, IO_TASK* io_tasks,
#include "factor.h"
-PORT* untag_port(CELL tagged)
+F_PORT* untag_port(CELL tagged)
{
- PORT* p;
+ F_PORT* p;
type_check(PORT_TYPE,tagged);
- p = (PORT*)UNTAG(tagged);
+ p = (F_PORT*)UNTAG(tagged);
/* after image load & save, ports are no longer valid */
if(p->fd == -1)
general_error(ERROR_EXPIRED,tagged);
return p;
}
-PORT* port(PORT_MODE type, CELL fd)
+F_PORT* port(PORT_MODE type, CELL fd)
{
- PORT* port = allot_object(PORT_TYPE,sizeof(PORT));
+ F_PORT* port = allot_object(PORT_TYPE,sizeof(F_PORT));
port->type = type;
port->closed = false;
port->fd = fd;
return port;
}
-void init_line_buffer(PORT* port, FIXNUM count)
+void init_line_buffer(F_PORT* port, F_FIXNUM count)
{
if(port->line == F)
port->line = tag_object(sbuf(LINE_SIZE));
}
-void fixup_port(PORT* port)
+void fixup_port(F_PORT* port)
{
port->fd = -1;
fixup(&port->buffer);
fixup(&port->io_error);
}
-void collect_port(PORT* port)
+void collect_port(F_PORT* port)
{
copy_object(&port->buffer);
copy_object(&port->line);
CELL make_io_error(const char* func)
{
- STRING* function = from_c_string(func);
- STRING* error = from_c_string(strerror(errno));
+ F_STRING* function = from_c_string(func);
+ F_STRING* error = from_c_string(strerror(errno));
return cons(tag_object(function),cons(tag_object(error),F));
}
-void postpone_io_error(PORT* port, const char* func)
+void postpone_io_error(F_PORT* port, const char* func)
{
port->io_error = make_io_error(func);
}
general_error(ERROR_IO,make_io_error(func));
}
-void pending_io_error(PORT* port)
+void pending_io_error(F_PORT* port)
{
CELL io_error = port->io_error;
if(io_error != F)
CELL header;
PORT_MODE type;
bool closed;
- FIXNUM fd;
+ F_FIXNUM fd;
CELL buffer;
/* top of buffer */
bool line_ready;
/* count for read# */
- FIXNUM count;
+ F_FIXNUM count;
/* tagged client info used by accept_fd */
CELL client_host;
/* a pending I/O error or F */
CELL io_error;
-} PORT;
-
-PORT* untag_port(CELL tagged);
-PORT* port(PORT_MODE type, CELL fd);
-void init_line_buffer(PORT* port, FIXNUM count);
-void fixup_port(PORT* port);
-void collect_port(PORT* port);
-void postpone_io_error(PORT* port, const char* func);
+} F_PORT;
+
+F_PORT* untag_port(CELL tagged);
+F_PORT* port(PORT_MODE type, CELL fd);
+void init_line_buffer(F_PORT* port, F_FIXNUM count);
+void fixup_port(F_PORT* port);
+void collect_port(F_PORT* port);
+void postpone_io_error(F_PORT* port, const char* func);
void io_error(const char* func);
-void pending_io_error(PORT* port);
+void pending_io_error(F_PORT* port);
void primitive_pending_io_error(void);
dpush(numerator);
else
{
- RATIO* ratio = allot(sizeof(RATIO));
+ F_RATIO* ratio = allot(sizeof(F_RATIO));
ratio->numerator = numerator;
ratio->denominator = denominator;
dpush(tag_ratio(ratio));
typedef struct {
CELL numerator;
CELL denominator;
-} RATIO;
+} F_RATIO;
-INLINE RATIO* untag_ratio(CELL tagged)
+INLINE F_RATIO* untag_ratio(CELL tagged)
{
type_check(RATIO_TYPE,tagged);
- return (RATIO*)UNTAG(tagged);
+ return (F_RATIO*)UNTAG(tagged);
}
-INLINE CELL tag_ratio(RATIO* ratio)
+INLINE CELL tag_ratio(F_RATIO* ratio)
{
return RETAG(ratio,RATIO_TYPE);
}
#include "factor.h"
/* Return true if something was read */
-bool read_step(PORT* port)
+bool read_step(F_PORT* port)
{
- FIXNUM amount = 0;
- STRING* buffer = untag_string(port->buffer);
+ F_FIXNUM amount = 0;
+ F_STRING* buffer = untag_string(port->buffer);
CELL capacity = buffer->capacity;
if(port->type == PORT_RECV)
}
}
-bool read_line_step(PORT* port)
+bool read_line_step(F_PORT* port)
{
int i;
BYTE ch;
- SBUF* line = untag_sbuf(port->line);
- STRING* buffer = untag_string(port->buffer);
+ F_SBUF* line = untag_sbuf(port->line);
+ F_STRING* buffer = untag_string(port->buffer);
for(i = port->buf_pos; i < port->buf_fill; i++)
{
- ch = bget((CELL)buffer + sizeof(STRING) + i);
+ ch = bget((CELL)buffer + sizeof(F_STRING) + i);
if(ch == '\r')
{
if(i != port->buf_fill - 1)
{
ch = bget((CELL)buffer
- + sizeof(STRING) + i + 1);
+ + sizeof(F_STRING) + i + 1);
if(ch == '\n')
i++;
}
return false;
}
-bool can_read_line(PORT* port)
+bool can_read_line(F_PORT* port)
{
pending_io_error(port);
void primitive_can_read_line(void)
{
- PORT* port = untag_port(dpop());
+ F_PORT* port = untag_port(dpop());
box_boolean(can_read_line(port));
}
init_line_buffer(untag_port(port),LINE_SIZE);
}
-bool perform_read_line_io_task(PORT* port)
+bool perform_read_line_io_task(F_PORT* port)
{
if(port->buf_pos >= port->buf_fill)
{
void primitive_read_line_8(void)
{
- PORT* port;
+ F_PORT* port;
maybe_garbage_collection();
}
-bool read_count_step(PORT* port)
+bool read_count_step(F_PORT* port)
{
int i;
BYTE ch;
- SBUF* line = untag_sbuf(port->line);
- STRING* buffer = untag_string(port->buffer);
+ F_SBUF* line = untag_sbuf(port->line);
+ F_STRING* buffer = untag_string(port->buffer);
for(i = port->buf_pos; i < port->buf_fill; i++)
{
- ch = bget((CELL)buffer + sizeof(STRING) + i);
+ ch = bget((CELL)buffer + sizeof(F_STRING) + i);
set_sbuf_nth(line,line->top,ch);
if(line->top == port->count)
{
return false;
}
-bool can_read_count(PORT* port, FIXNUM count)
+bool can_read_count(F_PORT* port, F_FIXNUM count)
{
pending_io_error(port);
void primitive_can_read_count(void)
{
- PORT* port;
- FIXNUM len;
+ F_PORT* port;
+ F_FIXNUM len;
maybe_garbage_collection();
void primitive_add_read_count_io_task(void)
{
CELL callback;
- PORT* port;
- FIXNUM count;
+ F_PORT* port;
+ F_FIXNUM count;
maybe_garbage_collection();
init_line_buffer(port,count);
}
-bool perform_read_count_io_task(PORT* port)
+bool perform_read_count_io_task(F_PORT* port)
{
if(port->buf_pos >= port->buf_fill)
{
void primitive_read_count_8(void)
{
- PORT* port;
- FIXNUM len;
+ F_PORT* port;
+ F_FIXNUM len;
maybe_garbage_collection();
-bool read_step(PORT* port);
+bool read_step(F_PORT* port);
#define LINE_SIZE 80
-bool read_line_step(PORT* port);
-bool can_read_line(PORT* port);
+bool read_line_step(F_PORT* port);
+bool can_read_line(F_PORT* port);
void primitive_can_read_line(void);
void primitive_add_read_line_io_task(void);
-bool perform_read_line_io_task(PORT* port);
+bool perform_read_line_io_task(F_PORT* port);
void primitive_read_line_8(void);
-bool read_count_step(PORT* port);
+bool read_count_step(F_PORT* port);
#define CAN_READ_COUNT(port,count) (untag_sbuf(port->line)->top >= count)
-bool can_read_count(PORT* port, FIXNUM count);
+bool can_read_count(F_PORT* port, F_FIXNUM count);
void primitive_can_read_count(void);
void primitive_add_read_count_io_task(void);
-bool perform_read_count_io_task(PORT* port);
+bool perform_read_count_io_task(F_PORT* port);
void primitive_read_count_8(void);
switch(untag_header(get(relocating)))
{
case WORD_TYPE:
- fixup_word((WORD*)relocating);
+ fixup_word((F_WORD*)relocating);
break;
case ARRAY_TYPE:
- fixup_array((ARRAY*)relocating);
+ fixup_array((F_ARRAY*)relocating);
break;
case VECTOR_TYPE:
- fixup_vector((VECTOR*)relocating);
+ fixup_vector((F_VECTOR*)relocating);
break;
case STRING_TYPE:
- rehash_string((STRING*)relocating);
+ rehash_string((F_STRING*)relocating);
break;
case SBUF_TYPE:
- fixup_sbuf((SBUF*)relocating);
+ fixup_sbuf((F_SBUF*)relocating);
break;
case PORT_TYPE:
- fixup_port((PORT*)relocating);
+ fixup_port((F_PORT*)relocating);
break;
case DLL_TYPE:
fixup_dll((DLL*)relocating);
if(TAG(next) == WORD_TYPE)
{
- executing = (WORD*)UNTAG(next);
+ executing = (F_WORD*)UNTAG(next);
EXECUTE(executing);
}
else
void primitive_getenv(void)
{
- FIXNUM e = to_fixnum(dpeek());
+ F_FIXNUM e = to_fixnum(dpeek());
if(e < 0 || e >= USER_ENV)
range_error(F,e,USER_ENV);
drepl(userenv[e]);
void primitive_setenv(void)
{
- FIXNUM e = to_fixnum(dpop());
+ F_FIXNUM e = to_fixnum(dpop());
CELL value = dpop();
if(e < 0 || e >= USER_ENV)
range_error(F,e,USER_ENV);
CELL callframe;
/* raw pointer to currently executing word */
-WORD* executing;
+F_WORD* executing;
/* TAGGED user environment data; see getenv/setenv prims */
CELL userenv[USER_ENV];
you could write alternate versions that don't require this type). */
/* #define BIGNUM_NO_ULONG */
-typedef ARRAY * bignum_type;
+typedef F_ARRAY * bignum_type;
#define BIGNUM_OUT_OF_BAND ((bignum_type) 0)
enum bignum_comparison
space when a bignum's length is reduced from its original value. */
#define BIGNUM_REDUCE_LENGTH(target, source, length) \
target = shrink_array(source, length + 1)
-/* extern ARRAY* shrink_array(ARRAY* array, CELL capacity); */
+/* extern F_ARRAY* shrink_array(F_ARRAY* array, CELL capacity); */
/* BIGNUM_DEALLOCATE is called when disposing of bignums which are
created as intermediate temporaries; Scheme doesn't need this. */
/* These definitions are here to facilitate caching of the constants
0, 1, and -1. */
-#define BIGNUM_ZERO() (ARRAY*)UNTAG(bignum_zero)
+#define BIGNUM_ZERO() (F_ARRAY*)UNTAG(bignum_zero)
#define BIGNUM_ONE(neg_p) \
- (ARRAY*)UNTAG(neg_p ? bignum_neg_one : bignum_pos_one)
+ (F_ARRAY*)UNTAG(neg_p ? bignum_neg_one : bignum_pos_one)
#define BIGNUM_ONE_P(bignum,negative_p) ((bignum) == BIGNUM_ONE(negative_p))
#include "factor.h"
-SBUF* sbuf(FIXNUM capacity)
+F_SBUF* sbuf(F_FIXNUM capacity)
{
- SBUF* sbuf = allot_object(SBUF_TYPE,sizeof(SBUF));
+ F_SBUF* sbuf = allot_object(SBUF_TYPE,sizeof(F_SBUF));
sbuf->top = 0;
sbuf->string = tag_object(string(capacity,'\0'));
return sbuf;
void primitive_set_sbuf_length(void)
{
- SBUF* sbuf;
- FIXNUM length;
- STRING* str;
+ F_SBUF* sbuf;
+ F_FIXNUM length;
+ F_STRING* str;
maybe_garbage_collection();
void primitive_sbuf_nth(void)
{
- SBUF* sbuf = untag_sbuf(dpop());
+ F_SBUF* sbuf = untag_sbuf(dpop());
CELL index = to_fixnum(dpop());
if(index < 0 || index >= sbuf->top)
dpush(string_nth(untag_string(sbuf->string),index));
}
-void sbuf_ensure_capacity(SBUF* sbuf, FIXNUM top)
+void sbuf_ensure_capacity(F_SBUF* sbuf, F_FIXNUM top)
{
- STRING* string = untag_string(sbuf->string);
+ F_STRING* string = untag_string(sbuf->string);
CELL capacity = string->capacity;
if(top >= capacity)
sbuf->string = tag_object(grow_string(string,top * 2 + 1,F));
sbuf->top = top;
}
-void set_sbuf_nth(SBUF* sbuf, CELL index, uint16_t value)
+void set_sbuf_nth(F_SBUF* sbuf, CELL index, uint16_t value)
{
if(index < 0)
range_error(tag_object(sbuf),index,sbuf->top);
void primitive_set_sbuf_nth(void)
{
- SBUF* sbuf;
- FIXNUM index;
+ F_SBUF* sbuf;
+ F_FIXNUM index;
CELL value;
maybe_garbage_collection();
set_sbuf_nth(sbuf,index,value);
}
-void sbuf_append_string(SBUF* sbuf, STRING* string)
+void sbuf_append_string(F_SBUF* sbuf, F_STRING* string)
{
CELL top = sbuf->top;
CELL strlen = string->capacity;
- STRING* str;
+ F_STRING* str;
sbuf_ensure_capacity(sbuf,top + strlen);
str = untag_string(sbuf->string);
- memcpy((void*)((CELL)str + sizeof(STRING) + top * CHARS),
- (void*)((CELL)string + sizeof(STRING)),strlen * CHARS);
+ memcpy((void*)((CELL)str + sizeof(F_STRING) + top * CHARS),
+ (void*)((CELL)string + sizeof(F_STRING)),strlen * CHARS);
}
void primitive_sbuf_append(void)
{
- SBUF* sbuf;
+ F_SBUF* sbuf;
CELL object;
maybe_garbage_collection();
void primitive_sbuf_to_string(void)
{
- SBUF* sbuf;
- STRING* s;
+ F_SBUF* sbuf;
+ F_STRING* s;
maybe_garbage_collection();
void primitive_sbuf_reverse(void)
{
- SBUF* sbuf = untag_sbuf(dpop());
+ F_SBUF* sbuf = untag_sbuf(dpop());
string_reverse(untag_string(sbuf->string),sbuf->top);
}
void primitive_sbuf_clone(void)
{
- SBUF* s;
- SBUF* new_s;
+ F_SBUF* s;
+ F_SBUF* new_s;
maybe_garbage_collection();
drepl(tag_object(new_s));
}
-bool sbuf_eq(SBUF* s1, SBUF* s2)
+bool sbuf_eq(F_SBUF* s1, F_SBUF* s2)
{
if(s1 == s2)
return true;
void primitive_sbuf_eq(void)
{
- SBUF* s1 = untag_sbuf(dpop());
+ F_SBUF* s1 = untag_sbuf(dpop());
CELL with = dpop();
if(typep(SBUF_TYPE,with))
- dpush(tag_boolean(sbuf_eq(s1,(SBUF*)UNTAG(with))));
+ dpush(tag_boolean(sbuf_eq(s1,(F_SBUF*)UNTAG(with))));
else
dpush(F);
}
void primitive_sbuf_hashcode(void)
{
- SBUF* sbuf = untag_sbuf(dpop());
+ F_SBUF* sbuf = untag_sbuf(dpop());
dpush(tag_fixnum(hash_string(untag_string(sbuf->string),sbuf->top)));
}
-void fixup_sbuf(SBUF* sbuf)
+void fixup_sbuf(F_SBUF* sbuf)
{
fixup(&sbuf->string);
}
-void collect_sbuf(SBUF* sbuf)
+void collect_sbuf(F_SBUF* sbuf)
{
copy_object(&sbuf->string);
}
CELL top;
/* tagged */
CELL string;
-} SBUF;
+} F_SBUF;
-INLINE SBUF* untag_sbuf(CELL tagged)
+INLINE F_SBUF* untag_sbuf(CELL tagged)
{
type_check(SBUF_TYPE,tagged);
- return (SBUF*)UNTAG(tagged);
+ return (F_SBUF*)UNTAG(tagged);
}
-SBUF* sbuf(FIXNUM capacity);
+F_SBUF* sbuf(F_FIXNUM capacity);
void primitive_sbuf(void);
void primitive_sbuf_length(void);
void primitive_set_sbuf_length(void);
void primitive_sbuf_nth(void);
-void sbuf_ensure_capacity(SBUF* sbuf, FIXNUM top);
-void set_sbuf_nth(SBUF* sbuf, CELL index, uint16_t value);
+void sbuf_ensure_capacity(F_SBUF* sbuf, F_FIXNUM top);
+void set_sbuf_nth(F_SBUF* sbuf, CELL index, uint16_t value);
void primitive_set_sbuf_nth(void);
-void sbuf_append_string(SBUF* sbuf, STRING* string);
+void sbuf_append_string(F_SBUF* sbuf, F_STRING* string);
void primitive_sbuf_append(void);
void primitive_sbuf_to_string(void);
void primitive_sbuf_reverse(void);
void primitive_sbuf_clone(void);
-bool sbuf_eq(SBUF* s1, SBUF* s2);
+bool sbuf_eq(F_SBUF* s1, F_SBUF* s2);
void primitive_sbuf_eq(void);
void primitive_sbuf_hashcode(void);
-void fixup_sbuf(SBUF* sbuf);
-void collect_sbuf(SBUF* sbuf);
+void fixup_sbuf(F_SBUF* sbuf);
+void collect_sbuf(F_SBUF* sbuf);
read_io_tasks,&read_fd_count);
}
-CELL accept_connection(PORT* p)
+CELL accept_connection(F_PORT* p)
{
struct sockaddr_in clientname;
size_t size = sizeof(clientname);
void primitive_accept_fd(void)
{
- PORT* p;
+ F_PORT* p;
maybe_garbage_collection();
p = untag_port(dpop());
pending_io_error(p);
int make_server_socket(uint16_t port);
void primitive_server_socket(void);
void primitive_add_accept_io_task(void);
-CELL accept_connection(PORT* p);
+CELL accept_connection(F_PORT* p);
void primitive_accept_fd(void);
dpush(cpop());
}
-VECTOR* stack_to_vector(CELL bottom, CELL top)
+F_VECTOR* stack_to_vector(CELL bottom, CELL top)
{
CELL depth = (top - bottom + CELLS) / CELLS;
- VECTOR* v = vector(depth);
- ARRAY* a = untag_array(v->array);
+ F_VECTOR* v = vector(depth);
+ F_ARRAY* a = untag_array(v->array);
memcpy(a + 1,(void*)bottom,depth * CELLS);
v->top = depth;
return v;
}
/* Returns top of stack */
-CELL vector_to_stack(VECTOR* vector, CELL bottom)
+CELL vector_to_stack(F_VECTOR* vector, CELL bottom)
{
CELL start = bottom;
CELL len = vector->top * CELLS;
void primitive_pick(void);
void primitive_to_r(void);
void primitive_from_r(void);
-VECTOR* stack_to_vector(CELL bottom, CELL top);
+F_VECTOR* stack_to_vector(CELL bottom, CELL top);
void primitive_datastack(void);
void primitive_callstack(void);
-CELL vector_to_stack(VECTOR* vector, CELL bottom);
+CELL vector_to_stack(F_VECTOR* vector, CELL bottom);
void primitive_set_datastack(void);
void primitive_set_callstack(void);
#include "factor.h"
/* untagged */
-STRING* allot_string(FIXNUM capacity)
+F_STRING* allot_string(F_FIXNUM capacity)
{
- STRING* string;
+ F_STRING* string;
if(capacity < 0)
general_error(ERROR_NEGATIVE_ARRAY_SIZE,tag_fixnum(capacity));
string = allot_object(STRING_TYPE,
- sizeof(STRING) + capacity * CHARS);
+ sizeof(F_STRING) + capacity * CHARS);
string->capacity = capacity;
return string;
}
/* call this after constructing a string */
/* uses same algorithm as java.lang.String for compatibility with
images generated from Java Factor. */
-FIXNUM hash_string(STRING* str, FIXNUM len)
+F_FIXNUM hash_string(F_STRING* str, F_FIXNUM len)
{
- FIXNUM hash = 0;
+ F_FIXNUM hash = 0;
CELL i;
for(i = 0; i < len; i++)
hash = 31*hash + string_nth(str,i);
return hash;
}
-void rehash_string(STRING* str)
+void rehash_string(F_STRING* str)
{
str->hashcode = hash_string(str,str->capacity);
}
/* untagged */
-STRING* string(FIXNUM capacity, CELL fill)
+F_STRING* string(F_FIXNUM capacity, CELL fill)
{
CELL i;
- STRING* string = allot_string(capacity);
+ F_STRING* string = allot_string(capacity);
for(i = 0; i < capacity; i++)
cput(SREF(string,i),fill);
return string;
}
-STRING* grow_string(STRING* string, FIXNUM capacity, uint16_t fill)
+F_STRING* grow_string(F_STRING* string, F_FIXNUM capacity, uint16_t fill)
{
/* later on, do an optimization: if end of array is here, just grow */
CELL i;
- STRING* new_string = allot_string(capacity);
+ F_STRING* new_string = allot_string(capacity);
memcpy(new_string + 1,string + 1,string->capacity * CHARS);
}
/* untagged */
-STRING* from_c_string(const BYTE* c_string)
+F_STRING* from_c_string(const BYTE* c_string)
{
CELL length = strlen(c_string);
- STRING* s = allot_string(length);
+ F_STRING* s = allot_string(length);
CELL i;
for(i = 0; i < length; i++)
}
/* untagged */
-BYTE* to_c_string(STRING* s)
+BYTE* to_c_string(F_STRING* s)
{
CELL i;
}
/* untagged */
-BYTE* to_c_string_unchecked(STRING* s)
+BYTE* to_c_string_unchecked(F_STRING* s)
{
- STRING* _c_str = allot_string(s->capacity / CHARS + 1);
+ F_STRING* _c_str = allot_string(s->capacity / CHARS + 1);
CELL i;
BYTE* c_str = (BYTE*)(_c_str + 1);
void primitive_string_nth(void)
{
- STRING* string = untag_string(dpop());
+ F_STRING* string = untag_string(dpop());
CELL index = to_fixnum(dpop());
if(index < 0 || index >= string->capacity)
dpush(tag_fixnum(string_nth(string,index)));
}
-FIXNUM string_compare_head(STRING* s1, STRING* s2, CELL len)
+F_FIXNUM string_compare_head(F_STRING* s1, F_STRING* s2, CELL len)
{
CELL i = 0;
while(i < len)
return 0;
}
-FIXNUM string_compare(STRING* s1, STRING* s2)
+F_FIXNUM string_compare(F_STRING* s1, F_STRING* s2)
{
CELL len1 = s1->capacity;
CELL len2 = s2->capacity;
void primitive_string_compare(void)
{
- STRING* s2 = untag_string(dpop());
- STRING* s1 = untag_string(dpop());
+ F_STRING* s2 = untag_string(dpop());
+ F_STRING* s1 = untag_string(dpop());
dpush(tag_fixnum(string_compare(s1,s2)));
}
-bool string_eq(STRING* s1, STRING* s2)
+bool string_eq(F_STRING* s1, F_STRING* s2)
{
if(s1 == s2)
return true;
void primitive_string_eq(void)
{
- STRING* s1 = untag_string(dpop());
+ F_STRING* s1 = untag_string(dpop());
CELL with = dpop();
if(typep(STRING_TYPE,with))
- dpush(tag_boolean(string_eq(s1,(STRING*)UNTAG(with))));
+ dpush(tag_boolean(string_eq(s1,(F_STRING*)UNTAG(with))));
else
dpush(F);
}
drepl(tag_fixnum(untag_string(dpeek())->hashcode));
}
-CELL index_of_ch(CELL index, STRING* string, CELL ch)
+CELL index_of_ch(CELL index, F_STRING* string, CELL ch)
{
while(index < string->capacity)
{
return -1;
}
-INLINE FIXNUM index_of_str(FIXNUM index, STRING* string, STRING* substring)
+INLINE F_FIXNUM index_of_str(F_FIXNUM index, F_STRING* string, F_STRING* substring)
{
CELL i = index;
CELL limit = string->capacity - substring->capacity;
void primitive_index_of(void)
{
CELL ch = dpop();
- STRING* string;
- FIXNUM index;
+ F_STRING* string;
+ F_FIXNUM index;
CELL result;
string = untag_string(dpop());
index = to_fixnum(dpop());
dpush(tag_fixnum(result));
}
-INLINE STRING* substring(CELL start, CELL end, STRING* string)
+INLINE F_STRING* substring(CELL start, CELL end, F_STRING* string)
{
- STRING* result;
+ F_STRING* result;
if(start < 0)
range_error(tag_object(string),start,string->capacity);
/* start end string -- string */
void primitive_substring(void)
{
- STRING* string;
+ F_STRING* string;
CELL end, start;
maybe_garbage_collection();
}
/* DESTRUCTIVE - don't use with user-visible strings */
-void string_reverse(STRING* s, int len)
+void string_reverse(F_STRING* s, int len)
{
int i, j;
uint16_t ch1, ch2;
}
/* Doesn't rehash the string! */
-STRING* string_clone(STRING* s, int len)
+F_STRING* string_clone(F_STRING* s, int len)
{
- STRING* copy = allot_string(len);
+ F_STRING* copy = allot_string(len);
memcpy(copy + 1,s + 1,len * CHARS);
return copy;
}
void primitive_string_reverse(void)
{
- STRING* s;
+ F_STRING* s;
maybe_garbage_collection();
/* untagged */
CELL capacity;
/* untagged */
- FIXNUM hashcode;
-} STRING;
+ F_FIXNUM hashcode;
+} F_STRING;
-INLINE STRING* untag_string(CELL tagged)
+INLINE F_STRING* untag_string(CELL tagged)
{
type_check(STRING_TYPE,tagged);
- return (STRING*)UNTAG(tagged);
+ return (F_STRING*)UNTAG(tagged);
}
-STRING* allot_string(FIXNUM capacity);
-STRING* string(FIXNUM capacity, CELL fill);
-FIXNUM hash_string(STRING* str, FIXNUM len);
-void rehash_string(STRING* str);
-STRING* grow_string(STRING* string, FIXNUM capacity, uint16_t fill);
-BYTE* to_c_string(STRING* s);
-BYTE* to_c_string_unchecked(STRING* s);
+F_STRING* allot_string(F_FIXNUM capacity);
+F_STRING* string(F_FIXNUM capacity, CELL fill);
+F_FIXNUM hash_string(F_STRING* str, F_FIXNUM len);
+void rehash_string(F_STRING* str);
+F_STRING* grow_string(F_STRING* string, F_FIXNUM capacity, uint16_t fill);
+BYTE* to_c_string(F_STRING* s);
+BYTE* to_c_string_unchecked(F_STRING* s);
void box_c_string(const BYTE* c_string);
-STRING* from_c_string(const BYTE* c_string);
+F_STRING* from_c_string(const BYTE* c_string);
BYTE* unbox_c_string(void);
-#define SREF(string,index) ((CELL)string + sizeof(STRING) + index * CHARS)
+#define SREF(string,index) ((CELL)string + sizeof(F_STRING) + index * CHARS)
-#define SSIZE(pointer) align8(sizeof(STRING) + \
- ((STRING*)pointer)->capacity * CHARS)
+#define SSIZE(pointer) align8(sizeof(F_STRING) + \
+ ((F_STRING*)pointer)->capacity * CHARS)
/* untagged & unchecked */
-INLINE CELL string_nth(STRING* string, CELL index)
+INLINE CELL string_nth(F_STRING* string, CELL index)
{
return cget(SREF(string,index));
}
/* untagged & unchecked */
-INLINE void set_string_nth(STRING* string, CELL index, uint16_t value)
+INLINE void set_string_nth(F_STRING* string, CELL index, uint16_t value)
{
cput(SREF(string,index),value);
}
void primitive_string_length(void);
void primitive_string_nth(void);
-FIXNUM string_compare_head(STRING* s1, STRING* s2, CELL len);
-FIXNUM string_compare(STRING* s1, STRING* s2);
+F_FIXNUM string_compare_head(F_STRING* s1, F_STRING* s2, CELL len);
+F_FIXNUM string_compare(F_STRING* s1, F_STRING* s2);
void primitive_string_compare(void);
void primitive_string_eq(void);
void primitive_string_hashcode(void);
void primitive_index_of(void);
void primitive_substring(void);
-void string_reverse(STRING* s, int len);
-STRING* string_clone(STRING* s, int len);
+void string_reverse(F_STRING* s, int len);
+F_STRING* string_clone(F_STRING* s, int len);
void primitive_string_reverse(void);
size = 0;
break;
case CONS_TYPE:
- size = sizeof(CONS);
+ size = sizeof(F_CONS);
break;
case WORD_TYPE:
- size = sizeof(WORD);
+ size = sizeof(F_WORD);
break;
case RATIO_TYPE:
- size = sizeof(RATIO);
+ size = sizeof(F_RATIO);
break;
case COMPLEX_TYPE:
- size = sizeof(COMPLEX);
+ size = sizeof(F_COMPLEX);
break;
case OBJECT_TYPE:
size = untagged_object_size(UNTAG(pointer));
switch(untag_header(get(pointer)))
{
case WORD_TYPE:
- size = sizeof(WORD);
+ size = sizeof(F_WORD);
break;
case T_TYPE:
size = CELLS * 2;
size = ASIZE(pointer);
break;
case VECTOR_TYPE:
- size = sizeof(VECTOR);
+ size = sizeof(F_VECTOR);
break;
case STRING_TYPE:
size = SSIZE(pointer);
break;
case SBUF_TYPE:
- size = sizeof(SBUF);
+ size = sizeof(F_SBUF);
break;
case FLOAT_TYPE:
- size = sizeof(FLOAT);
+ size = sizeof(F_FLOAT);
break;
case PORT_TYPE:
- size = sizeof(PORT);
+ size = sizeof(F_PORT);
break;
case DLL_TYPE:
size = sizeof(DLL);
#define TYPE_COUNT 17
/* Pseudo-types. For error reporting only. */
-#define INTEGER_TYPE 100 /* FIXNUM or BIGNUM */
-#define RATIONAL_TYPE 101 /* INTEGER or RATIO */
-#define REAL_TYPE 102 /* RATIONAL or FLOAT */
-#define NUMBER_TYPE 103 /* COMPLEX or REAL */
-#define TEXT_TYPE 104 /* FIXNUM or STRING */
+#define INTEGER_TYPE 100 /* F_FIXNUM or BIGNUM */
+#define RATIONAL_TYPE 101 /* INTEGER or F_RATIO */
+#define REAL_TYPE 102 /* RATIONAL or F_FLOAT */
+#define NUMBER_TYPE 103 /* F_COMPLEX or REAL */
+#define TEXT_TYPE 104 /* F_FIXNUM or F_STRING */
CELL type_of(CELL tagged);
bool typep(CELL type, CELL tagged);
#include "factor.h"
-VECTOR* vector(FIXNUM capacity)
+F_VECTOR* vector(F_FIXNUM capacity)
{
- VECTOR* vector = allot_object(VECTOR_TYPE,sizeof(VECTOR));
+ F_VECTOR* vector = allot_object(VECTOR_TYPE,sizeof(F_VECTOR));
vector->top = 0;
vector->array = tag_object(array(capacity,F));
return vector;
void primitive_set_vector_length(void)
{
- VECTOR* vector;
- FIXNUM length;
- ARRAY* array;
+ F_VECTOR* vector;
+ F_FIXNUM length;
+ F_ARRAY* array;
maybe_garbage_collection();
void primitive_vector_nth(void)
{
- VECTOR* vector = untag_vector(dpop());
+ F_VECTOR* vector = untag_vector(dpop());
CELL index = to_fixnum(dpop());
if(index < 0 || index >= vector->top)
dpush(array_nth(untag_array(vector->array),index));
}
-void vector_ensure_capacity(VECTOR* vector, CELL index)
+void vector_ensure_capacity(F_VECTOR* vector, CELL index)
{
- ARRAY* array = untag_array(vector->array);
+ F_ARRAY* array = untag_array(vector->array);
CELL capacity = array->capacity;
if(index >= capacity)
array = grow_array(array,index * 2 + 1,F);
void primitive_set_vector_nth(void)
{
- VECTOR* vector;
- FIXNUM index;
+ F_VECTOR* vector;
+ F_FIXNUM index;
CELL value;
maybe_garbage_collection();
set_array_nth(untag_array(vector->array),index,value);
}
-void fixup_vector(VECTOR* vector)
+void fixup_vector(F_VECTOR* vector)
{
fixup(&vector->array);
}
-void collect_vector(VECTOR* vector)
+void collect_vector(F_VECTOR* vector)
{
copy_object(&vector->array);
}
CELL top;
/* tagged */
CELL array;
-} VECTOR;
+} F_VECTOR;
-INLINE VECTOR* untag_vector(CELL tagged)
+INLINE F_VECTOR* untag_vector(CELL tagged)
{
type_check(VECTOR_TYPE,tagged);
- return (VECTOR*)UNTAG(tagged);
+ return (F_VECTOR*)UNTAG(tagged);
}
-VECTOR* vector(FIXNUM capacity);
+F_VECTOR* vector(F_FIXNUM capacity);
void primitive_vector(void);
void primitive_vector_length(void);
void primitive_set_vector_length(void);
void primitive_vector_nth(void);
-void vector_ensure_capacity(VECTOR* vector, CELL index);
+void vector_ensure_capacity(F_VECTOR* vector, CELL index);
void primitive_set_vector_nth(void);
-void fixup_vector(VECTOR* vector);
-void collect_vector(VECTOR* vector);
+void fixup_vector(F_VECTOR* vector);
+void collect_vector(F_VECTOR* vector);
#include "factor.h"
-WORD* word(CELL primitive, CELL parameter, CELL plist)
+F_WORD* word(CELL primitive, CELL parameter, CELL plist)
{
- WORD* word = allot_object(WORD_TYPE,sizeof(WORD));
+ F_WORD* word = allot_object(WORD_TYPE,sizeof(F_WORD));
word->hashcode = (CELL)word; /* initial address */
word->xt = primitive_to_xt(primitive);
word->primitive = primitive;
/* When a word is executed we jump to the value of the xt field. However this
value is an unportable function pointer, so in the image we store a primitive
number that indexes a list of xts. */
-void update_xt(WORD* word)
+void update_xt(F_WORD* word)
{
word->xt = primitive_to_xt(word->primitive);
}
void primitive_word(void)
{
CELL plist, parameter;
- FIXNUM primitive;
+ F_FIXNUM primitive;
maybe_garbage_collection();
void primitive_set_word_xt(void)
{
- WORD* word = untag_word(dpop());
+ F_WORD* word = untag_word(dpop());
word->xt = unbox_integer();
}
void primitive_set_word_primitive(void)
{
- WORD* word = untag_word(dpop());
+ F_WORD* word = untag_word(dpop());
word->primitive = to_fixnum(dpop());
update_xt(word);
}
void primitive_set_word_parameter(void)
{
- WORD* word = untag_word(dpop());
+ F_WORD* word = untag_word(dpop());
word->parameter = dpop();
}
void primitive_set_word_plist(void)
{
- WORD* word = untag_word(dpop());
+ F_WORD* word = untag_word(dpop());
word->plist = dpop();
}
void primitive_set_word_call_count(void)
{
- WORD* word = untag_word(dpop());
+ F_WORD* word = untag_word(dpop());
word->call_count = to_fixnum(dpop());
}
void primitive_set_word_allot_count(void)
{
- WORD* word = untag_word(dpop());
+ F_WORD* word = untag_word(dpop());
word->allot_count = to_fixnum(dpop());
}
void primitive_word_compiledp(void)
{
- WORD* word = untag_word(dpop());
+ F_WORD* word = untag_word(dpop());
box_boolean(word->xt != (CELL)docol && word->xt != (CELL)dosym);
}
-void fixup_word(WORD* word)
+void fixup_word(F_WORD* word)
{
update_xt(word);
fixup(&word->parameter);
fixup(&word->plist);
}
-void collect_word(WORD* word)
+void collect_word(F_WORD* word)
{
copy_object(&word->parameter);
copy_object(&word->plist);
CELL call_count;
/* UNTAGGED amount of memory allocated in word */
CELL allot_count;
-} WORD;
+} F_WORD;
-INLINE WORD* untag_word(CELL tagged)
+INLINE F_WORD* untag_word(CELL tagged)
{
type_check(WORD_TYPE,tagged);
- return (WORD*)UNTAG(tagged);
+ return (F_WORD*)UNTAG(tagged);
}
-INLINE CELL tag_word(WORD* word)
+INLINE CELL tag_word(F_WORD* word)
{
return RETAG(word,WORD_TYPE);
}
-WORD* word(CELL primitive, CELL parameter, CELL plist);
-void update_xt(WORD* word);
+F_WORD* word(CELL primitive, CELL parameter, CELL plist);
+void update_xt(F_WORD* word);
void primitive_word(void);
void primitive_word_hashcode(void);
void primitive_word_primitive(void);
void primitive_word_allot_count(void);
void primitive_set_word_allot_count(void);
void primitive_word_compiledp(void);
-void fixup_word(WORD* word);
-void collect_word(WORD* word);
+void fixup_word(F_WORD* word);
+void collect_word(F_WORD* word);
#include "factor.h"
/* Return true if write was done */
-void write_step(PORT* port)
+void write_step(F_PORT* port)
{
- BYTE* chars = (BYTE*)untag_string(port->buffer) + sizeof(STRING);
+ BYTE* chars = (BYTE*)untag_string(port->buffer) + sizeof(F_STRING);
- FIXNUM amount = write(port->fd,chars + port->buf_pos,
+ F_FIXNUM amount = write(port->fd,chars + port->buf_pos,
port->buf_fill - port->buf_pos);
if(amount == -1)
port->buf_pos += amount;
}
-bool can_write(PORT* port, FIXNUM len)
+bool can_write(F_PORT* port, F_FIXNUM len)
{
CELL buf_capacity;
void primitive_can_write(void)
{
- PORT* port;
- FIXNUM len;
+ F_PORT* port;
+ F_FIXNUM len;
maybe_garbage_collection();
write_io_tasks,&write_fd_count);
}
-bool perform_write_io_task(PORT* port)
+bool perform_write_io_task(F_PORT* port)
{
if(port->buf_pos == port->buf_fill || port->io_error != F)
{
}
}
-void write_char_8(PORT* port, FIXNUM ch)
+void write_char_8(F_PORT* port, F_FIXNUM ch)
{
BYTE c = (BYTE)ch;
if(!can_write(port,1))
io_error(__FUNCTION__);
- bput((CELL)untag_string(port->buffer) + sizeof(STRING) + port->buf_fill,c);
+ bput((CELL)untag_string(port->buffer) + sizeof(F_STRING) + port->buf_fill,c);
port->buf_fill++;
}
/* Caller must ensure buffer is of the right size. */
-void write_string_raw(PORT* port, BYTE* str, CELL len)
+void write_string_raw(F_PORT* port, BYTE* str, CELL len)
{
/* Append string to buffer */
- memcpy((void*)((CELL)untag_string(port->buffer) + sizeof(STRING)
+ memcpy((void*)((CELL)untag_string(port->buffer) + sizeof(F_STRING)
+ port->buf_fill),str,len);
port->buf_fill += len;
}
-void write_string_8(PORT* port, STRING* str)
+void write_string_8(F_PORT* port, F_STRING* str)
{
BYTE* c_str;
void primitive_write_8(void)
{
- PORT* port;
+ F_PORT* port;
CELL text, type;
- STRING* str;
+ F_STRING* str;
maybe_garbage_collection();
-void write_step(PORT* port);
-bool can_write(PORT* port, FIXNUM len);
+void write_step(F_PORT* port);
+bool can_write(F_PORT* port, F_FIXNUM len);
void primitive_can_write(void);
void primitive_add_write_io_task(void);
-bool perform_write_io_task(PORT* port);
-void write_char_8(PORT* port, FIXNUM ch);
-void write_string_raw(PORT* port, BYTE* str, CELL len);
-void write_string_8(PORT* port, STRING* str);
+bool perform_write_io_task(F_PORT* port);
+void write_char_8(F_PORT* port, F_FIXNUM ch);
+void write_string_raw(F_PORT* port, BYTE* str, CELL len);
+void write_string_8(F_PORT* port, F_STRING* str);
void primitive_write_8(void);