From 6b7717bf3729775538be433ac750b31b22cfcade Mon Sep 17 00:00:00 2001 From: Phil Dawes Date: Fri, 25 Sep 2009 20:43:01 +0100 Subject: [PATCH] forwarding functions replaced with PRIMITIVE_FORWARD() macro --- vm/alien.cpp | 35 ++----- vm/arrays.cpp | 10 +- vm/byte_arrays.cpp | 15 +-- vm/callstack.cpp | 30 ++---- vm/code_heap.cpp | 10 +- vm/contexts.cpp | 25 +---- vm/data_gc.cpp | 20 +--- vm/data_heap.cpp | 25 +---- vm/debug.cpp | 5 +- vm/dispatch.cpp | 20 +--- vm/errors.cpp | 10 +- vm/image.cpp | 10 +- vm/inline_cache.cpp | 10 +- vm/io.cpp | 40 ++------ vm/math.cpp | 220 +++++++++---------------------------------- vm/os-unix.cpp | 5 +- vm/os-windows-ce.cpp | 5 +- vm/os-windows.cpp | 5 +- vm/primitives.hpp | 9 +- vm/profiler.cpp | 5 +- vm/quotations.cpp | 20 +--- vm/run.cpp | 40 ++------ vm/strings.cpp | 25 +---- vm/tuples.cpp | 10 +- vm/words.cpp | 20 +--- 25 files changed, 132 insertions(+), 497 deletions(-) diff --git a/vm/alien.cpp b/vm/alien.cpp index 0242c12c9e..2f82071aa8 100755 --- a/vm/alien.cpp +++ b/vm/alien.cpp @@ -69,10 +69,7 @@ inline void factor_vm::primitive_displaced_alien() } } -PRIMITIVE(displaced_alien) -{ - PRIMITIVE_GETVM()->primitive_displaced_alien(); -} +PRIMITIVE_FORWARD(displaced_alien) /* address of an object representing a C pointer. Explicitly throw an error if the object is a byte array, as a sanity check. */ @@ -81,10 +78,7 @@ inline void factor_vm::primitive_alien_address() box_unsigned_cell((cell)pinned_alien_offset(dpop())); } -PRIMITIVE(alien_address) -{ - PRIMITIVE_GETVM()->primitive_alien_address(); -} +PRIMITIVE_FORWARD(alien_address) /* pop ( alien n ) from datastack, return alien's address plus n */ void *factor_vm::alien_pointer() @@ -131,10 +125,7 @@ inline void factor_vm::primitive_dlopen() dpush(library.value()); } -PRIMITIVE(dlopen) -{ - PRIMITIVE_GETVM()->primitive_dlopen(); -} +PRIMITIVE_FORWARD(dlopen) /* look up a symbol in a native library */ inline void factor_vm::primitive_dlsym() @@ -158,10 +149,7 @@ inline void factor_vm::primitive_dlsym() } } -PRIMITIVE(dlsym) -{ - PRIMITIVE_GETVM()->primitive_dlsym(); -} +PRIMITIVE_FORWARD(dlsym) /* close a native library handle */ inline void factor_vm::primitive_dlclose() @@ -171,10 +159,7 @@ inline void factor_vm::primitive_dlclose() ffi_dlclose(d); } -PRIMITIVE(dlclose) -{ - PRIMITIVE_GETVM()->primitive_dlclose(); -} +PRIMITIVE_FORWARD(dlclose) inline void factor_vm::primitive_dll_validp() { @@ -185,10 +170,7 @@ inline void factor_vm::primitive_dll_validp() dpush(untag_check(library)->dll == NULL ? F : T); } -PRIMITIVE(dll_validp) -{ - PRIMITIVE_GETVM()->primitive_dll_validp(); -} +PRIMITIVE_FORWARD(dll_validp) /* gets the address of an object representing a C pointer */ char *factor_vm::alien_offset(cell obj) @@ -308,9 +290,6 @@ inline void factor_vm::primitive_vm_ptr() box_alien(this); } -PRIMITIVE(vm_ptr) -{ - PRIMITIVE_GETVM()->primitive_vm_ptr(); -} +PRIMITIVE_FORWARD(vm_ptr) } diff --git a/vm/arrays.cpp b/vm/arrays.cpp index a50500a2db..4188c8bf0b 100644 --- a/vm/arrays.cpp +++ b/vm/arrays.cpp @@ -31,10 +31,7 @@ inline void factor_vm::primitive_array() dpush(tag(allot_array(size,initial))); } -PRIMITIVE(array) -{ - PRIMITIVE_GETVM()->primitive_array(); -} +PRIMITIVE_FORWARD(array) cell factor_vm::allot_array_1(cell obj_) { @@ -75,10 +72,7 @@ inline void factor_vm::primitive_resize_array() dpush(tag(reallot_array(a,capacity))); } -PRIMITIVE(resize_array) -{ - PRIMITIVE_GETVM()->primitive_resize_array(); -} +PRIMITIVE_FORWARD(resize_array) void growable_array::add(cell elt_) { diff --git a/vm/byte_arrays.cpp b/vm/byte_arrays.cpp index 4213ed45a8..9af981e61e 100644 --- a/vm/byte_arrays.cpp +++ b/vm/byte_arrays.cpp @@ -16,10 +16,7 @@ inline void factor_vm::primitive_byte_array() dpush(tag(allot_byte_array(size))); } -PRIMITIVE(byte_array) -{ - PRIMITIVE_GETVM()->primitive_byte_array(); -} +PRIMITIVE_FORWARD(byte_array) inline void factor_vm::primitive_uninitialized_byte_array() { @@ -27,10 +24,7 @@ inline void factor_vm::primitive_uninitialized_byte_array() dpush(tag(allot_array_internal(size))); } -PRIMITIVE(uninitialized_byte_array) -{ - PRIMITIVE_GETVM()->primitive_uninitialized_byte_array(); -} +PRIMITIVE_FORWARD(uninitialized_byte_array) inline void factor_vm::primitive_resize_byte_array() { @@ -39,10 +33,7 @@ inline void factor_vm::primitive_resize_byte_array() dpush(tag(reallot_array(array,capacity))); } -PRIMITIVE(resize_byte_array) -{ - PRIMITIVE_GETVM()->primitive_resize_byte_array(); -} +PRIMITIVE_FORWARD(resize_byte_array) void growable_byte_array::append_bytes(void *elts, cell len) { diff --git a/vm/callstack.cpp b/vm/callstack.cpp index 445ebf88ee..3518feafc1 100755 --- a/vm/callstack.cpp +++ b/vm/callstack.cpp @@ -60,10 +60,7 @@ inline void factor_vm::primitive_callstack() dpush(tag(stack)); } -PRIMITIVE(callstack) -{ - PRIMITIVE_GETVM()->primitive_callstack(); -} +PRIMITIVE_FORWARD(callstack) inline void factor_vm::primitive_set_callstack() { @@ -78,10 +75,7 @@ inline void factor_vm::primitive_set_callstack() critical_error("Bug in set_callstack()",0); } -PRIMITIVE(set_callstack) -{ - PRIMITIVE_GETVM()->primitive_set_callstack(); -} +PRIMITIVE_FORWARD(set_callstack) code_block *factor_vm::frame_code(stack_frame *frame) { @@ -172,10 +166,7 @@ inline void factor_vm::primitive_callstack_to_array() dpush(accum.frames.elements.value()); } -PRIMITIVE(callstack_to_array) -{ - PRIMITIVE_GETVM()->primitive_callstack_to_array(); -} +PRIMITIVE_FORWARD(callstack_to_array) stack_frame *factor_vm::innermost_stack_frame(callstack *stack) { @@ -203,20 +194,14 @@ inline void factor_vm::primitive_innermost_stack_frame_executing() dpush(frame_executing(innermost_stack_frame(untag_check(dpop())))); } -PRIMITIVE(innermost_stack_frame_executing) -{ - PRIMITIVE_GETVM()->primitive_innermost_stack_frame_executing(); -} +PRIMITIVE_FORWARD(innermost_stack_frame_executing) inline void factor_vm::primitive_innermost_stack_frame_scan() { dpush(frame_scan(innermost_stack_frame_quot(untag_check(dpop())))); } -PRIMITIVE(innermost_stack_frame_scan) -{ - PRIMITIVE_GETVM()->primitive_innermost_stack_frame_scan(); -} +PRIMITIVE_FORWARD(innermost_stack_frame_scan) inline void factor_vm::primitive_set_innermost_stack_frame_quot() { @@ -234,10 +219,7 @@ inline void factor_vm::primitive_set_innermost_stack_frame_quot() FRAME_RETURN_ADDRESS(inner) = (char *)quot->xt + offset; } -PRIMITIVE(set_innermost_stack_frame_quot) -{ - PRIMITIVE_GETVM()->primitive_set_innermost_stack_frame_quot(); -} +PRIMITIVE_FORWARD(set_innermost_stack_frame_quot) /* called before entry into Factor code. */ void factor_vm::save_callstack_bottom(stack_frame *callstack_bottom) diff --git a/vm/code_heap.cpp b/vm/code_heap.cpp index b2361d94ce..7d70b4c254 100755 --- a/vm/code_heap.cpp +++ b/vm/code_heap.cpp @@ -106,10 +106,7 @@ inline void factor_vm::primitive_modify_code_heap() update_code_heap_words(); } -PRIMITIVE(modify_code_heap) -{ - PRIMITIVE_GETVM()->primitive_modify_code_heap(); -} +PRIMITIVE_FORWARD(modify_code_heap) /* Push the free space and total size of the code heap */ inline void factor_vm::primitive_code_room() @@ -122,10 +119,7 @@ inline void factor_vm::primitive_code_room() dpush(tag_fixnum(max_free / 1024)); } -PRIMITIVE(code_room) -{ - PRIMITIVE_GETVM()->primitive_code_room(); -} +PRIMITIVE_FORWARD(code_room) code_block *factor_vm::forward_xt(code_block *compiled) { diff --git a/vm/contexts.cpp b/vm/contexts.cpp index 6e821552ed..6e51ed8ba9 100644 --- a/vm/contexts.cpp +++ b/vm/contexts.cpp @@ -146,10 +146,7 @@ inline void factor_vm::primitive_datastack() general_error(ERROR_DS_UNDERFLOW,F,F,NULL); } -PRIMITIVE(datastack) -{ - PRIMITIVE_GETVM()->primitive_datastack(); -} +PRIMITIVE_FORWARD(datastack) inline void factor_vm::primitive_retainstack() { @@ -157,10 +154,7 @@ inline void factor_vm::primitive_retainstack() general_error(ERROR_RS_UNDERFLOW,F,F,NULL); } -PRIMITIVE(retainstack) -{ - PRIMITIVE_GETVM()->primitive_retainstack(); -} +PRIMITIVE_FORWARD(retainstack) /* returns pointer to top of stack */ cell factor_vm::array_to_stack(array *array, cell bottom) @@ -175,20 +169,14 @@ inline void factor_vm::primitive_set_datastack() ds = array_to_stack(untag_check(dpop()),ds_bot); } -PRIMITIVE(set_datastack) -{ - PRIMITIVE_GETVM()->primitive_set_datastack(); -} +PRIMITIVE_FORWARD(set_datastack) inline void factor_vm::primitive_set_retainstack() { rs = array_to_stack(untag_check(dpop()),rs_bot); } -PRIMITIVE(set_retainstack) -{ - PRIMITIVE_GETVM()->primitive_set_retainstack(); -} +PRIMITIVE_FORWARD(set_retainstack) /* Used to implement call( */ inline void factor_vm::primitive_check_datastack() @@ -216,9 +204,6 @@ inline void factor_vm::primitive_check_datastack() } } -PRIMITIVE(check_datastack) -{ - PRIMITIVE_GETVM()->primitive_check_datastack(); -} +PRIMITIVE_FORWARD(check_datastack) } diff --git a/vm/data_gc.cpp b/vm/data_gc.cpp index 0c0b995732..18c38cade3 100755 --- a/vm/data_gc.cpp +++ b/vm/data_gc.cpp @@ -573,10 +573,7 @@ inline void factor_vm::primitive_gc() gc(); } -PRIMITIVE(gc) -{ - PRIMITIVE_GETVM()->primitive_gc(); -} +PRIMITIVE_FORWARD(gc) inline void factor_vm::primitive_gc_stats() { @@ -608,10 +605,7 @@ inline void factor_vm::primitive_gc_stats() dpush(result.elements.value()); } -PRIMITIVE(gc_stats) -{ - PRIMITIVE_GETVM()->primitive_gc_stats(); -} +PRIMITIVE_FORWARD(gc_stats) void factor_vm::clear_gc_stats() { @@ -629,10 +623,7 @@ inline void factor_vm::primitive_clear_gc_stats() clear_gc_stats(); } -PRIMITIVE(clear_gc_stats) -{ - PRIMITIVE_GETVM()->primitive_clear_gc_stats(); -} +PRIMITIVE_FORWARD(clear_gc_stats) /* classes.tuple uses this to reshape tuples; tools.deploy.shaker uses this to coalesce equal but distinct quotations and wrappers. */ @@ -665,10 +656,7 @@ inline void factor_vm::primitive_become() compile_all_words(); } -PRIMITIVE(become) -{ - PRIMITIVE_GETVM()->primitive_become(); -} +PRIMITIVE_FORWARD(become) void factor_vm::inline_gc(cell *gc_roots_base, cell gc_roots_size) { diff --git a/vm/data_heap.cpp b/vm/data_heap.cpp index 72bc9c5d84..5eaa715e6c 100755 --- a/vm/data_heap.cpp +++ b/vm/data_heap.cpp @@ -222,10 +222,7 @@ inline void factor_vm::primitive_size() box_unsigned_cell(object_size(dpop())); } -PRIMITIVE(size) -{ - PRIMITIVE_GETVM()->primitive_size(); -} +PRIMITIVE_FORWARD(size) /* The number of cells from the start of the object which should be scanned by the GC. Some types have a binary payload at the end (string, word, DLL) which @@ -284,10 +281,7 @@ inline void factor_vm::primitive_data_room() dpush(a.elements.value()); } -PRIMITIVE(data_room) -{ - PRIMITIVE_GETVM()->primitive_data_room(); -} +PRIMITIVE_FORWARD(data_room) /* Disables GC and activates next-object ( -- obj ) primitive */ void factor_vm::begin_scan() @@ -306,10 +300,7 @@ inline void factor_vm::primitive_begin_scan() begin_scan(); } -PRIMITIVE(begin_scan) -{ - PRIMITIVE_GETVM()->primitive_begin_scan(); -} +PRIMITIVE_FORWARD(begin_scan) cell factor_vm::next_object() { @@ -330,10 +321,7 @@ inline void factor_vm::primitive_next_object() dpush(next_object()); } -PRIMITIVE(next_object) -{ - PRIMITIVE_GETVM()->primitive_next_object(); -} +PRIMITIVE_FORWARD(next_object) /* Re-enables GC */ inline void factor_vm::primitive_end_scan() @@ -341,10 +329,7 @@ inline void factor_vm::primitive_end_scan() gc_off = false; } -PRIMITIVE(end_scan) -{ - PRIMITIVE_GETVM()->primitive_end_scan(); -} +PRIMITIVE_FORWARD(end_scan) template void factor_vm::each_object(TYPE &functor) { diff --git a/vm/debug.cpp b/vm/debug.cpp index 2b8264ee41..1ec73760d3 100755 --- a/vm/debug.cpp +++ b/vm/debug.cpp @@ -484,9 +484,6 @@ inline void factor_vm::primitive_die() factorbug(); } -PRIMITIVE(die) -{ - PRIMITIVE_GETVM()->primitive_die(); -} +PRIMITIVE_FORWARD(die) } diff --git a/vm/dispatch.cpp b/vm/dispatch.cpp index 1e13e90d5a..c283a3b9d7 100755 --- a/vm/dispatch.cpp +++ b/vm/dispatch.cpp @@ -120,10 +120,7 @@ inline void factor_vm::primitive_lookup_method() dpush(lookup_method(obj,methods)); } -PRIMITIVE(lookup_method) -{ - PRIMITIVE_GETVM()->primitive_lookup_method(); -} +PRIMITIVE_FORWARD(lookup_method) cell factor_vm::object_class(cell obj) { @@ -169,20 +166,14 @@ inline void factor_vm::primitive_mega_cache_miss() dpush(method); } -PRIMITIVE(mega_cache_miss) -{ - PRIMITIVE_GETVM()->primitive_mega_cache_miss(); -} +PRIMITIVE_FORWARD(mega_cache_miss) inline void factor_vm::primitive_reset_dispatch_stats() { megamorphic_cache_hits = megamorphic_cache_misses = 0; } -PRIMITIVE(reset_dispatch_stats) -{ - PRIMITIVE_GETVM()->primitive_reset_dispatch_stats(); -} +PRIMITIVE_FORWARD(reset_dispatch_stats) inline void factor_vm::primitive_dispatch_stats() { @@ -193,10 +184,7 @@ inline void factor_vm::primitive_dispatch_stats() dpush(stats.elements.value()); } -PRIMITIVE(dispatch_stats) -{ - PRIMITIVE_GETVM()->primitive_dispatch_stats(); -} +PRIMITIVE_FORWARD(dispatch_stats) void quotation_jit::emit_mega_cache_lookup(cell methods_, fixnum index, cell cache_) { diff --git a/vm/errors.cpp b/vm/errors.cpp index 4d9d06f7e2..78a6652902 100755 --- a/vm/errors.cpp +++ b/vm/errors.cpp @@ -133,10 +133,7 @@ inline void factor_vm::primitive_call_clear() throw_impl(dpop(),stack_chain->callstack_bottom,this); } -PRIMITIVE(call_clear) -{ - PRIMITIVE_GETVM()->primitive_call_clear(); -} +PRIMITIVE_FORWARD(call_clear) /* For testing purposes */ inline void factor_vm::primitive_unimplemented() @@ -144,10 +141,7 @@ inline void factor_vm::primitive_unimplemented() not_implemented_error(); } -PRIMITIVE(unimplemented) -{ - PRIMITIVE_GETVM()->primitive_unimplemented(); -} +PRIMITIVE_FORWARD(unimplemented) void factor_vm::memory_signal_handler_impl() { diff --git a/vm/image.cpp b/vm/image.cpp index 61b0de1b2a..ade654c2e2 100755 --- a/vm/image.cpp +++ b/vm/image.cpp @@ -128,10 +128,7 @@ inline void factor_vm::primitive_save_image() save_image((vm_char *)(path.untagged() + 1)); } -PRIMITIVE(save_image) -{ - PRIMITIVE_GETVM()->primitive_save_image(); -} +PRIMITIVE_FORWARD(save_image) inline void factor_vm::primitive_save_image_and_exit() { @@ -159,10 +156,7 @@ inline void factor_vm::primitive_save_image_and_exit() exit(1); } -PRIMITIVE(save_image_and_exit) -{ - PRIMITIVE_GETVM()->primitive_save_image_and_exit(); -} +PRIMITIVE_FORWARD(save_image_and_exit) void factor_vm::data_fixup(cell *cell) { diff --git a/vm/inline_cache.cpp b/vm/inline_cache.cpp index 9bb1d1c2f1..71076821b5 100755 --- a/vm/inline_cache.cpp +++ b/vm/inline_cache.cpp @@ -257,10 +257,7 @@ inline void factor_vm::primitive_reset_inline_cache_stats() for(i = 0; i < 4; i++) pic_counts[i] = 0; } -PRIMITIVE(reset_inline_cache_stats) -{ - PRIMITIVE_GETVM()->primitive_reset_inline_cache_stats(); -} +PRIMITIVE_FORWARD(reset_inline_cache_stats) inline void factor_vm::primitive_inline_cache_stats() { @@ -275,9 +272,6 @@ inline void factor_vm::primitive_inline_cache_stats() dpush(stats.elements.value()); } -PRIMITIVE(inline_cache_stats) -{ - PRIMITIVE_GETVM()->primitive_inline_cache_stats(); -} +PRIMITIVE_FORWARD(inline_cache_stats) } diff --git a/vm/io.cpp b/vm/io.cpp index 1ec9cf2cb6..b907813fdb 100755 --- a/vm/io.cpp +++ b/vm/io.cpp @@ -52,10 +52,7 @@ inline void factor_vm::primitive_fopen() } } -PRIMITIVE(fopen) -{ - PRIMITIVE_GETVM()->primitive_fopen(); -} +PRIMITIVE_FORWARD(fopen) inline void factor_vm::primitive_fgetc() { @@ -82,10 +79,7 @@ inline void factor_vm::primitive_fgetc() } } -PRIMITIVE(fgetc) -{ - PRIMITIVE_GETVM()->primitive_fgetc(); -} +PRIMITIVE_FORWARD(fgetc) inline void factor_vm::primitive_fread() { @@ -127,10 +121,7 @@ inline void factor_vm::primitive_fread() } } -PRIMITIVE(fread) -{ - PRIMITIVE_GETVM()->primitive_fread(); -} +PRIMITIVE_FORWARD(fread) inline void factor_vm::primitive_fputc() { @@ -150,10 +141,7 @@ inline void factor_vm::primitive_fputc() } } -PRIMITIVE(fputc) -{ - PRIMITIVE_GETVM()->primitive_fputc(); -} +PRIMITIVE_FORWARD(fputc) inline void factor_vm::primitive_fwrite() { @@ -184,10 +172,7 @@ inline void factor_vm::primitive_fwrite() } } -PRIMITIVE(fwrite) -{ - PRIMITIVE_GETVM()->primitive_fwrite(); -} +PRIMITIVE_FORWARD(fwrite) inline void factor_vm::primitive_fseek() { @@ -214,10 +199,7 @@ inline void factor_vm::primitive_fseek() } } -PRIMITIVE(fseek) -{ - PRIMITIVE_GETVM()->primitive_fseek(); -} +PRIMITIVE_FORWARD(fseek) inline void factor_vm::primitive_fflush() { @@ -231,10 +213,7 @@ inline void factor_vm::primitive_fflush() } } -PRIMITIVE(fflush) -{ - PRIMITIVE_GETVM()->primitive_fflush(); -} +PRIMITIVE_FORWARD(fflush) inline void factor_vm::primitive_fclose() { @@ -248,10 +227,7 @@ inline void factor_vm::primitive_fclose() } } -PRIMITIVE(fclose) -{ - PRIMITIVE_GETVM()->primitive_fclose(); -} +PRIMITIVE_FORWARD(fclose) /* This function is used by FFI I/O. Accessing the errno global directly is not portable, since on some libc's errno is not a global but a funky macro that diff --git a/vm/math.cpp b/vm/math.cpp index 638d9fa85c..fde2bc6748 100755 --- a/vm/math.cpp +++ b/vm/math.cpp @@ -8,20 +8,14 @@ inline void factor_vm::primitive_bignum_to_fixnum() drepl(tag_fixnum(bignum_to_fixnum(untag(dpeek())))); } -PRIMITIVE(bignum_to_fixnum) -{ - PRIMITIVE_GETVM()->primitive_bignum_to_fixnum(); -} +PRIMITIVE_FORWARD(bignum_to_fixnum) inline void factor_vm::primitive_float_to_fixnum() { drepl(tag_fixnum(float_to_fixnum(dpeek()))); } -PRIMITIVE(float_to_fixnum) -{ - PRIMITIVE_GETVM()->primitive_float_to_fixnum(); -} +PRIMITIVE_FORWARD(float_to_fixnum) /* Division can only overflow when we are dividing the most negative fixnum by -1. */ @@ -36,10 +30,7 @@ inline void factor_vm::primitive_fixnum_divint() drepl(tag_fixnum(result)); } -PRIMITIVE(fixnum_divint) -{ - PRIMITIVE_GETVM()->primitive_fixnum_divint(); -} +PRIMITIVE_FORWARD(fixnum_divint) inline void factor_vm::primitive_fixnum_divmod() { @@ -57,10 +48,7 @@ inline void factor_vm::primitive_fixnum_divmod() } } -PRIMITIVE(fixnum_divmod) -{ - PRIMITIVE_GETVM()->primitive_fixnum_divmod(); -} +PRIMITIVE_FORWARD(fixnum_divmod) /* * If we're shifting right by n bits, we won't overflow as long as none of the @@ -108,30 +96,21 @@ inline void factor_vm::primitive_fixnum_shift() fixnum_to_bignum(x),y))); } -PRIMITIVE(fixnum_shift) -{ - PRIMITIVE_GETVM()->primitive_fixnum_shift(); -} +PRIMITIVE_FORWARD(fixnum_shift) inline void factor_vm::primitive_fixnum_to_bignum() { drepl(tag(fixnum_to_bignum(untag_fixnum(dpeek())))); } -PRIMITIVE(fixnum_to_bignum) -{ - PRIMITIVE_GETVM()->primitive_fixnum_to_bignum(); -} +PRIMITIVE_FORWARD(fixnum_to_bignum) inline void factor_vm::primitive_float_to_bignum() { drepl(tag(float_to_bignum(dpeek()))); } -PRIMITIVE(float_to_bignum) -{ - PRIMITIVE_GETVM()->primitive_float_to_bignum(); -} +PRIMITIVE_FORWARD(float_to_bignum) #define POP_BIGNUMS(x,y) \ bignum * y = untag(dpop()); \ @@ -143,10 +122,7 @@ inline void factor_vm::primitive_bignum_eq() box_boolean(bignum_equal_p(x,y)); } -PRIMITIVE(bignum_eq) -{ - PRIMITIVE_GETVM()->primitive_bignum_eq(); -} +PRIMITIVE_FORWARD(bignum_eq) inline void factor_vm::primitive_bignum_add() { @@ -154,10 +130,7 @@ inline void factor_vm::primitive_bignum_add() dpush(tag(bignum_add(x,y))); } -PRIMITIVE(bignum_add) -{ - PRIMITIVE_GETVM()->primitive_bignum_add(); -} +PRIMITIVE_FORWARD(bignum_add) inline void factor_vm::primitive_bignum_subtract() { @@ -165,10 +138,7 @@ inline void factor_vm::primitive_bignum_subtract() dpush(tag(bignum_subtract(x,y))); } -PRIMITIVE(bignum_subtract) -{ - PRIMITIVE_GETVM()->primitive_bignum_subtract(); -} +PRIMITIVE_FORWARD(bignum_subtract) inline void factor_vm::primitive_bignum_multiply() { @@ -176,10 +146,7 @@ inline void factor_vm::primitive_bignum_multiply() dpush(tag(bignum_multiply(x,y))); } -PRIMITIVE(bignum_multiply) -{ - PRIMITIVE_GETVM()->primitive_bignum_multiply(); -} +PRIMITIVE_FORWARD(bignum_multiply) inline void factor_vm::primitive_bignum_divint() { @@ -187,10 +154,7 @@ inline void factor_vm::primitive_bignum_divint() dpush(tag(bignum_quotient(x,y))); } -PRIMITIVE(bignum_divint) -{ - PRIMITIVE_GETVM()->primitive_bignum_divint(); -} +PRIMITIVE_FORWARD(bignum_divint) inline void factor_vm::primitive_bignum_divmod() { @@ -201,10 +165,7 @@ inline void factor_vm::primitive_bignum_divmod() dpush(tag(r)); } -PRIMITIVE(bignum_divmod) -{ - PRIMITIVE_GETVM()->primitive_bignum_divmod(); -} +PRIMITIVE_FORWARD(bignum_divmod) inline void factor_vm::primitive_bignum_mod() { @@ -212,10 +173,7 @@ inline void factor_vm::primitive_bignum_mod() dpush(tag(bignum_remainder(x,y))); } -PRIMITIVE(bignum_mod) -{ - PRIMITIVE_GETVM()->primitive_bignum_mod(); -} +PRIMITIVE_FORWARD(bignum_mod) inline void factor_vm::primitive_bignum_and() { @@ -223,10 +181,7 @@ inline void factor_vm::primitive_bignum_and() dpush(tag(bignum_bitwise_and(x,y))); } -PRIMITIVE(bignum_and) -{ - PRIMITIVE_GETVM()->primitive_bignum_and(); -} +PRIMITIVE_FORWARD(bignum_and) inline void factor_vm::primitive_bignum_or() { @@ -234,10 +189,7 @@ inline void factor_vm::primitive_bignum_or() dpush(tag(bignum_bitwise_ior(x,y))); } -PRIMITIVE(bignum_or) -{ - PRIMITIVE_GETVM()->primitive_bignum_or(); -} +PRIMITIVE_FORWARD(bignum_or) inline void factor_vm::primitive_bignum_xor() { @@ -245,10 +197,7 @@ inline void factor_vm::primitive_bignum_xor() dpush(tag(bignum_bitwise_xor(x,y))); } -PRIMITIVE(bignum_xor) -{ - PRIMITIVE_GETVM()->primitive_bignum_xor(); -} +PRIMITIVE_FORWARD(bignum_xor) inline void factor_vm::primitive_bignum_shift() { @@ -257,10 +206,7 @@ inline void factor_vm::primitive_bignum_shift() dpush(tag(bignum_arithmetic_shift(x,y))); } -PRIMITIVE(bignum_shift) -{ - PRIMITIVE_GETVM()->primitive_bignum_shift(); -} +PRIMITIVE_FORWARD(bignum_shift) inline void factor_vm::primitive_bignum_less() { @@ -268,10 +214,7 @@ inline void factor_vm::primitive_bignum_less() box_boolean(bignum_compare(x,y) == bignum_comparison_less); } -PRIMITIVE(bignum_less) -{ - PRIMITIVE_GETVM()->primitive_bignum_less(); -} +PRIMITIVE_FORWARD(bignum_less) inline void factor_vm::primitive_bignum_lesseq() { @@ -279,10 +222,7 @@ inline void factor_vm::primitive_bignum_lesseq() box_boolean(bignum_compare(x,y) != bignum_comparison_greater); } -PRIMITIVE(bignum_lesseq) -{ - PRIMITIVE_GETVM()->primitive_bignum_lesseq(); -} +PRIMITIVE_FORWARD(bignum_lesseq) inline void factor_vm::primitive_bignum_greater() { @@ -290,10 +230,7 @@ inline void factor_vm::primitive_bignum_greater() box_boolean(bignum_compare(x,y) == bignum_comparison_greater); } -PRIMITIVE(bignum_greater) -{ - PRIMITIVE_GETVM()->primitive_bignum_greater(); -} +PRIMITIVE_FORWARD(bignum_greater) inline void factor_vm::primitive_bignum_greatereq() { @@ -301,20 +238,14 @@ inline void factor_vm::primitive_bignum_greatereq() box_boolean(bignum_compare(x,y) != bignum_comparison_less); } -PRIMITIVE(bignum_greatereq) -{ - PRIMITIVE_GETVM()->primitive_bignum_greatereq(); -} +PRIMITIVE_FORWARD(bignum_greatereq) inline void factor_vm::primitive_bignum_not() { drepl(tag(bignum_bitwise_not(untag(dpeek())))); } -PRIMITIVE(bignum_not) -{ - PRIMITIVE_GETVM()->primitive_bignum_not(); -} +PRIMITIVE_FORWARD(bignum_not) inline void factor_vm::primitive_bignum_bitp() { @@ -323,20 +254,14 @@ inline void factor_vm::primitive_bignum_bitp() box_boolean(bignum_logbitp(bit,x)); } -PRIMITIVE(bignum_bitp) -{ - PRIMITIVE_GETVM()->primitive_bignum_bitp(); -} +PRIMITIVE_FORWARD(bignum_bitp) inline void factor_vm::primitive_bignum_log2() { drepl(tag(bignum_integer_length(untag(dpeek())))); } -PRIMITIVE(bignum_log2) -{ - PRIMITIVE_GETVM()->primitive_bignum_log2(); -} +PRIMITIVE_FORWARD(bignum_log2) unsigned int factor_vm::bignum_producer(unsigned int digit) { @@ -356,10 +281,7 @@ inline void factor_vm::primitive_byte_array_to_bignum() drepl(tag(result)); } -PRIMITIVE(byte_array_to_bignum) -{ - PRIMITIVE_GETVM()->primitive_byte_array_to_bignum(); -} +PRIMITIVE_FORWARD(byte_array_to_bignum) cell factor_vm::unbox_array_size() { @@ -399,20 +321,14 @@ inline void factor_vm::primitive_fixnum_to_float() drepl(allot_float(fixnum_to_float(dpeek()))); } -PRIMITIVE(fixnum_to_float) -{ - PRIMITIVE_GETVM()->primitive_fixnum_to_float(); -} +PRIMITIVE_FORWARD(fixnum_to_float) inline void factor_vm::primitive_bignum_to_float() { drepl(allot_float(bignum_to_float(dpeek()))); } -PRIMITIVE(bignum_to_float) -{ - PRIMITIVE_GETVM()->primitive_bignum_to_float(); -} +PRIMITIVE_FORWARD(bignum_to_float) inline void factor_vm::primitive_str_to_float() { @@ -428,10 +344,7 @@ inline void factor_vm::primitive_str_to_float() drepl(F); } -PRIMITIVE(str_to_float) -{ - PRIMITIVE_GETVM()->primitive_str_to_float(); -} +PRIMITIVE_FORWARD(str_to_float) inline void factor_vm::primitive_float_to_str() { @@ -440,10 +353,7 @@ inline void factor_vm::primitive_float_to_str() dpush(tag(array)); } -PRIMITIVE(float_to_str) -{ - PRIMITIVE_GETVM()->primitive_float_to_str(); -} +PRIMITIVE_FORWARD(float_to_str) #define POP_FLOATS(x,y) \ double y = untag_float(dpop()); \ @@ -455,10 +365,7 @@ inline void factor_vm::primitive_float_eq() box_boolean(x == y); } -PRIMITIVE(float_eq) -{ - PRIMITIVE_GETVM()->primitive_float_eq(); -} +PRIMITIVE_FORWARD(float_eq) inline void factor_vm::primitive_float_add() { @@ -466,10 +373,7 @@ inline void factor_vm::primitive_float_add() box_double(x + y); } -PRIMITIVE(float_add) -{ - PRIMITIVE_GETVM()->primitive_float_add(); -} +PRIMITIVE_FORWARD(float_add) inline void factor_vm::primitive_float_subtract() { @@ -477,10 +381,7 @@ inline void factor_vm::primitive_float_subtract() box_double(x - y); } -PRIMITIVE(float_subtract) -{ - PRIMITIVE_GETVM()->primitive_float_subtract(); -} +PRIMITIVE_FORWARD(float_subtract) inline void factor_vm::primitive_float_multiply() { @@ -488,10 +389,7 @@ inline void factor_vm::primitive_float_multiply() box_double(x * y); } -PRIMITIVE(float_multiply) -{ - PRIMITIVE_GETVM()->primitive_float_multiply(); -} +PRIMITIVE_FORWARD(float_multiply) inline void factor_vm::primitive_float_divfloat() { @@ -499,10 +397,7 @@ inline void factor_vm::primitive_float_divfloat() box_double(x / y); } -PRIMITIVE(float_divfloat) -{ - PRIMITIVE_GETVM()->primitive_float_divfloat(); -} +PRIMITIVE_FORWARD(float_divfloat) inline void factor_vm::primitive_float_mod() { @@ -510,10 +405,7 @@ inline void factor_vm::primitive_float_mod() box_double(fmod(x,y)); } -PRIMITIVE(float_mod) -{ - PRIMITIVE_GETVM()->primitive_float_mod(); -} +PRIMITIVE_FORWARD(float_mod) inline void factor_vm::primitive_float_less() { @@ -521,10 +413,7 @@ inline void factor_vm::primitive_float_less() box_boolean(x < y); } -PRIMITIVE(float_less) -{ - PRIMITIVE_GETVM()->primitive_float_less(); -} +PRIMITIVE_FORWARD(float_less) inline void factor_vm::primitive_float_lesseq() { @@ -532,10 +421,7 @@ inline void factor_vm::primitive_float_lesseq() box_boolean(x <= y); } -PRIMITIVE(float_lesseq) -{ - PRIMITIVE_GETVM()->primitive_float_lesseq(); -} +PRIMITIVE_FORWARD(float_lesseq) inline void factor_vm::primitive_float_greater() { @@ -543,10 +429,7 @@ inline void factor_vm::primitive_float_greater() box_boolean(x > y); } -PRIMITIVE(float_greater) -{ - PRIMITIVE_GETVM()->primitive_float_greater(); -} +PRIMITIVE_FORWARD(float_greater) inline void factor_vm::primitive_float_greatereq() { @@ -554,50 +437,35 @@ inline void factor_vm::primitive_float_greatereq() box_boolean(x >= y); } -PRIMITIVE(float_greatereq) -{ - PRIMITIVE_GETVM()->primitive_float_greatereq(); -} +PRIMITIVE_FORWARD(float_greatereq) inline void factor_vm::primitive_float_bits() { box_unsigned_4(float_bits(untag_float_check(dpop()))); } -PRIMITIVE(float_bits) -{ - PRIMITIVE_GETVM()->primitive_float_bits(); -} +PRIMITIVE_FORWARD(float_bits) inline void factor_vm::primitive_bits_float() { box_float(bits_float(to_cell(dpop()))); } -PRIMITIVE(bits_float) -{ - PRIMITIVE_GETVM()->primitive_bits_float(); -} +PRIMITIVE_FORWARD(bits_float) inline void factor_vm::primitive_double_bits() { box_unsigned_8(double_bits(untag_float_check(dpop()))); } -PRIMITIVE(double_bits) -{ - PRIMITIVE_GETVM()->primitive_double_bits(); -} +PRIMITIVE_FORWARD(double_bits) inline void factor_vm::primitive_bits_double() { box_double(bits_double(to_unsigned_8(dpop()))); } -PRIMITIVE(bits_double) -{ - PRIMITIVE_GETVM()->primitive_bits_double(); -} +PRIMITIVE_FORWARD(bits_double) fixnum factor_vm::to_fixnum(cell tagged) { diff --git a/vm/os-unix.cpp b/vm/os-unix.cpp index e9e26240cd..5e8112bb5b 100644 --- a/vm/os-unix.cpp +++ b/vm/os-unix.cpp @@ -84,10 +84,7 @@ inline void factor_vm::primitive_existsp() box_boolean(stat(path,&sb) >= 0); } -PRIMITIVE(existsp) -{ - PRIMITIVE_GETVM()->primitive_existsp(); -} +PRIMITIVE_FORWARD(existsp) segment *factor_vm::alloc_segment(cell size) { diff --git a/vm/os-windows-ce.cpp b/vm/os-windows-ce.cpp index 6454535f43..57e7cc69d0 100644 --- a/vm/os-windows-ce.cpp +++ b/vm/os-windows-ce.cpp @@ -30,10 +30,7 @@ char *getenv(char *name) return 0; /* unreachable */ } -PRIMITIVE(os_envs) -{ - vm->not_implemented_error(); -} +PRIMITIVE_FORWARD(os_envs) void c_to_factor_toplevel(cell quot) { diff --git a/vm/os-windows.cpp b/vm/os-windows.cpp index 4e06c0efb9..7d4b345da6 100644 --- a/vm/os-windows.cpp +++ b/vm/os-windows.cpp @@ -96,10 +96,7 @@ inline void factor_vm::primitive_existsp() box_boolean(windows_stat(path)); } -PRIMITIVE(existsp) -{ - PRIMITIVE_GETVM()->primitive_existsp(); -} +PRIMITIVE_FORWARD(existsp) segment *factor_vm::alloc_segment(cell size) { diff --git a/vm/primitives.hpp b/vm/primitives.hpp index 4be190d4e6..d17ebe5833 100644 --- a/vm/primitives.hpp +++ b/vm/primitives.hpp @@ -4,10 +4,17 @@ namespace factor #if defined(FACTOR_X86) extern "C" __attribute__ ((regparm (1))) typedef void (*primitive_type)(void *myvm); #define PRIMITIVE(name) extern "C" __attribute__ ((regparm (1))) void primitive_##name(void *myvm) + #define PRIMITIVE_FORWARD(name) extern "C" __attribute__ ((regparm (1))) void primitive_##name(void *myvm) \ + { \ + PRIMITIVE_GETVM()->primitive_##name(); \ + } #else extern "C" typedef void (*primitive_type)(void *myvm); #define PRIMITIVE(name) extern "C" void primitive_##name(void *myvm) + #define PRIMITIVE_FORWARD(name) extern "C" void primitive_##name(void *myvm) \ + { \ + PRIMITIVE_GETVM()->primitive_##name(); \ + } #endif - extern const primitive_type primitives[]; } diff --git a/vm/profiler.cpp b/vm/profiler.cpp index cd99c9f27c..b054ed1222 100755 --- a/vm/profiler.cpp +++ b/vm/profiler.cpp @@ -52,9 +52,6 @@ inline void factor_vm::primitive_profiling() set_profiling(to_boolean(dpop())); } -PRIMITIVE(profiling) -{ - PRIMITIVE_GETVM()->primitive_profiling(); -} +PRIMITIVE_FORWARD(profiling) } diff --git a/vm/quotations.cpp b/vm/quotations.cpp index 1bc6240481..d58d1f1988 100755 --- a/vm/quotations.cpp +++ b/vm/quotations.cpp @@ -294,10 +294,7 @@ inline void factor_vm::primitive_jit_compile() jit_compile(dpop(),true); } -PRIMITIVE(jit_compile) -{ - PRIMITIVE_GETVM()->primitive_jit_compile(); -} +PRIMITIVE_FORWARD(jit_compile) /* push a new quotation on the stack */ inline void factor_vm::primitive_array_to_quotation() @@ -311,10 +308,7 @@ inline void factor_vm::primitive_array_to_quotation() drepl(tag(quot)); } -PRIMITIVE(array_to_quotation) -{ - PRIMITIVE_GETVM()->primitive_array_to_quotation(); -} +PRIMITIVE_FORWARD(array_to_quotation) inline void factor_vm::primitive_quotation_xt() { @@ -322,10 +316,7 @@ inline void factor_vm::primitive_quotation_xt() drepl(allot_cell((cell)quot->xt)); } -PRIMITIVE(quotation_xt) -{ - PRIMITIVE_GETVM()->primitive_quotation_xt(); -} +PRIMITIVE_FORWARD(quotation_xt) void factor_vm::compile_all_words() { @@ -381,9 +372,6 @@ inline void factor_vm::primitive_quot_compiled_p() dpush(tag_boolean(quot->code != NULL)); } -PRIMITIVE(quot_compiled_p) -{ - PRIMITIVE_GETVM()->primitive_quot_compiled_p(); -} +PRIMITIVE_FORWARD(quot_compiled_p) } diff --git a/vm/run.cpp b/vm/run.cpp index 2f162e3ace..d2170f4055 100755 --- a/vm/run.cpp +++ b/vm/run.cpp @@ -9,10 +9,7 @@ inline void factor_vm::primitive_getenv() drepl(userenv[e]); } -PRIMITIVE(getenv) -{ - PRIMITIVE_GETVM()->primitive_getenv(); -} +PRIMITIVE_FORWARD(getenv) inline void factor_vm::primitive_setenv() { @@ -21,40 +18,28 @@ inline void factor_vm::primitive_setenv() userenv[e] = value; } -PRIMITIVE(setenv) -{ - PRIMITIVE_GETVM()->primitive_setenv(); -} +PRIMITIVE_FORWARD(setenv) inline void factor_vm::primitive_exit() { exit(to_fixnum(dpop())); } -PRIMITIVE(exit) -{ - PRIMITIVE_GETVM()->primitive_exit(); -} +PRIMITIVE_FORWARD(exit) inline void factor_vm::primitive_micros() { box_unsigned_8(current_micros()); } -PRIMITIVE(micros) -{ - PRIMITIVE_GETVM()->primitive_micros(); -} +PRIMITIVE_FORWARD(micros) inline void factor_vm::primitive_sleep() { sleep_micros(to_cell(dpop())); } -PRIMITIVE(sleep) -{ - PRIMITIVE_GETVM()->primitive_sleep(); -} +PRIMITIVE_FORWARD(sleep) inline void factor_vm::primitive_set_slot() { @@ -66,10 +51,7 @@ inline void factor_vm::primitive_set_slot() write_barrier(obj); } -PRIMITIVE(set_slot) -{ - PRIMITIVE_GETVM()->primitive_set_slot(); -} +PRIMITIVE_FORWARD(set_slot) inline void factor_vm::primitive_load_locals() { @@ -79,10 +61,7 @@ inline void factor_vm::primitive_load_locals() rs += sizeof(cell) * count; } -PRIMITIVE(load_locals) -{ - PRIMITIVE_GETVM()->primitive_load_locals(); -} +PRIMITIVE_FORWARD(load_locals) cell factor_vm::clone_object(cell obj_) { @@ -104,9 +83,6 @@ inline void factor_vm::primitive_clone() drepl(clone_object(dpeek())); } -PRIMITIVE(clone) -{ - PRIMITIVE_GETVM()->primitive_clone(); -} +PRIMITIVE_FORWARD(clone) } diff --git a/vm/strings.cpp b/vm/strings.cpp index 912706024e..fb5eb1093d 100644 --- a/vm/strings.cpp +++ b/vm/strings.cpp @@ -106,10 +106,7 @@ inline void factor_vm::primitive_string() dpush(tag(allot_string(length,initial))); } -PRIMITIVE(string) -{ - PRIMITIVE_GETVM()->primitive_string(); -} +PRIMITIVE_FORWARD(string) bool factor_vm::reallot_string_in_place_p(string *str, cell capacity) { @@ -167,10 +164,7 @@ inline void factor_vm::primitive_resize_string() dpush(tag(reallot_string(str,capacity))); } -PRIMITIVE(resize_string) -{ - PRIMITIVE_GETVM()->primitive_resize_string(); -} +PRIMITIVE_FORWARD(resize_string) inline void factor_vm::primitive_string_nth() { @@ -179,10 +173,7 @@ inline void factor_vm::primitive_string_nth() dpush(tag_fixnum(string_nth(str,index))); } -PRIMITIVE(string_nth) -{ - PRIMITIVE_GETVM()->primitive_string_nth(); -} +PRIMITIVE_FORWARD(string_nth) inline void factor_vm::primitive_set_string_nth_fast() { @@ -192,10 +183,7 @@ inline void factor_vm::primitive_set_string_nth_fast() set_string_nth_fast(str,index,value); } -PRIMITIVE(set_string_nth_fast) -{ - PRIMITIVE_GETVM()->primitive_set_string_nth_fast(); -} +PRIMITIVE_FORWARD(set_string_nth_fast) inline void factor_vm::primitive_set_string_nth_slow() { @@ -205,9 +193,6 @@ inline void factor_vm::primitive_set_string_nth_slow() set_string_nth_slow(str,index,value); } -PRIMITIVE(set_string_nth_slow) -{ - PRIMITIVE_GETVM()->primitive_set_string_nth_slow(); -} +PRIMITIVE_FORWARD(set_string_nth_slow) } diff --git a/vm/tuples.cpp b/vm/tuples.cpp index a89265f709..d2734d3dfb 100644 --- a/vm/tuples.cpp +++ b/vm/tuples.cpp @@ -23,10 +23,7 @@ inline void factor_vm::primitive_tuple() dpush(tag(t)); } -PRIMITIVE(tuple) -{ - PRIMITIVE_GETVM()->primitive_tuple(); -} +PRIMITIVE_FORWARD(tuple) /* push a new tuple on the stack, filling its slots from the stack */ inline void factor_vm::primitive_tuple_boa() @@ -39,9 +36,6 @@ inline void factor_vm::primitive_tuple_boa() dpush(t.value()); } -PRIMITIVE(tuple_boa) -{ - PRIMITIVE_GETVM()->primitive_tuple_boa(); -} +PRIMITIVE_FORWARD(tuple_boa) } diff --git a/vm/words.cpp b/vm/words.cpp index e99f483685..ce25313ea2 100644 --- a/vm/words.cpp +++ b/vm/words.cpp @@ -39,10 +39,7 @@ inline void factor_vm::primitive_word() dpush(tag(allot_word(vocab,name))); } -PRIMITIVE(word) -{ - PRIMITIVE_GETVM()->primitive_word(); -} +PRIMITIVE_FORWARD(word) /* word-xt ( word -- start end ) */ inline void factor_vm::primitive_word_xt() @@ -53,10 +50,7 @@ inline void factor_vm::primitive_word_xt() dpush(allot_cell((cell)code + code->size)); } -PRIMITIVE(word_xt) -{ - PRIMITIVE_GETVM()->primitive_word_xt(); -} +PRIMITIVE_FORWARD(word_xt) /* Allocates memory */ void factor_vm::update_word_xt(cell w_) @@ -85,10 +79,7 @@ inline void factor_vm::primitive_optimized_p() drepl(tag_boolean(word_optimized_p(untag_check(dpeek())))); } -PRIMITIVE(optimized_p) -{ - PRIMITIVE_GETVM()->primitive_optimized_p(); -} +PRIMITIVE_FORWARD(optimized_p) inline void factor_vm::primitive_wrapper() { @@ -97,9 +88,6 @@ inline void factor_vm::primitive_wrapper() drepl(tag(new_wrapper)); } -PRIMITIVE(wrapper) -{ - PRIMITIVE_GETVM()->primitive_wrapper(); -} +PRIMITIVE_FORWARD(wrapper) } -- 2.34.1