VM: Refactor layouts/hpp to Factor style
							parent
							
								
									1eaddb0068
								
							
						
					
					
						commit
						0b5a12fdea
					
				| 
						 | 
				
			
			@ -1,5 +1,4 @@
 | 
			
		|||
namespace factor
 | 
			
		||||
{
 | 
			
		||||
namespace factor {
 | 
			
		||||
 | 
			
		||||
typedef unsigned char u8;
 | 
			
		||||
typedef unsigned short u16;
 | 
			
		||||
| 
						 | 
				
			
			@ -18,15 +17,9 @@ typedef signed long long s64;
 | 
			
		|||
typedef unsigned long cell;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
inline static cell align(cell a, cell b)
 | 
			
		||||
{
 | 
			
		||||
	return (a + (b-1)) & ~(b-1);
 | 
			
		||||
}
 | 
			
		||||
inline static cell align(cell a, cell b) { return (a + (b - 1)) & ~(b - 1); }
 | 
			
		||||
 | 
			
		||||
inline static cell alignment_for(cell a, cell b)
 | 
			
		||||
{
 | 
			
		||||
	return align(a,b) - a;
 | 
			
		||||
}
 | 
			
		||||
inline static cell alignment_for(cell a, cell b) { return align(a, b) - a; }
 | 
			
		||||
 | 
			
		||||
static const cell data_alignment = 16;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -56,10 +49,8 @@ static const cell data_alignment = 16;
 | 
			
		|||
 | 
			
		||||
#define TYPE_COUNT 14
 | 
			
		||||
 | 
			
		||||
static inline const char *type_name(cell type)
 | 
			
		||||
{
 | 
			
		||||
	switch (type)
 | 
			
		||||
	{
 | 
			
		||||
static inline const char* type_name(cell type) {
 | 
			
		||||
  switch (type) {
 | 
			
		||||
    case FIXNUM_TYPE:
 | 
			
		||||
      return "fixnum";
 | 
			
		||||
    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_optimized,
 | 
			
		||||
  code_block_pic
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* Constants used when floating-point trap exceptions are thrown */
 | 
			
		||||
enum
 | 
			
		||||
{
 | 
			
		||||
enum {
 | 
			
		||||
  FP_TRAP_INVALID_OPERATION = 1 << 0,
 | 
			
		||||
  FP_TRAP_OVERFLOW = 1 << 1,
 | 
			
		||||
  FP_TRAP_UNDERFLOW = 1 << 2,
 | 
			
		||||
| 
						 | 
				
			
			@ -114,22 +103,19 @@ enum
 | 
			
		|||
/* What Factor calls 'f' */
 | 
			
		||||
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 */
 | 
			
		||||
  return TAG(obj) <= F_TYPE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
inline static fixnum untag_fixnum(cell tagged)
 | 
			
		||||
{
 | 
			
		||||
inline static fixnum untag_fixnum(cell tagged) {
 | 
			
		||||
#ifdef FACTOR_DEBUG
 | 
			
		||||
  FACTOR_ASSERT(TAG(tagged) == FIXNUM_TYPE);
 | 
			
		||||
#endif
 | 
			
		||||
  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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -151,45 +137,23 @@ struct object {
 | 
			
		|||
 | 
			
		||||
  /* Only valid for objects in tenured space; must cast to free_heap_block
 | 
			
		||||
     to do anything with it if its free */
 | 
			
		||||
	bool free_p() const
 | 
			
		||||
	{
 | 
			
		||||
		return (header & 1) == 1;
 | 
			
		||||
	}
 | 
			
		||||
  bool free_p() const { return (header & 1) == 1; }
 | 
			
		||||
 | 
			
		||||
	cell type() const
 | 
			
		||||
	{
 | 
			
		||||
		return (header >> 2) & TAG_MASK;
 | 
			
		||||
	}
 | 
			
		||||
  cell type() const { return (header >> 2) & TAG_MASK; }
 | 
			
		||||
 | 
			
		||||
	void initialize(cell type)
 | 
			
		||||
	{
 | 
			
		||||
		header = type << 2;
 | 
			
		||||
	}
 | 
			
		||||
  void initialize(cell type) { header = type << 2; }
 | 
			
		||||
 | 
			
		||||
	cell hashcode() const
 | 
			
		||||
	{
 | 
			
		||||
		return (header >> 6);
 | 
			
		||||
	}
 | 
			
		||||
  cell hashcode() const { return (header >> 6); }
 | 
			
		||||
 | 
			
		||||
	void set_hashcode(cell hashcode)
 | 
			
		||||
	{
 | 
			
		||||
  void set_hashcode(cell hashcode) {
 | 
			
		||||
    header = (header & 0x3f) | (hashcode << 6);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
	bool forwarding_pointer_p() const
 | 
			
		||||
	{
 | 
			
		||||
		return (header & 2) == 2;
 | 
			
		||||
	}
 | 
			
		||||
  bool forwarding_pointer_p() const { return (header & 2) == 2; }
 | 
			
		||||
 | 
			
		||||
	object *forwarding_pointer() const
 | 
			
		||||
	{
 | 
			
		||||
		return (object *)UNTAG(header);
 | 
			
		||||
	}
 | 
			
		||||
  object* forwarding_pointer() const { return (object*)UNTAG(header); }
 | 
			
		||||
 | 
			
		||||
	void forward_to(object *pointer)
 | 
			
		||||
	{
 | 
			
		||||
		header = ((cell)pointer | 2);
 | 
			
		||||
	}
 | 
			
		||||
  void forward_to(object* pointer) { header = ((cell) pointer | 2); }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* Assembly code makes assumptions about the layout of this struct */
 | 
			
		||||
| 
						 | 
				
			
			@ -234,7 +198,9 @@ struct byte_array : public object {
 | 
			
		|||
  cell padding1;
 | 
			
		||||
#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 */
 | 
			
		||||
| 
						 | 
				
			
			@ -269,9 +235,11 @@ struct word : public object {
 | 
			
		|||
  cell def;
 | 
			
		||||
  /* TAGGED property assoc for library code */
 | 
			
		||||
  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;
 | 
			
		||||
	/* 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;
 | 
			
		||||
  /* TAGGED machine code for sub-primitive */
 | 
			
		||||
  cell subprimitive;
 | 
			
		||||
| 
						 | 
				
			
			@ -332,8 +300,7 @@ struct alien : public object {
 | 
			
		|||
  /* untagged */
 | 
			
		||||
  cell address;
 | 
			
		||||
 | 
			
		||||
	void update_address()
 | 
			
		||||
	{
 | 
			
		||||
  void update_address() {
 | 
			
		||||
    if (base == false_object)
 | 
			
		||||
      address = displacement;
 | 
			
		||||
    else
 | 
			
		||||
| 
						 | 
				
			
			@ -354,13 +321,14 @@ struct callstack : public object {
 | 
			
		|||
  /* tagged */
 | 
			
		||||
  cell length;
 | 
			
		||||
 | 
			
		||||
	void *frame_top_at(cell offset) const
 | 
			
		||||
	{
 | 
			
		||||
  void* frame_top_at(cell offset) const {
 | 
			
		||||
    return (void*)((char*)(this + 1) + offset);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  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 {
 | 
			
		||||
| 
						 | 
				
			
			@ -375,8 +343,8 @@ struct data_root_range {
 | 
			
		|||
  cell* start;
 | 
			
		||||
  cell len;
 | 
			
		||||
 | 
			
		||||
	explicit data_root_range(cell *start_, cell len_) :
 | 
			
		||||
		start(start_), len(len_) {}
 | 
			
		||||
  explicit data_root_range(cell* start_, cell len_)
 | 
			
		||||
      : start(start_), len(len_) {}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue