Skip to content

Commit

Permalink
[mycpp/runtime refactor] Remove uses of OBJ_HEADER() macro
Browse files Browse the repository at this point in the history
Just use the ObjHeader struct.
  • Loading branch information
Andy Chu committed Dec 25, 2022
1 parent 36bae9a commit 1eb2359
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
12 changes: 6 additions & 6 deletions mycpp/gc_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ValueError;
template <typename T, int N>
class GlobalList {
public:
OBJ_HEADER()
ObjHeader header_;
int len_;
int capacity_;
GlobalSlab<T, N>* slab_;
Expand Down Expand Up @@ -407,11 +407,11 @@ List<T>* list(List<T>* other) {
return result;
}

#define GLOBAL_LIST(T, N, name, array) \
GlobalSlab<T, N> _slab_##name = {Tag::Global, 0, kZeroMask, kNoObjLen, \
array}; \
GlobalList<T, N> _list_##name = {Tag::Global, 0, kZeroMask, kNoObjLen, \
N, N, &_slab_##name}; \
#define GLOBAL_LIST(T, N, name, array) \
GlobalSlab<T, N> _slab_##name = {{Tag::Global, 0, kZeroMask, kNoObjLen}, \
array}; \
GlobalList<T, N> _list_##name = { \
{Tag::Global, 0, kZeroMask, kNoObjLen}, N, N, &_slab_##name}; \
List<T>* name = reinterpret_cast<List<T>*>(&_list_##name);

template <class T>
Expand Down
8 changes: 4 additions & 4 deletions mycpp/gc_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const uint8_t kMycppDebugType = 255;
// And we can sort integers BEFORE pointers.

// TODO: ./configure could detect big or little endian, and then flip the
// fields in OBJ_HEADER?
// fields in Obj?
//
// https://stackoverflow.com/questions/2100331/c-macro-definition-to-determine-big-endian-or-little-endian-machine
//
Expand Down Expand Up @@ -107,7 +107,7 @@ class Obj {

class _DummyObj { // For maskbit()
public:
OBJ_HEADER()
ObjHeader header_;
int first_field_;
};

Expand All @@ -116,7 +116,7 @@ class _DummyObj { // For maskbit()
//
// - Note that we only call maskbit() on offsets of pointer fields, which must
// be POINTER-ALIGNED.
// - _DummyObj is used in case OBJ_HEADER() requires padding, then
// - _DummyObj is used in case ObjHeader requires padding, then
// sizeof(Obj) != offsetof(_DummyObj, first_field_)

constexpr int maskbit(int offset) {
Expand All @@ -126,7 +126,7 @@ constexpr int maskbit(int offset) {
class _DummyObj_v { // For maskbit_v()
public:
void* vtable; // how the compiler does dynamic dispatch
OBJ_HEADER()
ObjHeader header_;
int first_field_;
};

Expand Down
3 changes: 1 addition & 2 deletions mycpp/gc_slab.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ class GlobalSlab {
// A template type with the same layout as Str with length N-1 (which needs a
// buffer of size N). For initializing global constant instances.
public:
OBJ_HEADER()

ObjHeader header_;
T items_[N];

DISALLOW_COPY_AND_ASSIGN(GlobalSlab)
Expand Down
11 changes: 6 additions & 5 deletions mycpp/gc_str.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ class GlobalStr {
// A template type with the same layout as Str with length N-1 (which needs a
// buffer of size N). For initializing global constant instances.
public:
OBJ_HEADER()

ObjHeader header_;
int hash_value_;
const char data_[N];

Expand All @@ -195,9 +194,11 @@ class GlobalStr {
// https://old.reddit.com/r/cpp_questions/comments/j0khh6/how_to_constexpr_initialize_class_member_thats/
// https://stackoverflow.com/questions/10422487/how-can-i-initialize-char-arrays-in-a-constructor

#define GLOBAL_STR(name, val) \
GlobalStr<sizeof(val)> _##name = { \
Tag::Global, 0, kZeroMask, kStrHeaderSize + sizeof(val), -1, val}; \
#define GLOBAL_STR(name, val) \
GlobalStr<sizeof(val)> _##name = { \
{Tag::Global, kStrTypeTag, kZeroMask, kStrHeaderSize + sizeof(val)}, \
-1, \
val}; \
Str* name = reinterpret_cast<Str*>(&_##name);

#endif // MYCPP_GC_STR_H

0 comments on commit 1eb2359

Please sign in to comment.