mirror of https://github.com/mgba-emu/mgba.git
Scripting: Remove static members
This commit is contained in:
parent
17d2373975
commit
0c28e34a7e
|
@ -226,15 +226,6 @@ CXX_GUARD_START
|
|||
} \
|
||||
},
|
||||
|
||||
#define mSCRIPT_DEFINE_STATIC_MEMBER(TYPE, NAME) { \
|
||||
.type = mSCRIPT_CLASS_INIT_STATIC_MEMBER, \
|
||||
.info = { \
|
||||
.member = { \
|
||||
.name = #NAME, \
|
||||
.type = mSCRIPT_TYPE_MS_ ## TYPE \
|
||||
} \
|
||||
}, \
|
||||
},
|
||||
|
||||
#define mSCRIPT_DEFINE_INHERIT(PARENT) { \
|
||||
.type = mSCRIPT_CLASS_INIT_INHERIT, \
|
||||
|
@ -450,7 +441,6 @@ enum mScriptClassInitType {
|
|||
mSCRIPT_CLASS_INIT_END = 0,
|
||||
mSCRIPT_CLASS_INIT_DOCSTRING,
|
||||
mSCRIPT_CLASS_INIT_INSTANCE_MEMBER,
|
||||
mSCRIPT_CLASS_INIT_STATIC_MEMBER,
|
||||
mSCRIPT_CLASS_INIT_INHERIT,
|
||||
};
|
||||
|
||||
|
@ -505,7 +495,6 @@ struct mScriptTypeClass {
|
|||
bool init;
|
||||
const struct mScriptClassInitDetails* details;
|
||||
const struct mScriptType* parent;
|
||||
struct Table staticMembers;
|
||||
struct Table instanceMembers;
|
||||
};
|
||||
|
||||
|
|
|
@ -93,12 +93,6 @@ mSCRIPT_DEFINE_STRUCT(TestA)
|
|||
mSCRIPT_DEFINE_STRUCT_METHOD(TestA, ic1)
|
||||
mSCRIPT_DEFINE_STRUCT_METHOD(TestA, v0)
|
||||
mSCRIPT_DEFINE_STRUCT_METHOD(TestA, v1)
|
||||
|
||||
mSCRIPT_DEFINE_DOCSTRING(MEMBER_A_DOCSTRING)
|
||||
mSCRIPT_DEFINE_STATIC_MEMBER(S32, s_i)
|
||||
mSCRIPT_DEFINE_STATIC_MEMBER(S32, s_i2)
|
||||
mSCRIPT_DEFINE_STATIC_MEMBER(S8, s_b8)
|
||||
mSCRIPT_DEFINE_STATIC_MEMBER(S16, s_hUnaligned)
|
||||
mSCRIPT_DEFINE_END;
|
||||
|
||||
mSCRIPT_DEFINE_STRUCT(TestB)
|
||||
|
@ -123,7 +117,6 @@ M_TEST_DEFINE(testALayout) {
|
|||
|
||||
struct mScriptClassMember* member;
|
||||
|
||||
// Instance members
|
||||
member = HashTableLookup(&cls->instanceMembers, "i");
|
||||
assert_non_null(member);
|
||||
assert_string_equal(member->name, "i");
|
||||
|
@ -155,38 +148,6 @@ M_TEST_DEFINE(testALayout) {
|
|||
member = HashTableLookup(&cls->instanceMembers, "unknown");
|
||||
assert_null(member);
|
||||
|
||||
// Static members
|
||||
member = HashTableLookup(&cls->staticMembers, "s_i");
|
||||
assert_non_null(member);
|
||||
assert_string_equal(member->name, "s_i");
|
||||
assert_string_equal(member->docstring, MEMBER_A_DOCSTRING);
|
||||
assert_ptr_equal(member->type, mSCRIPT_TYPE_MS_S32);
|
||||
assert_int_equal(member->offset, 0);
|
||||
|
||||
member = HashTableLookup(&cls->staticMembers, "s_i2");
|
||||
assert_non_null(member);
|
||||
assert_string_equal(member->name, "s_i2");
|
||||
assert_null(member->docstring);
|
||||
assert_ptr_equal(member->type, mSCRIPT_TYPE_MS_S32);
|
||||
assert_int_equal(member->offset, sizeof(int32_t));
|
||||
|
||||
member = HashTableLookup(&cls->staticMembers, "s_b8");
|
||||
assert_non_null(member);
|
||||
assert_string_equal(member->name, "s_b8");
|
||||
assert_null(member->docstring);
|
||||
assert_ptr_equal(member->type, mSCRIPT_TYPE_MS_S8);
|
||||
assert_int_equal(member->offset, sizeof(int32_t) * 2);
|
||||
|
||||
member = HashTableLookup(&cls->staticMembers, "s_hUnaligned");
|
||||
assert_non_null(member);
|
||||
assert_string_equal(member->name, "s_hUnaligned");
|
||||
assert_null(member->docstring);
|
||||
assert_ptr_equal(member->type, mSCRIPT_TYPE_MS_S16);
|
||||
assert_int_not_equal(member->offset, sizeof(int32_t) * 2 + 1);
|
||||
|
||||
member = HashTableLookup(&cls->staticMembers, "unknown");
|
||||
assert_null(member);
|
||||
|
||||
mScriptClassDeinit(cls);
|
||||
assert_false(cls->init);
|
||||
}
|
||||
|
@ -474,7 +435,6 @@ M_TEST_DEFINE(testADynamic) {
|
|||
|
||||
struct mScriptClassMember* member;
|
||||
|
||||
// Instance methods
|
||||
member = HashTableLookup(&cls->instanceMembers, "ifn0");
|
||||
assert_non_null(member);
|
||||
assert_string_equal(member->name, "ifn0");
|
||||
|
@ -602,7 +562,6 @@ M_TEST_DEFINE(testBLayout) {
|
|||
|
||||
struct mScriptClassMember* member;
|
||||
|
||||
// Instance members
|
||||
member = HashTableLookup(&cls->instanceMembers, "i");
|
||||
assert_non_null(member);
|
||||
assert_string_equal(member->name, "i");
|
||||
|
@ -820,7 +779,6 @@ M_TEST_DEFINE(testDLayout) {
|
|||
|
||||
struct mScriptClassMember* member;
|
||||
|
||||
// Instance members
|
||||
member = HashTableLookup(&cls->instanceMembers, "a");
|
||||
assert_non_null(member);
|
||||
assert_string_equal(member->name, "a");
|
||||
|
|
|
@ -759,7 +759,6 @@ void mScriptFrameDeinit(struct mScriptFrame* frame) {
|
|||
|
||||
static void _mScriptClassInit(struct mScriptTypeClass* cls, const struct mScriptClassInitDetails* details, bool child) {
|
||||
const char* docstring = NULL;
|
||||
size_t staticOffset = 0;
|
||||
|
||||
size_t i;
|
||||
for (i = 0; details[i].type != mSCRIPT_CLASS_INIT_END; ++i) {
|
||||
|
@ -791,28 +790,6 @@ static void _mScriptClassInit(struct mScriptTypeClass* cls, const struct mScript
|
|||
}
|
||||
HashTableInsert(&cls->instanceMembers, member->name, member);
|
||||
break;
|
||||
case mSCRIPT_CLASS_INIT_STATIC_MEMBER:
|
||||
if (!child) {
|
||||
member = calloc(1, sizeof(*member));
|
||||
memcpy(member, &detail->info.member, sizeof(*member));
|
||||
if (docstring) {
|
||||
member->docstring = docstring;
|
||||
docstring = NULL;
|
||||
}
|
||||
|
||||
// Alignment check
|
||||
if (staticOffset & (detail->info.member.type->size - 1)) {
|
||||
size_t size = detail->info.member.type->size;
|
||||
if (size > MAX_ALIGNMENT) {
|
||||
size = MAX_ALIGNMENT;
|
||||
}
|
||||
staticOffset = (staticOffset & ~(size - 1)) + size;
|
||||
}
|
||||
member->offset = staticOffset;
|
||||
staticOffset += detail->info.member.type->size;
|
||||
HashTableInsert(&cls->staticMembers, member->name, member);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -821,7 +798,6 @@ void mScriptClassInit(struct mScriptTypeClass* cls) {
|
|||
if (cls->init) {
|
||||
return;
|
||||
}
|
||||
HashTableInit(&cls->staticMembers, 0, free);
|
||||
HashTableInit(&cls->instanceMembers, 0, free);
|
||||
|
||||
_mScriptClassInit(cls, cls->details, false);
|
||||
|
@ -834,7 +810,6 @@ void mScriptClassDeinit(struct mScriptTypeClass* cls) {
|
|||
return;
|
||||
}
|
||||
HashTableDeinit(&cls->instanceMembers);
|
||||
HashTableDeinit(&cls->staticMembers);
|
||||
cls->init = false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue