Skip to content

Commit

Permalink
Use C++ namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Slava Pestov committed May 4, 2009
1 parent 1857f90 commit 7f48eb2
Show file tree
Hide file tree
Showing 118 changed files with 594 additions and 52 deletions.
5 changes: 5 additions & 0 deletions 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)
Expand Down Expand Up @@ -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);
}

}
5 changes: 5 additions & 0 deletions vm/alien.hpp
@@ -1,3 +1,6 @@
namespace factor
{

CELL allot_alien(CELL delegate, CELL displacement);

PRIMITIVE(displaced_alien);
Expand Down Expand Up @@ -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);

}
5 changes: 5 additions & 0 deletions 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_)
{
Expand Down Expand Up @@ -80,3 +83,5 @@ void growable_array::trim()
{
array = reallot_array(array.untagged(),count);
}

}
5 changes: 5 additions & 0 deletions vm/arrays.hpp
@@ -1,3 +1,6 @@
namespace factor
{

inline static CELL array_nth(F_ARRAY *array, CELL slot)
{
#ifdef FACTOR_DEBUG
Expand Down Expand Up @@ -36,3 +39,5 @@ struct growable_array {
void add(CELL elt);
void trim();
};

}
5 changes: 5 additions & 0 deletions vm/bignum.cpp
Expand Up @@ -56,6 +56,9 @@ MIT in each case. */
#include <stdio.h>
#include <math.h>

namespace factor
{

/* Exports */

int
Expand Down Expand Up @@ -1841,3 +1844,5 @@ digit_stream_to_bignum(unsigned int n_digits,
}
}
}

}
5 changes: 5 additions & 0 deletions vm/bignum.hpp
@@ -1,3 +1,6 @@
namespace factor
{

/* :tabSize=2:indentSize=2:noTabs=true:
Copyright (C) 1989-1992 Massachusetts Institute of Technology
Expand Down Expand Up @@ -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);

}
5 changes: 5 additions & 0 deletions vm/bignumint.hpp
Expand Up @@ -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
Expand Down Expand Up @@ -98,3 +101,5 @@ typedef F_FIXNUM bignum_length_type;
}

#endif /* not BIGNUM_DISABLE_ASSERTION_CHECKS */

}
5 changes: 5 additions & 0 deletions vm/booleans.cpp
@@ -1,5 +1,8 @@
#include "master.hpp"

namespace factor
{

VM_C_API void box_boolean(bool value)
{
dpush(value ? T : F);
Expand All @@ -9,3 +12,5 @@ VM_C_API bool to_boolean(CELL value)
{
return value != F;
}

}
5 changes: 5 additions & 0 deletions vm/booleans.hpp
@@ -1,7 +1,12 @@
namespace factor
{

inline static CELL tag_boolean(CELL untagged)
{
return (untagged ? T : F);
}

VM_C_API void box_boolean(bool value);
VM_C_API bool to_boolean(CELL value);

}
5 changes: 5 additions & 0 deletions 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<F_BYTE_ARRAY>(size);
Expand Down Expand Up @@ -57,3 +60,5 @@ void growable_byte_array::trim()
{
array = reallot_array(array.untagged(),count);
}

}
5 changes: 5 additions & 0 deletions vm/byte_arrays.hpp
@@ -1,3 +1,6 @@
namespace factor
{

F_BYTE_ARRAY *allot_byte_array(CELL size);

PRIMITIVE(byte_array);
Expand All @@ -16,3 +19,5 @@ struct growable_byte_array {

void trim();
};

}
5 changes: 5 additions & 0 deletions vm/callstack.cpp
@@ -1,5 +1,8 @@
#include "master.hpp"

namespace factor
{

static void check_frame(F_STACK_FRAME *frame)
{
#ifdef FACTOR_DEBUG
Expand Down Expand Up @@ -223,3 +226,5 @@ VM_ASM_API void save_callstack_bottom(F_STACK_FRAME *callstack_bottom)
{
stack_chain->callstack_bottom = callstack_bottom;
}

}
5 changes: 5 additions & 0 deletions vm/callstack.hpp
@@ -1,3 +1,6 @@
namespace factor
{

inline static CELL callstack_size(CELL size)
{
return sizeof(F_CALLSTACK) + size;
Expand All @@ -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);

}
8 changes: 8 additions & 0 deletions 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);
Expand Down Expand Up @@ -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<F_ARRAY>(symbol);
Expand Down Expand Up @@ -485,3 +491,5 @@ F_CODE_BLOCK *add_code_block(

return compiled;
}

}
5 changes: 5 additions & 0 deletions vm/code_block.hpp
@@ -1,3 +1,6 @@
namespace factor
{

typedef enum {
/* arg is a primitive number */
RT_PRIMITIVE,
Expand Down Expand Up @@ -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);

}
5 changes: 5 additions & 0 deletions 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));
Expand Down Expand Up @@ -334,3 +337,5 @@ void compact_heap(F_HEAP *heap)
scan = next;
}
}

}
5 changes: 5 additions & 0 deletions vm/code_gc.hpp
@@ -1,3 +1,6 @@
namespace factor
{

#define FREE_LIST_COUNT 16
#define BLOCK_SIZE_INCREMENT 32

Expand Down Expand Up @@ -43,3 +46,5 @@ inline static F_BLOCK *last_block(F_HEAP *heap)
{
return (F_BLOCK *)heap->segment->end;
}

}
5 changes: 5 additions & 0 deletions vm/code_heap.cpp
@@ -1,5 +1,8 @@
#include "master.hpp"

namespace factor
{

F_HEAP code_heap;

/* Allocate a code heap during startup */
Expand Down Expand Up @@ -220,3 +223,5 @@ void compact_code_heap(void)
the end */
build_free_list(&code_heap,size);
}

}
5 changes: 5 additions & 0 deletions vm/code_heap.hpp
@@ -1,3 +1,6 @@
namespace factor
{

/* compiled code */
extern F_HEAP code_heap;

Expand Down Expand Up @@ -25,3 +28,5 @@ inline static void check_code_pointer(CELL pointer)
assert(pointer >= code_heap.segment->start && pointer < code_heap.segment->end);
#endif
}

}
8 changes: 7 additions & 1 deletion 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;

Expand Down Expand Up @@ -184,3 +188,5 @@ PRIMITIVE(check_datastack)
dpush(T);
}
}

}
9 changes: 7 additions & 2 deletions 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
Expand Down Expand Up @@ -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)
Expand All @@ -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;
5 changes: 5 additions & 0 deletions vm/cpu-arm.hpp
@@ -1,3 +1,6 @@
namespace factor
{

#define FACTOR_CPU_STRING "arm"

register CELL ds asm("r5");
Expand All @@ -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);

}
5 changes: 5 additions & 0 deletions vm/cpu-ppc.hpp
@@ -1,3 +1,6 @@
namespace factor
{

#define FACTOR_CPU_STRING "ppc"
#define VM_ASM_API

Expand All @@ -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);

}
5 changes: 5 additions & 0 deletions 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)))

}
5 changes: 5 additions & 0 deletions 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"

}
5 changes: 5 additions & 0 deletions vm/cpu-x86.hpp
@@ -1,5 +1,8 @@
#include <assert.h>

namespace factor
{

#define FRAME_RETURN_ADDRESS(frame) *(XT *)(frame_successor(frame) + 1)

inline static void flush_icache(CELL start, CELL len) {}
Expand Down Expand Up @@ -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));

}

0 comments on commit 7f48eb2

Please sign in to comment.