mirror of https://github.com/mgba-emu/mgba.git
Scripting: Code cleanup, add parameter names
This commit is contained in:
parent
421c645e14
commit
8c45d51b8e
|
@ -0,0 +1,79 @@
|
|||
/* Copyright (c) 2013-2022 Jeffrey Pfau
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
#ifndef M_MACROS_H
|
||||
#define M_MACROS_H
|
||||
|
||||
#define _mCPP_CAT(A, B) A ## B
|
||||
|
||||
#define _mCALL(FN, ...) FN(__VA_ARGS__)
|
||||
#define _mCAT(A, B) _mCPP_CAT(A, B)
|
||||
#define _mSTRINGIFY(X, ...) #X
|
||||
|
||||
#define _mCALL_0(FN, ...)
|
||||
#define _mCALL_1(FN, A) FN(A)
|
||||
#define _mCALL_2(FN, A, B) FN(A), FN(B)
|
||||
#define _mCALL_3(FN, A, ...) FN(A), _mCALL_2(FN, __VA_ARGS__)
|
||||
#define _mCALL_4(FN, A, ...) FN(A), _mCALL_3(FN, __VA_ARGS__)
|
||||
#define _mCALL_5(FN, A, ...) FN(A), _mCALL_4(FN, __VA_ARGS__)
|
||||
#define _mCALL_6(FN, A, ...) FN(A), _mCALL_5(FN, __VA_ARGS__)
|
||||
#define _mCALL_7(FN, A, ...) FN(A), _mCALL_6(FN, __VA_ARGS__)
|
||||
#define _mCALL_8(FN, A, ...) FN(A), _mCALL_7(FN, __VA_ARGS__)
|
||||
#define _mCALL_9(FN, A, ...) FN(A), _mCALL_8(FN, __VA_ARGS__)
|
||||
|
||||
#define _mCOMMA_0(N, ...) N
|
||||
#define _mCOMMA_1(N, ...) N, __VA_ARGS__
|
||||
#define _mCOMMA_2(N, ...) N, __VA_ARGS__
|
||||
#define _mCOMMA_3(N, ...) N, __VA_ARGS__
|
||||
#define _mCOMMA_4(N, ...) N, __VA_ARGS__
|
||||
#define _mCOMMA_5(N, ...) N, __VA_ARGS__
|
||||
#define _mCOMMA_6(N, ...) N, __VA_ARGS__
|
||||
#define _mCOMMA_7(N, ...) N, __VA_ARGS__
|
||||
#define _mCOMMA_8(N, ...) N, __VA_ARGS__
|
||||
#define _mCOMMA_9(N, ...) N, __VA_ARGS__
|
||||
|
||||
#define _mEVEN_0(...)
|
||||
#define _mEVEN_1(A, B, ...) A
|
||||
#define _mEVEN_2(A, B, ...) A, _mEVEN_1(__VA_ARGS__)
|
||||
#define _mEVEN_3(A, B, ...) A, _mEVEN_2(__VA_ARGS__)
|
||||
#define _mEVEN_4(A, B, ...) A, _mEVEN_3(__VA_ARGS__)
|
||||
#define _mEVEN_5(A, B, ...) A, _mEVEN_4(__VA_ARGS__)
|
||||
#define _mEVEN_6(A, B, ...) A, _mEVEN_5(__VA_ARGS__)
|
||||
#define _mEVEN_7(A, B, ...) A, _mEVEN_6(__VA_ARGS__)
|
||||
#define _mEVEN_8(A, B, ...) A, _mEVEN_7(__VA_ARGS__)
|
||||
#define _mEVEN_9(A, B, ...) A, _mEVEN_7(__VA_ARGS__)
|
||||
|
||||
#define _mODD_0(...)
|
||||
#define _mODD_1(A, B, ...) B
|
||||
#define _mODD_2(A, B, ...) B, _mODD_1(__VA_ARGS__)
|
||||
#define _mODD_3(A, B, ...) B, _mODD_2(__VA_ARGS__)
|
||||
#define _mODD_4(A, B, ...) B, _mODD_3(__VA_ARGS__)
|
||||
#define _mODD_5(A, B, ...) B, _mODD_4(__VA_ARGS__)
|
||||
#define _mODD_6(A, B, ...) B, _mODD_5(__VA_ARGS__)
|
||||
#define _mODD_7(A, B, ...) B, _mODD_6(__VA_ARGS__)
|
||||
#define _mODD_8(A, B, ...) B, _mODD_7(__VA_ARGS__)
|
||||
#define _mODD_9(A, B, ...) B, _mODD_7(__VA_ARGS__)
|
||||
|
||||
#define _mSUCC_0 1
|
||||
#define _mSUCC_1 2
|
||||
#define _mSUCC_2 3
|
||||
#define _mSUCC_3 4
|
||||
#define _mSUCC_4 5
|
||||
#define _mSUCC_5 6
|
||||
#define _mSUCC_6 7
|
||||
#define _mSUCC_7 8
|
||||
#define _mSUCC_8 9
|
||||
|
||||
#define _mPRED_1 0
|
||||
#define _mPRED_2 1
|
||||
#define _mPRED_3 2
|
||||
#define _mPRED_4 3
|
||||
#define _mPRED_5 4
|
||||
#define _mPRED_6 5
|
||||
#define _mPRED_7 6
|
||||
#define _mPRED_8 7
|
||||
#define _mPRED_9 8
|
||||
|
||||
#endif
|
|
@ -10,17 +10,10 @@
|
|||
|
||||
CXX_GUARD_START
|
||||
|
||||
#include <mgba-util/macros.h>
|
||||
#include <mgba-util/table.h>
|
||||
#include <mgba-util/vector.h>
|
||||
|
||||
#define _mCPP_EMPTY()
|
||||
#define _mCPP_CAT(A, B) A ## B
|
||||
|
||||
#define _mDEFER(X) X _mCPP_EMPTY()
|
||||
#define _mBLOCK(...) __VA_ARGS__ _mDEFER(_mCPP_EMPTY)()
|
||||
#define _mAPPLY(...) __VA_ARGS__
|
||||
#define _mCAT(A, B) _mCPP_CAT(A, B)
|
||||
|
||||
#define mSCRIPT_VALUE_UNREF -1
|
||||
#define mSCRIPT_PARAMS_MAX 8
|
||||
|
||||
|
@ -99,10 +92,10 @@ CXX_GUARD_START
|
|||
#define mSCRIPT_TYPE_CMP_S(STRUCT) mSCRIPT_TYPE_MS_S(STRUCT)->name == _mSCRIPT_FIELD_NAME
|
||||
#define mSCRIPT_TYPE_CMP_CS(STRUCT) mSCRIPT_TYPE_MS_CS(STRUCT)->name == _mSCRIPT_FIELD_NAME
|
||||
#define mSCRIPT_TYPE_CMP_S_METHOD(STRUCT, NAME) mSCRIPT_TYPE_MS_S_METHOD(STRUCT, NAME)->name == _mSCRIPT_FIELD_NAME
|
||||
#define mSCRIPT_TYPE_CMP(TYPE0, TYPE1) _mAPPLY(mSCRIPT_TYPE_CMP_ ## TYPE0(TYPE1))
|
||||
#define mSCRIPT_TYPE_CMP(TYPE0, TYPE1) mSCRIPT_TYPE_CMP_ ## TYPE0(TYPE1)
|
||||
|
||||
#define mSCRIPT_POP(STACK, TYPE, NAME) \
|
||||
_mAPPLY(mSCRIPT_TYPE_C_ ## TYPE) NAME; \
|
||||
mSCRIPT_TYPE_C_ ## TYPE NAME; \
|
||||
do { \
|
||||
struct mScriptValue* _val = mScriptListGetPointer(STACK, mScriptListSize(STACK) - 1); \
|
||||
if (!(mSCRIPT_TYPE_CMP(TYPE, _val->type))) { \
|
||||
|
@ -115,7 +108,7 @@ CXX_GUARD_START
|
|||
return false; \
|
||||
} \
|
||||
} \
|
||||
NAME = _val->value. _mAPPLY(mSCRIPT_TYPE_FIELD_ ## TYPE); \
|
||||
NAME = _val->value.mSCRIPT_TYPE_FIELD_ ## TYPE; \
|
||||
mScriptValueDeref(_val); \
|
||||
mScriptListResize(STACK, -1); \
|
||||
} while (0)
|
||||
|
@ -130,21 +123,12 @@ CXX_GUARD_START
|
|||
#define mSCRIPT_POP_7(FRAME, T0, T1, T2, T3, T4, T5, T6) mSCRIPT_POP(FRAME, T6, p6); mSCRIPT_POP_6(FRAME, T0, T1, T2, T3, T4, T5)
|
||||
#define mSCRIPT_POP_8(FRAME, T0, T1, T2, T3, T4, T5, T6, T7) mSCRIPT_POP(FRAME, T7, p7); mSCRIPT_POP_7(FRAME, T0, T1, T2, T3, T4, T5, T6)
|
||||
|
||||
#define _mCOMMA_0(N, ...) N
|
||||
#define _mCOMMA_1(N, ...) N, __VA_ARGS__
|
||||
#define _mCOMMA_2(N, ...) N, __VA_ARGS__
|
||||
#define _mCOMMA_3(N, ...) N, __VA_ARGS__
|
||||
#define _mCOMMA_4(N, ...) N, __VA_ARGS__
|
||||
#define _mCOMMA_5(N, ...) N, __VA_ARGS__
|
||||
#define _mCOMMA_6(N, ...) N, __VA_ARGS__
|
||||
#define _mCOMMA_7(N, ...) N, __VA_ARGS__
|
||||
|
||||
#define mSCRIPT_PUSH(STACK, TYPE, NAME) \
|
||||
do { \
|
||||
struct mScriptValue* _val = mScriptListAppend(STACK); \
|
||||
_val->type = _mAPPLY(mSCRIPT_TYPE_MS_ ## TYPE); \
|
||||
_val->type = mSCRIPT_TYPE_MS_ ## TYPE; \
|
||||
_val->refs = mSCRIPT_VALUE_UNREF; \
|
||||
_val->value._mAPPLY(mSCRIPT_TYPE_FIELD_ ## TYPE) = NAME; \
|
||||
_val->value.mSCRIPT_TYPE_FIELD_ ## TYPE = NAME; \
|
||||
} while (0)
|
||||
|
||||
#define mSCRIPT_ARG_NAMES_0
|
||||
|
@ -166,20 +150,11 @@ CXX_GUARD_START
|
|||
#define mSCRIPT_PREFIX_6(PREFIX, T0, T1, T2, T3, T4, T5) PREFIX ## T0, PREFIX ## T1, PREFIX ## T2, PREFIX ## T3, PREFIX ## T4, PREFIX ## T5
|
||||
#define mSCRIPT_PREFIX_7(PREFIX, T0, T1, T2, T3, T4, T5, T6) PREFIX ## T0, PREFIX ## T1, PREFIX ## T2, PREFIX ## T3, PREFIX ## T4, PREFIX ## T5, PREFIX ## T6
|
||||
#define mSCRIPT_PREFIX_8(PREFIX, T0, T1, T2, T3, T4, T5, T6, T7) PREFIX ## T0, PREFIX ## T1, PREFIX ## T2, PREFIX ## T3, PREFIX ## T4, PREFIX ## T5, PREFIX ## T6, PREFIX ## T7
|
||||
#define mSCRIPT_PREFIX_N(N) _mAPPLY(mSCRIPT_PREFIX_ ## N)
|
||||
|
||||
#define _mSUCC0 1
|
||||
#define _mSUCC1 2
|
||||
#define _mSUCC2 3
|
||||
#define _mSUCC3 4
|
||||
#define _mSUCC4 5
|
||||
#define _mSUCC5 6
|
||||
#define _mSUCC6 7
|
||||
#define _mSUCC7 8
|
||||
#define mSCRIPT_PREFIX_N(N) mSCRIPT_PREFIX_ ## N
|
||||
|
||||
#define _mSCRIPT_CALL_VOID(FUNCTION, NPARAMS) FUNCTION(_mCAT(mSCRIPT_ARG_NAMES_, NPARAMS))
|
||||
#define _mSCRIPT_CALL(RETURN, FUNCTION, NPARAMS) \
|
||||
_mAPPLY(mSCRIPT_TYPE_C_ ## RETURN) out = FUNCTION(_mCAT(mSCRIPT_ARG_NAMES_, NPARAMS)); \
|
||||
mSCRIPT_TYPE_C_ ## RETURN out = FUNCTION(_mCAT(mSCRIPT_ARG_NAMES_, NPARAMS)); \
|
||||
mSCRIPT_PUSH(&frame->returnValues, RETURN, out)
|
||||
|
||||
#define mSCRIPT_DECLARE_STRUCT(STRUCT) \
|
||||
|
@ -238,7 +213,7 @@ CXX_GUARD_START
|
|||
.info = { \
|
||||
.member = { \
|
||||
.name = #NAME, \
|
||||
.type = _mAPPLY(mSCRIPT_TYPE_MS_ ## TYPE), \
|
||||
.type = mSCRIPT_TYPE_MS_ ## TYPE, \
|
||||
.offset = offsetof(struct STRUCT, NAME) \
|
||||
} \
|
||||
} \
|
||||
|
@ -249,7 +224,7 @@ CXX_GUARD_START
|
|||
.info = { \
|
||||
.member = { \
|
||||
.name = #NAME, \
|
||||
.type = _mAPPLY(mSCRIPT_TYPE_MS_ ## TYPE) \
|
||||
.type = mSCRIPT_TYPE_MS_ ## TYPE \
|
||||
} \
|
||||
}, \
|
||||
},
|
||||
|
@ -262,7 +237,7 @@ CXX_GUARD_START
|
|||
},
|
||||
|
||||
#define _mSCRIPT_STRUCT_METHOD_POP(TYPE, S, NPARAMS, ...) \
|
||||
_mDEFER(_mDEFER(_mCAT(mSCRIPT_POP_, _mSUCC ## NPARAMS)) (&frame->arguments, _mCOMMA_ ## NPARAMS(S(TYPE), __VA_ARGS__))); \
|
||||
_mCALL(_mCAT(mSCRIPT_POP_, _mSUCC_ ## NPARAMS), &frame->arguments, _mCOMMA_ ## NPARAMS(S(TYPE), __VA_ARGS__)); \
|
||||
if (mScriptListSize(&frame->arguments)) { \
|
||||
return false; \
|
||||
}
|
||||
|
@ -283,8 +258,9 @@ CXX_GUARD_START
|
|||
.details = { \
|
||||
.function = { \
|
||||
.parameters = { \
|
||||
.count = _mSUCC ## NPARAMS, \
|
||||
.entries = { _mAPPLY(mSCRIPT_TYPE_MS_ ## S(TYPE)), mSCRIPT_PREFIX_ ## NPARAMS(mSCRIPT_TYPE_MS_, __VA_ARGS__) } \
|
||||
.count = _mSUCC_ ## NPARAMS, \
|
||||
.entries = { mSCRIPT_TYPE_MS_ ## S(TYPE), _mCALL(mSCRIPT_PREFIX_ ## NPARAMS, mSCRIPT_TYPE_MS_, _mEVEN_ ## NPARAMS(__VA_ARGS__)) }, \
|
||||
.names = { "this", _mCALL(_mCALL_ ## NPARAMS, _mSTRINGIFY, _mODD_ ## NPARAMS(__VA_ARGS__)) }, \
|
||||
}, \
|
||||
.returnType = { \
|
||||
.count = NRET, \
|
||||
|
@ -294,47 +270,50 @@ CXX_GUARD_START
|
|||
} \
|
||||
};
|
||||
|
||||
#define _mSCRIPT_DECLARE_STRUCT_METHOD_SIGNATURE(TYPE, RETURN, NAME, CONST, NPARAMS, ...) \
|
||||
typedef RETURN (*_mSTStructFunctionType_ ## TYPE ## _ ## NAME)(_mCOMMA_ ## NPARAMS(CONST struct TYPE* , mSCRIPT_PREFIX_ ## NPARAMS(mSCRIPT_TYPE_C_, __VA_ARGS__)))
|
||||
|
||||
#define mSCRIPT_DECLARE_STRUCT_METHOD(TYPE, RETURN, NAME, FUNCTION, NPARAMS, ...) \
|
||||
typedef _mAPPLY(mSCRIPT_TYPE_C_ ## RETURN) (*_mSTStructFunctionType_ ## TYPE ## _ ## NAME)(_mAPPLY(_mCOMMA_ ## NPARAMS(struct TYPE* , mSCRIPT_PREFIX_ ## NPARAMS(mSCRIPT_TYPE_C_, __VA_ARGS__)))); \
|
||||
_mSCRIPT_DECLARE_STRUCT_METHOD_SIGNATURE(TYPE, mSCRIPT_TYPE_C_ ## RETURN, NAME, , NPARAMS, _mEVEN_ ## NPARAMS(__VA_ARGS__)); \
|
||||
_mSCRIPT_DECLARE_STRUCT_METHOD(TYPE, NAME, S, 1, mSCRIPT_TYPE_MS_ ## RETURN, NPARAMS, __VA_ARGS__) \
|
||||
\
|
||||
static bool _mSTStructBinding_ ## TYPE ## _ ## NAME(struct mScriptFrame* frame, void* ctx) { \
|
||||
UNUSED(ctx); \
|
||||
_mSCRIPT_STRUCT_METHOD_POP(TYPE, S, NPARAMS, __VA_ARGS__); \
|
||||
_mSCRIPT_CALL(RETURN, FUNCTION, _mSUCC ## NPARAMS); \
|
||||
_mSCRIPT_STRUCT_METHOD_POP(TYPE, S, NPARAMS, _mEVEN_ ## NPARAMS(__VA_ARGS__)); \
|
||||
_mSCRIPT_CALL(RETURN, FUNCTION, _mSUCC_ ## NPARAMS); \
|
||||
return true; \
|
||||
} \
|
||||
|
||||
#define mSCRIPT_DECLARE_STRUCT_VOID_METHOD(TYPE, NAME, FUNCTION, NPARAMS, ...) \
|
||||
typedef void (*_mSTStructFunctionType_ ## TYPE ## _ ## NAME)(_mAPPLY(_mCOMMA_ ## NPARAMS(struct TYPE* , mSCRIPT_PREFIX_ ## NPARAMS(mSCRIPT_TYPE_C_, __VA_ARGS__)))); \
|
||||
_mSCRIPT_DECLARE_STRUCT_METHOD_SIGNATURE(TYPE, void, NAME, , NPARAMS, _mEVEN_ ## NPARAMS(__VA_ARGS__)); \
|
||||
_mSCRIPT_DECLARE_STRUCT_METHOD(TYPE, NAME, S, 0, , NPARAMS, __VA_ARGS__) \
|
||||
\
|
||||
static bool _mSTStructBinding_ ## TYPE ## _ ## NAME(struct mScriptFrame* frame, void* ctx) { \
|
||||
UNUSED(ctx); \
|
||||
_mSCRIPT_STRUCT_METHOD_POP(TYPE, S, NPARAMS, __VA_ARGS__); \
|
||||
_mSCRIPT_CALL_VOID(FUNCTION, _mSUCC ## NPARAMS); \
|
||||
_mSCRIPT_STRUCT_METHOD_POP(TYPE, S, NPARAMS, _mEVEN_ ## NPARAMS(__VA_ARGS__)); \
|
||||
_mSCRIPT_CALL_VOID(FUNCTION, _mSUCC_ ## NPARAMS); \
|
||||
return true; \
|
||||
} \
|
||||
|
||||
#define mSCRIPT_DECLARE_STRUCT_C_METHOD(TYPE, RETURN, NAME, FUNCTION, NPARAMS, ...) \
|
||||
typedef _mAPPLY(mSCRIPT_TYPE_C_ ## RETURN) (*_mSTStructFunctionType_ ## TYPE ## _ ## NAME)(_mAPPLY(_mCOMMA_ ## NPARAMS(struct TYPE* , mSCRIPT_PREFIX_ ## NPARAMS(mSCRIPT_TYPE_C_, __VA_ARGS__)))); \
|
||||
_mSCRIPT_DECLARE_STRUCT_METHOD_SIGNATURE(TYPE, mSCRIPT_TYPE_C_ ## RETURN, NAME, const, NPARAMS, _mEVEN_ ## NPARAMS(__VA_ARGS__)); \
|
||||
_mSCRIPT_DECLARE_STRUCT_METHOD(TYPE, NAME, CS, 1, mSCRIPT_TYPE_MS_ ## RETURN, NPARAMS, __VA_ARGS__) \
|
||||
\
|
||||
static bool _mSTStructBinding_ ## TYPE ## _ ## NAME(struct mScriptFrame* frame, void* ctx) { \
|
||||
UNUSED(ctx); \
|
||||
_mSCRIPT_STRUCT_METHOD_POP(TYPE, CS, NPARAMS, __VA_ARGS__); \
|
||||
_mSCRIPT_CALL(RETURN, FUNCTION, _mSUCC ## NPARAMS); \
|
||||
_mSCRIPT_STRUCT_METHOD_POP(TYPE, CS, NPARAMS, _mEVEN_ ## NPARAMS(__VA_ARGS__)); \
|
||||
_mSCRIPT_CALL(RETURN, FUNCTION, _mSUCC_ ## NPARAMS); \
|
||||
return true; \
|
||||
} \
|
||||
|
||||
#define mSCRIPT_DECLARE_STRUCT_VOID_C_METHOD(TYPE, NAME, FUNCTION, NPARAMS, ...) \
|
||||
typedef void (*_mSTStructFunctionType_ ## TYPE ## _ ## NAME)(_mAPPLY(_mCOMMA_ ## NPARAMS(struct TYPE* , mSCRIPT_PREFIX_ ## NPARAMS(mSCRIPT_TYPE_C_, __VA_ARGS__)))); \
|
||||
_mSCRIPT_DECLARE_STRUCT_METHOD_SIGNATURE(TYPE, void, NAME, const, NPARAMS, _mEVEN_ ## NPARAMS(__VA_ARGS__)); \
|
||||
_mSCRIPT_DECLARE_STRUCT_METHOD(TYPE, NAME, CS, 0, , NPARAMS, __VA_ARGS__) \
|
||||
\
|
||||
static bool _mSTStructBinding_ ## TYPE ## _ ## NAME(struct mScriptFrame* frame, void* ctx) { \
|
||||
UNUSED(ctx); \
|
||||
_mSCRIPT_STRUCT_METHOD_POP(TYPE, CS, NPARAMS, __VA_ARGS__); \
|
||||
_mSCRIPT_CALL_VOID(FUNCTION, _mSUCC ## NPARAMS); \
|
||||
_mSCRIPT_STRUCT_METHOD_POP(TYPE, CS, NPARAMS, _mEVEN_ ## NPARAMS(__VA_ARGS__)); \
|
||||
_mSCRIPT_CALL_VOID(FUNCTION, _mSUCC_ ## NPARAMS); \
|
||||
return true; \
|
||||
} \
|
||||
|
||||
|
@ -380,7 +359,8 @@ CXX_GUARD_START
|
|||
.function = { \
|
||||
.parameters = { \
|
||||
.count = NPARAMS, \
|
||||
.entries = { _mAPPLY(mSCRIPT_PREFIX_ ## NPARAMS(mSCRIPT_TYPE_MS_, __VA_ARGS__)) } \
|
||||
.entries = { _mCALL(mSCRIPT_PREFIX_ ## NPARAMS, mSCRIPT_TYPE_MS_, _mEVEN_ ## NPARAMS(__VA_ARGS__)) }, \
|
||||
.names = { _mCALL(_mCALL_ ## NPARAMS, _mSTRINGIFY, _mODD_ ## NPARAMS(__VA_ARGS__)) }, \
|
||||
}, \
|
||||
.returnType = { \
|
||||
.count = NRET, \
|
||||
|
@ -400,7 +380,7 @@ CXX_GUARD_START
|
|||
#define mSCRIPT_BIND_FUNCTION(NAME, RETURN, FUNCTION, NPARAMS, ...) \
|
||||
static bool _binding_ ## NAME(struct mScriptFrame* frame, void* ctx) { \
|
||||
UNUSED(ctx); \
|
||||
mSCRIPT_POP_ ## NPARAMS(&frame->arguments, __VA_ARGS__); \
|
||||
_mCALL(mSCRIPT_POP_ ## NPARAMS, &frame->arguments, _mEVEN_ ## NPARAMS(__VA_ARGS__)); \
|
||||
if (mScriptListSize(&frame->arguments)) { \
|
||||
return false; \
|
||||
} \
|
||||
|
@ -412,7 +392,7 @@ CXX_GUARD_START
|
|||
#define mSCRIPT_BIND_VOID_FUNCTION(NAME, FUNCTION, NPARAMS, ...) \
|
||||
static bool _binding_ ## NAME(struct mScriptFrame* frame, void* ctx) { \
|
||||
UNUSED(ctx); \
|
||||
mSCRIPT_POP_ ## NPARAMS(&frame->arguments, __VA_ARGS__); \
|
||||
_mCALL(mSCRIPT_POP_ ## NPARAMS, &frame->arguments, _mEVEN_ ## NPARAMS(__VA_ARGS__)); \
|
||||
if (mScriptListSize(&frame->arguments)) { \
|
||||
return false; \
|
||||
} \
|
||||
|
@ -486,6 +466,7 @@ extern const struct mScriptType mSTWrapper;
|
|||
struct mScriptTypeTuple {
|
||||
size_t count;
|
||||
const struct mScriptType* entries[mSCRIPT_PARAMS_MAX];
|
||||
const char* names[mSCRIPT_PARAMS_MAX];
|
||||
bool variable;
|
||||
};
|
||||
|
||||
|
|
|
@ -63,17 +63,17 @@ static void testAv1(struct TestA* a, int b) {
|
|||
|
||||
mSCRIPT_DECLARE_STRUCT(TestA);
|
||||
mSCRIPT_DECLARE_STRUCT_D_METHOD(TestA, S32, ifn0, 0);
|
||||
mSCRIPT_DECLARE_STRUCT_D_METHOD(TestA, S32, ifn1, 1, S32);
|
||||
mSCRIPT_DECLARE_STRUCT_D_METHOD(TestA, S32, ifn1, 1, S32, b);
|
||||
mSCRIPT_DECLARE_STRUCT_CD_METHOD(TestA, S32, icfn0, 0);
|
||||
mSCRIPT_DECLARE_STRUCT_CD_METHOD(TestA, S32, icfn1, 1, S32);
|
||||
mSCRIPT_DECLARE_STRUCT_CD_METHOD(TestA, S32, icfn1, 1, S32, b);
|
||||
mSCRIPT_DECLARE_STRUCT_VOID_D_METHOD(TestA, vfn0, 0);
|
||||
mSCRIPT_DECLARE_STRUCT_VOID_D_METHOD(TestA, vfn1, 1, S32);
|
||||
mSCRIPT_DECLARE_STRUCT_VOID_D_METHOD(TestA, vfn1, 1, S32, b);
|
||||
mSCRIPT_DECLARE_STRUCT_METHOD(TestA, S32, i0, testAi0, 0);
|
||||
mSCRIPT_DECLARE_STRUCT_METHOD(TestA, S32, i1, testAi1, 1, S32);
|
||||
mSCRIPT_DECLARE_STRUCT_METHOD(TestA, S32, i1, testAi1, 1, S32, b);
|
||||
mSCRIPT_DECLARE_STRUCT_C_METHOD(TestA, S32, ic0, testAic0, 0);
|
||||
mSCRIPT_DECLARE_STRUCT_C_METHOD(TestA, S32, ic1, testAic1, 1, S32);
|
||||
mSCRIPT_DECLARE_STRUCT_C_METHOD(TestA, S32, ic1, testAic1, 1, S32, b);
|
||||
mSCRIPT_DECLARE_STRUCT_VOID_METHOD(TestA, v0, testAv0, 0);
|
||||
mSCRIPT_DECLARE_STRUCT_VOID_METHOD(TestA, v1, testAv1, 1, S32);
|
||||
mSCRIPT_DECLARE_STRUCT_VOID_METHOD(TestA, v1, testAv1, 1, S32, b);
|
||||
|
||||
mSCRIPT_DEFINE_STRUCT(TestA)
|
||||
mSCRIPT_DEFINE_DOCSTRING(MEMBER_A_DOCSTRING)
|
||||
|
@ -191,6 +191,82 @@ M_TEST_DEFINE(testALayout) {
|
|||
assert_false(cls->init);
|
||||
}
|
||||
|
||||
M_TEST_DEFINE(testASignatures) {
|
||||
struct mScriptTypeClass* cls = mSCRIPT_TYPE_MS_S(TestA)->details.cls;
|
||||
assert_false(cls->init);
|
||||
mScriptClassInit(cls);
|
||||
assert_true(cls->init);
|
||||
|
||||
struct mScriptClassMember* member;
|
||||
|
||||
member = HashTableLookup(&cls->instanceMembers, "ifn0");
|
||||
assert_non_null(member);
|
||||
assert_string_equal(member->name, "ifn0");
|
||||
assert_int_equal(member->type->base, mSCRIPT_TYPE_FUNCTION);
|
||||
assert_int_equal(member->type->details.function.parameters.count, 1);
|
||||
assert_ptr_equal(member->type->details.function.parameters.entries[0], mSCRIPT_TYPE_MS_S(TestA));
|
||||
assert_string_equal(member->type->details.function.parameters.names[0], "this");
|
||||
assert_int_equal(member->type->details.function.returnType.count, 1);
|
||||
assert_ptr_equal(member->type->details.function.returnType.entries[0], mSCRIPT_TYPE_MS_S32);
|
||||
|
||||
member = HashTableLookup(&cls->instanceMembers, "ifn1");
|
||||
assert_non_null(member);
|
||||
assert_string_equal(member->name, "ifn1");
|
||||
assert_int_equal(member->type->base, mSCRIPT_TYPE_FUNCTION);
|
||||
assert_int_equal(member->type->details.function.parameters.count, 2);
|
||||
assert_ptr_equal(member->type->details.function.parameters.entries[0], mSCRIPT_TYPE_MS_S(TestA));
|
||||
assert_ptr_equal(member->type->details.function.parameters.entries[1], mSCRIPT_TYPE_MS_S32);
|
||||
assert_string_equal(member->type->details.function.parameters.names[0], "this");
|
||||
assert_string_equal(member->type->details.function.parameters.names[1], "b");
|
||||
assert_int_equal(member->type->details.function.returnType.count, 1);
|
||||
assert_ptr_equal(member->type->details.function.returnType.entries[0], mSCRIPT_TYPE_MS_S32);
|
||||
|
||||
member = HashTableLookup(&cls->instanceMembers, "vfn0");
|
||||
assert_non_null(member);
|
||||
assert_string_equal(member->name, "vfn0");
|
||||
assert_int_equal(member->type->base, mSCRIPT_TYPE_FUNCTION);
|
||||
assert_int_equal(member->type->details.function.parameters.count, 1);
|
||||
assert_ptr_equal(member->type->details.function.parameters.entries[0], mSCRIPT_TYPE_MS_S(TestA));
|
||||
assert_string_equal(member->type->details.function.parameters.names[0], "this");
|
||||
assert_int_equal(member->type->details.function.returnType.count, 0);
|
||||
|
||||
member = HashTableLookup(&cls->instanceMembers, "vfn1");
|
||||
assert_non_null(member);
|
||||
assert_string_equal(member->name, "vfn1");
|
||||
assert_int_equal(member->type->base, mSCRIPT_TYPE_FUNCTION);
|
||||
assert_int_equal(member->type->details.function.parameters.count, 2);
|
||||
assert_ptr_equal(member->type->details.function.parameters.entries[0], mSCRIPT_TYPE_MS_S(TestA));
|
||||
assert_ptr_equal(member->type->details.function.parameters.entries[1], mSCRIPT_TYPE_MS_S32);
|
||||
assert_string_equal(member->type->details.function.parameters.names[0], "this");
|
||||
assert_string_equal(member->type->details.function.parameters.names[1], "b");
|
||||
assert_int_equal(member->type->details.function.returnType.count, 0);
|
||||
|
||||
member = HashTableLookup(&cls->instanceMembers, "icfn0");
|
||||
assert_non_null(member);
|
||||
assert_string_equal(member->name, "icfn0");
|
||||
assert_int_equal(member->type->base, mSCRIPT_TYPE_FUNCTION);
|
||||
assert_int_equal(member->type->details.function.parameters.count, 1);
|
||||
assert_ptr_equal(member->type->details.function.parameters.entries[0], mSCRIPT_TYPE_MS_CS(TestA));
|
||||
assert_string_equal(member->type->details.function.parameters.names[0], "this");
|
||||
assert_int_equal(member->type->details.function.returnType.count, 1);
|
||||
assert_ptr_equal(member->type->details.function.returnType.entries[0], mSCRIPT_TYPE_MS_S32);
|
||||
|
||||
member = HashTableLookup(&cls->instanceMembers, "icfn1");
|
||||
assert_non_null(member);
|
||||
assert_string_equal(member->name, "icfn1");
|
||||
assert_int_equal(member->type->base, mSCRIPT_TYPE_FUNCTION);
|
||||
assert_int_equal(member->type->details.function.parameters.count, 2);
|
||||
assert_ptr_equal(member->type->details.function.parameters.entries[0], mSCRIPT_TYPE_MS_CS(TestA));
|
||||
assert_ptr_equal(member->type->details.function.parameters.entries[1], mSCRIPT_TYPE_MS_S32);
|
||||
assert_string_equal(member->type->details.function.parameters.names[0], "this");
|
||||
assert_string_equal(member->type->details.function.parameters.names[1], "b");
|
||||
assert_int_equal(member->type->details.function.returnType.count, 1);
|
||||
assert_ptr_equal(member->type->details.function.returnType.entries[0], mSCRIPT_TYPE_MS_S32);
|
||||
|
||||
mScriptClassDeinit(cls);
|
||||
assert_false(cls->init);
|
||||
}
|
||||
|
||||
M_TEST_DEFINE(testAGet) {
|
||||
struct mScriptTypeClass* cls = mSCRIPT_TYPE_MS_S(TestA)->details.cls;
|
||||
|
||||
|
@ -836,6 +912,7 @@ M_TEST_DEFINE(testDSet) {
|
|||
|
||||
M_TEST_SUITE_DEFINE(mScriptClasses,
|
||||
cmocka_unit_test(testALayout),
|
||||
cmocka_unit_test(testASignatures),
|
||||
cmocka_unit_test(testAGet),
|
||||
cmocka_unit_test(testASet),
|
||||
cmocka_unit_test(testAStatic),
|
||||
|
|
|
@ -58,20 +58,20 @@ static void testV1(struct Test* a, int b) {
|
|||
a->i += b;
|
||||
}
|
||||
|
||||
mSCRIPT_BIND_FUNCTION(boundIdentityInt, S32, identityInt, 1, S32);
|
||||
mSCRIPT_BIND_FUNCTION(boundAddInts, S32, addInts, 2, S32, S32);
|
||||
mSCRIPT_BIND_FUNCTION(boundIdentityInt, S32, identityInt, 1, S32, a);
|
||||
mSCRIPT_BIND_FUNCTION(boundAddInts, S32, addInts, 2, S32, a, S32, b);
|
||||
|
||||
mSCRIPT_DECLARE_STRUCT(Test);
|
||||
mSCRIPT_DECLARE_STRUCT_D_METHOD(Test, S32, ifn0, 0);
|
||||
mSCRIPT_DECLARE_STRUCT_D_METHOD(Test, S32, ifn1, 1, S32);
|
||||
mSCRIPT_DECLARE_STRUCT_D_METHOD(Test, S32, ifn1, 1, S32, b);
|
||||
mSCRIPT_DECLARE_STRUCT_CD_METHOD(Test, S32, icfn0, 0);
|
||||
mSCRIPT_DECLARE_STRUCT_VOID_D_METHOD(Test, vfn0, 0);
|
||||
mSCRIPT_DECLARE_STRUCT_VOID_D_METHOD(Test, vfn1, 1, S32);
|
||||
mSCRIPT_DECLARE_STRUCT_VOID_D_METHOD(Test, vfn1, 1, S32, b);
|
||||
mSCRIPT_DECLARE_STRUCT_METHOD(Test, S32, i0, testI0, 0);
|
||||
mSCRIPT_DECLARE_STRUCT_METHOD(Test, S32, i1, testI1, 1, S32);
|
||||
mSCRIPT_DECLARE_STRUCT_METHOD(Test, S32, i1, testI1, 1, S32, b);
|
||||
mSCRIPT_DECLARE_STRUCT_C_METHOD(Test, S32, ic0, testIC0, 0);
|
||||
mSCRIPT_DECLARE_STRUCT_VOID_METHOD(Test, v0, testV0, 0);
|
||||
mSCRIPT_DECLARE_STRUCT_VOID_METHOD(Test, v1, testV1, 1, S32);
|
||||
mSCRIPT_DECLARE_STRUCT_VOID_METHOD(Test, v1, testV1, 1, S32, b);
|
||||
|
||||
mSCRIPT_DEFINE_STRUCT(Test)
|
||||
mSCRIPT_DEFINE_STRUCT_MEMBER(Test, S32, i)
|
||||
|
|
|
@ -52,14 +52,14 @@ static int isHello(const char* str) {
|
|||
}
|
||||
|
||||
mSCRIPT_BIND_FUNCTION(boundVoidOne, S32, voidOne, 0);
|
||||
mSCRIPT_BIND_VOID_FUNCTION(boundDiscard, discard, 1, S32);
|
||||
mSCRIPT_BIND_FUNCTION(boundIdentityInt, S32, identityInt, 1, S32);
|
||||
mSCRIPT_BIND_FUNCTION(boundIdentityInt64, S64, identityInt64, 1, S64);
|
||||
mSCRIPT_BIND_FUNCTION(boundIdentityFloat, F32, identityFloat, 1, F32);
|
||||
mSCRIPT_BIND_FUNCTION(boundIdentityStruct, S(Test), identityStruct, 1, S(Test));
|
||||
mSCRIPT_BIND_FUNCTION(boundAddInts, S32, addInts, 2, S32, S32);
|
||||
mSCRIPT_BIND_FUNCTION(boundSubInts, S32, subInts, 2, S32, S32);
|
||||
mSCRIPT_BIND_FUNCTION(boundIsHello, S32, isHello, 1, CHARP);
|
||||
mSCRIPT_BIND_VOID_FUNCTION(boundDiscard, discard, 1, S32, ignored);
|
||||
mSCRIPT_BIND_FUNCTION(boundIdentityInt, S32, identityInt, 1, S32, in);
|
||||
mSCRIPT_BIND_FUNCTION(boundIdentityInt64, S64, identityInt64, 1, S64, in);
|
||||
mSCRIPT_BIND_FUNCTION(boundIdentityFloat, F32, identityFloat, 1, F32, in);
|
||||
mSCRIPT_BIND_FUNCTION(boundIdentityStruct, S(Test), identityStruct, 1, S(Test), t);
|
||||
mSCRIPT_BIND_FUNCTION(boundAddInts, S32, addInts, 2, S32, a, S32, b);
|
||||
mSCRIPT_BIND_FUNCTION(boundSubInts, S32, subInts, 2, S32, a, S32, b);
|
||||
mSCRIPT_BIND_FUNCTION(boundIsHello, S32, isHello, 1, CHARP, str);
|
||||
|
||||
M_TEST_DEFINE(voidArgs) {
|
||||
struct mScriptFrame frame;
|
||||
|
|
|
@ -295,12 +295,12 @@ uint32_t _hashScalar(const struct mScriptValue* val) {
|
|||
return true; \
|
||||
}
|
||||
|
||||
_mAPPLY(AS(SInt32, S32));
|
||||
_mAPPLY(AS(UInt32, U32));
|
||||
_mAPPLY(AS(Float32, F32));
|
||||
_mAPPLY(AS(SInt64, S64));
|
||||
_mAPPLY(AS(UInt64, U64));
|
||||
_mAPPLY(AS(Float64, F64));
|
||||
AS(SInt32, S32);
|
||||
AS(UInt32, U32);
|
||||
AS(Float32, F32);
|
||||
AS(SInt64, S64);
|
||||
AS(UInt64, U64);
|
||||
AS(Float64, F64);
|
||||
|
||||
bool _castScalar(const struct mScriptValue* input, const struct mScriptType* type, struct mScriptValue* output) {
|
||||
switch (type->base) {
|
||||
|
|
Loading…
Reference in New Issue