Skip to content

Commit

Permalink
lj_obj.h: Redefine GCRef as simple GCobj* pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
lukego committed Dec 4, 2017
1 parent 14120c1 commit 2f5a9a3
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/lj_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,27 @@ typedef struct MRef {

/* -- GC object references (32 bit address space) ------------------------- */

/* Forward declaration. */
union GCobj;

/* GCobj reference */
typedef struct GCRef {
uint64_t gcptr64; /* True 64 bit pointer. */
} GCRef;
typedef union GCobj * GCRef;

/* Common GC header for all collectable objects. */
#define GCHeader GCRef nextgc; uint8_t marked; uint8_t gct
/* This occupies 6 bytes, so use the next 2 bytes for non-32 bit fields. */

#define gcref(r) ((GCobj *)(r).gcptr64)
#define gcrefp(r, t) ((t *)(void *)(r).gcptr64)
#define gcrefu(r) ((r).gcptr64)
#define gcrefeq(r1, r2) ((r1).gcptr64 == (r2).gcptr64)
#define gcref(r) (r)
#define gcrefp(r, t) ((t *)(void *)(r))
#define gcrefu(r) ((uint64_t)(r))
#define gcrefeq(r1, r2) ((r1)==(r2))

#define setgcref(r, gc) ((r).gcptr64 = (uint64_t)&(gc)->gch)
#define setgcref(r, gc) ((r) = (GCobj *)&(gc)->gch)
#define setgcreft(r, gc, it) \
(r).gcptr64 = (uint64_t)&(gc)->gch | (((uint64_t)(it)) << 47)
#define setgcrefp(r, p) ((r).gcptr64 = (uint64_t)(p))
#define setgcrefnull(r) ((r).gcptr64 = 0)
#define setgcrefr(r, v) ((r).gcptr64 = (v).gcptr64)
(r) = (GCobj *)((uint64_t)&(gc)->gch | ((uint64_t)(it) << 47))
#define setgcrefp(r, p) ((r) = (GCobj *)p)
#define setgcrefnull(r) ((r) = NULL)
#define setgcrefr(r, v) ((r) = (v))

#define gcnext(gc) (gcref((gc)->gch.nextgc))

Expand Down

0 comments on commit 2f5a9a3

Please sign in to comment.