Scripting: Combine frame argument and return value stacks

These were never used a the same time, and it reduces malloc/free churn
This commit is contained in:
Vicki Pfau 2024-11-08 00:50:19 -08:00
parent 645d1cf344
commit 4d6fb5b3c5
10 changed files with 234 additions and 230 deletions

View File

@ -76,10 +76,14 @@ CXX_GUARD_START
#define _mSCRIPT_FIELD_NAME(V) (V)->type->name #define _mSCRIPT_FIELD_NAME(V) (V)->type->name
#define _mSCRIPT_WRAPPED_FIELD_NAME(V) (V)->value.wrapped->type->name #define _mSCRIPT_WRAPPED_FIELD_NAME(V) (V)->value.wrapped->type->name
#define _mSCRIPT_CALL_VOID(FUNCTION, NPARAMS) FUNCTION(_mCAT(mSCRIPT_ARG_NAMES_, NPARAMS)) #define _mSCRIPT_CALL_VOID(FUNCTION, NPARAMS) \
FUNCTION(_mCAT(mSCRIPT_ARG_NAMES_, NPARAMS)); \
mScriptListClear(&frame->stack)
#define _mSCRIPT_CALL(RETURN, FUNCTION, NPARAMS) \ #define _mSCRIPT_CALL(RETURN, FUNCTION, NPARAMS) \
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) mScriptListClear(&frame->stack); \
mSCRIPT_PUSH(&frame->stack, RETURN, out)
#define mSCRIPT_DECLARE_STRUCT(STRUCT) \ #define mSCRIPT_DECLARE_STRUCT(STRUCT) \
extern const struct mScriptType mSTStruct_ ## STRUCT; \ extern const struct mScriptType mSTStruct_ ## STRUCT; \
@ -249,8 +253,8 @@ CXX_GUARD_START
}, },
#define _mSCRIPT_STRUCT_METHOD_POP(TYPE, S, NPARAMS, ...) \ #define _mSCRIPT_STRUCT_METHOD_POP(TYPE, S, NPARAMS, ...) \
_mCALL(_mCAT(mSCRIPT_POP_, _mSUCC_ ## NPARAMS), &frame->arguments, _mCOMMA_ ## NPARAMS(S(TYPE), __VA_ARGS__)); \ _mCALL(_mCAT(mSCRIPT_POP_, _mSUCC_ ## NPARAMS), &frame->stack, _mCOMMA_ ## NPARAMS(S(TYPE), __VA_ARGS__)); \
if (mScriptListSize(&frame->arguments)) { \ if (mScriptListSize(&frame->stack)) { \
return false; \ return false; \
} }
@ -326,11 +330,11 @@ CXX_GUARD_START
static const struct mScriptFunctionOverload _mSTStructBindingOverloads_ ## TYPE ## _ ## NAME[mSCRIPT_OVERLOADS_MAX]; \ static const struct mScriptFunctionOverload _mSTStructBindingOverloads_ ## TYPE ## _ ## NAME[mSCRIPT_OVERLOADS_MAX]; \
static bool _mSTStructBinding_ ## TYPE ## _ ## NAME(struct mScriptFrame* frame, void* ctx) { \ static bool _mSTStructBinding_ ## TYPE ## _ ## NAME(struct mScriptFrame* frame, void* ctx) { \
UNUSED(ctx); \ UNUSED(ctx); \
const struct mScriptFunctionOverload* overload = mScriptFunctionFindOverload(_mSTStructBindingOverloads_ ## TYPE ## _ ## NAME, &frame->arguments); \ const struct mScriptFunctionOverload* overload = mScriptFunctionFindOverload(_mSTStructBindingOverloads_ ## TYPE ## _ ## NAME, &frame->stack); \
if (!overload) { \ if (!overload) { \
return false; \ return false; \
} \ } \
if (!mScriptCoerceFrame(&overload->type->details.function.parameters, &frame->arguments, &frame->arguments)) { \ if (!mScriptCoerceFrame(&overload->type->details.function.parameters, &frame->stack, &frame->stack)) { \
return false; \ return false; \
} \ } \
return overload->function->call(frame, overload->function->context); \ return overload->function->call(frame, overload->function->context); \
@ -552,8 +556,8 @@ CXX_GUARD_START
#define _mSCRIPT_BIND_N_FUNCTION(NAME, RETURN, FUNCTION, DEFAULTS, NPARAMS, ...) \ #define _mSCRIPT_BIND_N_FUNCTION(NAME, RETURN, FUNCTION, DEFAULTS, NPARAMS, ...) \
static bool _binding_ ## NAME(struct mScriptFrame* frame, void* ctx) { \ static bool _binding_ ## NAME(struct mScriptFrame* frame, void* ctx) { \
UNUSED(ctx); \ UNUSED(ctx); \
_mCALL(mSCRIPT_POP_ ## NPARAMS, &frame->arguments, _mEVEN_ ## NPARAMS(__VA_ARGS__)); \ _mCALL(mSCRIPT_POP_ ## NPARAMS, &frame->stack, _mEVEN_ ## NPARAMS(__VA_ARGS__)); \
if (mScriptListSize(&frame->arguments)) { \ if (mScriptListSize(&frame->stack)) { \
return false; \ return false; \
} \ } \
_mSCRIPT_CALL(RETURN, FUNCTION, NPARAMS); \ _mSCRIPT_CALL(RETURN, FUNCTION, NPARAMS); \
@ -564,8 +568,8 @@ CXX_GUARD_START
#define _mSCRIPT_BIND_VOID_FUNCTION(NAME, FUNCTION, DEFAULTS, NPARAMS, ...) \ #define _mSCRIPT_BIND_VOID_FUNCTION(NAME, FUNCTION, DEFAULTS, NPARAMS, ...) \
static bool _binding_ ## NAME(struct mScriptFrame* frame, void* ctx) { \ static bool _binding_ ## NAME(struct mScriptFrame* frame, void* ctx) { \
UNUSED(ctx); \ UNUSED(ctx); \
_mCALL(mSCRIPT_POP_ ## NPARAMS, &frame->arguments, _mEVEN_ ## NPARAMS(__VA_ARGS__)); \ _mCALL(mSCRIPT_POP_ ## NPARAMS, &frame->stack, _mEVEN_ ## NPARAMS(__VA_ARGS__)); \
if (mScriptListSize(&frame->arguments)) { \ if (mScriptListSize(&frame->stack)) { \
return false; \ return false; \
} \ } \
_mSCRIPT_CALL_VOID(FUNCTION, NPARAMS); \ _mSCRIPT_CALL_VOID(FUNCTION, NPARAMS); \

View File

@ -325,8 +325,7 @@ struct mScriptString {
}; };
struct mScriptFrame { struct mScriptFrame {
struct mScriptList arguments; struct mScriptList stack;
struct mScriptList returnValues;
// TODO: Exception/failure codes // TODO: Exception/failure codes
}; };

View File

@ -1205,11 +1205,11 @@ static bool _callRotationCb(struct mScriptCoreAdapter* adapter, const char* cbNa
struct mScriptValue* context = mScriptTableLookup(adapter->rotationCbTable, &mSCRIPT_MAKE_CHARP("context")); struct mScriptValue* context = mScriptTableLookup(adapter->rotationCbTable, &mSCRIPT_MAKE_CHARP("context"));
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
if (context) { if (context) {
mScriptValueWrap(context, mScriptListAppend(&frame.arguments)); mScriptValueWrap(context, mScriptListAppend(&frame.stack));
} }
bool ok = mScriptContextInvoke(adapter->context, cb, &frame); bool ok = mScriptContextInvoke(adapter->context, cb, &frame);
if (ok && out && mScriptListSize(&frame.returnValues) == 1) { if (ok && out && mScriptListSize(&frame.stack) == 1) {
if (!mScriptCast(mSCRIPT_TYPE_MS_F32, mScriptListGetPointer(&frame.returnValues, 0), out)) { if (!mScriptCast(mSCRIPT_TYPE_MS_F32, mScriptListGetPointer(&frame.stack, 0), out)) {
ok = false; ok = false;
} }
} }
@ -1278,8 +1278,8 @@ static uint8_t _readLuminance(struct GBALuminanceSource* luminance) {
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
bool ok = mScriptContextInvoke(adapter->context, adapter->luminanceCb, &frame); bool ok = mScriptContextInvoke(adapter->context, adapter->luminanceCb, &frame);
struct mScriptValue out = {0}; struct mScriptValue out = {0};
if (ok && mScriptListSize(&frame.returnValues) == 1) { if (ok && mScriptListSize(&frame.stack) == 1) {
if (!mScriptCast(mSCRIPT_TYPE_MS_U8, mScriptListGetPointer(&frame.returnValues, 0), &out)) { if (!mScriptCast(mSCRIPT_TYPE_MS_U8, mScriptListGetPointer(&frame.stack, 0), &out)) {
ok = false; ok = false;
} }
} }

View File

@ -266,7 +266,7 @@ void mScriptContextTriggerCallback(struct mScriptContext* context, const char* c
if (fn) { if (fn) {
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
if (args) { if (args) {
mScriptListCopy(&frame.arguments, args); mScriptListCopy(&frame.stack, args);
} }
mScriptContextInvoke(context, fn, &frame); mScriptContextInvoke(context, fn, &frame);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
@ -481,7 +481,7 @@ bool mScriptInvoke(const struct mScriptValue* val, struct mScriptFrame* frame) {
return false; return false;
} }
const struct mScriptTypeFunction* signature = &val->type->details.function; const struct mScriptTypeFunction* signature = &val->type->details.function;
if (!mScriptCoerceFrame(&signature->parameters, &frame->arguments, &frame->arguments)) { if (!mScriptCoerceFrame(&signature->parameters, &frame->stack, &frame->stack)) {
return false; return false;
} }
const struct mScriptFunction* fn = val->value.opaque; const struct mScriptFunction* fn = val->value.opaque;

View File

@ -912,12 +912,12 @@ void _luaError(struct mScriptEngineContextLua* luaContext) {
if (ok) { if (ok) {
struct mScriptFrame frame; struct mScriptFrame frame;
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
struct mScriptValue* this = mScriptListAppend(&frame.arguments); struct mScriptValue* this = mScriptListAppend(&frame.stack);
this->type = console->type; this->type = console->type;
this->refs = mSCRIPT_VALUE_UNREF; this->refs = mSCRIPT_VALUE_UNREF;
this->flags = 0; this->flags = 0;
this->value.opaque = console->value.opaque; this->value.opaque = console->value.opaque;
mSCRIPT_PUSH(&frame.arguments, CHARP, luaContext->lastError); mSCRIPT_PUSH(&frame.stack, CHARP, luaContext->lastError);
ok = mScriptInvoke(&error, &frame); ok = mScriptInvoke(&error, &frame);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
} }
@ -1115,7 +1115,7 @@ void _autofreeFrame(struct mScriptContext* context, struct mScriptList* frame) {
bool _luaInvoke(struct mScriptEngineContextLua* luaContext, struct mScriptFrame* frame) { bool _luaInvoke(struct mScriptEngineContextLua* luaContext, struct mScriptFrame* frame) {
int nargs = 0; int nargs = 0;
if (frame) { if (frame) {
nargs = mScriptListSize(&frame->arguments); nargs = mScriptListSize(&frame->stack);
} }
if (luaContext->lastError) { if (luaContext->lastError) {
@ -1127,10 +1127,13 @@ bool _luaInvoke(struct mScriptEngineContextLua* luaContext, struct mScriptFrame*
return false; return false;
} }
if (frame && !_luaPushFrame(luaContext, luaContext->lua, &frame->arguments)) { if (frame) {
if (!_luaPushFrame(luaContext, luaContext->lua, &frame->stack)) {
mScriptContextDeactivate(luaContext->d.context); mScriptContextDeactivate(luaContext->d.context);
return false; return false;
} }
mScriptListClear(&frame->stack);
}
lua_pushliteral(luaContext->lua, "mCtx"); lua_pushliteral(luaContext->lua, "mCtx");
lua_pushlightuserdata(luaContext->lua, luaContext); lua_pushlightuserdata(luaContext->lua, luaContext);
@ -1151,7 +1154,7 @@ bool _luaInvoke(struct mScriptEngineContextLua* luaContext, struct mScriptFrame*
return false; return false;
} }
if (frame && !_luaPopFrame(luaContext, luaContext->lua, &frame->returnValues)) { if (frame && !_luaPopFrame(luaContext, luaContext->lua, &frame->stack)) {
mScriptContextDrainPool(luaContext->d.context); mScriptContextDrainPool(luaContext->d.context);
return false; return false;
} }
@ -1191,8 +1194,8 @@ int _luaThunk(lua_State* lua) {
struct mScriptEngineContextLua* luaContext = _luaGetContext(lua); struct mScriptEngineContextLua* luaContext = _luaGetContext(lua);
struct mScriptFrame frame; struct mScriptFrame frame;
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
if (!_luaPopFrame(luaContext, lua, &frame.arguments)) { if (!_luaPopFrame(luaContext, lua, &frame.stack)) {
_freeFrame(&frame.arguments); _freeFrame(&frame.stack);
mScriptContextDrainPool(luaContext->d.context); mScriptContextDrainPool(luaContext->d.context);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
luaL_traceback(lua, lua, "Error calling function (translating arguments into runtime)", 1); luaL_traceback(lua, lua, "Error calling function (translating arguments into runtime)", 1);
@ -1200,7 +1203,7 @@ int _luaThunk(lua_State* lua) {
} }
struct mScriptValue* fn = lua_touserdata(lua, lua_upvalueindex(1)); struct mScriptValue* fn = lua_touserdata(lua, lua_upvalueindex(1));
_autofreeFrame(luaContext->d.context, &frame.arguments); _autofreeFrame(luaContext->d.context, &frame.stack);
if (!fn || !mScriptContextInvoke(luaContext->d.context, fn, &frame)) { if (!fn || !mScriptContextInvoke(luaContext->d.context, fn, &frame)) {
mScriptContextDrainPool(luaContext->d.context); mScriptContextDrainPool(luaContext->d.context);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
@ -1208,7 +1211,7 @@ int _luaThunk(lua_State* lua) {
return lua_error(lua); return lua_error(lua);
} }
bool ok = _luaPushFrame(luaContext, lua, &frame.returnValues); bool ok = _luaPushFrame(luaContext, lua, &frame.stack);
mScriptContextDrainPool(luaContext->d.context); mScriptContextDrainPool(luaContext->d.context);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
if (!ok) { if (!ok) {

View File

@ -519,106 +519,106 @@ M_TEST_DEFINE(testAStatic) {
assert_true(mScriptObjectGet(&sval, "i0", &val)); assert_true(mScriptObjectGet(&sval, "i0", &val));
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); mSCRIPT_PUSH(&frame.stack, S(TestA), &s);
assert_true(mScriptInvoke(&val, &frame)); assert_true(mScriptInvoke(&val, &frame));
assert_true(mScriptPopS32(&frame.returnValues, &rval)); assert_true(mScriptPopS32(&frame.stack, &rval));
assert_int_equal(rval, 1); assert_int_equal(rval, 1);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
assert_true(mScriptObjectGet(&sval, "i1", &val)); assert_true(mScriptObjectGet(&sval, "i1", &val));
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); mSCRIPT_PUSH(&frame.stack, S(TestA), &s);
mSCRIPT_PUSH(&frame.arguments, S32, 1); mSCRIPT_PUSH(&frame.stack, S32, 1);
assert_true(mScriptInvoke(&val, &frame)); assert_true(mScriptInvoke(&val, &frame));
assert_true(mScriptPopS32(&frame.returnValues, &rval)); assert_true(mScriptPopS32(&frame.stack, &rval));
assert_int_equal(rval, 2); assert_int_equal(rval, 2);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
assert_true(mScriptObjectGet(&sval, "ic0", &val)); assert_true(mScriptObjectGet(&sval, "ic0", &val));
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, CS(TestA), &s); mSCRIPT_PUSH(&frame.stack, CS(TestA), &s);
assert_true(mScriptInvoke(&val, &frame)); assert_true(mScriptInvoke(&val, &frame));
assert_true(mScriptPopS32(&frame.returnValues, &rval)); assert_true(mScriptPopS32(&frame.stack, &rval));
assert_int_equal(rval, 1); assert_int_equal(rval, 1);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
assert_true(mScriptObjectGet(&sval, "ic0", &val)); assert_true(mScriptObjectGet(&sval, "ic0", &val));
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); mSCRIPT_PUSH(&frame.stack, S(TestA), &s);
assert_true(mScriptInvoke(&val, &frame)); assert_true(mScriptInvoke(&val, &frame));
assert_true(mScriptPopS32(&frame.returnValues, &rval)); assert_true(mScriptPopS32(&frame.stack, &rval));
assert_int_equal(rval, 1); assert_int_equal(rval, 1);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
assert_true(mScriptObjectGet(&sval, "ic1", &val)); assert_true(mScriptObjectGet(&sval, "ic1", &val));
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, CS(TestA), &s); mSCRIPT_PUSH(&frame.stack, CS(TestA), &s);
mSCRIPT_PUSH(&frame.arguments, S32, 1); mSCRIPT_PUSH(&frame.stack, S32, 1);
assert_true(mScriptInvoke(&val, &frame)); assert_true(mScriptInvoke(&val, &frame));
assert_true(mScriptPopS32(&frame.returnValues, &rval)); assert_true(mScriptPopS32(&frame.stack, &rval));
assert_int_equal(rval, 2); assert_int_equal(rval, 2);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
assert_true(mScriptObjectGet(&sval, "ic1", &val)); assert_true(mScriptObjectGet(&sval, "ic1", &val));
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); mSCRIPT_PUSH(&frame.stack, S(TestA), &s);
mSCRIPT_PUSH(&frame.arguments, S32, 1); mSCRIPT_PUSH(&frame.stack, S32, 1);
assert_true(mScriptInvoke(&val, &frame)); assert_true(mScriptInvoke(&val, &frame));
assert_true(mScriptPopS32(&frame.returnValues, &rval)); assert_true(mScriptPopS32(&frame.stack, &rval));
assert_int_equal(rval, 2); assert_int_equal(rval, 2);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
assert_true(mScriptObjectGet(&sval, "v0", &val)); assert_true(mScriptObjectGet(&sval, "v0", &val));
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); mSCRIPT_PUSH(&frame.stack, S(TestA), &s);
assert_true(mScriptInvoke(&val, &frame)); assert_true(mScriptInvoke(&val, &frame));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
assert_true(mScriptObjectGet(&sval, "i0", &val)); assert_true(mScriptObjectGet(&sval, "i0", &val));
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); mSCRIPT_PUSH(&frame.stack, S(TestA), &s);
assert_true(mScriptInvoke(&val, &frame)); assert_true(mScriptInvoke(&val, &frame));
assert_true(mScriptPopS32(&frame.returnValues, &rval)); assert_true(mScriptPopS32(&frame.stack, &rval));
assert_int_equal(rval, 2); assert_int_equal(rval, 2);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
assert_true(mScriptObjectGet(&sval, "ic0", &val)); assert_true(mScriptObjectGet(&sval, "ic0", &val));
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, CS(TestA), &s); mSCRIPT_PUSH(&frame.stack, CS(TestA), &s);
assert_true(mScriptInvoke(&val, &frame)); assert_true(mScriptInvoke(&val, &frame));
assert_true(mScriptPopS32(&frame.returnValues, &rval)); assert_true(mScriptPopS32(&frame.stack, &rval));
assert_int_equal(rval, 2); assert_int_equal(rval, 2);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
assert_true(mScriptObjectGet(&sval, "v1", &val)); assert_true(mScriptObjectGet(&sval, "v1", &val));
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); mSCRIPT_PUSH(&frame.stack, S(TestA), &s);
mSCRIPT_PUSH(&frame.arguments, S32, 2); mSCRIPT_PUSH(&frame.stack, S32, 2);
assert_true(mScriptInvoke(&val, &frame)); assert_true(mScriptInvoke(&val, &frame));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
assert_true(mScriptObjectGet(&sval, "v2", &val)); assert_true(mScriptObjectGet(&sval, "v2", &val));
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); mSCRIPT_PUSH(&frame.stack, S(TestA), &s);
mSCRIPT_PUSH(&frame.arguments, S32, 1); mSCRIPT_PUSH(&frame.stack, S32, 1);
mSCRIPT_PUSH(&frame.arguments, S32, -2); mSCRIPT_PUSH(&frame.stack, S32, -2);
assert_true(mScriptInvoke(&val, &frame)); assert_true(mScriptInvoke(&val, &frame));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
assert_true(mScriptObjectGet(&sval, "v2", &val)); assert_true(mScriptObjectGet(&sval, "v2", &val));
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); mSCRIPT_PUSH(&frame.stack, S(TestA), &s);
mSCRIPT_PUSH(&frame.arguments, S32, 1); mSCRIPT_PUSH(&frame.stack, S32, 1);
assert_true(mScriptInvoke(&val, &frame)); assert_true(mScriptInvoke(&val, &frame));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
assert_true(mScriptObjectGet(&sval, "i0", &val)); assert_true(mScriptObjectGet(&sval, "i0", &val));
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); mSCRIPT_PUSH(&frame.stack, S(TestA), &s);
assert_true(mScriptInvoke(&val, &frame)); assert_true(mScriptInvoke(&val, &frame));
assert_true(mScriptPopS32(&frame.returnValues, &rval)); assert_true(mScriptPopS32(&frame.stack, &rval));
assert_int_equal(rval, 4); assert_int_equal(rval, 4);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
assert_true(mScriptObjectGet(&sval, "ic0", &val)); assert_true(mScriptObjectGet(&sval, "ic0", &val));
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, CS(TestA), &s); mSCRIPT_PUSH(&frame.stack, CS(TestA), &s);
assert_true(mScriptInvoke(&val, &frame)); assert_true(mScriptInvoke(&val, &frame));
assert_true(mScriptPopS32(&frame.returnValues, &rval)); assert_true(mScriptPopS32(&frame.stack, &rval));
assert_int_equal(rval, 4); assert_int_equal(rval, 4);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
@ -659,93 +659,93 @@ M_TEST_DEFINE(testADynamic) {
assert_true(mScriptObjectGet(&sval, "ifn0", &val)); assert_true(mScriptObjectGet(&sval, "ifn0", &val));
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); mSCRIPT_PUSH(&frame.stack, S(TestA), &s);
assert_true(mScriptInvoke(&val, &frame)); assert_true(mScriptInvoke(&val, &frame));
assert_true(mScriptPopS32(&frame.returnValues, &rval)); assert_true(mScriptPopS32(&frame.stack, &rval));
assert_int_equal(rval, 1); assert_int_equal(rval, 1);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
assert_true(mScriptObjectGet(&sval, "ifn1", &val)); assert_true(mScriptObjectGet(&sval, "ifn1", &val));
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); mSCRIPT_PUSH(&frame.stack, S(TestA), &s);
mSCRIPT_PUSH(&frame.arguments, S32, 1); mSCRIPT_PUSH(&frame.stack, S32, 1);
assert_true(mScriptInvoke(&val, &frame)); assert_true(mScriptInvoke(&val, &frame));
assert_true(mScriptPopS32(&frame.returnValues, &rval)); assert_true(mScriptPopS32(&frame.stack, &rval));
assert_int_equal(rval, 2); assert_int_equal(rval, 2);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
assert_true(mScriptObjectGet(&sval, "icfn0", &val)); assert_true(mScriptObjectGet(&sval, "icfn0", &val));
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, CS(TestA), &s); mSCRIPT_PUSH(&frame.stack, CS(TestA), &s);
assert_true(mScriptInvoke(&val, &frame)); assert_true(mScriptInvoke(&val, &frame));
assert_true(mScriptPopS32(&frame.returnValues, &rval)); assert_true(mScriptPopS32(&frame.stack, &rval));
assert_int_equal(rval, 1); assert_int_equal(rval, 1);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
assert_true(mScriptObjectGet(&sval, "icfn0", &val)); assert_true(mScriptObjectGet(&sval, "icfn0", &val));
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); mSCRIPT_PUSH(&frame.stack, S(TestA), &s);
assert_true(mScriptInvoke(&val, &frame)); assert_true(mScriptInvoke(&val, &frame));
assert_true(mScriptPopS32(&frame.returnValues, &rval)); assert_true(mScriptPopS32(&frame.stack, &rval));
assert_int_equal(rval, 1); assert_int_equal(rval, 1);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
assert_true(mScriptObjectGet(&sval, "icfn1", &val)); assert_true(mScriptObjectGet(&sval, "icfn1", &val));
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, CS(TestA), &s); mSCRIPT_PUSH(&frame.stack, CS(TestA), &s);
mSCRIPT_PUSH(&frame.arguments, S32, 1); mSCRIPT_PUSH(&frame.stack, S32, 1);
assert_true(mScriptInvoke(&val, &frame)); assert_true(mScriptInvoke(&val, &frame));
assert_true(mScriptPopS32(&frame.returnValues, &rval)); assert_true(mScriptPopS32(&frame.stack, &rval));
assert_int_equal(rval, 2); assert_int_equal(rval, 2);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
assert_true(mScriptObjectGet(&sval, "icfn1", &val)); assert_true(mScriptObjectGet(&sval, "icfn1", &val));
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); mSCRIPT_PUSH(&frame.stack, S(TestA), &s);
mSCRIPT_PUSH(&frame.arguments, S32, 1); mSCRIPT_PUSH(&frame.stack, S32, 1);
assert_true(mScriptInvoke(&val, &frame)); assert_true(mScriptInvoke(&val, &frame));
assert_true(mScriptPopS32(&frame.returnValues, &rval)); assert_true(mScriptPopS32(&frame.stack, &rval));
assert_int_equal(rval, 2); assert_int_equal(rval, 2);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
assert_true(mScriptObjectGet(&sval, "vfn0", &val)); assert_true(mScriptObjectGet(&sval, "vfn0", &val));
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); mSCRIPT_PUSH(&frame.stack, S(TestA), &s);
assert_true(mScriptInvoke(&val, &frame)); assert_true(mScriptInvoke(&val, &frame));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
assert_true(mScriptObjectGet(&sval, "ifn0", &val)); assert_true(mScriptObjectGet(&sval, "ifn0", &val));
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); mSCRIPT_PUSH(&frame.stack, S(TestA), &s);
assert_true(mScriptInvoke(&val, &frame)); assert_true(mScriptInvoke(&val, &frame));
assert_true(mScriptPopS32(&frame.returnValues, &rval)); assert_true(mScriptPopS32(&frame.stack, &rval));
assert_int_equal(rval, 2); assert_int_equal(rval, 2);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
assert_true(mScriptObjectGet(&sval, "icfn0", &val)); assert_true(mScriptObjectGet(&sval, "icfn0", &val));
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, CS(TestA), &s); mSCRIPT_PUSH(&frame.stack, CS(TestA), &s);
assert_true(mScriptInvoke(&val, &frame)); assert_true(mScriptInvoke(&val, &frame));
assert_true(mScriptPopS32(&frame.returnValues, &rval)); assert_true(mScriptPopS32(&frame.stack, &rval));
assert_int_equal(rval, 2); assert_int_equal(rval, 2);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
assert_true(mScriptObjectGet(&sval, "vfn1", &val)); assert_true(mScriptObjectGet(&sval, "vfn1", &val));
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); mSCRIPT_PUSH(&frame.stack, S(TestA), &s);
mSCRIPT_PUSH(&frame.arguments, S32, 2); mSCRIPT_PUSH(&frame.stack, S32, 2);
assert_true(mScriptInvoke(&val, &frame)); assert_true(mScriptInvoke(&val, &frame));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
assert_true(mScriptObjectGet(&sval, "ifn0", &val)); assert_true(mScriptObjectGet(&sval, "ifn0", &val));
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); mSCRIPT_PUSH(&frame.stack, S(TestA), &s);
assert_true(mScriptInvoke(&val, &frame)); assert_true(mScriptInvoke(&val, &frame));
assert_true(mScriptPopS32(&frame.returnValues, &rval)); assert_true(mScriptPopS32(&frame.stack, &rval));
assert_int_equal(rval, 4); assert_int_equal(rval, 4);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
assert_true(mScriptObjectGet(&sval, "icfn0", &val)); assert_true(mScriptObjectGet(&sval, "icfn0", &val));
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, CS(TestA), &s); mSCRIPT_PUSH(&frame.stack, CS(TestA), &s);
assert_true(mScriptInvoke(&val, &frame)); assert_true(mScriptInvoke(&val, &frame));
assert_true(mScriptPopS32(&frame.returnValues, &rval)); assert_true(mScriptPopS32(&frame.stack, &rval));
assert_int_equal(rval, 4); assert_int_equal(rval, 4);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
@ -1228,16 +1228,16 @@ M_TEST_DEFINE(testOverloadsBasic) {
assert_true(mScriptObjectGet(&sval, "call", &fn)); assert_true(mScriptObjectGet(&sval, "call", &fn));
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S(TestI), &s); mSCRIPT_PUSH(&frame.stack, S(TestI), &s);
mSCRIPT_PUSH(&frame.arguments, U32, 1); mSCRIPT_PUSH(&frame.stack, U32, 1);
assert_true(mScriptInvoke(&fn, &frame)); assert_true(mScriptInvoke(&fn, &frame));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
assert_int_equal(s.num, 1); assert_int_equal(s.num, 1);
assert_null(s.str); assert_null(s.str);
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S(TestI), &s); mSCRIPT_PUSH(&frame.stack, S(TestI), &s);
mSCRIPT_PUSH(&frame.arguments, CHARP, "called"); mSCRIPT_PUSH(&frame.stack, CHARP, "called");
assert_true(mScriptInvoke(&fn, &frame)); assert_true(mScriptInvoke(&fn, &frame));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
assert_int_equal(s.num, 1); assert_int_equal(s.num, 1);

