diff --git a/vm/alien.cpp b/vm/alien.cpp index fdfa887a8f..c53890f3b4 100755 --- a/vm/alien.cpp +++ b/vm/alien.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + /* gets the address of an object representing a C pointer, with the intention of storing the pointer across code which may potentially GC. */ char *pinned_alien_offset(CELL object) @@ -222,3 +225,5 @@ VM_C_API void box_medium_struct(CELL x1, CELL x2, CELL x3, CELL x4, CELL size) data[3] = x4; box_value_struct(data,size); } + +} diff --git a/vm/alien.hpp b/vm/alien.hpp index 377a4317bc..18678af0cf 100755 --- a/vm/alien.hpp +++ b/vm/alien.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + CELL allot_alien(CELL delegate, CELL displacement); PRIMITIVE(displaced_alien); @@ -42,3 +45,5 @@ VM_C_API void to_value_struct(CELL src, void *dest, CELL size); VM_C_API void box_value_struct(void *src, CELL size); VM_C_API void box_small_struct(CELL x, CELL y, CELL size); VM_C_API void box_medium_struct(CELL x1, CELL x2, CELL x3, CELL x4, CELL size); + +} diff --git a/vm/arrays.cpp b/vm/arrays.cpp index 3aa725e434..fde0d3b942 100644 --- a/vm/arrays.cpp +++ b/vm/arrays.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + /* make a new array with an initial element */ F_ARRAY *allot_array(CELL capacity, CELL fill_) { @@ -80,3 +83,5 @@ void growable_array::trim() { array = reallot_array(array.untagged(),count); } + +} diff --git a/vm/arrays.hpp b/vm/arrays.hpp index a42bc81833..87432404fb 100644 --- a/vm/arrays.hpp +++ b/vm/arrays.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + inline static CELL array_nth(F_ARRAY *array, CELL slot) { #ifdef FACTOR_DEBUG @@ -36,3 +39,5 @@ struct growable_array { void add(CELL elt); void trim(); }; + +} diff --git a/vm/bignum.cpp b/vm/bignum.cpp index 8cd17f7dc6..f5f9091750 100755 --- a/vm/bignum.cpp +++ b/vm/bignum.cpp @@ -56,6 +56,9 @@ MIT in each case. */ #include #include +namespace factor +{ + /* Exports */ int @@ -1841,3 +1844,5 @@ digit_stream_to_bignum(unsigned int n_digits, } } } + +} diff --git a/vm/bignum.hpp b/vm/bignum.hpp index 208a0e436d..f8058c9497 100644 --- a/vm/bignum.hpp +++ b/vm/bignum.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + /* :tabSize=2:indentSize=2:noTabs=true: Copyright (C) 1989-1992 Massachusetts Institute of Technology @@ -124,3 +127,5 @@ F_BIGNUM * digit_stream_to_bignum(unsigned int n_digits, unsigned int (*producer)(unsigned int), unsigned int radix, int negative_p); + +} diff --git a/vm/bignumint.hpp b/vm/bignumint.hpp index 72430eaa8e..deed0bd910 100644 --- a/vm/bignumint.hpp +++ b/vm/bignumint.hpp @@ -33,6 +33,9 @@ Technology nor of any adaptation thereof in any advertising, promotional, or sales literature without prior written consent from MIT in each case. */ +namespace factor +{ + /* Internal Interface to Bignum Code */ #undef BIGNUM_ZERO_P #undef BIGNUM_NEGATIVE_P @@ -98,3 +101,5 @@ typedef F_FIXNUM bignum_length_type; } #endif /* not BIGNUM_DISABLE_ASSERTION_CHECKS */ + +} diff --git a/vm/booleans.cpp b/vm/booleans.cpp index b63a67cd1c..9ff848058f 100644 --- a/vm/booleans.cpp +++ b/vm/booleans.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + VM_C_API void box_boolean(bool value) { dpush(value ? T : F); @@ -9,3 +12,5 @@ VM_C_API bool to_boolean(CELL value) { return value != F; } + +} diff --git a/vm/booleans.hpp b/vm/booleans.hpp index 7634afa02c..f5310de498 100644 --- a/vm/booleans.hpp +++ b/vm/booleans.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + inline static CELL tag_boolean(CELL untagged) { return (untagged ? T : F); @@ -5,3 +8,5 @@ inline static CELL tag_boolean(CELL untagged) VM_C_API void box_boolean(bool value); VM_C_API bool to_boolean(CELL value); + +} diff --git a/vm/byte_arrays.cpp b/vm/byte_arrays.cpp index eaf0eff4b1..18ec087d93 100644 --- a/vm/byte_arrays.cpp +++ b/vm/byte_arrays.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + F_BYTE_ARRAY *allot_byte_array(CELL size) { F_BYTE_ARRAY *array = allot_array_internal(size); @@ -57,3 +60,5 @@ void growable_byte_array::trim() { array = reallot_array(array.untagged(),count); } + +} diff --git a/vm/byte_arrays.hpp b/vm/byte_arrays.hpp index dcc6658976..3dd4138aef 100644 --- a/vm/byte_arrays.hpp +++ b/vm/byte_arrays.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + F_BYTE_ARRAY *allot_byte_array(CELL size); PRIMITIVE(byte_array); @@ -16,3 +19,5 @@ struct growable_byte_array { void trim(); }; + +} diff --git a/vm/callstack.cpp b/vm/callstack.cpp index 3597716dcc..dc0d5a1af1 100755 --- a/vm/callstack.cpp +++ b/vm/callstack.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + static void check_frame(F_STACK_FRAME *frame) { #ifdef FACTOR_DEBUG @@ -223,3 +226,5 @@ VM_ASM_API void save_callstack_bottom(F_STACK_FRAME *callstack_bottom) { stack_chain->callstack_bottom = callstack_bottom; } + +} diff --git a/vm/callstack.hpp b/vm/callstack.hpp index fbdadcc859..922a52bf27 100755 --- a/vm/callstack.hpp +++ b/vm/callstack.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + inline static CELL callstack_size(CELL size) { return sizeof(F_CALLSTACK) + size; @@ -24,3 +27,5 @@ PRIMITIVE(innermost_stack_frame_scan); PRIMITIVE(set_innermost_stack_frame_quot); VM_ASM_API void save_callstack_bottom(F_STACK_FRAME *callstack_bottom); + +} diff --git a/vm/code_block.cpp b/vm/code_block.cpp index 97a2e141da..4b49027ff6 100644 --- a/vm/code_block.cpp +++ b/vm/code_block.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + void flush_icache_for(F_CODE_BLOCK *block) { flush_icache((CELL)block,block->block.size); @@ -321,7 +324,10 @@ void *get_rel_symbol(F_ARRAY *literals, CELL index) if(sym) return sym; else + { + printf("%s\n",name); return (void *)undefined_symbol; + } case ARRAY_TYPE: CELL i; F_ARRAY *names = untag(symbol); @@ -485,3 +491,5 @@ F_CODE_BLOCK *add_code_block( return compiled; } + +} diff --git a/vm/code_block.hpp b/vm/code_block.hpp index 94bf0bddfc..4e33022262 100644 --- a/vm/code_block.hpp +++ b/vm/code_block.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + typedef enum { /* arg is a primitive number */ RT_PRIMITIVE, @@ -85,3 +88,5 @@ inline static bool stack_traces_p(void) } F_CODE_BLOCK *add_code_block(CELL type, CELL code, CELL labels, CELL relocation, CELL literals); + +} diff --git a/vm/code_gc.cpp b/vm/code_gc.cpp index 174622ff17..94c1fe286d 100755 --- a/vm/code_gc.cpp +++ b/vm/code_gc.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + static void clear_free_list(F_HEAP *heap) { memset(&heap->free,0,sizeof(F_HEAP_FREE_LIST)); @@ -334,3 +337,5 @@ void compact_heap(F_HEAP *heap) scan = next; } } + +} diff --git a/vm/code_gc.hpp b/vm/code_gc.hpp index eef3b24629..c0531472de 100755 --- a/vm/code_gc.hpp +++ b/vm/code_gc.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + #define FREE_LIST_COUNT 16 #define BLOCK_SIZE_INCREMENT 32 @@ -43,3 +46,5 @@ inline static F_BLOCK *last_block(F_HEAP *heap) { return (F_BLOCK *)heap->segment->end; } + +} diff --git a/vm/code_heap.cpp b/vm/code_heap.cpp index 00fb56c81a..b4fea25f59 100755 --- a/vm/code_heap.cpp +++ b/vm/code_heap.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + F_HEAP code_heap; /* Allocate a code heap during startup */ @@ -220,3 +223,5 @@ void compact_code_heap(void) the end */ build_free_list(&code_heap,size); } + +} diff --git a/vm/code_heap.hpp b/vm/code_heap.hpp index 6baff94988..57200ba8df 100755 --- a/vm/code_heap.hpp +++ b/vm/code_heap.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + /* compiled code */ extern F_HEAP code_heap; @@ -25,3 +28,5 @@ inline static void check_code_pointer(CELL pointer) assert(pointer >= code_heap.segment->start && pointer < code_heap.segment->end); #endif } + +} diff --git a/vm/contexts.cpp b/vm/contexts.cpp index f800191630..3356e365e3 100644 --- a/vm/contexts.cpp +++ b/vm/contexts.cpp @@ -1,6 +1,10 @@ #include "master.hpp" -F_CONTEXT *stack_chain; +factor::F_CONTEXT *stack_chain; + +namespace factor +{ + CELL ds_size, rs_size; F_CONTEXT *unused_contexts; @@ -184,3 +188,5 @@ PRIMITIVE(check_datastack) dpush(T); } } + +} diff --git a/vm/contexts.hpp b/vm/contexts.hpp index 2c4ba71d37..3bf54e3171 100644 --- a/vm/contexts.hpp +++ b/vm/contexts.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + /* Assembly code makes assumptions about the layout of this struct: - callstack_top field is 0 - callstack_bottom field is 1 @@ -33,8 +36,6 @@ struct F_CONTEXT { F_CONTEXT *next; }; -extern F_CONTEXT *stack_chain; - extern CELL ds_size, rs_size; #define ds_bot (stack_chain->datastack_region->start) @@ -59,3 +60,7 @@ PRIMITIVE(check_datastack); VM_C_API void save_stacks(void); VM_C_API void nest_stacks(void); VM_C_API void unnest_stacks(void); + +} + +VM_C_API factor::F_CONTEXT *stack_chain; diff --git a/vm/cpu-arm.hpp b/vm/cpu-arm.hpp index e6ea0a1158..1438199a02 100755 --- a/vm/cpu-arm.hpp +++ b/vm/cpu-arm.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + #define FACTOR_CPU_STRING "arm" register CELL ds asm("r5"); @@ -11,3 +14,5 @@ void c_to_factor(CELL quot); void set_callstack(F_STACK_FRAME *to, F_STACK_FRAME *from, CELL length, void *memcpy); void throw_impl(CELL quot, F_STACK_FRAME *rewind); void lazy_jit_compile(CELL quot); + +} diff --git a/vm/cpu-ppc.hpp b/vm/cpu-ppc.hpp index 20dfb9855a..cebb104a81 100755 --- a/vm/cpu-ppc.hpp +++ b/vm/cpu-ppc.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + #define FACTOR_CPU_STRING "ppc" #define VM_ASM_API @@ -10,3 +13,5 @@ void set_callstack(F_STACK_FRAME *to, F_STACK_FRAME *from, CELL length, void *me void throw_impl(CELL quot, F_STACK_FRAME *rewind); void lazy_jit_compile(CELL quot); void flush_icache(CELL start, CELL len); + +} diff --git a/vm/cpu-x86.32.hpp b/vm/cpu-x86.32.hpp index 97713d9ba2..0629571aed 100755 --- a/vm/cpu-x86.32.hpp +++ b/vm/cpu-x86.32.hpp @@ -1,6 +1,11 @@ +namespace factor +{ + #define FACTOR_CPU_STRING "x86.32" register CELL ds asm("esi"); register CELL rs asm("edi"); #define VM_ASM_API extern "C" __attribute__ ((regparm (2))) + +} diff --git a/vm/cpu-x86.64.hpp b/vm/cpu-x86.64.hpp index 497c85d998..fdc5158a73 100644 --- a/vm/cpu-x86.64.hpp +++ b/vm/cpu-x86.64.hpp @@ -1,6 +1,11 @@ +namespace factor +{ + #define FACTOR_CPU_STRING "x86.64" register CELL ds asm("r14"); register CELL rs asm("r15"); #define VM_ASM_API extern "C" + +} diff --git a/vm/cpu-x86.hpp b/vm/cpu-x86.hpp index 58a13b5d95..f730d38c2f 100755 --- a/vm/cpu-x86.hpp +++ b/vm/cpu-x86.hpp @@ -1,5 +1,8 @@ #include +namespace factor +{ + #define FRAME_RETURN_ADDRESS(frame) *(XT *)(frame_successor(frame) + 1) inline static void flush_icache(CELL start, CELL len) {} @@ -37,3 +40,5 @@ VM_C_API void set_callstack(F_STACK_FRAME *to, F_STACK_FRAME *from, CELL length, void *(*memcpy)(void*,const void*, size_t)); + +} diff --git a/vm/data_gc.cpp b/vm/data_gc.cpp index dd229c7ad2..302859ebfb 100755 --- a/vm/data_gc.cpp +++ b/vm/data_gc.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + /* used during garbage collection only */ F_ZONE *newspace; bool performing_gc; @@ -682,3 +685,5 @@ VM_C_API void minor_gc(void) { garbage_collection(NURSERY,false,0); } + +} diff --git a/vm/data_gc.hpp b/vm/data_gc.hpp index 068429bfdd..1d911b1828 100755 --- a/vm/data_gc.hpp +++ b/vm/data_gc.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + /* statistics */ struct F_GC_STATS { CELL collections; @@ -133,3 +136,5 @@ inline static void check_tagged_pointer(CELL tagged) VM_C_API void minor_gc(void); + +} diff --git a/vm/data_heap.cpp b/vm/data_heap.cpp index 39d58d6796..fe8d887b89 100644 --- a/vm/data_heap.cpp +++ b/vm/data_heap.cpp @@ -1,5 +1,10 @@ #include "master.hpp" +factor::F_ZONE nursery; + +namespace factor +{ + /* Set by the -securegc command line argument */ bool secure_gc; @@ -11,8 +16,6 @@ bool gc_off; F_DATA_HEAP *data_heap; -F_ZONE nursery; - CELL init_zone(F_ZONE *z, CELL size, CELL start) { z->size = size; @@ -375,3 +378,5 @@ CELL find_all_words(void) words.trim(); return words.array.value(); } + +} diff --git a/vm/data_heap.hpp b/vm/data_heap.hpp index d32f53fb2b..5d48dfb009 100644 --- a/vm/data_heap.hpp +++ b/vm/data_heap.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + /* Set by the -securegc command line argument */ extern bool secure_gc; @@ -46,9 +49,6 @@ extern F_DATA_HEAP *data_heap; #define MIN_GEN_COUNT 1 #define MAX_GEN_COUNT 3 -/* new objects are allocated here */ -extern F_ZONE nursery; - inline static bool in_zone(F_ZONE *z, F_OBJECT *pointer) { return (CELL)pointer >= z->start && (CELL)pointer < z->end; @@ -128,3 +128,7 @@ inline static void do_slots(CELL obj, void (* iter)(CELL *)) } } +} + +/* new objects are allocated here */ +VM_C_API factor::F_ZONE nursery; diff --git a/vm/debug.cpp b/vm/debug.cpp index 411570b50d..513b6d550e 100755 --- a/vm/debug.cpp +++ b/vm/debug.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + static bool fep_disabled; static bool full_output; @@ -472,3 +475,5 @@ PRIMITIVE(die) print_string("you have triggered a bug in Factor. Please report.\n"); factorbug(); } + +} diff --git a/vm/debug.hpp b/vm/debug.hpp index 97b0c32d54..008776c6a6 100755 --- a/vm/debug.hpp +++ b/vm/debug.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + void print_obj(CELL obj); void print_nested_obj(CELL obj, F_FIXNUM nesting); void dump_generations(void); @@ -5,3 +8,5 @@ void factorbug(void); void dump_zone(F_ZONE *z); PRIMITIVE(die); + +} diff --git a/vm/dispatch.cpp b/vm/dispatch.cpp index b8c2b85779..e178157446 100644 --- a/vm/dispatch.cpp +++ b/vm/dispatch.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + CELL megamorphic_cache_hits; CELL megamorphic_cache_misses; @@ -205,3 +208,5 @@ void quotation_jit::emit_mega_cache_lookup(CELL methods_, F_FIXNUM index, CELL c emit(userenv[JIT_EPILOG]); emit(userenv[JIT_EXECUTE_JUMP]); } + +} diff --git a/vm/dispatch.hpp b/vm/dispatch.hpp index d86854982f..6b86fabd7f 100644 --- a/vm/dispatch.hpp +++ b/vm/dispatch.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + CELL lookup_method(CELL object, CELL methods); PRIMITIVE(lookup_method); @@ -11,3 +14,5 @@ PRIMITIVE(dispatch_stats); void jit_emit_class_lookup(jit *jit, F_FIXNUM index, CELL type); void jit_emit_mega_cache_lookup(jit *jit, CELL methods, F_FIXNUM index, CELL cache); + +} diff --git a/vm/errors.cpp b/vm/errors.cpp index 8e21a6a13d..45954c5d9f 100755 --- a/vm/errors.cpp +++ b/vm/errors.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + /* Global variables used to pass fault handler state from signal handler to user-space */ CELL signal_number; @@ -147,3 +150,5 @@ void misc_signal_handler_impl(void) { signal_error(signal_number,signal_callstack_top); } + +} diff --git a/vm/errors.hpp b/vm/errors.hpp index da7d1458f3..fae3949a54 100755 --- a/vm/errors.hpp +++ b/vm/errors.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + /* Runtime errors */ typedef enum { @@ -44,3 +47,5 @@ extern F_STACK_FRAME *signal_callstack_top; void memory_signal_handler_impl(void); void misc_signal_handler_impl(void); + +} diff --git a/vm/factor.cpp b/vm/factor.cpp index 1e261a91ba..9c6af72264 100755 --- a/vm/factor.cpp +++ b/vm/factor.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + VM_C_API void default_parameters(F_PARAMETERS *p) { p->image_path = NULL; @@ -209,3 +212,5 @@ VM_C_API void factor_sleep(long us) void (*callback)(long) = (void (*)(long))alien_offset(userenv[SLEEP_CALLBACK_ENV]); callback(us); } + +} diff --git a/vm/factor.hpp b/vm/factor.hpp index 08fa9be6b1..0ae87736d1 100644 --- a/vm/factor.hpp +++ b/vm/factor.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + VM_C_API void default_parameters(F_PARAMETERS *p); VM_C_API void init_parameters_from_args(F_PARAMETERS *p, int argc, F_CHAR **argv); VM_C_API void init_factor(F_PARAMETERS *p); @@ -9,3 +12,5 @@ VM_C_API char *factor_eval_string(char *string); VM_C_API void factor_eval_free(char *result); VM_C_API void factor_yield(void); VM_C_API void factor_sleep(long ms); + +} diff --git a/vm/float_bits.hpp b/vm/float_bits.hpp index d380400640..829fe8d3ca 100644 --- a/vm/float_bits.hpp +++ b/vm/float_bits.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + /* Some functions for converting floating point numbers to binary representations and vice versa */ @@ -38,3 +41,5 @@ inline static float bits_float(u32 y) b.y = y; return b.x; } + +} diff --git a/vm/generic_arrays.hpp b/vm/generic_arrays.hpp index 5774f3b001..6147c0eeed 100644 --- a/vm/generic_arrays.hpp +++ b/vm/generic_arrays.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + template CELL array_capacity(T *array) { #ifdef FACTOR_DEBUG @@ -52,3 +55,5 @@ template T *reallot_array(T *array_, CELL capacity) return new_array; } } + +} diff --git a/vm/image.cpp b/vm/image.cpp index d0571bb241..6e13c5fa36 100755 --- a/vm/image.cpp +++ b/vm/image.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + /* Certain special objects in the image are known to the runtime */ static void init_objects(F_IMAGE_HEADER *h) { @@ -337,3 +340,5 @@ void load_image(F_PARAMETERS *p) /* Store image path name */ userenv[IMAGE_ENV] = allot_alien(F,(CELL)p->image_path); } + +} diff --git a/vm/image.hpp b/vm/image.hpp index 68545d1162..0f7001ad99 100755 --- a/vm/image.hpp +++ b/vm/image.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + #define IMAGE_MAGIC 0x0f0e0d0c #define IMAGE_VERSION 4 @@ -43,3 +46,5 @@ bool save_image(const F_CHAR *file); PRIMITIVE(save_image); PRIMITIVE(save_image_and_exit); + +} diff --git a/vm/inline_cache.cpp b/vm/inline_cache.cpp index 5c02c419dd..15008fafa0 100644 --- a/vm/inline_cache.cpp +++ b/vm/inline_cache.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + CELL max_pic_size; CELL cold_call_to_ic_transitions; @@ -252,3 +255,5 @@ PRIMITIVE(inline_cache_stats) stats.trim(); dpush(stats.array.value()); } + +} diff --git a/vm/inline_cache.hpp b/vm/inline_cache.hpp index a85879459f..d1d4226b15 100644 --- a/vm/inline_cache.hpp +++ b/vm/inline_cache.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + extern CELL max_pic_size; void init_inline_caching(int max_size); @@ -7,3 +10,5 @@ PRIMITIVE(inline_cache_stats); PRIMITIVE(inline_cache_miss); extern "C" XT inline_cache_miss(CELL return_address); + +} diff --git a/vm/io.cpp b/vm/io.cpp index 43ca5f9064..e73735fb85 100755 --- a/vm/io.cpp +++ b/vm/io.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + /* Simple wrappers for ANSI C I/O functions, used for bootstrapping. Note the ugly loop logic in almost every function; we have to handle EINTR @@ -222,3 +225,5 @@ VM_C_API void clear_err_no(void) { errno = 0; } + +} diff --git a/vm/io.hpp b/vm/io.hpp index f857302568..968e96f0b5 100755 --- a/vm/io.hpp +++ b/vm/io.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + void init_c_io(void); void io_error(void); @@ -17,3 +20,5 @@ PRIMITIVE(read_dir); VM_C_API int err_no(void); VM_C_API void clear_err_no(void); + +} diff --git a/vm/jit.cpp b/vm/jit.cpp index fee8c4684b..0174faa351 100644 --- a/vm/jit.cpp +++ b/vm/jit.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + /* Simple code generator used by: - profiler (profiler.cpp), - quotation compiler (quotations.cpp), @@ -112,3 +115,5 @@ F_CODE_BLOCK *jit::code_block() } + +} diff --git a/vm/jit.hpp b/vm/jit.hpp index 07f33ce2e3..ae6c133141 100644 --- a/vm/jit.hpp +++ b/vm/jit.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + struct jit { CELL type; gc_root owner; @@ -57,3 +60,5 @@ struct jit { F_CODE_BLOCK *code_block(); }; + +} diff --git a/vm/layouts.hpp b/vm/layouts.hpp index 240cc3da18..abdd99be21 100755 --- a/vm/layouts.hpp +++ b/vm/layouts.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + typedef unsigned char u8; typedef unsigned short u16; typedef unsigned int u32; @@ -324,3 +327,5 @@ struct F_TUPLE : public F_OBJECT { CELL *data() { return (CELL *)(this + 1); } }; + +} diff --git a/vm/local_roots.cpp b/vm/local_roots.cpp index 05d5602f0e..41bb8191ea 100644 --- a/vm/local_roots.cpp +++ b/vm/local_roots.cpp @@ -1,7 +1,12 @@ #include "master.hpp" +namespace factor +{ + F_SEGMENT *gc_locals_region; CELL gc_locals; F_SEGMENT *gc_bignums_region; CELL gc_bignums; + +} diff --git a/vm/local_roots.hpp b/vm/local_roots.hpp index 05278b9f2b..bd4eed7f67 100644 --- a/vm/local_roots.hpp +++ b/vm/local_roots.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + /* If a runtime function needs to call another function which potentially allocates memory, it must wrap any local variable references to Factor objects in gc_root instances */ @@ -40,3 +43,5 @@ struct gc_bignum }; #define GC_BIGNUM(x) gc_bignum x##__gc_root(&x) + +} diff --git a/vm/mach_signal.cpp b/vm/mach_signal.cpp index 74f2e724ca..901f3de971 100644 --- a/vm/mach_signal.cpp +++ b/vm/mach_signal.cpp @@ -1,5 +1,6 @@ /* Fault handler information. MacOSX version. Copyright (C) 1993-1999, 2002-2003 Bruno Haible + Copyright (C) 2003 Paolo Bonzini Used under BSD license with permission from Paolo Bonzini and Bruno Haible, @@ -11,6 +12,9 @@ Modified for Factor by Slava Pestov */ #include "master.hpp" +namespace factor +{ + /* The exception port on which our thread listens. */ mach_port_t our_exception_port; @@ -164,7 +168,6 @@ mach_exception_thread (void *arg) } } - /* Initialize the Mach exception handler thread. */ void mach_initialize (void) { @@ -201,3 +204,5 @@ void mach_initialize (void) != KERN_SUCCESS) fatal_error("task_set_exception_ports() failed",0); } + +} diff --git a/vm/mach_signal.hpp b/vm/mach_signal.hpp index fdeef7b2a5..5dd344c080 100644 --- a/vm/mach_signal.hpp +++ b/vm/mach_signal.hpp @@ -76,4 +76,9 @@ catch_exception_raise_state_identity (mach_port_t exception_port, thread_state_t out_state, mach_msg_type_number_t *out_state_count); +namespace factor +{ + void mach_initialize (void); + +} diff --git a/vm/main-unix.cpp b/vm/main-unix.cpp index 33fd471d42..bc605e3cfd 100644 --- a/vm/main-unix.cpp +++ b/vm/main-unix.cpp @@ -2,6 +2,6 @@ int main(int argc, char **argv) { - start_standalone_factor(argc,argv); + factor::start_standalone_factor(argc,argv); return 0; } diff --git a/vm/main-windows-ce.cpp b/vm/main-windows-ce.cpp index 61aeb12729..526f3b2c36 100644 --- a/vm/main-windows-ce.cpp +++ b/vm/main-windows-ce.cpp @@ -128,7 +128,7 @@ WinMain( int nCmdShow) { parse_args(&__argc, &__argv, lpCmdLine); - start_standalone_factor(__argc,(LPWSTR*)__argv); + factor::start_standalone_factor(__argc,(LPWSTR*)__argv); // memory leak from malloc, wcsdup return 0; } diff --git a/vm/main-windows-nt.cpp b/vm/main-windows-nt.cpp index 026947c4f0..eaaad0f55b 100755 --- a/vm/main-windows-nt.cpp +++ b/vm/main-windows-nt.cpp @@ -1,6 +1,3 @@ -#include -#include -#include #include "master.hpp" int WINAPI WinMain( @@ -19,7 +16,7 @@ int WINAPI WinMain( return 1; } - start_standalone_factor(nArgs,szArglist); + factor::start_standalone_factor(nArgs,szArglist); LocalFree(szArglist); diff --git a/vm/math.cpp b/vm/math.cpp index 8d6b503512..7a01b1adb4 100644 --- a/vm/math.cpp +++ b/vm/math.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + CELL bignum_zero; CELL bignum_pos_one; CELL bignum_neg_one; @@ -509,3 +512,5 @@ VM_ASM_API void overflow_fixnum_multiply(F_FIXNUM x, F_FIXNUM y) GC_BIGNUM(by); drepl(tag(bignum_multiply(bx,by))); } + +} diff --git a/vm/math.hpp b/vm/math.hpp index 07257c89f0..05624d56e2 100644 --- a/vm/math.hpp +++ b/vm/math.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + extern CELL bignum_zero; extern CELL bignum_pos_one; extern CELL bignum_neg_one; @@ -142,3 +145,5 @@ VM_C_API CELL to_cell(CELL tagged); VM_ASM_API void overflow_fixnum_add(F_FIXNUM x, F_FIXNUM y); VM_ASM_API void overflow_fixnum_subtract(F_FIXNUM x, F_FIXNUM y); VM_ASM_API void overflow_fixnum_multiply(F_FIXNUM x, F_FIXNUM y); + +} diff --git a/vm/os-freebsd-x86.32.hpp b/vm/os-freebsd-x86.32.hpp index a5a96d84ca..c276ce6174 100644 --- a/vm/os-freebsd-x86.32.hpp +++ b/vm/os-freebsd-x86.32.hpp @@ -1,5 +1,8 @@ #include +namespace factor +{ + inline static void *ucontext_stack_pointer(void *uap) { ucontext_t *ucontext = (ucontext_t *)uap; @@ -7,3 +10,5 @@ inline static void *ucontext_stack_pointer(void *uap) } #define UAP_PROGRAM_COUNTER(ucontext) (((ucontext_t *)(ucontext))->uc_mcontext.mc_eip) + +} diff --git a/vm/os-freebsd-x86.64.hpp b/vm/os-freebsd-x86.64.hpp index d74278fb19..6ee491f3ae 100644 --- a/vm/os-freebsd-x86.64.hpp +++ b/vm/os-freebsd-x86.64.hpp @@ -1,5 +1,8 @@ #include +namespace factor +{ + inline static void *ucontext_stack_pointer(void *uap) { ucontext_t *ucontext = (ucontext_t *)uap; @@ -7,3 +10,5 @@ inline static void *ucontext_stack_pointer(void *uap) } #define UAP_PROGRAM_COUNTER(ucontext) (((ucontext_t *)(ucontext))->uc_mcontext.mc_rip) + +} diff --git a/vm/os-freebsd.cpp b/vm/os-freebsd.cpp index c5bb0a7837..63313f61e0 100644 --- a/vm/os-freebsd.cpp +++ b/vm/os-freebsd.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + /* From SBCL */ const char *vm_executable_path(void) { @@ -32,3 +35,5 @@ const char *vm_executable_path(void) return safe_strdup(path); } + +} diff --git a/vm/os-freebsd.hpp b/vm/os-freebsd.hpp index 617a6686c2..0acf537d45 100644 --- a/vm/os-freebsd.hpp +++ b/vm/os-freebsd.hpp @@ -1,9 +1,8 @@ #include - -extern int getosreldate(void); - #include +extern "C" int getosreldate(void); + #ifndef KERN_PROC_PATHNAME #define KERN_PROC_PATHNAME 12 #endif diff --git a/vm/os-genunix.cpp b/vm/os-genunix.cpp index 6f5087bc6e..53b65b1f7d 100755 --- a/vm/os-genunix.cpp +++ b/vm/os-genunix.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + void c_to_factor_toplevel(CELL quot) { c_to_factor(quot); @@ -33,3 +36,5 @@ const char *default_image_path(void) memcpy(new_path + len,SUFFIX,SUFFIX_LEN + 1); return new_path; } + +} diff --git a/vm/os-genunix.hpp b/vm/os-genunix.hpp index 72e9a43a1c..91cdba9d2c 100644 --- a/vm/os-genunix.hpp +++ b/vm/os-genunix.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + #define VM_C_API extern "C" #define NULL_DLL NULL @@ -6,3 +9,5 @@ void init_signals(void); void early_init(void); const char *vm_executable_path(void); const char *default_image_path(void); + +} diff --git a/vm/os-linux-arm.cpp b/vm/os-linux-arm.cpp index d8131f1ffb..fe98226369 100644 --- a/vm/os-linux-arm.cpp +++ b/vm/os-linux-arm.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + void flush_icache(CELL start, CELL len) { int result; @@ -24,3 +27,5 @@ void flush_icache(CELL start, CELL len) if(result < 0) critical_error("flush_icache() failed",result); } + +} diff --git a/vm/os-linux-arm.hpp b/vm/os-linux-arm.hpp index 92900281cd..c767ec858e 100644 --- a/vm/os-linux-arm.hpp +++ b/vm/os-linux-arm.hpp @@ -2,6 +2,9 @@ #include #include +namespace factor +{ + inline static void *ucontext_stack_pointer(void *uap) { ucontext_t *ucontext = (ucontext_t *)uap; @@ -12,3 +15,5 @@ inline static void *ucontext_stack_pointer(void *uap) (((ucontext_t *)(ucontext))->uc_mcontext.arm_pc) void flush_icache(CELL start, CELL len); + +} diff --git a/vm/os-linux-ppc.hpp b/vm/os-linux-ppc.hpp index da0333036c..da098ddeaf 100644 --- a/vm/os-linux-ppc.hpp +++ b/vm/os-linux-ppc.hpp @@ -1,5 +1,8 @@ #include +namespace factor +{ + #define FRAME_RETURN_ADDRESS(frame) *((XT *)(frame_successor(frame) + 1) + 1) inline static void *ucontext_stack_pointer(void *uap) @@ -10,3 +13,5 @@ inline static void *ucontext_stack_pointer(void *uap) #define UAP_PROGRAM_COUNTER(ucontext) \ (((ucontext_t *)(ucontext))->uc_mcontext.uc_regs->gregs[PT_NIP]) + +} diff --git a/vm/os-linux-x86.32.hpp b/vm/os-linux-x86.32.hpp index 2906bf2810..4ba7c77e4b 100644 --- a/vm/os-linux-x86.32.hpp +++ b/vm/os-linux-x86.32.hpp @@ -1,5 +1,8 @@ #include +namespace factor +{ + inline static void *ucontext_stack_pointer(void *uap) { ucontext_t *ucontext = (ucontext_t *)uap; @@ -8,3 +11,5 @@ inline static void *ucontext_stack_pointer(void *uap) #define UAP_PROGRAM_COUNTER(ucontext) \ (((ucontext_t *)(ucontext))->uc_mcontext.gregs[14]) + +} diff --git a/vm/os-linux-x86.64.hpp b/vm/os-linux-x86.64.hpp index 7c817f3b4d..477e21708c 100644 --- a/vm/os-linux-x86.64.hpp +++ b/vm/os-linux-x86.64.hpp @@ -1,5 +1,8 @@ #include +namespace factor +{ + inline static void *ucontext_stack_pointer(void *uap) { ucontext_t *ucontext = (ucontext_t *)uap; @@ -8,3 +11,5 @@ inline static void *ucontext_stack_pointer(void *uap) #define UAP_PROGRAM_COUNTER(ucontext) \ (((ucontext_t *)(ucontext))->uc_mcontext.gregs[16]) + +} diff --git a/vm/os-linux.cpp b/vm/os-linux.cpp index fcffd75a8e..c3e10668e7 100644 --- a/vm/os-linux.cpp +++ b/vm/os-linux.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + /* Snarfed from SBCL linux-so.c. You must free() this yourself. */ const char *vm_executable_path(void) { @@ -56,3 +59,5 @@ int inotify_rm_watch(int fd, u32 wd) } #endif + +} diff --git a/vm/os-linux.hpp b/vm/os-linux.hpp index 8e78595687..4e2f22b95f 100644 --- a/vm/os-linux.hpp +++ b/vm/os-linux.hpp @@ -1,5 +1,10 @@ #include +namespace factor +{ + int inotify_init(void); int inotify_add_watch(int fd, const char *name, u32 mask); int inotify_rm_watch(int fd, u32 wd); + +} diff --git a/vm/os-macosx-ppc.hpp b/vm/os-macosx-ppc.hpp index 07924f854b..026b523b16 100644 --- a/vm/os-macosx-ppc.hpp +++ b/vm/os-macosx-ppc.hpp @@ -1,3 +1,8 @@ +#include + +namespace factor +{ + /* Fault handler information. MacOSX version. Copyright (C) 1993-1999, 2002-2003 Bruno Haible Copyright (C) 2003 Paolo Bonzini @@ -8,8 +13,6 @@ Used under BSD license with permission from Paolo Bonzini and Bruno Haible, http://sourceforge.net/mailarchive/message.php?msg_name=200503102200.32002.bruno%40clisp.org Modified for Factor by Slava Pestov */ -#include - #define FRAME_RETURN_ADDRESS(frame) *((XT *)(frame_successor(frame) + 1) + 2) #define MACH_EXC_STATE_TYPE ppc_exception_state_t @@ -37,3 +40,5 @@ inline static CELL fix_stack_pointer(CELL sp) { return sp; } + +} diff --git a/vm/os-macosx-x86.32.hpp b/vm/os-macosx-x86.32.hpp index 1ae7ca65cc..9f781631c2 100644 --- a/vm/os-macosx-x86.32.hpp +++ b/vm/os-macosx-x86.32.hpp @@ -1,3 +1,8 @@ +#include + +namespace factor +{ + /* Fault handler information. MacOSX version. Copyright (C) 1993-1999, 2002-2003 Bruno Haible Copyright (C) 2003 Paolo Bonzini @@ -8,8 +13,6 @@ Used under BSD license with permission from Paolo Bonzini and Bruno Haible, http://sourceforge.net/mailarchive/message.php?msg_name=200503102200.32002.bruno%40clisp.org Modified for Factor by Slava Pestov */ -#include - #define MACH_EXC_STATE_TYPE i386_exception_state_t #define MACH_EXC_STATE_FLAVOR i386_EXCEPTION_STATE #define MACH_EXC_STATE_COUNT i386_EXCEPTION_STATE_COUNT @@ -35,3 +38,5 @@ inline static CELL fix_stack_pointer(CELL sp) { return ((sp + 4) & ~15) - 4; } + +} diff --git a/vm/os-macosx-x86.64.hpp b/vm/os-macosx-x86.64.hpp index ee32c8f21b..cd4253bcc8 100644 --- a/vm/os-macosx-x86.64.hpp +++ b/vm/os-macosx-x86.64.hpp @@ -1,3 +1,8 @@ +#include + +namespace factor +{ + /* Fault handler information. MacOSX version. Copyright (C) 1993-1999, 2002-2003 Bruno Haible Copyright (C) 2003 Paolo Bonzini @@ -8,8 +13,6 @@ Used under BSD license with permission from Paolo Bonzini and Bruno Haible, http://sourceforge.net/mailarchive/message.php?msg_name=200503102200.32002.bruno%40clisp.org Modified for Factor by Slava Pestov and Daniel Ehrenberg */ -#include - #define MACH_EXC_STATE_TYPE x86_exception_state64_t #define MACH_EXC_STATE_FLAVOR x86_EXCEPTION_STATE64 #define MACH_EXC_STATE_COUNT x86_EXCEPTION_STATE64_COUNT @@ -35,3 +38,5 @@ inline static CELL fix_stack_pointer(CELL sp) { return ((sp + 8) & ~15) - 8; } + +} diff --git a/vm/os-macosx.hpp b/vm/os-macosx.hpp index 10aa515fd2..bb54592364 100644 --- a/vm/os-macosx.hpp +++ b/vm/os-macosx.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + #define VM_C_API extern "C" __attribute__((visibility("default"))) #define FACTOR_OS_STRING "macosx" #define NULL_DLL "libfactor.dylib" @@ -15,3 +18,5 @@ inline static void *ucontext_stack_pointer(void *uap) } void c_to_factor_toplevel(CELL quot); + +} diff --git a/vm/os-macosx.mm b/vm/os-macosx.mm index a47bdda3d1..e7c2c1d602 100644 --- a/vm/os-macosx.mm +++ b/vm/os-macosx.mm @@ -2,6 +2,9 @@ #include "master.hpp" +namespace factor +{ + void c_to_factor_toplevel(CELL quot) { for(;;) @@ -80,3 +83,5 @@ Protocol *objc_getProtocol(char *name) else return nil; } + +} diff --git a/vm/os-netbsd-x86.32.hpp b/vm/os-netbsd-x86.32.hpp index ca4a9f88f5..ebba4f356d 100644 --- a/vm/os-netbsd-x86.32.hpp +++ b/vm/os-netbsd-x86.32.hpp @@ -1,3 +1,8 @@ #include +namespace factor +{ + #define ucontext_stack_pointer(uap) ((void *)_UC_MACHINE_SP((ucontext_t *)uap)) + +} diff --git a/vm/os-netbsd-x86.64.hpp b/vm/os-netbsd-x86.64.hpp index 587dc85ec7..1a062cc6ef 100644 --- a/vm/os-netbsd-x86.64.hpp +++ b/vm/os-netbsd-x86.64.hpp @@ -1,4 +1,9 @@ #include +namespace factor +{ + #define ucontext_stack_pointer(uap) \ ((void *)(((ucontext_t *)(uap))->uc_mcontext.__gregs[_REG_URSP])) + +} diff --git a/vm/os-netbsd.cpp b/vm/os-netbsd.cpp index 088f6eb9cf..cd397bdae1 100755 --- a/vm/os-netbsd.cpp +++ b/vm/os-netbsd.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + extern int main(); const char *vm_executable_path(void) @@ -9,3 +12,5 @@ const char *vm_executable_path(void) dladdr(main, &info); return info.dli_fname; } + +} diff --git a/vm/os-netbsd.hpp b/vm/os-netbsd.hpp index 6486acda4a..635361e3e4 100644 --- a/vm/os-netbsd.hpp +++ b/vm/os-netbsd.hpp @@ -1,5 +1,10 @@ #include +namespace factor +{ + #define UAP_PROGRAM_COUNTER(uap) _UC_MACHINE_PC((ucontext_t *)uap) #define DIRECTORY_P(file) ((file)->d_type == DT_DIR) + +} diff --git a/vm/os-openbsd-x86.32.hpp b/vm/os-openbsd-x86.32.hpp index 93d66298aa..6065d96a5f 100644 --- a/vm/os-openbsd-x86.32.hpp +++ b/vm/os-openbsd-x86.32.hpp @@ -1,5 +1,8 @@ #include +namespace factor +{ + inline static void *openbsd_stack_pointer(void *uap) { struct sigcontext *sc = (struct sigcontext*) uap; @@ -8,3 +11,5 @@ inline static void *openbsd_stack_pointer(void *uap) #define ucontext_stack_pointer openbsd_stack_pointer #define UAP_PROGRAM_COUNTER(uap) (((struct sigcontext*)(uap))->sc_eip) + +} diff --git a/vm/os-openbsd-x86.64.hpp b/vm/os-openbsd-x86.64.hpp index d318f9e3ab..7338b04e6f 100644 --- a/vm/os-openbsd-x86.64.hpp +++ b/vm/os-openbsd-x86.64.hpp @@ -1,5 +1,8 @@ #include +namespace factor +{ + inline static void *openbsd_stack_pointer(void *uap) { struct sigcontext *sc = (struct sigcontext*) uap; @@ -8,3 +11,5 @@ inline static void *openbsd_stack_pointer(void *uap) #define ucontext_stack_pointer openbsd_stack_pointer #define UAP_PROGRAM_COUNTER(uap) (((struct sigcontext*)(uap))->sc_rip) + +} diff --git a/vm/os-openbsd.cpp b/vm/os-openbsd.cpp index 855298a810..fc8aac8cf7 100644 --- a/vm/os-openbsd.cpp +++ b/vm/os-openbsd.cpp @@ -1,6 +1,11 @@ #include "master.hpp" +namespace factor +{ + const char *vm_executable_path(void) { return NULL; } + +} diff --git a/vm/os-solaris-x86.32.hpp b/vm/os-solaris-x86.32.hpp index 1261f191d1..b89b8d541b 100644 --- a/vm/os-solaris-x86.32.hpp +++ b/vm/os-solaris-x86.32.hpp @@ -1,5 +1,8 @@ #include +namespace factor +{ + inline static void *ucontext_stack_pointer(void *uap) { ucontext_t *ucontext = (ucontext_t *)uap; @@ -8,3 +11,5 @@ inline static void *ucontext_stack_pointer(void *uap) #define UAP_PROGRAM_COUNTER(ucontext) \ (((ucontext_t *)(ucontext))->uc_mcontext.gregs[EIP]) + +} diff --git a/vm/os-solaris-x86.64.hpp b/vm/os-solaris-x86.64.hpp index 4dc3a118d3..0d3a74e11d 100644 --- a/vm/os-solaris-x86.64.hpp +++ b/vm/os-solaris-x86.64.hpp @@ -1,5 +1,8 @@ #include +namespace factor +{ + inline static void *ucontext_stack_pointer(void *uap) { ucontext_t *ucontext = (ucontext_t *)uap; @@ -8,3 +11,5 @@ inline static void *ucontext_stack_pointer(void *uap) #define UAP_PROGRAM_COUNTER(ucontext) \ (((ucontext_t *)(ucontext))->uc_mcontext.gregs[RIP]) + +} diff --git a/vm/os-solaris.cpp b/vm/os-solaris.cpp index 855298a810..fc8aac8cf7 100644 --- a/vm/os-solaris.cpp +++ b/vm/os-solaris.cpp @@ -1,6 +1,11 @@ #include "master.hpp" +namespace factor +{ + const char *vm_executable_path(void) { return NULL; } + +} diff --git a/vm/os-unix.cpp b/vm/os-unix.cpp index c3d70fa354..417f79c5ba 100755 --- a/vm/os-unix.cpp +++ b/vm/os-unix.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + void start_thread(void *(*start_routine)(void *)) { pthread_attr_t attr; @@ -311,3 +314,5 @@ VM_C_API void wait_for_stdin(void) fatal_error("Error writing control fd",errno); } } + +} diff --git a/vm/os-unix.hpp b/vm/os-unix.hpp index 6ea11cbf14..cb0afc4e61 100755 --- a/vm/os-unix.hpp +++ b/vm/os-unix.hpp @@ -8,11 +8,12 @@ #include #include +namespace factor +{ + typedef char F_CHAR; typedef char F_SYMBOL; -#define string_to_native_alien(string) string_to_char_alien(string,true) - #define STRING_LITERAL(string) string #define SSCANF sscanf @@ -54,3 +55,5 @@ s64 current_micros(void); void sleep_micros(CELL usec); void open_console(void); + +} diff --git a/vm/os-windows-ce.cpp b/vm/os-windows-ce.cpp index ea8a7bb159..af127016de 100755 --- a/vm/os-windows-ce.cpp +++ b/vm/os-windows-ce.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + s64 current_micros(void) { SYSTEMTIME st; @@ -38,3 +41,5 @@ void c_to_factor_toplevel(CELL quot) } void open_console(void) { } + +} diff --git a/vm/os-windows-ce.hpp b/vm/os-windows-ce.hpp index bc10017262..49b6d73077 100755 --- a/vm/os-windows-ce.hpp +++ b/vm/os-windows-ce.hpp @@ -5,6 +5,9 @@ #include #include +namespace factor +{ + typedef wchar_t F_SYMBOL; #define FACTOR_OS_STRING "wince" @@ -22,3 +25,5 @@ char *getenv(char *name); s64 current_micros(void); void c_to_factor_toplevel(CELL quot); void open_console(void); + +} diff --git a/vm/os-windows-nt.32.hpp b/vm/os-windows-nt.32.hpp index 9b10671ba0..ed67e28b8b 100644 --- a/vm/os-windows-nt.32.hpp +++ b/vm/os-windows-nt.32.hpp @@ -1,2 +1,7 @@ +namespace factor +{ + #define ESP Esp #define EIP Eip + +} diff --git a/vm/os-windows-nt.64.hpp b/vm/os-windows-nt.64.hpp index 1f61c2335f..30ce150754 100644 --- a/vm/os-windows-nt.64.hpp +++ b/vm/os-windows-nt.64.hpp @@ -1,2 +1,7 @@ +namespace factor +{ + #define ESP Rsp #define EIP Rip + +} diff --git a/vm/os-windows-nt.cpp b/vm/os-windows-nt.cpp index 2f449e15cf..d148a32df6 100755 --- a/vm/os-windows-nt.cpp +++ b/vm/os-windows-nt.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + s64 current_micros(void) { FILETIME t; @@ -49,3 +52,5 @@ void c_to_factor_toplevel(CELL quot) void open_console(void) { } + +} diff --git a/vm/os-windows-nt.hpp b/vm/os-windows-nt.hpp index 8ae4121ae6..e55d6ee97c 100755 --- a/vm/os-windows-nt.hpp +++ b/vm/os-windows-nt.hpp @@ -5,8 +5,12 @@ #define UNICODE #endif +#include #include +namespace factor +{ + typedef char F_SYMBOL; #define FACTOR_OS_STRING "winnt" @@ -16,3 +20,5 @@ typedef char F_SYMBOL; void c_to_factor_toplevel(CELL quot); long exception_handler(PEXCEPTION_POINTERS pe); void open_console(void); + +} diff --git a/vm/os-windows.cpp b/vm/os-windows.cpp index 604c718a33..24b49ff61b 100755 --- a/vm/os-windows.cpp +++ b/vm/os-windows.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + HMODULE hFactorDll; void init_ffi(void) @@ -144,3 +147,5 @@ void sleep_micros(u64 usec) { Sleep((DWORD)(usec / 1000)); } + +} diff --git a/vm/os-windows.hpp b/vm/os-windows.hpp index 0b66120764..db83688b13 100755 --- a/vm/os-windows.hpp +++ b/vm/os-windows.hpp @@ -5,9 +5,10 @@ #include #endif -typedef wchar_t F_CHAR; +namespace factor +{ -#define string_to_native_alien(string) string_to_u16_alien(string,true) +typedef wchar_t F_CHAR; #define STRING_LITERAL(string) L##string @@ -55,3 +56,4 @@ long getpagesize (void); s64 current_micros(void); +} diff --git a/vm/primitives.cpp b/vm/primitives.cpp index e629bebb3c..0c9fc32dff 100755 --- a/vm/primitives.cpp +++ b/vm/primitives.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + void *primitives[] = { (void *)primitive_bignum_to_fixnum, (void *)primitive_float_to_fixnum, @@ -152,3 +155,5 @@ void *primitives[] = { (void *)primitive_inline_cache_stats, (void *)primitive_optimized_p, }; + +} diff --git a/vm/primitives.hpp b/vm/primitives.hpp index 68c6f17e9d..b26638274b 100644 --- a/vm/primitives.hpp +++ b/vm/primitives.hpp @@ -1,5 +1,10 @@ +namespace factor +{ + //typedef extern "C" void (*F_PRIMITIVE)(void); extern void *primitives[]; #define PRIMITIVE(name) extern "C" void primitive_##name() + +} diff --git a/vm/profiler.cpp b/vm/profiler.cpp index 7790578cb1..7a832e6219 100755 --- a/vm/profiler.cpp +++ b/vm/profiler.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + bool profiling_p; void init_profiler(void) @@ -50,3 +53,5 @@ PRIMITIVE(profiling) { set_profiling(to_boolean(dpop())); } + +} diff --git a/vm/profiler.hpp b/vm/profiler.hpp index fc31ef4002..60f83721b2 100755 --- a/vm/profiler.hpp +++ b/vm/profiler.hpp @@ -1,4 +1,9 @@ +namespace factor +{ + extern bool profiling_p; void init_profiler(void); F_CODE_BLOCK *compile_profiling_stub(CELL word); PRIMITIVE(profiling); + +} diff --git a/vm/quotations.cpp b/vm/quotations.cpp index b9c538f45c..d0d995cd65 100755 --- a/vm/quotations.cpp +++ b/vm/quotations.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + /* Simple non-optimizing compiler. This is one of the two compilers implementing Factor; the second one is written @@ -334,3 +337,5 @@ VM_ASM_API CELL lazy_jit_compile_impl(CELL quot_, F_STACK_FRAME *stack) jit_compile(quot.value(),true); return quot.value(); } + +} diff --git a/vm/quotations.hpp b/vm/quotations.hpp index 92f49732d5..6472cb1329 100755 --- a/vm/quotations.hpp +++ b/vm/quotations.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + struct quotation_jit : public jit { gc_root array; bool compiling, relocate; @@ -31,3 +34,5 @@ PRIMITIVE(array_to_quotation); PRIMITIVE(quotation_xt); VM_ASM_API CELL lazy_jit_compile_impl(CELL quot, F_STACK_FRAME *stack); + +} diff --git a/vm/run.cpp b/vm/run.cpp index c979ca1750..b10fd0e96b 100755 --- a/vm/run.cpp +++ b/vm/run.cpp @@ -1,6 +1,10 @@ #include "master.hpp" -CELL userenv[USER_ENV]; +factor::CELL userenv[USER_ENV]; + +namespace factor +{ + CELL T; PRIMITIVE(getenv) @@ -68,3 +72,5 @@ PRIMITIVE(clone) { drepl(clone_object(dpeek())); } + +} diff --git a/vm/run.hpp b/vm/run.hpp index c82c8d678d..48c3f9f6c2 100755 --- a/vm/run.hpp +++ b/vm/run.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + #define USER_ENV 70 typedef enum { @@ -90,9 +93,6 @@ typedef enum { #define FIRST_SAVE_ENV BOOT_ENV #define LAST_SAVE_ENV STAGE2_ENV -/* TAGGED user environment data; see getenv/setenv prims */ -extern CELL userenv[USER_ENV]; - /* Canonical T object. It's just a word */ extern CELL T; @@ -104,3 +104,8 @@ PRIMITIVE(sleep); PRIMITIVE(set_slot); PRIMITIVE(load_locals); PRIMITIVE(clone); + +} + +/* TAGGED user environment data; see getenv/setenv prims */ +VM_C_API factor::CELL userenv[USER_ENV]; diff --git a/vm/segments.hpp b/vm/segments.hpp index 2a33b35cfd..6e8ea3f491 100644 --- a/vm/segments.hpp +++ b/vm/segments.hpp @@ -1,5 +1,10 @@ +namespace factor +{ + struct F_SEGMENT { CELL start; CELL size; CELL end; }; + +} diff --git a/vm/stacks.hpp b/vm/stacks.hpp index f11481b18f..3a4e88cb9d 100644 --- a/vm/stacks.hpp +++ b/vm/stacks.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + #define DEFPUSHPOP(prefix,ptr) \ inline static CELL prefix##peek() { return *(CELL *)ptr; } \ inline static void prefix##repl(CELL tagged) { *(CELL *)ptr = tagged; } \ @@ -12,3 +15,5 @@ ptr += CELLS; \ prefix##repl(tagged); \ } + +} diff --git a/vm/strings.cpp b/vm/strings.cpp index d7f2bc884b..a6905aad25 100644 --- a/vm/strings.cpp +++ b/vm/strings.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + CELL string_nth(F_STRING* string, CELL index) { /* If high bit is set, the most significant 16 bits of the char @@ -181,3 +184,5 @@ PRIMITIVE(set_string_nth_slow) CELL value = untag_fixnum(dpop()); set_string_nth_slow(string,index,value); } + +} diff --git a/vm/strings.hpp b/vm/strings.hpp index f35053e78d..f9cdc74bb1 100644 --- a/vm/strings.hpp +++ b/vm/strings.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + inline static CELL string_capacity(F_STRING *str) { return untag_fixnum(str->length); @@ -21,3 +24,5 @@ void set_string_nth(F_STRING* string, CELL index, CELL value); PRIMITIVE(string_nth); PRIMITIVE(set_string_nth_slow); PRIMITIVE(set_string_nth_fast); + +} diff --git a/vm/tagged.hpp b/vm/tagged.hpp index fb14e7fa70..c31389f6b0 100644 --- a/vm/tagged.hpp +++ b/vm/tagged.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + template CELL tag(T *value) { return RETAG(value,tag_for(T::type_number)); @@ -38,7 +41,7 @@ struct tagged #endif } - explicit tagged(T *untagged) : value_(::tag(untagged)) { + explicit tagged(T *untagged) : value_(factor::tag(untagged)) { #ifdef FACTOR_DEBUG untag_check(); #endif @@ -65,3 +68,5 @@ template T *untag(CELL value) { return tagged(value).untagged(); } + +} diff --git a/vm/test.cpp b/vm/test.cpp deleted file mode 100644 index 694416031d..0000000000 --- a/vm/test.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "master.hpp" - - -template struct blah { - const T *x_; - blah(T *x) : x_(x) {} - - blah& operator=(const T *x) { x_ = x; } -}; - -CELL test() -{ - int x = 100; - blah u(&x); - u = &x; -} diff --git a/vm/tuples.cpp b/vm/tuples.cpp index ec93cc4adc..5807d4baf4 100644 --- a/vm/tuples.cpp +++ b/vm/tuples.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + /* push a new tuple on the stack */ F_TUPLE *allot_tuple(CELL layout_) { @@ -30,3 +33,5 @@ PRIMITIVE(tuple_boa) ds -= size; dpush(tuple.value()); } + +} diff --git a/vm/tuples.hpp b/vm/tuples.hpp index bcbc268d72..477510307b 100644 --- a/vm/tuples.hpp +++ b/vm/tuples.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + inline static CELL tuple_size(F_TUPLE_LAYOUT *layout) { CELL size = untag_fixnum(layout->size); @@ -18,3 +21,5 @@ inline static void set_tuple_nth(F_TUPLE *tuple, CELL slot, CELL value) PRIMITIVE(tuple); PRIMITIVE(tuple_boa); PRIMITIVE(tuple_layout); + +} diff --git a/vm/utilities.cpp b/vm/utilities.cpp index b567c4d0a9..2ccc0aaf78 100755 --- a/vm/utilities.cpp +++ b/vm/utilities.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + /* If memory allocation fails, bail out */ void *safe_malloc(size_t size) { @@ -53,3 +56,5 @@ CELL read_cell_hex(void) if(scanf(CELL_HEX_FORMAT,&cell) < 0) exit(1); return cell; }; + +} diff --git a/vm/utilities.hpp b/vm/utilities.hpp index d2b3223ce4..249ea562f5 100755 --- a/vm/utilities.hpp +++ b/vm/utilities.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + void *safe_malloc(size_t size); F_CHAR *safe_strdup(const F_CHAR *str); @@ -8,3 +11,5 @@ void print_cell_hex(CELL x); void print_cell_hex_pad(CELL x); void print_fixnum(F_FIXNUM x); CELL read_cell_hex(void); + +} diff --git a/vm/words.cpp b/vm/words.cpp index 17ddc9b747..d1523ebccf 100644 --- a/vm/words.cpp +++ b/vm/words.cpp @@ -1,5 +1,8 @@ #include "master.hpp" +namespace factor +{ + F_WORD *allot_word(CELL vocab_, CELL name_) { gc_root vocab(vocab_); @@ -74,3 +77,5 @@ PRIMITIVE(wrapper) wrapper->object = dpeek(); drepl(tag(wrapper)); } + +} diff --git a/vm/words.hpp b/vm/words.hpp index d976dccbdd..15c541e9ea 100644 --- a/vm/words.hpp +++ b/vm/words.hpp @@ -1,3 +1,6 @@ +namespace factor +{ + F_WORD *allot_word(CELL vocab, CELL name); PRIMITIVE(word); @@ -12,3 +15,5 @@ inline bool word_optimized_p(F_WORD *word) PRIMITIVE(optimized_p); PRIMITIVE(wrapper); + +} diff --git a/vm/write_barrier.cpp b/vm/write_barrier.cpp index a97caff69e..3ea138f456 100644 --- a/vm/write_barrier.cpp +++ b/vm/write_barrier.cpp @@ -1,5 +1,7 @@ #include "master.hpp" +using namespace factor; + CELL cards_offset; CELL decks_offset; CELL allot_markers_offset; diff --git a/vm/write_barrier.hpp b/vm/write_barrier.hpp index f207547cec..9c317d45b4 100644 --- a/vm/write_barrier.hpp +++ b/vm/write_barrier.hpp @@ -6,6 +6,9 @@ card has a slot written to. the offset of the first object is set by the allocator. */ +namespace factor +{ + /* if CARD_POINTS_TO_NURSERY is set, CARD_POINTS_TO_AGING must also be set. */ #define CARD_POINTS_TO_NURSERY 0x80 #define CARD_POINTS_TO_AGING 0x40 @@ -16,7 +19,7 @@ typedef u8 F_CARD; #define CARD_SIZE (1<> CARD_BITS) + cards_offset) #define CARD_TO_ADDR(c) (CELL*)(((CELL)(c) - cards_offset)<> DECK_BITS) + decks_offset) #define DECK_TO_ADDR(c) (CELL*)(((CELL)(c) - decks_offset) << DECK_BITS) @@ -39,7 +42,7 @@ extern "C" CELL decks_offset; #define INVALID_ALLOT_MARKER 0xff -extern "C" CELL allot_markers_offset; +VM_C_API CELL allot_markers_offset; /* the write barrier must be called any time we are potentially storing a pointer from an older generation to a younger one */ @@ -56,3 +59,5 @@ inline static void allot_barrier(F_OBJECT *address) if(*ptr == INVALID_ALLOT_MARKER) *ptr = ((CELL)address & ADDR_CARD_MASK); } + +}