]> gitweb.factorcode.org Git - factor.git/commitdiff
VM no longer uses printf since format string directives are not portable between...
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Wed, 19 Nov 2008 00:21:42 +0000 (18:21 -0600)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Wed, 19 Nov 2008 00:21:42 +0000 (18:21 -0600)
15 files changed:
vm/Config.x86.64
vm/code_gc.c
vm/code_heap.c
vm/data_gc.c
vm/debug.c
vm/errors.c
vm/factor.c
vm/ffi_test.c
vm/image.c
vm/main-windows-nt.c
vm/os-unix.h
vm/os-windows.c
vm/os-windows.h
vm/utilities.c
vm/utilities.h

index 53a4d3c5e12ca0e2ff3a0fb2a12d6d0f36ee3229..63f06d5a786337245463030ce0ee22f7f1be8d40 100644 (file)
@@ -1 +1,2 @@
 PLAF_DLL_OBJS += vm/cpu-x86.64.o
+CFLAGS += -DFACTOR_64
index bd6384408b61795e6606e1bc964ba8ee798dc6ec..59e99b0260911974f1184b10ecca3bcdfa2a1342 100755 (executable)
@@ -333,12 +333,14 @@ void dump_heap(F_HEAP *heap)
                        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 */
@@ -460,9 +462,6 @@ void compact_code_heap(void)
        /* 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);
 
index 2268df27e30c26e4e0113f5c08f5ac63d12de1fc..f3a4071e98482d089fe1b26ea0be65ab93ed9866 100755 (executable)
@@ -238,10 +238,10 @@ CELL allot_code_block(CELL size)
                        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);
                }
        }
index cf1632811c1803343b2cbe38afd5d6c589d79ab6..9f8ffb625e1af3affba70d67ffb9da7f4fc9b84c 100755 (executable)
@@ -1,20 +1,5 @@
 #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;
@@ -36,8 +21,6 @@ F_DATA_HEAP *alloc_data_heap(CELL gens,
        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);
@@ -438,8 +421,6 @@ void collect_gen_cards(CELL gen)
 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);
@@ -468,9 +449,7 @@ void collect_callstack(F_CONTEXT *stacks)
                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");
        }
 }
 
@@ -486,7 +465,6 @@ void collect_gc_locals(void)
 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);
@@ -759,14 +737,6 @@ void begin_gc(CELL requested_bytes)
                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)
@@ -823,8 +793,6 @@ void garbage_collection(CELL gen,
                return;
        }
 
-       GC_PRINT(GC_REQUESTED,growing_data_heap_,requested_bytes);
-
        s64 start = current_millis();
 
        performing_gc = true;
@@ -858,7 +826,6 @@ void garbage_collection(CELL gen,
                }
        }
 
-       GC_PRINT(BEGIN_GC,growing_data_heap,collecting_gen);
        begin_gc(requested_bytes);
 
        /* initialize chase pointer */
@@ -895,7 +862,6 @@ void garbage_collection(CELL gen,
 
        CELL gc_elapsed = (current_millis() - start);
 
-       GC_PRINT(END_GC,gc_elapsed);
        end_gc(gc_elapsed);
 
        performing_gc = false;
index 41205d4aff6399d51a994d5726154ea69f1e245f..8c6ec203adaed612e6a5654539d297547ba5d004 100755 (executable)
@@ -15,20 +15,20 @@ void print_word(F_WORD* word, CELL nesting)
        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);
@@ -51,12 +51,12 @@ void print_array(F_ARRAY* array, CELL nesting)
 
        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)
@@ -64,7 +64,7 @@ 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;
@@ -80,19 +80,19 @@ void print_tuple(F_TUPLE* tuple, CELL nesting)
 
        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;
        }
 
@@ -101,35 +101,35 @@ void print_nested_obj(CELL obj, F_FIXNUM nesting)
        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;
        }
 }
@@ -144,35 +144,35 @@ void print_objects(CELL start, CELL end)
        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);
@@ -180,11 +180,11 @@ void print_callstack(void)
 
 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))
        {
@@ -192,24 +192,29 @@ void dump_cell(CELL 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)
@@ -222,32 +227,35 @@ 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)
@@ -260,9 +268,10 @@ 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();
                }
        }
 
@@ -277,9 +286,10 @@ void find_data_references_step(CELL *scan)
 {
        if(look_for == *scan)
        {
-               printf("%lx ",obj);
+               print_cell_hex_pad(obj);
+               print_string(" ");
                print_nested_obj(obj,2);
-               printf("\n");
+               nl();
        }
 }
 
@@ -312,9 +322,10 @@ void find_code_references_step(F_COMPILED *compiled, CELL code_start, CELL liter
 
                if(look_for == get(scan))
                {
-                       printf("%lx ",obj);
+                       print_cell_hex_pad(obj);
+                       print_string(" ");
                        print_nested_obj(obj,2);
-                       printf("\n");
+                       nl();
                }
        }
 }
@@ -329,34 +340,34 @@ void factorbug(void)
 {
        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;
 
@@ -364,7 +375,7 @@ void factorbug(void)
        {
                char cmd[1024];
 
-               printf("READY\n");
+               print_string("READY\n");
                fflush(stdout);
 
                if(scanf("%1000s",cmd) <= 0)
@@ -389,23 +400,22 @@ void factorbug(void)
 
                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;
@@ -429,15 +439,15 @@ void factorbug(void)
                        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;
@@ -449,13 +459,12 @@ void factorbug(void)
                        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);
@@ -463,20 +472,19 @@ void factorbug(void)
                        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();
 }