View File

@ -328,10 +328,10 @@ M_TEST_DEFINE(callLuaFunc) {
struct mScriptFrame frame; struct mScriptFrame frame;
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S32, 1); mSCRIPT_PUSH(&frame.stack, S32, 1);
assert_true(mScriptInvoke(fn, &frame)); assert_true(mScriptInvoke(fn, &frame));
int64_t val; int64_t val;
assert_true(mScriptPopS64(&frame.returnValues, &val)); assert_true(mScriptPopS64(&frame.stack, &val));
assert_int_equal(val, 2); assert_int_equal(val, 2);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
@ -342,10 +342,10 @@ M_TEST_DEFINE(callLuaFunc) {
assert_int_equal(fn->type->base, mSCRIPT_TYPE_FUNCTION); assert_int_equal(fn->type->base, mSCRIPT_TYPE_FUNCTION);
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S32, 1); mSCRIPT_PUSH(&frame.stack, S32, 1);
mSCRIPT_PUSH(&frame.arguments, S32, 2); mSCRIPT_PUSH(&frame.stack, S32, 2);
assert_true(mScriptInvoke(fn, &frame)); assert_true(mScriptInvoke(fn, &frame));
assert_true(mScriptPopS64(&frame.returnValues, &val)); assert_true(mScriptPopS64(&frame.stack, &val));
assert_int_equal(val, 3); assert_int_equal(val, 3);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);

