Skip to content

Commit

Permalink
move remaining fields to start of types
Browse files Browse the repository at this point in the history
  • Loading branch information
ashinn committed Jul 29, 2020
1 parent b60a6a2 commit 60ee6d7
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 62 deletions.
30 changes: 18 additions & 12 deletions include/chibi/sexp.h
Expand Up @@ -373,21 +373,21 @@ struct sexp_library_entry_t { /* for static builds */
};

struct sexp_type_struct {
sexp name, cpl, slots, getters, setters, id, print, dl, finalize_name;
sexp_tag_t tag;
short field_base, field_eq_len_base, field_len_base, field_len_off;
unsigned short field_len_scale;
short size_base, size_off;
unsigned short size_scale;
short weak_base, weak_len_base, weak_len_off, weak_len_scale, weak_len_extra;
short depth;
sexp name, cpl, slots, getters, setters, id, print, dl, finalize_name;
sexp_proc2 finalize;
};

struct sexp_opcode_struct {
unsigned char op_class, code, num_args, flags, inverse;
sexp name, data, data2, proc, ret_type, arg1_type, arg2_type, arg3_type,
argn_type, methods, dl;
unsigned char op_class, code, num_args, flags, inverse;
sexp_proc1 func;
};

Expand All @@ -401,9 +401,12 @@ struct sexp_mark_stack_ptr_t {
struct sexp_mark_stack_ptr_t *prev; /* TODO: remove for allocations on stack */
};

