projects
/
muddle-interpreter.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Compute the version number dynamically
[muddle-interpreter.git]
/
src
/
object.h
diff --git
a/src/object.h
b/src/object.h
index 8ebd80704a39ebdf8a70ba378bb070d34d9f9164..1435f5d353098a0105296df4b9fe01ac116a996d 100644
(file)
--- a/
src/object.h
+++ b/
src/object.h
@@
-122,8
+122,17
@@
typedef union object object;
typedef struct
{
typedef struct
{
- alignas (8) uint32_t _pad;
+ alignas (8)
+ // layout so that value can be upcast by reinterpreting as a fix64
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+ int32_t n;
+ uint32_t _pad;
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+ uint32_t _pad;
int32_t n;
int32_t n;
+#else
+#error Unusual endianness?
+#endif
} fix32_val;
typedef struct
{
} fix32_val;
typedef struct
{
@@
-252,6
+261,7
@@
typedef union pool_object
vector_object vector;
uvector_object uvector;
atom_object atom;
vector_object vector;
uvector_object uvector;
atom_object atom;
+ subr_object subr;
} pool_object;
union object
} pool_object;
union object
@@
-262,7
+272,11
@@
union object
// NB. never take the address of these type-punned fields!
alignas (16) evaltype type;
opaque32 _unknown0;
// NB. never take the address of these type-punned fields!
alignas (16) evaltype type;
opaque32 _unknown0;
- opaque64 _unknown1;
+ union
+ {
+ opaque64 _unknown1;
+ uv_val uv_val;
+ };
};
/// objects of statically known type
/// use as_X() for checked downcast
};
/// objects of statically known type
/// use as_X() for checked downcast
@@
-274,6
+288,7
@@
union object
uvector_object uvector;
atom_object atom;
tuple_object tuple;
uvector_object uvector;
atom_object atom;
tuple_object tuple;
+ subr_object subr;
};
/**
};
/**
@@
-313,7
+328,6
@@
new_list (pool_ptr head)
,};
}
,};
}
-// TODO: take a dope_object like uvector
static inline vector_object
new_vector (heap_ptr body, uint32_t length)
{
static inline vector_object
new_vector (heap_ptr body, uint32_t length)
{
@@
-380,6
+394,8
@@
Common object operations.
uint32_t list_length (const list_object * o);
uint32_t list_length (const list_object * o);
+dope_object *vec_dope (const vector_object * o);
+
dope_object *uv_dope (const uvector_object * o);
static inline evaltype
dope_object *uv_dope (const uvector_object * o);
static inline evaltype
@@
-388,6
+404,10
@@
utype (const uvector_object * o)
return uv_dope (o)->type;
}
return uv_dope (o)->type;
}
+object
+uv_get (const uvector_object * o, uint32_t i);
+
+
// Change the EVALTYPE of an object. New type must have same PRIMTYPE.
static inline void
chtype (object * o, evaltype type)
// Change the EVALTYPE of an object. New type must have same PRIMTYPE.
static inline void
chtype (object * o, evaltype type)
@@
-396,10
+416,23
@@
chtype (object * o, evaltype type)
o->type = type;
}
o->type = type;
}
+// Allocate an vector of LOSEs and return a handle with length=0.
+vector_object vector_create (uint32_t capacity);
+
+// Stack-like interface to a VECTOR (with automatic GROW!)
+object *stack_push (vector_object * v);
+
/**
Checked downcasts.
*/
/**
Checked downcasts.
*/
+static inline fix32_object *
+as_fix32 (object * o)
+{
+ assert (TYPEPRIM_EQ (o->type, TYPEPRIM_FIX32));
+ return &o->fix32;
+}
+
static inline list_object *
as_list (object * o)
{
static inline list_object *
as_list (object * o)
{