View File

@ -111,7 +111,7 @@ M_TEST_DEFINE(voidArgs) {
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
assert_true(mScriptInvoke(&boundVoidOne, &frame)); assert_true(mScriptInvoke(&boundVoidOne, &frame));
int32_t val; int32_t val;
assert_true(mScriptPopS32(&frame.returnValues, &val)); assert_true(mScriptPopS32(&frame.stack, &val));
assert_int_equal(val, 1); assert_int_equal(val, 1);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
} }
@ -119,7 +119,7 @@ M_TEST_DEFINE(voidArgs) {
M_TEST_DEFINE(voidFunc) { M_TEST_DEFINE(voidFunc) {
struct mScriptFrame frame; struct mScriptFrame frame;
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S32, 1); mSCRIPT_PUSH(&frame.stack, S32, 1);
assert_true(mScriptInvoke(&boundDiscard, &frame)); assert_true(mScriptInvoke(&boundDiscard, &frame));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
} }
@ -127,10 +127,10 @@ M_TEST_DEFINE(voidFunc) {
M_TEST_DEFINE(identityFunctionS32) { M_TEST_DEFINE(identityFunctionS32) {
struct mScriptFrame frame; struct mScriptFrame frame;
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S32, 1); mSCRIPT_PUSH(&frame.stack, S32, 1);
assert_true(mScriptInvoke(&boundIdentityInt, &frame)); assert_true(mScriptInvoke(&boundIdentityInt, &frame));
int32_t val; int32_t val;
assert_true(mScriptPopS32(&frame.returnValues, &val)); assert_true(mScriptPopS32(&frame.stack, &val));
assert_int_equal(val, 1); assert_int_equal(val, 1);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
} }
@ -138,10 +138,10 @@ M_TEST_DEFINE(identityFunctionS32) {
M_TEST_DEFINE(identityFunctionS64) { M_TEST_DEFINE(identityFunctionS64) {
struct mScriptFrame frame; struct mScriptFrame frame;
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S64, 1); mSCRIPT_PUSH(&frame.stack, S64, 1);
assert_true(mScriptInvoke(&boundIdentityInt64, &frame)); assert_true(mScriptInvoke(&boundIdentityInt64, &frame));
int64_t val; int64_t val;
assert_true(mScriptPopS64(&frame.returnValues, &val)); assert_true(mScriptPopS64(&frame.stack, &val));
assert_int_equal(val, 1); assert_int_equal(val, 1);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
} }
@ -149,10 +149,10 @@ M_TEST_DEFINE(identityFunctionS64) {
M_TEST_DEFINE(identityFunctionF32) { M_TEST_DEFINE(identityFunctionF32) {
struct mScriptFrame frame; struct mScriptFrame frame;
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, F32, 3.125f); mSCRIPT_PUSH(&frame.stack, F32, 3.125f);
assert_true(mScriptInvoke(&boundIdentityFloat, &frame)); assert_true(mScriptInvoke(&boundIdentityFloat, &frame));
float val; float val;
assert_true(mScriptPopF32(&frame.returnValues, &val)); assert_true(mScriptPopF32(&frame.stack, &val));
assert_float_equal(val, 3.125f, 0.f); assert_float_equal(val, 3.125f, 0.f);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
} }
@ -161,10 +161,10 @@ M_TEST_DEFINE(identityFunctionStruct) {
struct mScriptFrame frame; struct mScriptFrame frame;
struct Test v = {}; struct Test v = {};
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S(Test), &v); mSCRIPT_PUSH(&frame.stack, S(Test), &v);
assert_true(mScriptInvoke(&boundIdentityStruct, &frame)); assert_true(mScriptInvoke(&boundIdentityStruct, &frame));
struct Test* val; struct Test* val;
assert_true(mScriptPopPointer(&frame.returnValues, (void**) &val)); assert_true(mScriptPopPointer(&frame.stack, (void**) &val));
assert_ptr_equal(val, &v); assert_ptr_equal(val, &v);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
} }
@ -172,11 +172,11 @@ M_TEST_DEFINE(identityFunctionStruct) {
M_TEST_DEFINE(addS32) { M_TEST_DEFINE(addS32) {
struct mScriptFrame frame; struct mScriptFrame frame;
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S32, 1); mSCRIPT_PUSH(&frame.stack, S32, 1);
mSCRIPT_PUSH(&frame.arguments, S32, 2); mSCRIPT_PUSH(&frame.stack, S32, 2);
assert_true(mScriptInvoke(&boundAddInts, &frame)); assert_true(mScriptInvoke(&boundAddInts, &frame));
int32_t val; int32_t val;
assert_true(mScriptPopS32(&frame.returnValues, &val)); assert_true(mScriptPopS32(&frame.stack, &val));
assert_int_equal(val, 3); assert_int_equal(val, 3);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
} }
@ -186,17 +186,17 @@ M_TEST_DEFINE(addS32Defaults) {
int32_t val; int32_t val;
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S32, 1); mSCRIPT_PUSH(&frame.stack, S32, 1);
mSCRIPT_PUSH(&frame.arguments, S32, 2); mSCRIPT_PUSH(&frame.stack, S32, 2);
assert_true(mScriptInvoke(&boundAddIntWithDefaults, &frame)); assert_true(mScriptInvoke(&boundAddIntWithDefaults, &frame));
assert_true(mScriptPopS32(&frame.returnValues, &val)); assert_true(mScriptPopS32(&frame.stack, &val));
assert_int_equal(val, 3); assert_int_equal(val, 3);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S32, 1); mSCRIPT_PUSH(&frame.stack, S32, 1);
assert_true(mScriptInvoke(&boundAddIntWithDefaults, &frame)); assert_true(mScriptInvoke(&boundAddIntWithDefaults, &frame));
assert_true(mScriptPopS32(&frame.returnValues, &val)); assert_true(mScriptPopS32(&frame.stack, &val));
assert_int_equal(val, 1); assert_int_equal(val, 1);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
@ -208,11 +208,11 @@ M_TEST_DEFINE(addS32Defaults) {
M_TEST_DEFINE(subS32) { M_TEST_DEFINE(subS32) {
struct mScriptFrame frame; struct mScriptFrame frame;
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S32, 2); mSCRIPT_PUSH(&frame.stack, S32, 2);
mSCRIPT_PUSH(&frame.arguments, S32, 1); mSCRIPT_PUSH(&frame.stack, S32, 1);
assert_true(mScriptInvoke(&boundSubInts, &frame)); assert_true(mScriptInvoke(&boundSubInts, &frame));
int32_t val; int32_t val;
assert_true(mScriptPopS32(&frame.returnValues, &val)); assert_true(mScriptPopS32(&frame.stack, &val));
assert_int_equal(val, 1); assert_int_equal(val, 1);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
} }
@ -227,8 +227,8 @@ M_TEST_DEFINE(wrongArgCountLo) {
M_TEST_DEFINE(wrongArgCountHi) { M_TEST_DEFINE(wrongArgCountHi) {
struct mScriptFrame frame; struct mScriptFrame frame;
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S32, 1); mSCRIPT_PUSH(&frame.stack, S32, 1);
mSCRIPT_PUSH(&frame.arguments, S32, 1); mSCRIPT_PUSH(&frame.stack, S32, 1);
assert_false(mScriptInvoke(&boundIdentityInt, &frame)); assert_false(mScriptInvoke(&boundIdentityInt, &frame));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
} }
@ -236,7 +236,7 @@ M_TEST_DEFINE(wrongArgCountHi) {
M_TEST_DEFINE(wrongArgType) { M_TEST_DEFINE(wrongArgType) {
struct mScriptFrame frame; struct mScriptFrame frame;
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S32, 1); mSCRIPT_PUSH(&frame.stack, S32, 1);
assert_false(mScriptInvoke(&boundIdentityStruct, &frame)); assert_false(mScriptInvoke(&boundIdentityStruct, &frame));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
} }
@ -252,55 +252,55 @@ M_TEST_DEFINE(wrongPopType) {
bool b; bool b;
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S32, 0); mSCRIPT_PUSH(&frame.stack, S32, 0);
assert_false(mScriptPopU32(&frame.arguments, &u32)); assert_false(mScriptPopU32(&frame.stack, &u32));
assert_false(mScriptPopF32(&frame.arguments, &f32)); assert_false(mScriptPopF32(&frame.stack, &f32));
assert_false(mScriptPopBool(&frame.arguments, &b)); assert_false(mScriptPopBool(&frame.stack, &b));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S64, 0); mSCRIPT_PUSH(&frame.stack, S64, 0);
assert_false(mScriptPopU64(&frame.arguments, &u64)); assert_false(mScriptPopU64(&frame.stack, &u64));
assert_false(mScriptPopF64(&frame.arguments, &f64)); assert_false(mScriptPopF64(&frame.stack, &f64));
assert_false(mScriptPopBool(&frame.arguments, &b)); assert_false(mScriptPopBool(&frame.stack, &b));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, U32, 0); mSCRIPT_PUSH(&frame.stack, U32, 0);
assert_false(mScriptPopS32(&frame.arguments, &s32)); assert_false(mScriptPopS32(&frame.stack, &s32));
assert_false(mScriptPopF32(&frame.arguments, &f32)); assert_false(mScriptPopF32(&frame.stack, &f32));
assert_false(mScriptPopBool(&frame.arguments, &b)); assert_false(mScriptPopBool(&frame.stack, &b));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, U64, 0); mSCRIPT_PUSH(&frame.stack, U64, 0);
assert_false(mScriptPopS64(&frame.arguments, &s64)); assert_false(mScriptPopS64(&frame.stack, &s64));
assert_false(mScriptPopF64(&frame.arguments, &f64)); assert_false(mScriptPopF64(&frame.stack, &f64));
assert_false(mScriptPopBool(&frame.arguments, &b)); assert_false(mScriptPopBool(&frame.stack, &b));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, F32, 0); mSCRIPT_PUSH(&frame.stack, F32, 0);
assert_false(mScriptPopS32(&frame.arguments, &s32)); assert_false(mScriptPopS32(&frame.stack, &s32));
assert_false(mScriptPopU32(&frame.arguments, &u32)); assert_false(mScriptPopU32(&frame.stack, &u32));
assert_false(mScriptPopBool(&frame.arguments, &b)); assert_false(mScriptPopBool(&frame.stack, &b));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, F64, 0); mSCRIPT_PUSH(&frame.stack, F64, 0);
assert_false(mScriptPopS64(&frame.arguments, &s64)); assert_false(mScriptPopS64(&frame.stack, &s64));
assert_false(mScriptPopU64(&frame.arguments, &u64)); assert_false(mScriptPopU64(&frame.stack, &u64));
assert_false(mScriptPopBool(&frame.arguments, &b)); assert_false(mScriptPopBool(&frame.stack, &b));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, BOOL, 0); mSCRIPT_PUSH(&frame.stack, BOOL, 0);
assert_false(mScriptPopS32(&frame.arguments, &s32)); assert_false(mScriptPopS32(&frame.stack, &s32));
assert_false(mScriptPopU32(&frame.arguments, &u32)); assert_false(mScriptPopU32(&frame.stack, &u32));
assert_false(mScriptPopS64(&frame.arguments, &s64)); assert_false(mScriptPopS64(&frame.stack, &s64));
assert_false(mScriptPopU64(&frame.arguments, &u64)); assert_false(mScriptPopU64(&frame.stack, &u64));
assert_false(mScriptPopF32(&frame.arguments, &f32)); assert_false(mScriptPopF32(&frame.stack, &f32));
assert_false(mScriptPopF64(&frame.arguments, &f64)); assert_false(mScriptPopF64(&frame.stack, &f64));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
} }
@ -314,33 +314,33 @@ M_TEST_DEFINE(wrongPopSize) {
double f64; double f64;
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S32, 0); mSCRIPT_PUSH(&frame.stack, S32, 0);
assert_false(mScriptPopS64(&frame.arguments, &s64)); assert_false(mScriptPopS64(&frame.stack, &s64));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S64, 0); mSCRIPT_PUSH(&frame.stack, S64, 0);
assert_false(mScriptPopS32(&frame.arguments, &s32)); assert_false(mScriptPopS32(&frame.stack, &s32));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, U32, 0); mSCRIPT_PUSH(&frame.stack, U32, 0);
assert_false(mScriptPopU64(&frame.arguments, &u64)); assert_false(mScriptPopU64(&frame.stack, &u64));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, U64, 0); mSCRIPT_PUSH(&frame.stack, U64, 0);
assert_false(mScriptPopU32(&frame.arguments, &u32)); assert_false(mScriptPopU32(&frame.stack, &u32));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, F32, 0); mSCRIPT_PUSH(&frame.stack, F32, 0);
assert_false(mScriptPopF64(&frame.arguments, &f64)); assert_false(mScriptPopF64(&frame.stack, &f64));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, F64, 0); mSCRIPT_PUSH(&frame.stack, F64, 0);
assert_false(mScriptPopF32(&frame.arguments, &f32)); assert_false(mScriptPopF32(&frame.stack, &f32));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
} }
@ -370,63 +370,63 @@ M_TEST_DEFINE(wrongConst) {
mScriptClassInit(mSCRIPT_TYPE_MS_CS(Test)->details.cls); mScriptClassInit(mSCRIPT_TYPE_MS_CS(Test)->details.cls);
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S(Test), &a); mSCRIPT_PUSH(&frame.stack, S(Test), &a);
signature.entries[0] = mSCRIPT_TYPE_MS_S(Test); signature.entries[0] = mSCRIPT_TYPE_MS_S(Test);
assert_true(mScriptCoerceFrame(&signature, &frame.arguments, &frame.arguments)); assert_true(mScriptCoerceFrame(&signature, &frame.stack, &frame.stack));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, CS(Test), &a); mSCRIPT_PUSH(&frame.stack, CS(Test), &a);
signature.entries[0] = mSCRIPT_TYPE_MS_CS(Test); signature.entries[0] = mSCRIPT_TYPE_MS_CS(Test);
assert_true(mScriptCoerceFrame(&signature, &frame.arguments, &frame.arguments)); assert_true(mScriptCoerceFrame(&signature, &frame.stack, &frame.stack));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S(Test), &a); mSCRIPT_PUSH(&frame.stack, S(Test), &a);
signature.entries[0] = mSCRIPT_TYPE_MS_CS(Test); signature.entries[0] = mSCRIPT_TYPE_MS_CS(Test);
assert_true(mScriptCoerceFrame(&signature, &frame.arguments, &frame.arguments)); assert_true(mScriptCoerceFrame(&signature, &frame.stack, &frame.stack));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, CS(Test), &a); mSCRIPT_PUSH(&frame.stack, CS(Test), &a);
signature.entries[0] = mSCRIPT_TYPE_MS_S(Test); signature.entries[0] = mSCRIPT_TYPE_MS_S(Test);
assert_false(mScriptCoerceFrame(&signature, &frame.arguments, &frame.arguments)); assert_false(mScriptCoerceFrame(&signature, &frame.stack, &frame.stack));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S(Test), &a); mSCRIPT_PUSH(&frame.stack, S(Test), &a);
assert_true(mScriptPopSTest(&frame.arguments, &b)); assert_true(mScriptPopSTest(&frame.stack, &b));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S(Test), &a); mSCRIPT_PUSH(&frame.stack, S(Test), &a);
assert_false(mScriptPopCSTest(&frame.arguments, &cb)); assert_false(mScriptPopCSTest(&frame.stack, &cb));
signature.entries[0] = mSCRIPT_TYPE_MS_CS(Test); signature.entries[0] = mSCRIPT_TYPE_MS_CS(Test);
assert_true(mScriptCoerceFrame(&signature, &frame.arguments, &frame.arguments)); assert_true(mScriptCoerceFrame(&signature, &frame.stack, &frame.stack));
assert_true(mScriptPopCSTest(&frame.arguments, &cb)); assert_true(mScriptPopCSTest(&frame.stack, &cb));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, CS(Test), &a); mSCRIPT_PUSH(&frame.stack, CS(Test), &a);
assert_false(mScriptPopSTest(&frame.arguments, &b)); assert_false(mScriptPopSTest(&frame.stack, &b));
signature.entries[0] = mSCRIPT_TYPE_MS_S(Test); signature.entries[0] = mSCRIPT_TYPE_MS_S(Test);
assert_false(mScriptCoerceFrame(&signature, &frame.arguments, &frame.arguments)); assert_false(mScriptCoerceFrame(&signature, &frame.stack, &frame.stack));
assert_false(mScriptPopSTest(&frame.arguments, &b)); assert_false(mScriptPopSTest(&frame.stack, &b));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, CS(Test), &a); mSCRIPT_PUSH(&frame.stack, CS(Test), &a);
assert_true(mScriptPopCSTest(&frame.arguments, &cb)); assert_true(mScriptPopCSTest(&frame.stack, &cb));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
} }
M_TEST_DEFINE(coerceToFloat) { M_TEST_DEFINE(coerceToFloat) {
struct mScriptFrame frame; struct mScriptFrame frame;
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S32, 1); mSCRIPT_PUSH(&frame.stack, S32, 1);
assert_true(mScriptInvoke(&boundIdentityFloat, &frame)); assert_true(mScriptInvoke(&boundIdentityFloat, &frame));
float val; float val;
assert_true(mScriptPopF32(&frame.returnValues, &val)); assert_true(mScriptPopF32(&frame.stack, &val));
assert_float_equal(val, 1.f, 0.f); assert_float_equal(val, 1.f, 0.f);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
} }
@ -434,10 +434,10 @@ M_TEST_DEFINE(coerceToFloat) {
M_TEST_DEFINE(coerceFromFloat) { M_TEST_DEFINE(coerceFromFloat) {
struct mScriptFrame frame; struct mScriptFrame frame;
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, F32, 1.25f); mSCRIPT_PUSH(&frame.stack, F32, 1.25f);
assert_true(mScriptInvoke(&boundIdentityInt, &frame)); assert_true(mScriptInvoke(&boundIdentityInt, &frame));
int val; int val;
assert_true(mScriptPopS32(&frame.returnValues, &val)); assert_true(mScriptPopS32(&frame.stack, &val));
assert_int_equal(val, 1); assert_int_equal(val, 1);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
} }
@ -539,10 +539,10 @@ M_TEST_DEFINE(coerceFromBool) {
M_TEST_DEFINE(coerceWiden) { M_TEST_DEFINE(coerceWiden) {
struct mScriptFrame frame; struct mScriptFrame frame;
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S32, -1); mSCRIPT_PUSH(&frame.stack, S32, -1);
assert_true(mScriptInvoke(&boundIdentityInt64, &frame)); assert_true(mScriptInvoke(&boundIdentityInt64, &frame));
int64_t val; int64_t val;
assert_true(mScriptPopS64(&frame.returnValues, &val)); assert_true(mScriptPopS64(&frame.stack, &val));
assert_true(val == -1LL); assert_true(val == -1LL);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
} }
@ -550,10 +550,10 @@ M_TEST_DEFINE(coerceWiden) {
M_TEST_DEFINE(coerceNarrow) { M_TEST_DEFINE(coerceNarrow) {
struct mScriptFrame frame; struct mScriptFrame frame;
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S64, -1); mSCRIPT_PUSH(&frame.stack, S64, -1);
assert_true(mScriptInvoke(&boundIdentityInt, &frame)); assert_true(mScriptInvoke(&boundIdentityInt, &frame));
int32_t val; int32_t val;
assert_true(mScriptPopS32(&frame.returnValues, &val)); assert_true(mScriptPopS32(&frame.stack, &val));
assert_true(val == -1); assert_true(val == -1);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
} }
@ -1244,10 +1244,10 @@ M_TEST_DEFINE(hashTableString) {
M_TEST_DEFINE(stringIsHello) { M_TEST_DEFINE(stringIsHello) {
struct mScriptFrame frame; struct mScriptFrame frame;
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, CHARP, "hello"); mSCRIPT_PUSH(&frame.stack, CHARP, "hello");
assert_true(mScriptInvoke(&boundIsHello, &frame)); assert_true(mScriptInvoke(&boundIsHello, &frame));
int val; int val;
assert_true(mScriptPopS32(&frame.returnValues, &val)); assert_true(mScriptPopS32(&frame.stack, &val));
assert_int_equal(val, 1); assert_int_equal(val, 1);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
} }
@ -1255,10 +1255,10 @@ M_TEST_DEFINE(stringIsHello) {
M_TEST_DEFINE(stringIsNotHello) { M_TEST_DEFINE(stringIsNotHello) {
struct mScriptFrame frame; struct mScriptFrame frame;
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, CHARP, "world"); mSCRIPT_PUSH(&frame.stack, CHARP, "world");
assert_true(mScriptInvoke(&boundIsHello, &frame)); assert_true(mScriptInvoke(&boundIsHello, &frame));
int val; int val;
assert_true(mScriptPopS32(&frame.returnValues, &val)); assert_true(mScriptPopS32(&frame.stack, &val));
assert_int_equal(val, 0); assert_int_equal(val, 0);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
} }
@ -1271,33 +1271,33 @@ M_TEST_DEFINE(invokeList) {
mScriptListInit(&list, 0); mScriptListInit(&list, 0);
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, LIST, &list); mSCRIPT_PUSH(&frame.stack, LIST, &list);
assert_true(mScriptInvoke(&boundIsSequential, &frame)); assert_true(mScriptInvoke(&boundIsSequential, &frame));
assert_true(mScriptPopS32(&frame.returnValues, &val)); assert_true(mScriptPopS32(&frame.stack, &val));
assert_int_equal(val, 1); assert_int_equal(val, 1);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
*mScriptListAppend(&list) = mSCRIPT_MAKE_S32(1); *mScriptListAppend(&list) = mSCRIPT_MAKE_S32(1);
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, LIST, &list); mSCRIPT_PUSH(&frame.stack, LIST, &list);
assert_true(mScriptInvoke(&boundIsSequential, &frame)); assert_true(mScriptInvoke(&boundIsSequential, &frame));
assert_true(mScriptPopS32(&frame.returnValues, &val)); assert_true(mScriptPopS32(&frame.stack, &val));
assert_int_equal(val, 1); assert_int_equal(val, 1);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
*mScriptListAppend(&list) = mSCRIPT_MAKE_S32(2); *mScriptListAppend(&list) = mSCRIPT_MAKE_S32(2);
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, LIST, &list); mSCRIPT_PUSH(&frame.stack, LIST, &list);
assert_true(mScriptInvoke(&boundIsSequential, &frame)); assert_true(mScriptInvoke(&boundIsSequential, &frame));
assert_true(mScriptPopS32(&frame.returnValues, &val)); assert_true(mScriptPopS32(&frame.stack, &val));
assert_int_equal(val, 1); assert_int_equal(val, 1);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
*mScriptListAppend(&list) = mSCRIPT_MAKE_S32(4); *mScriptListAppend(&list) = mSCRIPT_MAKE_S32(4);
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, LIST, &list); mSCRIPT_PUSH(&frame.stack, LIST, &list);
assert_true(mScriptInvoke(&boundIsSequential, &frame)); assert_true(mScriptInvoke(&boundIsSequential, &frame));
assert_true(mScriptPopS32(&frame.returnValues, &val)); assert_true(mScriptPopS32(&frame.stack, &val));
assert_int_equal(val, 0); assert_int_equal(val, 0);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
@ -1309,14 +1309,14 @@ M_TEST_DEFINE(nullString) {
bool res; bool res;
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, CHARP, "hi"); mSCRIPT_PUSH(&frame.stack, CHARP, "hi");
assert_true(mScriptInvoke(&boundIsNullCharp, &frame)); assert_true(mScriptInvoke(&boundIsNullCharp, &frame));
assert_true(mScriptPopBool(&frame.returnValues, &res)); assert_true(mScriptPopBool(&frame.stack, &res));
assert_false(res); assert_false(res);
mSCRIPT_PUSH(&frame.arguments, CHARP, NULL); mSCRIPT_PUSH(&frame.stack, CHARP, NULL);
assert_true(mScriptInvoke(&boundIsNullCharp, &frame)); assert_true(mScriptInvoke(&boundIsNullCharp, &frame));
assert_true(mScriptPopBool(&frame.returnValues, &res)); assert_true(mScriptPopBool(&frame.stack, &res));
assert_true(res); assert_true(res);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
@ -1328,14 +1328,14 @@ M_TEST_DEFINE(nullStruct) {
bool res; bool res;
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, S(Test), &v); mSCRIPT_PUSH(&frame.stack, S(Test), &v);
assert_true(mScriptInvoke(&boundIsNullStruct, &frame)); assert_true(mScriptInvoke(&boundIsNullStruct, &frame));
assert_true(mScriptPopBool(&frame.returnValues, &res)); assert_true(mScriptPopBool(&frame.stack, &res));
assert_false(res); assert_false(res);
mSCRIPT_PUSH(&frame.arguments, S(Test), NULL); mSCRIPT_PUSH(&frame.stack, S(Test), NULL);
assert_true(mScriptInvoke(&boundIsNullStruct, &frame)); assert_true(mScriptInvoke(&boundIsNullStruct, &frame));
assert_true(mScriptPopBool(&frame.returnValues, &res)); assert_true(mScriptPopBool(&frame.stack, &res));
assert_true(res); assert_true(res);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);

