VM: Refactor layouts/hpp to Factor style

db4
Erik Charlebois 2013-05-11 22:08:13 -04:00
parent 1eaddb0068
commit 0b5a12fdea
1 changed files with 201 additions and 233 deletions

View File

@ -1,5 +1,4 @@
namespace factor namespace factor {
{
typedef unsigned char u8; typedef unsigned char u8;
typedef unsigned short u16; typedef unsigned short u16;
@ -18,15 +17,9 @@ typedef signed long long s64;
typedef unsigned long cell; typedef unsigned long cell;
#endif #endif
inline static cell align(cell a, cell b) inline static cell align(cell a, cell b) { return (a + (b - 1)) & ~(b - 1); }
{
return (a + (b-1)) & ~(b-1);
}
inline static cell alignment_for(cell a, cell b) inline static cell alignment_for(cell a, cell b) { return align(a, b) - a; }
{
return align(a,b) - a;
}
static const cell data_alignment = 16; static const cell data_alignment = 16;
@ -56,10 +49,8 @@ static const cell data_alignment = 16;
#define TYPE_COUNT 14 #define TYPE_COUNT 14
static inline const char *type_name(cell type) static inline const char* type_name(cell type) {
{ switch (type) {
switch (type)
{
case FIXNUM_TYPE: case FIXNUM_TYPE:
return "fixnum"; return "fixnum";
case F_TYPE: case F_TYPE:
@ -94,16 +85,14 @@ static inline const char *type_name(cell type)
} }
} }
enum code_block_type enum code_block_type {
{
code_block_unoptimized, code_block_unoptimized,
code_block_optimized, code_block_optimized,
code_block_pic code_block_pic
}; };
/* Constants used when floating-point trap exceptions are thrown */ /* Constants used when floating-point trap exceptions are thrown */
enum enum {
{
FP_TRAP_INVALID_OPERATION = 1 << 0, FP_TRAP_INVALID_OPERATION = 1 << 0,
FP_TRAP_OVERFLOW = 1 << 1, FP_TRAP_OVERFLOW = 1 << 1,
FP_TRAP_UNDERFLOW = 1 << 2, FP_TRAP_UNDERFLOW = 1 << 2,
@ -114,22 +103,19 @@ enum
/* What Factor calls 'f' */ /* What Factor calls 'f' */
static const cell false_object = F_TYPE; static const cell false_object = F_TYPE;
inline static bool immediate_p(cell obj) inline static bool immediate_p(cell obj) {
{
/* We assume that fixnums have tag 0 and false_object has tag 1 */ /* We assume that fixnums have tag 0 and false_object has tag 1 */
return TAG(obj) <= F_TYPE; return TAG(obj) <= F_TYPE;
} }
inline static fixnum untag_fixnum(cell tagged) inline static fixnum untag_fixnum(cell tagged) {
{
#ifdef FACTOR_DEBUG #ifdef FACTOR_DEBUG
FACTOR_ASSERT(TAG(tagged) == FIXNUM_TYPE); FACTOR_ASSERT(TAG(tagged) == FIXNUM_TYPE);
#endif #endif
return ((fixnum) tagged) >> TAG_BITS; return ((fixnum) tagged) >> TAG_BITS;
} }
inline static cell tag_fixnum(fixnum untagged) inline static cell tag_fixnum(fixnum untagged) {
{
return (untagged << TAG_BITS) | FIXNUM_TYPE; return (untagged << TAG_BITS) | FIXNUM_TYPE;
} }
@ -151,45 +137,23 @@ struct object {
/* Only valid for objects in tenured space; must cast to free_heap_block /* Only valid for objects in tenured space; must cast to free_heap_block
to do anything with it if its free */ to do anything with it if its free */
bool free_p() const bool free_p() const { return (header & 1) == 1; }
{
return (header & 1) == 1;
}
cell type() const cell type() const { return (header >> 2) & TAG_MASK; }
{
return (header >> 2) & TAG_MASK;
}
void initialize(cell type) void initialize(cell type) { header = type << 2; }
{
header = type << 2;
}
cell hashcode() const cell hashcode() const { return (header >> 6); }
{
return (header >> 6);
}
void set_hashcode(cell hashcode) void set_hashcode(cell hashcode) {
{
header = (header & 0x3f) | (hashcode << 6); header = (header & 0x3f) | (hashcode << 6);
} }
bool forwarding_pointer_p() const bool forwarding_pointer_p() const { return (header & 2) == 2; }
{
return (header & 2) == 2;
}
object *forwarding_pointer() const object* forwarding_pointer() const { return (object*)UNTAG(header); }
{
return (object *)UNTAG(header);
}
void forward_to(object *pointer) void forward_to(object* pointer) { header = ((cell) pointer | 2); }
{
header = ((cell)pointer | 2);
}
}; };
/* Assembly code makes assumptions about the layout of this struct */ /* Assembly code makes assumptions about the layout of this struct */
@ -234,7 +198,9 @@ struct byte_array : public object {
cell padding1; cell padding1;
#endif #endif
template<typename Scalar> Scalar *data() const { return (Scalar *)(this + 1); } template <typename Scalar> Scalar* data() const {
return (Scalar*)(this + 1);
}
}; };
/* Assembly code makes assumptions about the layout of this struct */ /* Assembly code makes assumptions about the layout of this struct */
@ -269,9 +235,11 @@ struct word : public object {
cell def; cell def;
/* TAGGED property assoc for library code */ /* TAGGED property assoc for library code */
cell props; cell props;
/* TAGGED alternative entry point for direct non-tail calls. Used for inline caching */ /* TAGGED alternative entry point for direct non-tail calls. Used for inline
* caching */
cell pic_def; cell pic_def;
/* TAGGED alternative entry point for direct tail calls. Used for inline caching */ /* TAGGED alternative entry point for direct tail calls. Used for inline
* caching */
cell pic_tail_def; cell pic_tail_def;
/* TAGGED machine code for sub-primitive */ /* TAGGED machine code for sub-primitive */
cell subprimitive; cell subprimitive;
@ -332,8 +300,7 @@ struct alien : public object {
/* untagged */ /* untagged */
cell address; cell address;
void update_address() void update_address() {
{
if (base == false_object) if (base == false_object)
address = displacement; address = displacement;
else else
@ -354,13 +321,14 @@ struct callstack : public object {
/* tagged */ /* tagged */
cell length; cell length;
void *frame_top_at(cell offset) const void* frame_top_at(cell offset) const {
{
return (void*)((char*)(this + 1) + offset); return (void*)((char*)(this + 1) + offset);
} }
void* top() const { return (void*)(this + 1); } void* top() const { return (void*)(this + 1); }
void *bottom() const { return (void *)((cell)(this + 1) + untag_fixnum(length)); } void* bottom() const {
return (void*)((cell)(this + 1) + untag_fixnum(length));
}
}; };
struct tuple : public object { struct tuple : public object {
@ -375,8 +343,8 @@ struct data_root_range {
cell* start; cell* start;
cell len; cell len;
explicit data_root_range(cell *start_, cell len_) : explicit data_root_range(cell* start_, cell len_)
start(start_), len(len_) {} : start(start_), len(len_) {}
}; };
} }