/* Note this must be kept in sync with the type registry in sexp.c. */
/* sexp fields must be placed first if you use slot-ref/set!, as is */
/* done by write. */
/* Note this must be kept in sync with the _sexp_type_specs type */
/* registry in sexp.c. The structure of a sexp type is: */
/* [ HEADER [[EQ_FIELDS... ] GC_FIELDS...] [WEAK_FIELDS...] [OTHER...] ] */
/* Thus all sexp's must be contiguous and align at the start of the type. */
/* This is used by the gc, equal? and slot-ref (although only the latter */
/* expects the alignment at the start of the type). */
struct sexp_struct {
sexp_tag_t tag;
char markedp;
Expand Down Expand Up @@ -442,14 +445,17 @@ struct sexp_struct {
} uvector;
struct {
#if SEXP_USE_PACKED_STRINGS
#if SEXP_USE_STRING_INDEX_TABLE
sexp charlens;
#endif
sexp_uint_t length;
char data SEXP_FLEXIBLE_ARRAY;
#else
sexp_uint_t offset, length;
sexp bytes;
#endif
#if SEXP_USE_STRING_INDEX_TABLE
sexp charlens;
#endif
sexp_uint_t offset, length;
#endif
} string;
struct {
Expand Down Expand Up @@ -548,6 +554,11 @@ struct sexp_struct {
sexp data SEXP_FLEXIBLE_ARRAY;
} stack;
struct {
sexp stack, env, parent, child,
globals, dk, params, proc, name, specific, event, result;
#if SEXP_USE_STABLE_ABI || SEXP_USE_DL
sexp dl;
#endif
sexp_heap heap;
struct sexp_mark_stack_ptr_t mark_stack[SEXP_MARK_STACK_COUNT];
struct sexp_mark_stack_ptr_t *mark_stack_ptr;
Expand All @@ -569,11 +580,6 @@ struct sexp_struct {
#endif
#if SEXP_USE_TRACK_ALLOC_SIZES
sexp_uint_t alloc_histogram[SEXP_ALLOC_HISTOGRAM_BUCKETS];
#endif
sexp stack, env, parent, child,
globals, dk, params, proc, name, specific, event, result;
#if SEXP_USE_STABLE_ABI || SEXP_USE_DL
sexp dl;
#endif
} context;
#if SEXP_USE_STABLE_ABI || SEXP_USE_AUTO_FORCE
Expand Down
4 changes: 2 additions & 2 deletions lib/chibi/optimize/rest.c
Expand Up @@ -9,9 +9,9 @@ static sexp sexp_num_parameters (sexp ctx, sexp self, sexp_sint_t n) {
}

struct sexp_opcode_struct local_ref_op =
{SEXP_OPC_GENERIC, SEXP_OP_LOCAL_REF, 1, 8, 0, (sexp)"local-ref", SEXP_VOID,
{(sexp)"local-ref", SEXP_VOID,
NULL, NULL, sexp_make_fixnum(SEXP_OBJECT), sexp_make_fixnum(SEXP_FIXNUM),
0, 0, NULL};
0, 0, 0, 0, 0, SEXP_OPC_GENERIC, SEXP_OP_LOCAL_REF, 1, 8, 0, NULL};

static sexp copy_opcode (sexp ctx, struct sexp_opcode_struct *op) {
sexp res = sexp_alloc_type(ctx, opcode, SEXP_OPCODE);
Expand Down
8 changes: 4 additions & 4 deletions opcodes.c
Expand Up @@ -4,18 +4,18 @@
#define _I(n) sexp_make_fixnum(n)

#define _OP(c,o,n,m,rt,a1,a2,a3,i,s,d,f) \
{c, o, n, m, i, (sexp)s, d, NULL, NULL, rt, a1, a2, a3, NULL, NULL, SEXP_FALSE, f}
{(sexp)s, d, NULL, NULL, rt, a1, a2, a3, NULL, NULL, SEXP_FALSE, c, o, n, m, i, f}

#define _GETTER(name, type, index) \
{SEXP_OPC_GETTER, SEXP_OP_SLOT_REF, 1, 0, 0, (sexp)name, _I(type), _I(index), NULL, _I(SEXP_OBJECT), _I(type), NULL, NULL, NULL, NULL, SEXP_FALSE, NULL}
{(sexp)name, _I(type), _I(index), NULL, _I(SEXP_OBJECT), _I(type), NULL, NULL, NULL, NULL, SEXP_FALSE, SEXP_OPC_GETTER, SEXP_OP_SLOT_REF, 1, 0, 0, NULL}
#define _SETTER(name, type, index) \
{SEXP_OPC_SETTER, SEXP_OP_SLOT_SET, 2, 0, 0, (sexp)name, _I(type), _I(index), NULL, SEXP_VOID, _I(type), _I(SEXP_OBJECT), NULL, NULL, NULL, SEXP_FALSE, NULL}
{(sexp)name, _I(type), _I(index), NULL, SEXP_VOID, _I(type), _I(SEXP_OBJECT), NULL, NULL, NULL, SEXP_FALSE, SEXP_OPC_SETTER, SEXP_OP_SLOT_SET, 2, 0, 0, NULL}

#define _PARAM(n, t) \
_OP(SEXP_OPC_PARAMETER, SEXP_OP_PARAMETER_REF, 0, 1, t, t, SEXP_FALSE, SEXP_FALSE, 0, n, SEXP_FALSE, 0)

#if SEXP_USE_IMAGE_LOADING
#define _FN(o,n,m,rt,a1,a2,a3,s,d,f) {SEXP_OPC_FOREIGN, o, n, m, 0, (sexp)s, d, (sexp)#f, NULL, rt, a1, a2, a3, NULL, NULL, SEXP_FALSE, (sexp_proc1)f}
#define _FN(o,n,m,rt,a1,a2,a3,s,d,f) {(sexp)s, d, (sexp)#f, NULL, rt, a1, a2, a3, NULL, NULL, SEXP_FALSE, SEXP_OPC_FOREIGN, o, n, m, 0, (sexp_proc1)f}
#else
#define _FN(o,n,m,rt,a1,a2,a3,s,d,f) _OP(SEXP_OPC_FOREIGN, o, n, m, rt, a1, a2, a3, 0, s, d, (sexp_proc1)f)
#endif
Expand Down

0 comments on commit 60ee6d7

Please sign in to comment.