View File

@ -1118,13 +1118,11 @@ bool mScriptTableIteratorLookup(struct mScriptValue* table, struct TableIterator
} }
void mScriptFrameInit(struct mScriptFrame* frame) { void mScriptFrameInit(struct mScriptFrame* frame) {
mScriptListInit(&frame->arguments, 4); mScriptListInit(&frame->stack, 4);
mScriptListInit(&frame->returnValues, 1);
} }
void mScriptFrameDeinit(struct mScriptFrame* frame) { void mScriptFrameDeinit(struct mScriptFrame* frame) {
mScriptListDeinit(&frame->returnValues); mScriptListDeinit(&frame->stack);
mScriptListDeinit(&frame->arguments);
} }
struct mScriptValue* mScriptLambdaCreate0(struct mScriptValue* fn, struct mScriptList* args) { struct mScriptValue* mScriptLambdaCreate0(struct mScriptValue* fn, struct mScriptList* args) {
@ -1150,15 +1148,15 @@ struct mScriptValue* mScriptLambdaCreate0(struct mScriptValue* fn, struct mScrip
} }
bool _callLambda0(struct mScriptFrame* frame, void* context) { bool _callLambda0(struct mScriptFrame* frame, void* context) {
if (mScriptListSize(&frame->arguments)) { if (mScriptListSize(&frame->stack)) {
return false; return false;
} }
struct mScriptLambda* lambda = context; struct mScriptLambda* lambda = context;
struct mScriptFrame subframe; struct mScriptFrame subframe;
mScriptFrameInit(&subframe); mScriptFrameInit(&subframe);
mScriptListCopy(&subframe.arguments, &lambda->arguments); mScriptListCopy(&subframe.stack, &lambda->arguments);
bool ok = mScriptInvoke(lambda->fn, &subframe); bool ok = mScriptInvoke(lambda->fn, &subframe);
if (mScriptListSize(&subframe.returnValues)) { if (mScriptListSize(&subframe.stack)) {
ok = false; ok = false;
} }
mScriptFrameDeinit(&subframe); mScriptFrameDeinit(&subframe);
@ -1399,17 +1397,17 @@ bool mScriptObjectGet(struct mScriptValue* obj, const char* member, struct mScri
} }
struct mScriptFrame frame; struct mScriptFrame frame;
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
struct mScriptValue* this = mScriptListAppend(&frame.arguments); struct mScriptValue* this = mScriptListAppend(&frame.stack);
this->type = obj->type; this->type = obj->type;
this->refs = mSCRIPT_VALUE_UNREF; this->refs = mSCRIPT_VALUE_UNREF;
this->flags = 0; this->flags = 0;
this->value.opaque = obj->value.opaque; this->value.opaque = obj->value.opaque;
mSCRIPT_PUSH(&frame.arguments, CHARP, member); mSCRIPT_PUSH(&frame.stack, CHARP, member);
if (!mScriptInvoke(&getMember, &frame) || mScriptListSize(&frame.returnValues) != 1) { if (!mScriptInvoke(&getMember, &frame) || mScriptListSize(&frame.stack) != 1) {
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
return false; return false;
} }
memcpy(val, mScriptListGetPointer(&frame.returnValues, 0), sizeof(*val)); memcpy(val, mScriptListGetPointer(&frame.stack, 0), sizeof(*val));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
return true; return true;
} }
@ -1547,14 +1545,14 @@ bool mScriptObjectSet(struct mScriptValue* obj, const char* member, struct mScri
} }
struct mScriptFrame frame; struct mScriptFrame frame;
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
struct mScriptValue* this = mScriptListAppend(&frame.arguments); struct mScriptValue* this = mScriptListAppend(&frame.stack);
this->type = obj->type; this->type = obj->type;
this->refs = mSCRIPT_VALUE_UNREF; this->refs = mSCRIPT_VALUE_UNREF;
this->flags = 0; this->flags = 0;
this->value.opaque = obj->value.opaque; this->value.opaque = obj->value.opaque;
mSCRIPT_PUSH(&frame.arguments, CHARP, member); mSCRIPT_PUSH(&frame.stack, CHARP, member);
mScriptValueWrap(val, mScriptListAppend(&frame.arguments)); mScriptValueWrap(val, mScriptListAppend(&frame.stack));
if (!mScriptInvoke(&setMember, &frame) || mScriptListSize(&frame.returnValues) != 0) { if (!mScriptInvoke(&setMember, &frame) || mScriptListSize(&frame.stack) != 0) {
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
return false; return false;
} }
@ -1665,7 +1663,7 @@ void mScriptObjectFree(struct mScriptValue* value) {
if (_accessRawMember(value->type->details.cls->free, value->value.opaque, value->type->isConst, &deinitMember)) { if (_accessRawMember(value->type->details.cls->free, value->value.opaque, value->type->isConst, &deinitMember)) {
struct mScriptFrame frame; struct mScriptFrame frame;
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.arguments, WRAPPER, value); mSCRIPT_PUSH(&frame.stack, WRAPPER, value);
mScriptInvoke(&deinitMember, &frame); mScriptInvoke(&deinitMember, &frame);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
} }