index fe6e79be6d4650abf0daff074f49131fa27de9ac..7c06ec1310568a98a7058e1ff2bfa7a244a3e67e 100755 (executable)
@@ -2,21 +2,23 @@
 
 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();
 }
 
@@ -57,10 +59,10 @@ void throw_error(CELL error, F_STACK_FRAME *callstack_top)
        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();
        }
 }
index c8b07cba64d0c82727dc5d50d27f01ea556f3299..8e0aadb4fd2ed752804cafe3d8aa829060af8179 100755 (executable)
@@ -41,8 +41,8 @@ void default_parameters(F_PARAMETERS *p)
 /* 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();
 
@@ -65,8 +65,8 @@ void do_stage1_init(void)
 
        userenv[STAGE2_ENV] = T;
 
-       fprintf(stderr,"done\n");
-       fflush(stderr);
+       print_string("done\n");
+       fflush(stdout);
 }
 
 /* Get things started */
index 7ae4491d80b17c2704d16f84e6c54d56f4d477fc..1ec41ac2b937ea94e4d830dbdfd9a7766f5c1b88 100755 (executable)
@@ -6,91 +6,76 @@
 
 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;
 }
@@ -119,7 +104,6 @@ struct tiny ffi_test_17(int x)
 
 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;
 }
 
@@ -134,8 +118,6 @@ void ffi_test_20(double x1, double x2, double x3,
        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)
@@ -145,7 +127,6 @@ 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;
 }
 
@@ -226,13 +207,11 @@ struct test_struct_7 ffi_test_30(void)
 
 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;
 }
 
@@ -265,17 +244,12 @@ static int global_var;
 
 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;
 }
 
@@ -286,7 +260,6 @@ unsigned long long ffi_test_38(unsigned long long x, unsigned long long y)
 
 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;
 }
@@ -296,7 +269,6 @@ struct test_struct_14 ffi_test_40(double x1, double x2)
        struct test_struct_14 retval;
        retval.x1 = x1;
        retval.x2 = x2;
-       printf("ffi_test_40(%f,%f)\n",x1,x2);
        return retval;
 }
 
@@ -305,7 +277,6 @@ struct test_struct_12 ffi_test_41(int a, double x)
        struct test_struct_12 retval;
        retval.a = a;
        retval.x = x;
-       printf("ffi_test_41(%d,%f)\n",a,x);
        return retval;
 }
 
@@ -314,7 +285,6 @@ struct test_struct_15 ffi_test_42(float x, float y)
        struct test_struct_15 retval;
        retval.x = x;
        retval.y = y;
-       printf("ffi_test_42(%f,%f)\n",x,y);
        return retval;
 }
 
@@ -323,7 +293,6 @@ struct test_struct_16 ffi_test_43(float x, int a)
        struct test_struct_16 retval;
        retval.x = x;
        retval.a = a;
-       printf("ffi_test_43(%f,%d)\n",x,a);
        return retval;
 }
 
@@ -332,6 +301,5 @@ struct test_struct_14 ffi_test_44(void)
        struct test_struct_14 retval;
        retval.x1 = 1.0;
        retval.x2 = 2.0;
-       //printf("ffi_test_44()\n");
        return retval;
 }
index 289c1e94c8eb33416b97335e1de7a16093238bf8..0e6591f8d80db956b95906e3b8bc9fb07725e004 100755 (executable)
@@ -28,12 +28,15 @@ INLINE void load_data_heap(FILE *file, F_HEADER *h, F_PARAMETERS *p)
 
        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);
        }
 
@@ -52,11 +55,14 @@ INLINE void load_code_heap(FILE *file, F_HEADER *h, F_PARAMETERS *p)
 
        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);
                }
        }
@@ -72,8 +78,8 @@ void load_image(F_PARAMETERS *p)
        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);
        }
 
@@ -106,12 +112,11 @@ bool save_image(const F_CHAR *filename)
        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;
        }
 
@@ -142,19 +147,19 @@ bool save_image(const F_CHAR *filename)
 
        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;
        }
 
index 743831958b095b31ba567c31a33a7d16ba98cefb..95fd68549d8a7def64b071b567d444dce43192c2 100644 (file)
@@ -13,9 +13,9 @@ int WINAPI WinMain(
        int nArgs;
 
        szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
-       if( NULL == szArglist )
+       if(NULL == szArglist)
        {
-               wprintf(L"CommandLineToArgvW failed\n");
+               print_string("CommandLineToArgvW failed\n");
                return 1;
        }
 
index 6db03148cd7fa56d3a2e1ff2e6e414164c2290bf..2c5cc20e8d15ff85b10fd40db960f19e590fcd8f 100755 (executable)
@@ -23,9 +23,21 @@ typedef char F_SYMBOL;
 #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 *));
 
index fc289c288ea8f97fd89f2fe24ad6e3fbb32a39de..7d486bb86bb488b30c591f61ff0806571e49170f 100755 (executable)
@@ -92,7 +92,6 @@ void primitive_existsp(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,
index f292c407e5c8d7ac2defc3a63857d2c64cbfbb96..2a56b03ef62b244debc443ea2c68c007e9f76b11 100755 (executable)
@@ -20,10 +20,21 @@ typedef wchar_t F_CHAR;
 #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
index ebc8e8797784beb6ab60131c410c545700f98ef5..35fc7ad087f19f1e726e006c00bb9e336f1352c0 100755 (executable)
@@ -14,3 +14,42 @@ F_CHAR *safe_strdup(const F_CHAR *str)
        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;
+};
index 89a8ba57a37c9428566dfab918b5650d8bc1251a..d2b3223ce4b9c877956e00e62d1e08ecfad35b08 100755 (executable)
@@ -1,2 +1,10 @@
 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);