PLAF_DLL_OBJS += vm/cpu-x86.64.o
+CFLAGS += -DFACTOR_64
break;
}
- fprintf(stderr,"%lx %lx %s\n",(CELL)scan,scan->size,status);
+ print_cell_hex((CELL)scan); print_string(" ");
+ print_cell_hex(scan->size); print_string(" ");
+ print_string(status); print_string("\n");
scan = next_block(heap,scan);
}
- printf("%ld bytes of relocation data\n",size);
+ print_cell(size); print_string(" bytes of relocation data\n");
}
/* Compute where each block is going to go, after compaction */
/* Free all unreachable code blocks */
gc();
- fprintf(stderr,"*** Code heap compaction...\n");
- fflush(stderr);
-
/* Figure out where the code heap blocks are going to end up */
CELL size = compute_heap_forwarding(&code_heap);
CELL used, total_free, max_free;
heap_usage(&code_heap,&used,&total_free,&max_free);
- fprintf(stderr,"Code heap stats:\n");
- fprintf(stderr,"Used: %ld\n",used);
- fprintf(stderr,"Total free space: %ld\n",total_free);
- fprintf(stderr,"Largest free block: %ld\n",max_free);
+ print_string("Code heap stats:\n");
+ print_string("Used: "); print_cell(used); nl();
+ print_string("Total free space: "); print_cell(total_free); nl();
+ print_string("Largest free block: "); print_cell(max_free); nl();
fatal_error("Out of memory in add-compiled-block",0);
}
}
#include "master.h"
-#define ALLOC_DATA_HEAP "alloc_data_heap: gens=%ld, young_size=%ld, aging_size=%ld, tenured_size=%ld\n"
-#define GC_REQUESTED "garbage_collection: growing_data_heap=%d, requested_bytes=%ld\n"
-#define BEGIN_GC "begin_gc: growing_data_heap=%d, collecting_gen=%ld\n"
-#define END_GC "end_gc: gc_elapsed=%ld\n"
-#define END_AGING_GC "end_gc: aging_collections=%ld, cards_scanned=%ld\n"
-#define END_NURSERY_GC "end_gc: nursery_collections=%ld, cards_scanned=%ld\n"
-
-/* #define GC_DEBUG */
-
-#ifdef GC_DEBUG
- #define GC_PRINT printf
-#else
- INLINE void GC_PRINT() { }
-#endif
-
CELL init_zone(F_ZONE *z, CELL size, CELL start)
{
z->size = size;
CELL aging_size,
CELL tenured_size)
{
- GC_PRINT(ALLOC_DATA_HEAP,gens,young_size,aging_size,tenured_size);
-
young_size = align(young_size,DECK_SIZE);
aging_size = align(aging_size,DECK_SIZE);
tenured_size = align(tenured_size,DECK_SIZE);
old->new references */
void collect_cards(void)
{
- GC_PRINT("Collect cards\n");
-
int i;
for(i = collecting_gen + 1; i < data_heap->gen_count; i++)
collect_gen_cards(i);
CELL top = (CELL)stacks->callstack_top;
CELL bottom = (CELL)stacks->callstack_bottom;
- GC_PRINT("Collect callstack %ld %ld\n",top,bottom);
iterate_callstack(top,bottom,collect_stack_frame);
- GC_PRINT("Done\n");
}
}
the user environment and extra roots registered with REGISTER_ROOT */
void collect_roots(void)
{
- GC_PRINT("Collect roots\n");
copy_handle(&T);
copy_handle(&bignum_zero);
copy_handle(&bignum_pos_one);
so we set the newspace so the next generation. */
newspace = &data_heap->generations[collecting_gen + 1];
}
-
-#ifdef GC_DEBUG
- printf("\n");
- dump_generations();
- printf("Newspace: ");
- dump_zone(newspace);
- printf("\n");
-#endif
}
void end_gc(CELL gc_elapsed)
return;
}
- GC_PRINT(GC_REQUESTED,growing_data_heap_,requested_bytes);
-
s64 start = current_millis();
performing_gc = true;
}
}
- GC_PRINT(BEGIN_GC,growing_data_heap,collecting_gen);
begin_gc(requested_bytes);
/* initialize chase pointer */
CELL gc_elapsed = (current_millis() - start);
- GC_PRINT(END_GC,gc_elapsed);
end_gc(gc_elapsed);
performing_gc = false;
if(type_of(word->vocabulary) == STRING_TYPE)
{
print_chars(untag_string(word->vocabulary));
- printf(":");
+ print_string(":");
}
if(type_of(word->name) == STRING_TYPE)
print_chars(untag_string(word->name));
else
{
- printf("#<not a string: ");
+ print_string("#<not a string: ");
print_nested_obj(word->name,nesting);
- printf(">");
+ print_string(">");
}
}
-void print_string(F_STRING* str)
+void print_factor_string(F_STRING* str)
{
putchar('"');
print_chars(str);
for(i = 0; i < length; i++)
{
- printf(" ");
+ print_string(" ");
print_nested_obj(array_nth(array,i),nesting);
}
if(trimmed)
- printf("...");
+ print_string("...");
}
void print_tuple(F_TUPLE* tuple, CELL nesting)
F_TUPLE_LAYOUT *layout = untag_object(tuple->layout);
CELL length = to_fixnum(layout->size);
- printf(" ");
+ print_string(" ");
print_nested_obj(layout->class,nesting);
CELL i;
for(i = 0; i < length; i++)
{
- printf(" ");
+ print_string(" ");
print_nested_obj(tuple_nth(tuple,i),nesting);
}
if(trimmed)
- printf("...");
+ print_string("...");
}
void print_nested_obj(CELL obj, F_FIXNUM nesting)
{
if(nesting <= 0 && !full_output)
{
- printf(" ... ");
+ print_string(" ... ");
return;
}
switch(type_of(obj))
{
case FIXNUM_TYPE:
- printf("%ld",untag_fixnum_fast(obj));
+ print_fixnum(untag_fixnum_fast(obj));
break;
case WORD_TYPE:
print_word(untag_word(obj),nesting - 1);
break;
case STRING_TYPE:
- print_string(untag_string(obj));
+ print_factor_string(untag_string(obj));
break;
case F_TYPE:
- printf("f");
+ print_string("f");
break;
case TUPLE_TYPE:
- printf("T{");
+ print_string("T{");
print_tuple(untag_object(obj),nesting - 1);
- printf(" }");
+ print_string(" }");
break;
case ARRAY_TYPE:
- printf("{");
+ print_string("{");
print_array(untag_object(obj),nesting - 1);
- printf(" }");
+ print_string(" }");
break;
case QUOTATION_TYPE:
- printf("[");
+ print_string("[");
quot = untag_object(obj);
print_array(untag_object(quot->array),nesting - 1);
- printf(" ]");
+ print_string(" ]");
break;
default:
- printf("#<type %ld @ %lx>",type_of(obj),obj);
+ print_string("#<type "); print_cell(type_of(obj)); print_string(" @ "); print_cell_hex(obj);
break;
}
}
for(; start <= end; start += CELLS)
{
print_obj(get(start));
- printf("\n");
+ nl();
}
}
void print_datastack(void)
{
- printf("==== DATA STACK:\n");
+ print_string("==== DATA STACK:\n");
print_objects(ds_bot,ds);
}
void print_retainstack(void)
{
- printf("==== RETAIN STACK:\n");
+ print_string("==== RETAIN STACK:\n");
print_objects(rs_bot,rs);
}
void print_stack_frame(F_STACK_FRAME *frame)
{
print_obj(frame_executing(frame));
- printf("\n");
+ print_string("\n");
print_obj(frame_scan(frame));
- printf("\n");
- printf("%lx\n",(CELL)frame_executing(frame));
- printf("%lx\n",(CELL)frame->xt);
+ print_string("\n");
+ print_cell_hex((CELL)frame_executing(frame));
+ print_cell_hex((CELL)frame->xt);
}
void print_callstack(void)
{
- printf("==== CALL STACK:\n");
+ print_string("==== CALL STACK:\n");
CELL bottom = (CELL)stack_chain->callstack_bottom;
CELL top = (CELL)stack_chain->callstack_top;
iterate_callstack(top,bottom,print_stack_frame);
void dump_cell(CELL cell)
{
- printf("%08lx: ",cell);
+ print_cell_hex_pad(cell); print_string(": ");
cell = get(cell);
- printf("%08lx tag %ld",cell,TAG(cell));
+ print_cell_hex_pad(cell); print_string(" tag "); print_cell(TAG(cell));
switch(TAG(cell))
{
case BIGNUM_TYPE:
case FLOAT_TYPE:
if(cell == F)
- printf(" -- F");
+ print_string(" -- F");
else if(cell < TYPE_COUNT<<TAG_BITS)
- printf(" -- possible header: %ld",cell>>TAG_BITS);
+ {
+ print_string(" -- possible header: ");
+ print_cell(cell>>TAG_BITS);
+ }
else if(cell >= data_heap->segment->start
&& cell < data_heap->segment->end)
{
CELL header = get(UNTAG(cell));
CELL type = header>>TAG_BITS;
- printf(" -- object; ");
+ print_string(" -- object; ");
if(TAG(header) == 0 && type < TYPE_COUNT)
- printf(" type %ld",type);
+ {
+ print_string(" type "); print_cell(type);
+ }
else
- printf(" header corrupt");
+ print_string(" header corrupt");
}
break;
}
- printf("\n");
+ nl();
}
void dump_memory(CELL from, CELL to)
void dump_zone(F_ZONE *z)
{
- printf("start=%ld, size=%ld, here=%ld\n",
- z->start,z->size,z->here - z->start);
+ print_string("Start="); print_cell(z->start);
+ print_string(", size="); print_cell(z->size);
+ print_string(", here="); print_cell(z->here - z->start); nl();
}
void dump_generations(void)
{
- int i;
+ CELL i;
- printf("Nursery: ");
+ print_string("Nursery: ");
dump_zone(&nursery);
for(i = 1; i < data_heap->gen_count; i++)
{
- printf("Generation %d: ",i);
+ print_string("Generation "); print_cell(i); print_string(": ");
dump_zone(&data_heap->generations[i]);
}
for(i = 0; i < data_heap->gen_count; i++)
{
- printf("Semispace %d: ",i);
+ print_string("Semispace "); print_cell(i); print_string(": ");
dump_zone(&data_heap->semispaces[i]);
}
- printf("Cards: base=%lx, size=%lx\n",
- (CELL)data_heap->cards,
- (CELL)(data_heap->cards_end - data_heap->cards));
+ print_string("Cards: base=");
+ print_cell((CELL)data_heap->cards);
+ print_string(", size=");
+ print_cell((CELL)(data_heap->cards_end - data_heap->cards));
+ nl();
}
void dump_objects(F_FIXNUM type)
{
if(type == -1 || type_of(obj) == type)
{
- printf("%lx ",obj);
+ print_cell_hex_pad(obj);
+ print_string(" ");
print_nested_obj(obj,2);
- printf("\n");
+ nl();
}
}
{
if(look_for == *scan)
{
- printf("%lx ",obj);
+ print_cell_hex_pad(obj);
+ print_string(" ");
print_nested_obj(obj,2);
- printf("\n");
+ nl();
}
}
if(look_for == get(scan))
{
- printf("%lx ",obj);
+ print_cell_hex_pad(obj);
+ print_string(" ");
print_nested_obj(obj,2);
- printf("\n");
+ nl();
}
}
}
{
if(fep_disabled)
{
- printf("Low level debugger disabled\n");
+ print_string("Low level debugger disabled\n");
exit(1);
}
- open_console();
-
- printf("Starting low level debugger...\n");
- printf(" Basic commands:\n");
- printf("q -- continue executing Factor - NOT SAFE\n");
- printf("im -- save image to fep.image\n");
- printf("x -- exit Factor\n");
- printf(" Advanced commands:\n");
- printf("d <addr> <count> -- dump memory\n");
- printf("u <addr> -- dump object at tagged <addr>\n");
- printf(". <addr> -- print object at tagged <addr>\n");
- printf("t -- toggle output trimming\n");
- printf("s r -- dump data, retain stacks\n");
- printf(".s .r .c -- print data, retain, call stacks\n");
- printf("e -- dump environment\n");
- printf("g -- dump generations\n");
- printf("card <addr> -- print card containing address\n");
- printf("addr <card> -- print address containing card\n");
- printf("data -- data heap dump\n");
- printf("words -- words dump\n");
- printf("tuples -- tuples dump\n");
- printf("refs <addr> -- find data heap references to object\n");
- printf("push <addr> -- push object on data stack - NOT SAFE\n");
- printf("code -- code heap dump\n");
+ /* open_console(); */
+
+ print_string("Starting low level debugger...\n");
+ print_string(" Basic commands:\n");
+ print_string("q -- continue executing Factor - NOT SAFE\n");
+ print_string("im -- save image to fep.image\n");
+ print_string("x -- exit Factor\n");
+ print_string(" Advanced commands:\n");
+ print_string("d <addr> <count> -- dump memory\n");
+ print_string("u <addr> -- dump object at tagged <addr>\n");
+ print_string(". <addr> -- print object at tagged <addr>\n");
+ print_string("t -- toggle output trimming\n");
+ print_string("s r -- dump data, retain stacks\n");
+ print_string(".s .r .c -- print data, retain, call stacks\n");
+ print_string("e -- dump environment\n");
+ print_string("g -- dump generations\n");
+ print_string("card <addr> -- print card containing address\n");
+ print_string("addr <card> -- print address containing card\n");
+ print_string("data -- data heap dump\n");
+ print_string("words -- words dump\n");
+ print_string("tuples -- tuples dump\n");
+ print_string("refs <addr> -- find data heap references to object\n");
+ print_string("push <addr> -- push object on data stack - NOT SAFE\n");
+ print_string("code -- code heap dump\n");
bool seen_command = false;
{
char cmd[1024];
- printf("READY\n");
+ print_string("READY\n");
fflush(stdout);
if(scanf("%1000s",cmd) <= 0)
if(strcmp(cmd,"d") == 0)
{
- CELL addr, count;
- scanf("%lx %lx",&addr,&count);
+ CELL addr = read_cell_hex();
+ scanf(" ");
+ CELL count = read_cell_hex();
dump_memory(addr,addr+count);
}
- if(strcmp(cmd,"u") == 0)
+ else if(strcmp(cmd,"u") == 0)
{
- CELL addr, count;
- scanf("%lx",&addr);
- count = object_size(addr);
+ CELL addr = read_cell_hex();
+ CELL count = object_size(addr);
dump_memory(addr,addr+count);
}
else if(strcmp(cmd,".") == 0)
{
- CELL addr;
- scanf("%lx",&addr);
+ CELL addr = read_cell_hex();
print_obj(addr);
- printf("\n");
+ print_string("\n");
}
else if(strcmp(cmd,"t") == 0)
full_output = !full_output;
dump_generations();
else if(strcmp(cmd,"card") == 0)
{
- CELL addr;
- scanf("%lx",&addr);
- printf("%lx\n",(CELL)ADDR_TO_CARD(addr));
+ CELL addr = read_cell_hex();
+ print_cell_hex((CELL)ADDR_TO_CARD(addr));
+ nl();
}
else if(strcmp(cmd,"addr") == 0)
{
- CELL card;
- scanf("%lx",&card);
- printf("%lx\n",(CELL)CARD_TO_ADDR(card));
+ CELL card = read_cell_hex();
+ print_cell_hex((CELL)CARD_TO_ADDR(card));
+ nl();
}
else if(strcmp(cmd,"q") == 0)
return;
dump_objects(-1);
else if(strcmp(cmd,"refs") == 0)
{
- CELL addr;
- scanf("%lx",&addr);
- printf("Data heap references:\n");
+ CELL addr = read_cell_hex();
+ print_string("Data heap references:\n");
find_data_references(addr);
- printf("Code heap references:\n");
+ print_string("Code heap references:\n");
find_code_references(addr);
- printf("\n");
+ nl();
}
else if(strcmp(cmd,"words") == 0)
dump_objects(WORD_TYPE);
dump_objects(TUPLE_TYPE);
else if(strcmp(cmd,"push") == 0)
{
- CELL addr;
- scanf("%lx",&addr);
+ CELL addr = read_cell_hex();
dpush(addr);
}
else if(strcmp(cmd,"code") == 0)
dump_heap(&code_heap);
else
- printf("unknown command\n");
+ print_string("unknown command\n");
}
}
void primitive_die(void)
{
- fprintf(stderr,"The die word was called by the library. Unless you called it yourself,\n");
- fprintf(stderr,"you have triggered a bug in Factor. Please report.\n");
+ print_string("The die word was called by the library. Unless you called it yourself,\n");
+ print_string("you have triggered a bug in Factor. Please report.\n");
factorbug();
}
void out_of_memory(void)
{
- fprintf(stderr,"Out of memory\n\n");
+ print_string("Out of memory\n\n");
dump_generations();
exit(1);
}
void fatal_error(char* msg, CELL tagged)
{
- fprintf(stderr,"fatal_error: %s %lx\n",msg,tagged);
+ print_string("fatal_error: "); print_string(msg);
+ print_string(": "); print_cell_hex(tagged); nl();
exit(1);
}
void critical_error(char* msg, CELL tagged)
{
- fprintf(stderr,"You have triggered a bug in Factor. Please report.\n");
- fprintf(stderr,"critical_error: %s %lx\n",msg,tagged);
+ print_string("You have triggered a bug in Factor. Please report.\n");
+ print_string("critical_error: "); print_string(msg);
+ print_string(": "); print_cell_hex(tagged); nl();
factorbug();
}
crash. */
else
{
- printf("You have triggered a bug in Factor. Please report.\n");
- printf("early_error: ");
+ print_string("You have triggered a bug in Factor. Please report.\n");
+ print_string("early_error: ");
print_obj(error);
- printf("\n");
+ nl();
factorbug();
}
}
/* Do some initialization that we do once only */
void do_stage1_init(void)
{
- fprintf(stderr,"*** Stage 2 early init... ");
- fflush(stderr);
+ print_string("*** Stage 2 early init... ");
+ fflush(stdout);
CELL words = find_all_words();
userenv[STAGE2_ENV] = T;
- fprintf(stderr,"done\n");
- fflush(stderr);
+ print_string("done\n");
+ fflush(stdout);
}
/* Get things started */
void ffi_test_0(void)
{
- printf("ffi_test_0()\n");
}
int ffi_test_1(void)
{
- printf("ffi_test_1()\n");
return 3;
}
int ffi_test_2(int x, int y)
{
- printf("ffi_test_2(%d,%d)\n",x,y);
return x + y;
}
int ffi_test_3(int x, int y, int z, int t)
{
- printf("ffi_test_3(%d,%d,%d,%d)\n",x,y,z,t);
return x + y + z * t;
}
float ffi_test_4(void)
{
- printf("ffi_test_4()\n");
return 1.5;
}
double ffi_test_5(void)
{
- printf("ffi_test_5()\n");
return 1.5;
}
double ffi_test_6(float x, float y)
{
- printf("ffi_test_6(%f,%f)\n",x,y);
return x * y;
}
double ffi_test_7(double x, double y)
{
- printf("ffi_test_7(%f,%f)\n",x,y);
return x * y;
}
double ffi_test_8(double x, float y, double z, float t, int w)
{
- printf("ffi_test_8(%f,%f,%f,%f,%d)\n",x,y,z,t,w);
return x * y + z * t + w;
}
int ffi_test_9(int a, int b, int c, int d, int e, int f, int g)
{
- printf("ffi_test_9(%d,%d,%d,%d,%d,%d,%d)\n",a,b,c,d,e,f,g);
return a + b + c + d + e + f + g;
}
int ffi_test_10(int a, int b, double c, int d, float e, int f, int g, int h)
{
- printf("ffi_test_10(%d,%d,%f,%d,%f,%d,%d,%d)\n",a,b,c,d,e,f,g,h);
return a - b - c - d - e - f - g - h;
}
int ffi_test_11(int a, struct foo b, int c)
{
- printf("ffi_test_11(%d,{%d,%d},%d)\n",a,b.x,b.y,c);
return a * b.x + c * b.y;
}
int ffi_test_12(int a, int b, struct rect c, int d, int e, int f)
{
- printf("ffi_test_12(%d,%d,{%f,%f,%f,%f},%d,%d,%d)\n",a,b,c.x,c.y,c.w,c.h,d,e,f);
return a + b + c.x + c.y + c.w + c.h + d + e + f;
}
int ffi_test_13(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k)
{
- printf("ffi_test_13(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)\n",a,b,c,d,e,f,g,h,i,j,k);
return a + b + c + d + e + f + g + h + i + j + k;
}
struct foo ffi_test_14(int x, int y)
{
struct foo r;
- printf("ffi_test_14(%d,%d)\n",x,y);
r.x = x; r.y = y;
return r;
}
F_STDCALL int ffi_test_18(int x, int y, int z, int t)
{
- printf("ffi_test_18(%d,%d,%d,%d)\n",x,y,z,t);
return x + y + z * t;
}
double y1, double y2, double y3,
double z1, double z2, double z3)
{
- printf("ffi_test_20(%f,%f,%f,%f,%f,%f,%f,%f,%f)\n",
- x1, x2, x3, y1, y2, y3, z1, z2, z3);
}
long long ffi_test_21(long x, long y)
long ffi_test_22(long x, long long y, long long z)
{
- printf("ffi_test_22(%ld,%lld,%lld)\n",x,y,z);
return x + y / z;
}
int ffi_test_31(int x0, int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9, int x10, int x11, int x12, int x13, int x14, int x15, int x16, int x17, int x18, int x19, int x20, int x21, int x22, int x23, int x24, int x25, int x26, int x27, int x28, int x29, int x30, int x31, int x32, int x33, int x34, int x35, int x36, int x37, int x38, int x39, int x40, int x41)
{
- printf("ffi_test_31(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)\n",x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18,x19,x20,x21,x22,x23,x24,x25,x26,x27,x28,x29,x30,x31,x32,x33,x34,x35,x36,x37,x38,x39,x40,x41);
return x0 + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 + x21 + x22 + x23 + x24 + x25 + x26 + x27 + x28 + x29 + x30 + x31 + x32 + x33 + x34 + x35 + x36 + x37 + x38 + x39 + x40 + x41;
}
float ffi_test_31_point_5(float x0, float x1, float x2, float x3, float x4, float x5, float x6, float x7, float x8, float x9, float x10, float x11, float x12, float x13, float x14, float x15, float x16, float x17, float x18, float x19, float x20, float x21, float x22, float x23, float x24, float x25, float x26, float x27, float x28, float x29, float x30, float x31, float x32, float x33, float x34, float x35, float x36, float x37, float x38, float x39, float x40, float x41)
{
- printf("ffi_test_31_point_5(%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f)\n",x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18,x19,x20,x21,x22,x23,x24,x25,x26,x27,x28,x29,x30,x31,x32,x33,x34,x35,x36,x37,x38,x39,x40,x41);
return x0 + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 + x21 + x22 + x23 + x24 + x25 + x26 + x27 + x28 + x29 + x30 + x31 + x32 + x33 + x34 + x35 + x36 + x37 + x38 + x39 + x40 + x41;
}
void ffi_test_36_point_5(void)
{
- printf("ffi_test_36_point_5\n");
global_var = 0;
}
int ffi_test_37(int (*f)(int, int, int))
{
- printf("ffi_test_37\n");
- printf("global_var is %d\n",global_var);
global_var = f(global_var,global_var * 2,global_var * 3);
- printf("global_var is %d\n",global_var);
- fflush(stdout);
return global_var;
}
int ffi_test_39(long a, long b, struct test_struct_13 s)
{
- printf("ffi_test_39(%ld,%ld,%f,%f,%f,%f,%f,%f)\n",a,b,s.x1,s.x2,s.x3,s.x4,s.x5,s.x6);
if(a != b) abort();
return s.x1 + s.x2 + s.x3 + s.x4 + s.x5 + s.x6;
}
struct test_struct_14 retval;
retval.x1 = x1;
retval.x2 = x2;
- printf("ffi_test_40(%f,%f)\n",x1,x2);
return retval;
}
struct test_struct_12 retval;
retval.a = a;
retval.x = x;
- printf("ffi_test_41(%d,%f)\n",a,x);
return retval;
}
struct test_struct_15 retval;
retval.x = x;
retval.y = y;
- printf("ffi_test_42(%f,%f)\n",x,y);
return retval;
}
struct test_struct_16 retval;
retval.x = x;
retval.a = a;
- printf("ffi_test_43(%f,%d)\n",x,a);
return retval;
}
struct test_struct_14 retval;
retval.x1 = 1.0;
retval.x2 = 2.0;
- //printf("ffi_test_44()\n");
return retval;
}
F_ZONE *tenured = &data_heap->generations[TENURED];
- long int bytes_read = fread((void*)tenured->start,1,h->data_size,file);
+ F_FIXNUM bytes_read = fread((void*)tenured->start,1,h->data_size,file);
if(bytes_read != h->data_size)
{
- fprintf(stderr,"truncated image: %ld bytes read, %ld bytes expected\n",
- bytes_read,h->data_size);
+ print_string("truncated image: ");
+ print_fixnum(bytes_read);
+ print_string(" bytes read, ");
+ print_cell(h->data_size);
+ print_string(" bytes expected\n");
fatal_error("load_data_heap failed",0);
}
if(h->code_size != 0)
{
- long int bytes_read = fread(first_block(&code_heap),1,h->code_size,file);
+ F_FIXNUM bytes_read = fread(first_block(&code_heap),1,h->code_size,file);
if(bytes_read != h->code_size)
{
- fprintf(stderr,"truncated image: %ld bytes read, %ld bytes expected\n",
- bytes_read,h->code_size);
+ print_string("truncated image: ");
+ print_fixnum(bytes_read);
+ print_string(" bytes read, ");
+ print_cell(h->code_size);
+ print_string(" bytes expected\n");
fatal_error("load_code_heap failed",0);
}
}
FILE *file = OPEN_READ(p->image);
if(file == NULL)
{
- FPRINTF(stderr,"Cannot open image file: %s\n",p->image);
- fprintf(stderr,"%s\n",strerror(errno));
+ print_string("Cannot open image file: "); print_native_string(p->image); nl();
+ print_string(strerror(errno)); nl();
exit(1);
}
FILE* file;
F_HEADER h;
- FPRINTF(stderr,"*** Saving %s...\n",filename);
-
file = OPEN_WRITE(filename);
if(file == NULL)
{
- fprintf(stderr,"Cannot open image file: %s\n",strerror(errno));
+ print_string("Cannot open image file: "); print_native_string(filename); nl();
+ print_string(strerror(errno)); nl();
return false;
}
if(fwrite((void*)tenured->start,h.data_size,1,file) != 1)
{
- fprintf(stderr,"Save data heap failed: %s\n",strerror(errno));
+ print_string("Save data heap failed: "); print_string(strerror(errno)); nl();
return false;
}
if(fwrite(first_block(&code_heap),h.code_size,1,file) != 1)
{
- fprintf(stderr,"Save code heap failed: %s\n",strerror(errno));
+ print_string("Save code heap failed: "); print_string(strerror(errno)); nl();
return false;
}
if(fclose(file))
{
- fprintf(stderr,"Failed to close image file: %s\n",strerror(errno));
+ print_string("Failed to close image file: "); print_string(strerror(errno)); nl();
return false;
}
int nArgs;
szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
- if( NULL == szArglist )
+ if(NULL == szArglist)
{
- wprintf(L"CommandLineToArgvW failed\n");
+ print_string("CommandLineToArgvW failed\n");
return 1;
}
#define STRNCMP strncmp
#define STRDUP strdup
+#define CELL_FORMAT "%lu"
+#define CELL_HEX_FORMAT "%lx"
+
+#ifdef FACTOR_64
+ #define CELL_HEX_PAD_FORMAT "%016lx"
+#else
+ #define CELL_HEX_PAD_FORMAT "%08lx"
+#endif
+
+#define FIXNUM_FORMAT "%ld"
+
#define OPEN_READ(path) fopen(path,"rb")
#define OPEN_WRITE(path) fopen(path,"wb")
-#define FPRINTF(stream,format,arg) fprintf(stream,format,arg)
+
+#define print_native_string(string) print_string(string)
void start_thread(void *(*start_routine)(void *));
BY_HANDLE_FILE_INFORMATION bhfi;
F_CHAR *path = unbox_u16_string();
- //wprintf(L"path = %s\n", path);
HANDLE h = CreateFileW(path,
GENERIC_READ,
FILE_SHARE_READ,
#define STRNCMP wcsncmp
#define STRDUP _wcsdup
+#define CELL_FORMAT "%Iu"
+#define CELL_HEX_FORMAT "%Ix"
+
+#ifdef FACTOR_64
+ #define CELL_HEX_PAD_FORMAT "%016Ix"
+#else
+ #define CELL_HEX_PAD_FORMAT "%08Ix"
+#endif
+
+#define FIXNUM_FORMAT "%Id"
+
#define OPEN_READ(path) _wfopen(path,L"rb")
#define OPEN_WRITE(path) _wfopen(path,L"wb")
-#define FPRINTF(stream,format,arg) fwprintf(stream,L##format,arg)
+#define print_native_string(string) wprintf(L"%s",arg)
/* Difference between Jan 1 00:00:00 1601 and Jan 1 00:00:00 1970 */
#define EPOCH_OFFSET 0x019db1ded53e8000LL
if(!ptr) fatal_error("Out of memory in safe_strdup", 0);
return ptr;
}
+
+/* We don't use printf directly, because format directives are not portable.
+Instead we define the common cases here. */
+void nl(void)
+{
+ fputs("\n",stdout);
+}
+
+void print_string(const char *str)
+{
+ fputs(str,stdout);
+}
+
+void print_cell(CELL x)
+{
+ printf(CELL_FORMAT,x);
+}
+
+void print_cell_hex(CELL x)
+{
+ printf(CELL_HEX_FORMAT,x);
+}
+
+void print_cell_hex_pad(CELL x)
+{
+ printf(CELL_HEX_PAD_FORMAT,x);
+}
+
+void print_fixnum(F_FIXNUM x)
+{
+ printf(CELL_FORMAT,x);
+}
+
+CELL read_cell_hex(void)
+{
+ CELL cell;
+ scanf(CELL_HEX_FORMAT,&cell);
+ return cell;
+};
void *safe_malloc(size_t size);
F_CHAR *safe_strdup(const F_CHAR *str);
+
+void nl(void);
+void print_string(const char *str);
+void print_cell(CELL x);
+void print_cell_hex(CELL x);
+void print_cell_hex_pad(CELL x);
+void print_fixnum(F_FIXNUM x);
+CELL read_cell_hex(void);