View File

@ -362,7 +362,7 @@ bool call(struct mScriptValue* obj, const char* method, struct mScriptFrame* fra
if (!mScriptObjectGet(obj, method, &fn)) { if (!mScriptObjectGet(obj, method, &fn)) {
return false; return false;
} }
mSCRIPT_PUSH(&frame->arguments, WRAPPER, obj); mSCRIPT_PUSH(&frame->stack, WRAPPER, obj);
return mScriptInvoke(&fn, frame); return mScriptInvoke(&fn, frame);
} }
@ -394,12 +394,12 @@ void explainCore(struct mCore* core) {
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
call(value, "base", &frame); call(value, "base", &frame);
mScriptPopU32(&frame.returnValues, &baseVal); mScriptPopU32(&frame.stack, &baseVal);
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
mScriptFrameInit(&frame); mScriptFrameInit(&frame);
call(value, "name", &frame); call(value, "name", &frame);
shortName = mScriptValueUnwrap(mScriptListGetPointer(&frame.returnValues, 0)); shortName = mScriptValueUnwrap(mScriptListGetPointer(&frame.stack, 0));
mScriptFrameDeinit(&frame); mScriptFrameDeinit(&frame);
fprintf(out, " base: 0x%x\n", baseVal); fprintf(out, " base: 0x%x\n", baseVal);