diff --git a/include/mgba/script/macros.h b/include/mgba/script/macros.h index 70eed0af5..a1ef0d669 100644 --- a/include/mgba/script/macros.h +++ b/include/mgba/script/macros.h @@ -76,10 +76,14 @@ CXX_GUARD_START #define _mSCRIPT_FIELD_NAME(V) (V)->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) \ 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) \ extern const struct mScriptType mSTStruct_ ## STRUCT; \ @@ -249,8 +253,8 @@ CXX_GUARD_START }, #define _mSCRIPT_STRUCT_METHOD_POP(TYPE, S, NPARAMS, ...) \ - _mCALL(_mCAT(mSCRIPT_POP_, _mSUCC_ ## NPARAMS), &frame->arguments, _mCOMMA_ ## NPARAMS(S(TYPE), __VA_ARGS__)); \ - if (mScriptListSize(&frame->arguments)) { \ + _mCALL(_mCAT(mSCRIPT_POP_, _mSUCC_ ## NPARAMS), &frame->stack, _mCOMMA_ ## NPARAMS(S(TYPE), __VA_ARGS__)); \ + if (mScriptListSize(&frame->stack)) { \ return false; \ } @@ -326,11 +330,11 @@ CXX_GUARD_START static const struct mScriptFunctionOverload _mSTStructBindingOverloads_ ## TYPE ## _ ## NAME[mSCRIPT_OVERLOADS_MAX]; \ static bool _mSTStructBinding_ ## TYPE ## _ ## NAME(struct mScriptFrame* frame, void* 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) { \ 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 overload->function->call(frame, overload->function->context); \ @@ -552,8 +556,8 @@ CXX_GUARD_START #define _mSCRIPT_BIND_N_FUNCTION(NAME, RETURN, FUNCTION, DEFAULTS, NPARAMS, ...) \ static bool _binding_ ## NAME(struct mScriptFrame* frame, void* ctx) { \ UNUSED(ctx); \ - _mCALL(mSCRIPT_POP_ ## NPARAMS, &frame->arguments, _mEVEN_ ## NPARAMS(__VA_ARGS__)); \ - if (mScriptListSize(&frame->arguments)) { \ + _mCALL(mSCRIPT_POP_ ## NPARAMS, &frame->stack, _mEVEN_ ## NPARAMS(__VA_ARGS__)); \ + if (mScriptListSize(&frame->stack)) { \ return false; \ } \ _mSCRIPT_CALL(RETURN, FUNCTION, NPARAMS); \ @@ -564,8 +568,8 @@ CXX_GUARD_START #define _mSCRIPT_BIND_VOID_FUNCTION(NAME, FUNCTION, DEFAULTS, NPARAMS, ...) \ static bool _binding_ ## NAME(struct mScriptFrame* frame, void* ctx) { \ UNUSED(ctx); \ - _mCALL(mSCRIPT_POP_ ## NPARAMS, &frame->arguments, _mEVEN_ ## NPARAMS(__VA_ARGS__)); \ - if (mScriptListSize(&frame->arguments)) { \ + _mCALL(mSCRIPT_POP_ ## NPARAMS, &frame->stack, _mEVEN_ ## NPARAMS(__VA_ARGS__)); \ + if (mScriptListSize(&frame->stack)) { \ return false; \ } \ _mSCRIPT_CALL_VOID(FUNCTION, NPARAMS); \ diff --git a/include/mgba/script/types.h b/include/mgba/script/types.h index 5b07abe3b..684059d32 100644 --- a/include/mgba/script/types.h +++ b/include/mgba/script/types.h @@ -325,8 +325,7 @@ struct mScriptString { }; struct mScriptFrame { - struct mScriptList arguments; - struct mScriptList returnValues; + struct mScriptList stack; // TODO: Exception/failure codes }; diff --git a/src/core/scripting.c b/src/core/scripting.c index dc56c1783..9e46b619c 100644 --- a/src/core/scripting.c +++ b/src/core/scripting.c @@ -1205,11 +1205,11 @@ static bool _callRotationCb(struct mScriptCoreAdapter* adapter, const char* cbNa struct mScriptValue* context = mScriptTableLookup(adapter->rotationCbTable, &mSCRIPT_MAKE_CHARP("context")); mScriptFrameInit(&frame); if (context) { - mScriptValueWrap(context, mScriptListAppend(&frame.arguments)); + mScriptValueWrap(context, mScriptListAppend(&frame.stack)); } bool ok = mScriptContextInvoke(adapter->context, cb, &frame); - if (ok && out && mScriptListSize(&frame.returnValues) == 1) { - if (!mScriptCast(mSCRIPT_TYPE_MS_F32, mScriptListGetPointer(&frame.returnValues, 0), out)) { + if (ok && out && mScriptListSize(&frame.stack) == 1) { + if (!mScriptCast(mSCRIPT_TYPE_MS_F32, mScriptListGetPointer(&frame.stack, 0), out)) { ok = false; } } @@ -1278,8 +1278,8 @@ static uint8_t _readLuminance(struct GBALuminanceSource* luminance) { mScriptFrameInit(&frame); bool ok = mScriptContextInvoke(adapter->context, adapter->luminanceCb, &frame); struct mScriptValue out = {0}; - if (ok && mScriptListSize(&frame.returnValues) == 1) { - if (!mScriptCast(mSCRIPT_TYPE_MS_U8, mScriptListGetPointer(&frame.returnValues, 0), &out)) { + if (ok && mScriptListSize(&frame.stack) == 1) { + if (!mScriptCast(mSCRIPT_TYPE_MS_U8, mScriptListGetPointer(&frame.stack, 0), &out)) { ok = false; } } diff --git a/src/script/context.c b/src/script/context.c index d9afd55a1..0d770dfde 100644 --- a/src/script/context.c +++ b/src/script/context.c @@ -266,7 +266,7 @@ void mScriptContextTriggerCallback(struct mScriptContext* context, const char* c if (fn) { mScriptFrameInit(&frame); if (args) { - mScriptListCopy(&frame.arguments, args); + mScriptListCopy(&frame.stack, args); } mScriptContextInvoke(context, fn, &frame); mScriptFrameDeinit(&frame); @@ -481,7 +481,7 @@ bool mScriptInvoke(const struct mScriptValue* val, struct mScriptFrame* frame) { return false; } 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; } const struct mScriptFunction* fn = val->value.opaque; diff --git a/src/script/engines/lua.c b/src/script/engines/lua.c index 732d54e99..f4f4026e9 100644 --- a/src/script/engines/lua.c +++ b/src/script/engines/lua.c @@ -912,12 +912,12 @@ void _luaError(struct mScriptEngineContextLua* luaContext) { if (ok) { struct mScriptFrame frame; mScriptFrameInit(&frame); - struct mScriptValue* this = mScriptListAppend(&frame.arguments); + struct mScriptValue* this = mScriptListAppend(&frame.stack); this->type = console->type; this->refs = mSCRIPT_VALUE_UNREF; this->flags = 0; this->value.opaque = console->value.opaque; - mSCRIPT_PUSH(&frame.arguments, CHARP, luaContext->lastError); + mSCRIPT_PUSH(&frame.stack, CHARP, luaContext->lastError); ok = mScriptInvoke(&error, &frame); mScriptFrameDeinit(&frame); } @@ -1115,7 +1115,7 @@ void _autofreeFrame(struct mScriptContext* context, struct mScriptList* frame) { bool _luaInvoke(struct mScriptEngineContextLua* luaContext, struct mScriptFrame* frame) { int nargs = 0; if (frame) { - nargs = mScriptListSize(&frame->arguments); + nargs = mScriptListSize(&frame->stack); } if (luaContext->lastError) { @@ -1127,9 +1127,12 @@ bool _luaInvoke(struct mScriptEngineContextLua* luaContext, struct mScriptFrame* return false; } - if (frame && !_luaPushFrame(luaContext, luaContext->lua, &frame->arguments)) { - mScriptContextDeactivate(luaContext->d.context); - return false; + if (frame) { + if (!_luaPushFrame(luaContext, luaContext->lua, &frame->stack)) { + mScriptContextDeactivate(luaContext->d.context); + return false; + } + mScriptListClear(&frame->stack); } lua_pushliteral(luaContext->lua, "mCtx"); @@ -1151,7 +1154,7 @@ bool _luaInvoke(struct mScriptEngineContextLua* luaContext, struct mScriptFrame* return false; } - if (frame && !_luaPopFrame(luaContext, luaContext->lua, &frame->returnValues)) { + if (frame && !_luaPopFrame(luaContext, luaContext->lua, &frame->stack)) { mScriptContextDrainPool(luaContext->d.context); return false; } @@ -1191,8 +1194,8 @@ int _luaThunk(lua_State* lua) { struct mScriptEngineContextLua* luaContext = _luaGetContext(lua); struct mScriptFrame frame; mScriptFrameInit(&frame); - if (!_luaPopFrame(luaContext, lua, &frame.arguments)) { - _freeFrame(&frame.arguments); + if (!_luaPopFrame(luaContext, lua, &frame.stack)) { + _freeFrame(&frame.stack); mScriptContextDrainPool(luaContext->d.context); mScriptFrameDeinit(&frame); 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)); - _autofreeFrame(luaContext->d.context, &frame.arguments); + _autofreeFrame(luaContext->d.context, &frame.stack); if (!fn || !mScriptContextInvoke(luaContext->d.context, fn, &frame)) { mScriptContextDrainPool(luaContext->d.context); mScriptFrameDeinit(&frame); @@ -1208,7 +1211,7 @@ int _luaThunk(lua_State* lua) { return lua_error(lua); } - bool ok = _luaPushFrame(luaContext, lua, &frame.returnValues); + bool ok = _luaPushFrame(luaContext, lua, &frame.stack); mScriptContextDrainPool(luaContext->d.context); mScriptFrameDeinit(&frame); if (!ok) { diff --git a/src/script/test/classes.c b/src/script/test/classes.c index e0ce39d47..1b688cae4 100644 --- a/src/script/test/classes.c +++ b/src/script/test/classes.c @@ -519,106 +519,106 @@ M_TEST_DEFINE(testAStatic) { assert_true(mScriptObjectGet(&sval, "i0", &val)); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); + mSCRIPT_PUSH(&frame.stack, S(TestA), &s); assert_true(mScriptInvoke(&val, &frame)); - assert_true(mScriptPopS32(&frame.returnValues, &rval)); + assert_true(mScriptPopS32(&frame.stack, &rval)); assert_int_equal(rval, 1); mScriptFrameDeinit(&frame); assert_true(mScriptObjectGet(&sval, "i1", &val)); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); - mSCRIPT_PUSH(&frame.arguments, S32, 1); + mSCRIPT_PUSH(&frame.stack, S(TestA), &s); + mSCRIPT_PUSH(&frame.stack, S32, 1); assert_true(mScriptInvoke(&val, &frame)); - assert_true(mScriptPopS32(&frame.returnValues, &rval)); + assert_true(mScriptPopS32(&frame.stack, &rval)); assert_int_equal(rval, 2); mScriptFrameDeinit(&frame); assert_true(mScriptObjectGet(&sval, "ic0", &val)); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, CS(TestA), &s); + mSCRIPT_PUSH(&frame.stack, CS(TestA), &s); assert_true(mScriptInvoke(&val, &frame)); - assert_true(mScriptPopS32(&frame.returnValues, &rval)); + assert_true(mScriptPopS32(&frame.stack, &rval)); assert_int_equal(rval, 1); mScriptFrameDeinit(&frame); assert_true(mScriptObjectGet(&sval, "ic0", &val)); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); + mSCRIPT_PUSH(&frame.stack, S(TestA), &s); assert_true(mScriptInvoke(&val, &frame)); - assert_true(mScriptPopS32(&frame.returnValues, &rval)); + assert_true(mScriptPopS32(&frame.stack, &rval)); assert_int_equal(rval, 1); mScriptFrameDeinit(&frame); assert_true(mScriptObjectGet(&sval, "ic1", &val)); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, CS(TestA), &s); - mSCRIPT_PUSH(&frame.arguments, S32, 1); + mSCRIPT_PUSH(&frame.stack, CS(TestA), &s); + mSCRIPT_PUSH(&frame.stack, S32, 1); assert_true(mScriptInvoke(&val, &frame)); - assert_true(mScriptPopS32(&frame.returnValues, &rval)); + assert_true(mScriptPopS32(&frame.stack, &rval)); assert_int_equal(rval, 2); mScriptFrameDeinit(&frame); assert_true(mScriptObjectGet(&sval, "ic1", &val)); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); - mSCRIPT_PUSH(&frame.arguments, S32, 1); + mSCRIPT_PUSH(&frame.stack, S(TestA), &s); + mSCRIPT_PUSH(&frame.stack, S32, 1); assert_true(mScriptInvoke(&val, &frame)); - assert_true(mScriptPopS32(&frame.returnValues, &rval)); + assert_true(mScriptPopS32(&frame.stack, &rval)); assert_int_equal(rval, 2); mScriptFrameDeinit(&frame); assert_true(mScriptObjectGet(&sval, "v0", &val)); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); + mSCRIPT_PUSH(&frame.stack, S(TestA), &s); assert_true(mScriptInvoke(&val, &frame)); mScriptFrameDeinit(&frame); assert_true(mScriptObjectGet(&sval, "i0", &val)); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); + mSCRIPT_PUSH(&frame.stack, S(TestA), &s); assert_true(mScriptInvoke(&val, &frame)); - assert_true(mScriptPopS32(&frame.returnValues, &rval)); + assert_true(mScriptPopS32(&frame.stack, &rval)); assert_int_equal(rval, 2); mScriptFrameDeinit(&frame); assert_true(mScriptObjectGet(&sval, "ic0", &val)); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, CS(TestA), &s); + mSCRIPT_PUSH(&frame.stack, CS(TestA), &s); assert_true(mScriptInvoke(&val, &frame)); - assert_true(mScriptPopS32(&frame.returnValues, &rval)); + assert_true(mScriptPopS32(&frame.stack, &rval)); assert_int_equal(rval, 2); mScriptFrameDeinit(&frame); assert_true(mScriptObjectGet(&sval, "v1", &val)); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); - mSCRIPT_PUSH(&frame.arguments, S32, 2); + mSCRIPT_PUSH(&frame.stack, S(TestA), &s); + mSCRIPT_PUSH(&frame.stack, S32, 2); assert_true(mScriptInvoke(&val, &frame)); mScriptFrameDeinit(&frame); assert_true(mScriptObjectGet(&sval, "v2", &val)); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); - mSCRIPT_PUSH(&frame.arguments, S32, 1); - mSCRIPT_PUSH(&frame.arguments, S32, -2); + mSCRIPT_PUSH(&frame.stack, S(TestA), &s); + mSCRIPT_PUSH(&frame.stack, S32, 1); + mSCRIPT_PUSH(&frame.stack, S32, -2); assert_true(mScriptInvoke(&val, &frame)); mScriptFrameDeinit(&frame); assert_true(mScriptObjectGet(&sval, "v2", &val)); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); - mSCRIPT_PUSH(&frame.arguments, S32, 1); + mSCRIPT_PUSH(&frame.stack, S(TestA), &s); + mSCRIPT_PUSH(&frame.stack, S32, 1); assert_true(mScriptInvoke(&val, &frame)); mScriptFrameDeinit(&frame); assert_true(mScriptObjectGet(&sval, "i0", &val)); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); + mSCRIPT_PUSH(&frame.stack, S(TestA), &s); assert_true(mScriptInvoke(&val, &frame)); - assert_true(mScriptPopS32(&frame.returnValues, &rval)); + assert_true(mScriptPopS32(&frame.stack, &rval)); assert_int_equal(rval, 4); mScriptFrameDeinit(&frame); assert_true(mScriptObjectGet(&sval, "ic0", &val)); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, CS(TestA), &s); + mSCRIPT_PUSH(&frame.stack, CS(TestA), &s); assert_true(mScriptInvoke(&val, &frame)); - assert_true(mScriptPopS32(&frame.returnValues, &rval)); + assert_true(mScriptPopS32(&frame.stack, &rval)); assert_int_equal(rval, 4); mScriptFrameDeinit(&frame); @@ -659,93 +659,93 @@ M_TEST_DEFINE(testADynamic) { assert_true(mScriptObjectGet(&sval, "ifn0", &val)); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); + mSCRIPT_PUSH(&frame.stack, S(TestA), &s); assert_true(mScriptInvoke(&val, &frame)); - assert_true(mScriptPopS32(&frame.returnValues, &rval)); + assert_true(mScriptPopS32(&frame.stack, &rval)); assert_int_equal(rval, 1); mScriptFrameDeinit(&frame); assert_true(mScriptObjectGet(&sval, "ifn1", &val)); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); - mSCRIPT_PUSH(&frame.arguments, S32, 1); + mSCRIPT_PUSH(&frame.stack, S(TestA), &s); + mSCRIPT_PUSH(&frame.stack, S32, 1); assert_true(mScriptInvoke(&val, &frame)); - assert_true(mScriptPopS32(&frame.returnValues, &rval)); + assert_true(mScriptPopS32(&frame.stack, &rval)); assert_int_equal(rval, 2); mScriptFrameDeinit(&frame); assert_true(mScriptObjectGet(&sval, "icfn0", &val)); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, CS(TestA), &s); + mSCRIPT_PUSH(&frame.stack, CS(TestA), &s); assert_true(mScriptInvoke(&val, &frame)); - assert_true(mScriptPopS32(&frame.returnValues, &rval)); + assert_true(mScriptPopS32(&frame.stack, &rval)); assert_int_equal(rval, 1); mScriptFrameDeinit(&frame); assert_true(mScriptObjectGet(&sval, "icfn0", &val)); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); + mSCRIPT_PUSH(&frame.stack, S(TestA), &s); assert_true(mScriptInvoke(&val, &frame)); - assert_true(mScriptPopS32(&frame.returnValues, &rval)); + assert_true(mScriptPopS32(&frame.stack, &rval)); assert_int_equal(rval, 1); mScriptFrameDeinit(&frame); assert_true(mScriptObjectGet(&sval, "icfn1", &val)); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, CS(TestA), &s); - mSCRIPT_PUSH(&frame.arguments, S32, 1); + mSCRIPT_PUSH(&frame.stack, CS(TestA), &s); + mSCRIPT_PUSH(&frame.stack, S32, 1); assert_true(mScriptInvoke(&val, &frame)); - assert_true(mScriptPopS32(&frame.returnValues, &rval)); + assert_true(mScriptPopS32(&frame.stack, &rval)); assert_int_equal(rval, 2); mScriptFrameDeinit(&frame); assert_true(mScriptObjectGet(&sval, "icfn1", &val)); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); - mSCRIPT_PUSH(&frame.arguments, S32, 1); + mSCRIPT_PUSH(&frame.stack, S(TestA), &s); + mSCRIPT_PUSH(&frame.stack, S32, 1); assert_true(mScriptInvoke(&val, &frame)); - assert_true(mScriptPopS32(&frame.returnValues, &rval)); + assert_true(mScriptPopS32(&frame.stack, &rval)); assert_int_equal(rval, 2); mScriptFrameDeinit(&frame); assert_true(mScriptObjectGet(&sval, "vfn0", &val)); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); + mSCRIPT_PUSH(&frame.stack, S(TestA), &s); assert_true(mScriptInvoke(&val, &frame)); mScriptFrameDeinit(&frame); assert_true(mScriptObjectGet(&sval, "ifn0", &val)); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); + mSCRIPT_PUSH(&frame.stack, S(TestA), &s); assert_true(mScriptInvoke(&val, &frame)); - assert_true(mScriptPopS32(&frame.returnValues, &rval)); + assert_true(mScriptPopS32(&frame.stack, &rval)); assert_int_equal(rval, 2); mScriptFrameDeinit(&frame); assert_true(mScriptObjectGet(&sval, "icfn0", &val)); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, CS(TestA), &s); + mSCRIPT_PUSH(&frame.stack, CS(TestA), &s); assert_true(mScriptInvoke(&val, &frame)); - assert_true(mScriptPopS32(&frame.returnValues, &rval)); + assert_true(mScriptPopS32(&frame.stack, &rval)); assert_int_equal(rval, 2); mScriptFrameDeinit(&frame); assert_true(mScriptObjectGet(&sval, "vfn1", &val)); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); - mSCRIPT_PUSH(&frame.arguments, S32, 2); + mSCRIPT_PUSH(&frame.stack, S(TestA), &s); + mSCRIPT_PUSH(&frame.stack, S32, 2); assert_true(mScriptInvoke(&val, &frame)); mScriptFrameDeinit(&frame); assert_true(mScriptObjectGet(&sval, "ifn0", &val)); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S(TestA), &s); + mSCRIPT_PUSH(&frame.stack, S(TestA), &s); assert_true(mScriptInvoke(&val, &frame)); - assert_true(mScriptPopS32(&frame.returnValues, &rval)); + assert_true(mScriptPopS32(&frame.stack, &rval)); assert_int_equal(rval, 4); mScriptFrameDeinit(&frame); assert_true(mScriptObjectGet(&sval, "icfn0", &val)); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, CS(TestA), &s); + mSCRIPT_PUSH(&frame.stack, CS(TestA), &s); assert_true(mScriptInvoke(&val, &frame)); - assert_true(mScriptPopS32(&frame.returnValues, &rval)); + assert_true(mScriptPopS32(&frame.stack, &rval)); assert_int_equal(rval, 4); mScriptFrameDeinit(&frame); @@ -1228,16 +1228,16 @@ M_TEST_DEFINE(testOverloadsBasic) { assert_true(mScriptObjectGet(&sval, "call", &fn)); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S(TestI), &s); - mSCRIPT_PUSH(&frame.arguments, U32, 1); + mSCRIPT_PUSH(&frame.stack, S(TestI), &s); + mSCRIPT_PUSH(&frame.stack, U32, 1); assert_true(mScriptInvoke(&fn, &frame)); mScriptFrameDeinit(&frame); assert_int_equal(s.num, 1); assert_null(s.str); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S(TestI), &s); - mSCRIPT_PUSH(&frame.arguments, CHARP, "called"); + mSCRIPT_PUSH(&frame.stack, S(TestI), &s); + mSCRIPT_PUSH(&frame.stack, CHARP, "called"); assert_true(mScriptInvoke(&fn, &frame)); mScriptFrameDeinit(&frame); assert_int_equal(s.num, 1); diff --git a/src/script/test/lua.c b/src/script/test/lua.c index 49c5521d7..388d79084 100644 --- a/src/script/test/lua.c +++ b/src/script/test/lua.c @@ -328,10 +328,10 @@ M_TEST_DEFINE(callLuaFunc) { struct mScriptFrame frame; mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S32, 1); + mSCRIPT_PUSH(&frame.stack, S32, 1); assert_true(mScriptInvoke(fn, &frame)); int64_t val; - assert_true(mScriptPopS64(&frame.returnValues, &val)); + assert_true(mScriptPopS64(&frame.stack, &val)); assert_int_equal(val, 2); mScriptFrameDeinit(&frame); @@ -342,10 +342,10 @@ M_TEST_DEFINE(callLuaFunc) { assert_int_equal(fn->type->base, mSCRIPT_TYPE_FUNCTION); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S32, 1); - mSCRIPT_PUSH(&frame.arguments, S32, 2); + mSCRIPT_PUSH(&frame.stack, S32, 1); + mSCRIPT_PUSH(&frame.stack, S32, 2); assert_true(mScriptInvoke(fn, &frame)); - assert_true(mScriptPopS64(&frame.returnValues, &val)); + assert_true(mScriptPopS64(&frame.stack, &val)); assert_int_equal(val, 3); mScriptFrameDeinit(&frame); diff --git a/src/script/test/types.c b/src/script/test/types.c index 67b6fba9a..51420eecd 100644 --- a/src/script/test/types.c +++ b/src/script/test/types.c @@ -111,7 +111,7 @@ M_TEST_DEFINE(voidArgs) { mScriptFrameInit(&frame); assert_true(mScriptInvoke(&boundVoidOne, &frame)); int32_t val; - assert_true(mScriptPopS32(&frame.returnValues, &val)); + assert_true(mScriptPopS32(&frame.stack, &val)); assert_int_equal(val, 1); mScriptFrameDeinit(&frame); } @@ -119,7 +119,7 @@ M_TEST_DEFINE(voidArgs) { M_TEST_DEFINE(voidFunc) { struct mScriptFrame frame; mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S32, 1); + mSCRIPT_PUSH(&frame.stack, S32, 1); assert_true(mScriptInvoke(&boundDiscard, &frame)); mScriptFrameDeinit(&frame); } @@ -127,10 +127,10 @@ M_TEST_DEFINE(voidFunc) { M_TEST_DEFINE(identityFunctionS32) { struct mScriptFrame frame; mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S32, 1); + mSCRIPT_PUSH(&frame.stack, S32, 1); assert_true(mScriptInvoke(&boundIdentityInt, &frame)); int32_t val; - assert_true(mScriptPopS32(&frame.returnValues, &val)); + assert_true(mScriptPopS32(&frame.stack, &val)); assert_int_equal(val, 1); mScriptFrameDeinit(&frame); } @@ -138,10 +138,10 @@ M_TEST_DEFINE(identityFunctionS32) { M_TEST_DEFINE(identityFunctionS64) { struct mScriptFrame frame; mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S64, 1); + mSCRIPT_PUSH(&frame.stack, S64, 1); assert_true(mScriptInvoke(&boundIdentityInt64, &frame)); int64_t val; - assert_true(mScriptPopS64(&frame.returnValues, &val)); + assert_true(mScriptPopS64(&frame.stack, &val)); assert_int_equal(val, 1); mScriptFrameDeinit(&frame); } @@ -149,10 +149,10 @@ M_TEST_DEFINE(identityFunctionS64) { M_TEST_DEFINE(identityFunctionF32) { struct mScriptFrame frame; mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, F32, 3.125f); + mSCRIPT_PUSH(&frame.stack, F32, 3.125f); assert_true(mScriptInvoke(&boundIdentityFloat, &frame)); float val; - assert_true(mScriptPopF32(&frame.returnValues, &val)); + assert_true(mScriptPopF32(&frame.stack, &val)); assert_float_equal(val, 3.125f, 0.f); mScriptFrameDeinit(&frame); } @@ -161,10 +161,10 @@ M_TEST_DEFINE(identityFunctionStruct) { struct mScriptFrame frame; struct Test v = {}; mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S(Test), &v); + mSCRIPT_PUSH(&frame.stack, S(Test), &v); assert_true(mScriptInvoke(&boundIdentityStruct, &frame)); struct Test* val; - assert_true(mScriptPopPointer(&frame.returnValues, (void**) &val)); + assert_true(mScriptPopPointer(&frame.stack, (void**) &val)); assert_ptr_equal(val, &v); mScriptFrameDeinit(&frame); } @@ -172,11 +172,11 @@ M_TEST_DEFINE(identityFunctionStruct) { M_TEST_DEFINE(addS32) { struct mScriptFrame frame; mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S32, 1); - mSCRIPT_PUSH(&frame.arguments, S32, 2); + mSCRIPT_PUSH(&frame.stack, S32, 1); + mSCRIPT_PUSH(&frame.stack, S32, 2); assert_true(mScriptInvoke(&boundAddInts, &frame)); int32_t val; - assert_true(mScriptPopS32(&frame.returnValues, &val)); + assert_true(mScriptPopS32(&frame.stack, &val)); assert_int_equal(val, 3); mScriptFrameDeinit(&frame); } @@ -186,17 +186,17 @@ M_TEST_DEFINE(addS32Defaults) { int32_t val; mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S32, 1); - mSCRIPT_PUSH(&frame.arguments, S32, 2); + mSCRIPT_PUSH(&frame.stack, S32, 1); + mSCRIPT_PUSH(&frame.stack, S32, 2); assert_true(mScriptInvoke(&boundAddIntWithDefaults, &frame)); - assert_true(mScriptPopS32(&frame.returnValues, &val)); + assert_true(mScriptPopS32(&frame.stack, &val)); assert_int_equal(val, 3); mScriptFrameDeinit(&frame); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S32, 1); + mSCRIPT_PUSH(&frame.stack, S32, 1); assert_true(mScriptInvoke(&boundAddIntWithDefaults, &frame)); - assert_true(mScriptPopS32(&frame.returnValues, &val)); + assert_true(mScriptPopS32(&frame.stack, &val)); assert_int_equal(val, 1); mScriptFrameDeinit(&frame); @@ -208,11 +208,11 @@ M_TEST_DEFINE(addS32Defaults) { M_TEST_DEFINE(subS32) { struct mScriptFrame frame; mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S32, 2); - mSCRIPT_PUSH(&frame.arguments, S32, 1); + mSCRIPT_PUSH(&frame.stack, S32, 2); + mSCRIPT_PUSH(&frame.stack, S32, 1); assert_true(mScriptInvoke(&boundSubInts, &frame)); int32_t val; - assert_true(mScriptPopS32(&frame.returnValues, &val)); + assert_true(mScriptPopS32(&frame.stack, &val)); assert_int_equal(val, 1); mScriptFrameDeinit(&frame); } @@ -227,8 +227,8 @@ M_TEST_DEFINE(wrongArgCountLo) { M_TEST_DEFINE(wrongArgCountHi) { struct mScriptFrame frame; mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S32, 1); - mSCRIPT_PUSH(&frame.arguments, S32, 1); + mSCRIPT_PUSH(&frame.stack, S32, 1); + mSCRIPT_PUSH(&frame.stack, S32, 1); assert_false(mScriptInvoke(&boundIdentityInt, &frame)); mScriptFrameDeinit(&frame); } @@ -236,7 +236,7 @@ M_TEST_DEFINE(wrongArgCountHi) { M_TEST_DEFINE(wrongArgType) { struct mScriptFrame frame; mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S32, 1); + mSCRIPT_PUSH(&frame.stack, S32, 1); assert_false(mScriptInvoke(&boundIdentityStruct, &frame)); mScriptFrameDeinit(&frame); } @@ -252,55 +252,55 @@ M_TEST_DEFINE(wrongPopType) { bool b; mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S32, 0); - assert_false(mScriptPopU32(&frame.arguments, &u32)); - assert_false(mScriptPopF32(&frame.arguments, &f32)); - assert_false(mScriptPopBool(&frame.arguments, &b)); + mSCRIPT_PUSH(&frame.stack, S32, 0); + assert_false(mScriptPopU32(&frame.stack, &u32)); + assert_false(mScriptPopF32(&frame.stack, &f32)); + assert_false(mScriptPopBool(&frame.stack, &b)); mScriptFrameDeinit(&frame); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S64, 0); - assert_false(mScriptPopU64(&frame.arguments, &u64)); - assert_false(mScriptPopF64(&frame.arguments, &f64)); - assert_false(mScriptPopBool(&frame.arguments, &b)); + mSCRIPT_PUSH(&frame.stack, S64, 0); + assert_false(mScriptPopU64(&frame.stack, &u64)); + assert_false(mScriptPopF64(&frame.stack, &f64)); + assert_false(mScriptPopBool(&frame.stack, &b)); mScriptFrameDeinit(&frame); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, U32, 0); - assert_false(mScriptPopS32(&frame.arguments, &s32)); - assert_false(mScriptPopF32(&frame.arguments, &f32)); - assert_false(mScriptPopBool(&frame.arguments, &b)); + mSCRIPT_PUSH(&frame.stack, U32, 0); + assert_false(mScriptPopS32(&frame.stack, &s32)); + assert_false(mScriptPopF32(&frame.stack, &f32)); + assert_false(mScriptPopBool(&frame.stack, &b)); mScriptFrameDeinit(&frame); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, U64, 0); - assert_false(mScriptPopS64(&frame.arguments, &s64)); - assert_false(mScriptPopF64(&frame.arguments, &f64)); - assert_false(mScriptPopBool(&frame.arguments, &b)); + mSCRIPT_PUSH(&frame.stack, U64, 0); + assert_false(mScriptPopS64(&frame.stack, &s64)); + assert_false(mScriptPopF64(&frame.stack, &f64)); + assert_false(mScriptPopBool(&frame.stack, &b)); mScriptFrameDeinit(&frame); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, F32, 0); - assert_false(mScriptPopS32(&frame.arguments, &s32)); - assert_false(mScriptPopU32(&frame.arguments, &u32)); - assert_false(mScriptPopBool(&frame.arguments, &b)); + mSCRIPT_PUSH(&frame.stack, F32, 0); + assert_false(mScriptPopS32(&frame.stack, &s32)); + assert_false(mScriptPopU32(&frame.stack, &u32)); + assert_false(mScriptPopBool(&frame.stack, &b)); mScriptFrameDeinit(&frame); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, F64, 0); - assert_false(mScriptPopS64(&frame.arguments, &s64)); - assert_false(mScriptPopU64(&frame.arguments, &u64)); - assert_false(mScriptPopBool(&frame.arguments, &b)); + mSCRIPT_PUSH(&frame.stack, F64, 0); + assert_false(mScriptPopS64(&frame.stack, &s64)); + assert_false(mScriptPopU64(&frame.stack, &u64)); + assert_false(mScriptPopBool(&frame.stack, &b)); mScriptFrameDeinit(&frame); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, BOOL, 0); - assert_false(mScriptPopS32(&frame.arguments, &s32)); - assert_false(mScriptPopU32(&frame.arguments, &u32)); - assert_false(mScriptPopS64(&frame.arguments, &s64)); - assert_false(mScriptPopU64(&frame.arguments, &u64)); - assert_false(mScriptPopF32(&frame.arguments, &f32)); - assert_false(mScriptPopF64(&frame.arguments, &f64)); + mSCRIPT_PUSH(&frame.stack, BOOL, 0); + assert_false(mScriptPopS32(&frame.stack, &s32)); + assert_false(mScriptPopU32(&frame.stack, &u32)); + assert_false(mScriptPopS64(&frame.stack, &s64)); + assert_false(mScriptPopU64(&frame.stack, &u64)); + assert_false(mScriptPopF32(&frame.stack, &f32)); + assert_false(mScriptPopF64(&frame.stack, &f64)); mScriptFrameDeinit(&frame); } @@ -314,33 +314,33 @@ M_TEST_DEFINE(wrongPopSize) { double f64; mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S32, 0); - assert_false(mScriptPopS64(&frame.arguments, &s64)); + mSCRIPT_PUSH(&frame.stack, S32, 0); + assert_false(mScriptPopS64(&frame.stack, &s64)); mScriptFrameDeinit(&frame); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S64, 0); - assert_false(mScriptPopS32(&frame.arguments, &s32)); + mSCRIPT_PUSH(&frame.stack, S64, 0); + assert_false(mScriptPopS32(&frame.stack, &s32)); mScriptFrameDeinit(&frame); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, U32, 0); - assert_false(mScriptPopU64(&frame.arguments, &u64)); + mSCRIPT_PUSH(&frame.stack, U32, 0); + assert_false(mScriptPopU64(&frame.stack, &u64)); mScriptFrameDeinit(&frame); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, U64, 0); - assert_false(mScriptPopU32(&frame.arguments, &u32)); + mSCRIPT_PUSH(&frame.stack, U64, 0); + assert_false(mScriptPopU32(&frame.stack, &u32)); mScriptFrameDeinit(&frame); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, F32, 0); - assert_false(mScriptPopF64(&frame.arguments, &f64)); + mSCRIPT_PUSH(&frame.stack, F32, 0); + assert_false(mScriptPopF64(&frame.stack, &f64)); mScriptFrameDeinit(&frame); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, F64, 0); - assert_false(mScriptPopF32(&frame.arguments, &f32)); + mSCRIPT_PUSH(&frame.stack, F64, 0); + assert_false(mScriptPopF32(&frame.stack, &f32)); mScriptFrameDeinit(&frame); } @@ -370,63 +370,63 @@ M_TEST_DEFINE(wrongConst) { mScriptClassInit(mSCRIPT_TYPE_MS_CS(Test)->details.cls); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S(Test), &a); + mSCRIPT_PUSH(&frame.stack, S(Test), &a); 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); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, CS(Test), &a); + mSCRIPT_PUSH(&frame.stack, CS(Test), &a); 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); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S(Test), &a); + mSCRIPT_PUSH(&frame.stack, S(Test), &a); 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); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, CS(Test), &a); + mSCRIPT_PUSH(&frame.stack, CS(Test), &a); 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); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S(Test), &a); - assert_true(mScriptPopSTest(&frame.arguments, &b)); + mSCRIPT_PUSH(&frame.stack, S(Test), &a); + assert_true(mScriptPopSTest(&frame.stack, &b)); mScriptFrameDeinit(&frame); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S(Test), &a); - assert_false(mScriptPopCSTest(&frame.arguments, &cb)); + mSCRIPT_PUSH(&frame.stack, S(Test), &a); + assert_false(mScriptPopCSTest(&frame.stack, &cb)); signature.entries[0] = mSCRIPT_TYPE_MS_CS(Test); - assert_true(mScriptCoerceFrame(&signature, &frame.arguments, &frame.arguments)); - assert_true(mScriptPopCSTest(&frame.arguments, &cb)); + assert_true(mScriptCoerceFrame(&signature, &frame.stack, &frame.stack)); + assert_true(mScriptPopCSTest(&frame.stack, &cb)); mScriptFrameDeinit(&frame); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, CS(Test), &a); - assert_false(mScriptPopSTest(&frame.arguments, &b)); + mSCRIPT_PUSH(&frame.stack, CS(Test), &a); + assert_false(mScriptPopSTest(&frame.stack, &b)); signature.entries[0] = mSCRIPT_TYPE_MS_S(Test); - assert_false(mScriptCoerceFrame(&signature, &frame.arguments, &frame.arguments)); - assert_false(mScriptPopSTest(&frame.arguments, &b)); + assert_false(mScriptCoerceFrame(&signature, &frame.stack, &frame.stack)); + assert_false(mScriptPopSTest(&frame.stack, &b)); mScriptFrameDeinit(&frame); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, CS(Test), &a); - assert_true(mScriptPopCSTest(&frame.arguments, &cb)); + mSCRIPT_PUSH(&frame.stack, CS(Test), &a); + assert_true(mScriptPopCSTest(&frame.stack, &cb)); mScriptFrameDeinit(&frame); } M_TEST_DEFINE(coerceToFloat) { struct mScriptFrame frame; mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S32, 1); + mSCRIPT_PUSH(&frame.stack, S32, 1); assert_true(mScriptInvoke(&boundIdentityFloat, &frame)); float val; - assert_true(mScriptPopF32(&frame.returnValues, &val)); + assert_true(mScriptPopF32(&frame.stack, &val)); assert_float_equal(val, 1.f, 0.f); mScriptFrameDeinit(&frame); } @@ -434,10 +434,10 @@ M_TEST_DEFINE(coerceToFloat) { M_TEST_DEFINE(coerceFromFloat) { struct mScriptFrame frame; mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, F32, 1.25f); + mSCRIPT_PUSH(&frame.stack, F32, 1.25f); assert_true(mScriptInvoke(&boundIdentityInt, &frame)); int val; - assert_true(mScriptPopS32(&frame.returnValues, &val)); + assert_true(mScriptPopS32(&frame.stack, &val)); assert_int_equal(val, 1); mScriptFrameDeinit(&frame); } @@ -539,10 +539,10 @@ M_TEST_DEFINE(coerceFromBool) { M_TEST_DEFINE(coerceWiden) { struct mScriptFrame frame; mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S32, -1); + mSCRIPT_PUSH(&frame.stack, S32, -1); assert_true(mScriptInvoke(&boundIdentityInt64, &frame)); int64_t val; - assert_true(mScriptPopS64(&frame.returnValues, &val)); + assert_true(mScriptPopS64(&frame.stack, &val)); assert_true(val == -1LL); mScriptFrameDeinit(&frame); } @@ -550,10 +550,10 @@ M_TEST_DEFINE(coerceWiden) { M_TEST_DEFINE(coerceNarrow) { struct mScriptFrame frame; mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S64, -1); + mSCRIPT_PUSH(&frame.stack, S64, -1); assert_true(mScriptInvoke(&boundIdentityInt, &frame)); int32_t val; - assert_true(mScriptPopS32(&frame.returnValues, &val)); + assert_true(mScriptPopS32(&frame.stack, &val)); assert_true(val == -1); mScriptFrameDeinit(&frame); } @@ -1244,10 +1244,10 @@ M_TEST_DEFINE(hashTableString) { M_TEST_DEFINE(stringIsHello) { struct mScriptFrame frame; mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, CHARP, "hello"); + mSCRIPT_PUSH(&frame.stack, CHARP, "hello"); assert_true(mScriptInvoke(&boundIsHello, &frame)); int val; - assert_true(mScriptPopS32(&frame.returnValues, &val)); + assert_true(mScriptPopS32(&frame.stack, &val)); assert_int_equal(val, 1); mScriptFrameDeinit(&frame); } @@ -1255,10 +1255,10 @@ M_TEST_DEFINE(stringIsHello) { M_TEST_DEFINE(stringIsNotHello) { struct mScriptFrame frame; mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, CHARP, "world"); + mSCRIPT_PUSH(&frame.stack, CHARP, "world"); assert_true(mScriptInvoke(&boundIsHello, &frame)); int val; - assert_true(mScriptPopS32(&frame.returnValues, &val)); + assert_true(mScriptPopS32(&frame.stack, &val)); assert_int_equal(val, 0); mScriptFrameDeinit(&frame); } @@ -1271,33 +1271,33 @@ M_TEST_DEFINE(invokeList) { mScriptListInit(&list, 0); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, LIST, &list); + mSCRIPT_PUSH(&frame.stack, LIST, &list); assert_true(mScriptInvoke(&boundIsSequential, &frame)); - assert_true(mScriptPopS32(&frame.returnValues, &val)); + assert_true(mScriptPopS32(&frame.stack, &val)); assert_int_equal(val, 1); mScriptFrameDeinit(&frame); *mScriptListAppend(&list) = mSCRIPT_MAKE_S32(1); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, LIST, &list); + mSCRIPT_PUSH(&frame.stack, LIST, &list); assert_true(mScriptInvoke(&boundIsSequential, &frame)); - assert_true(mScriptPopS32(&frame.returnValues, &val)); + assert_true(mScriptPopS32(&frame.stack, &val)); assert_int_equal(val, 1); mScriptFrameDeinit(&frame); *mScriptListAppend(&list) = mSCRIPT_MAKE_S32(2); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, LIST, &list); + mSCRIPT_PUSH(&frame.stack, LIST, &list); assert_true(mScriptInvoke(&boundIsSequential, &frame)); - assert_true(mScriptPopS32(&frame.returnValues, &val)); + assert_true(mScriptPopS32(&frame.stack, &val)); assert_int_equal(val, 1); mScriptFrameDeinit(&frame); *mScriptListAppend(&list) = mSCRIPT_MAKE_S32(4); mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, LIST, &list); + mSCRIPT_PUSH(&frame.stack, LIST, &list); assert_true(mScriptInvoke(&boundIsSequential, &frame)); - assert_true(mScriptPopS32(&frame.returnValues, &val)); + assert_true(mScriptPopS32(&frame.stack, &val)); assert_int_equal(val, 0); mScriptFrameDeinit(&frame); @@ -1309,14 +1309,14 @@ M_TEST_DEFINE(nullString) { bool res; mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, CHARP, "hi"); + mSCRIPT_PUSH(&frame.stack, CHARP, "hi"); assert_true(mScriptInvoke(&boundIsNullCharp, &frame)); - assert_true(mScriptPopBool(&frame.returnValues, &res)); + assert_true(mScriptPopBool(&frame.stack, &res)); assert_false(res); - mSCRIPT_PUSH(&frame.arguments, CHARP, NULL); + mSCRIPT_PUSH(&frame.stack, CHARP, NULL); assert_true(mScriptInvoke(&boundIsNullCharp, &frame)); - assert_true(mScriptPopBool(&frame.returnValues, &res)); + assert_true(mScriptPopBool(&frame.stack, &res)); assert_true(res); mScriptFrameDeinit(&frame); @@ -1328,14 +1328,14 @@ M_TEST_DEFINE(nullStruct) { bool res; mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, S(Test), &v); + mSCRIPT_PUSH(&frame.stack, S(Test), &v); assert_true(mScriptInvoke(&boundIsNullStruct, &frame)); - assert_true(mScriptPopBool(&frame.returnValues, &res)); + assert_true(mScriptPopBool(&frame.stack, &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(mScriptPopBool(&frame.returnValues, &res)); + assert_true(mScriptPopBool(&frame.stack, &res)); assert_true(res); mScriptFrameDeinit(&frame); diff --git a/src/script/types.c b/src/script/types.c index 00422d20c..799c6fb71 100644 --- a/src/script/types.c +++ b/src/script/types.c @@ -1118,13 +1118,11 @@ bool mScriptTableIteratorLookup(struct mScriptValue* table, struct TableIterator } void mScriptFrameInit(struct mScriptFrame* frame) { - mScriptListInit(&frame->arguments, 4); - mScriptListInit(&frame->returnValues, 1); + mScriptListInit(&frame->stack, 4); } void mScriptFrameDeinit(struct mScriptFrame* frame) { - mScriptListDeinit(&frame->returnValues); - mScriptListDeinit(&frame->arguments); + mScriptListDeinit(&frame->stack); } 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) { - if (mScriptListSize(&frame->arguments)) { + if (mScriptListSize(&frame->stack)) { return false; } struct mScriptLambda* lambda = context; struct mScriptFrame subframe; mScriptFrameInit(&subframe); - mScriptListCopy(&subframe.arguments, &lambda->arguments); + mScriptListCopy(&subframe.stack, &lambda->arguments); bool ok = mScriptInvoke(lambda->fn, &subframe); - if (mScriptListSize(&subframe.returnValues)) { + if (mScriptListSize(&subframe.stack)) { ok = false; } mScriptFrameDeinit(&subframe); @@ -1399,17 +1397,17 @@ bool mScriptObjectGet(struct mScriptValue* obj, const char* member, struct mScri } struct mScriptFrame frame; mScriptFrameInit(&frame); - struct mScriptValue* this = mScriptListAppend(&frame.arguments); + struct mScriptValue* this = mScriptListAppend(&frame.stack); this->type = obj->type; this->refs = mSCRIPT_VALUE_UNREF; this->flags = 0; this->value.opaque = obj->value.opaque; - mSCRIPT_PUSH(&frame.arguments, CHARP, member); - if (!mScriptInvoke(&getMember, &frame) || mScriptListSize(&frame.returnValues) != 1) { + mSCRIPT_PUSH(&frame.stack, CHARP, member); + if (!mScriptInvoke(&getMember, &frame) || mScriptListSize(&frame.stack) != 1) { mScriptFrameDeinit(&frame); return false; } - memcpy(val, mScriptListGetPointer(&frame.returnValues, 0), sizeof(*val)); + memcpy(val, mScriptListGetPointer(&frame.stack, 0), sizeof(*val)); mScriptFrameDeinit(&frame); return true; } @@ -1547,14 +1545,14 @@ bool mScriptObjectSet(struct mScriptValue* obj, const char* member, struct mScri } struct mScriptFrame frame; mScriptFrameInit(&frame); - struct mScriptValue* this = mScriptListAppend(&frame.arguments); + struct mScriptValue* this = mScriptListAppend(&frame.stack); this->type = obj->type; this->refs = mSCRIPT_VALUE_UNREF; this->flags = 0; this->value.opaque = obj->value.opaque; - mSCRIPT_PUSH(&frame.arguments, CHARP, member); - mScriptValueWrap(val, mScriptListAppend(&frame.arguments)); - if (!mScriptInvoke(&setMember, &frame) || mScriptListSize(&frame.returnValues) != 0) { + mSCRIPT_PUSH(&frame.stack, CHARP, member); + mScriptValueWrap(val, mScriptListAppend(&frame.stack)); + if (!mScriptInvoke(&setMember, &frame) || mScriptListSize(&frame.stack) != 0) { mScriptFrameDeinit(&frame); 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)) { struct mScriptFrame frame; mScriptFrameInit(&frame); - mSCRIPT_PUSH(&frame.arguments, WRAPPER, value); + mSCRIPT_PUSH(&frame.stack, WRAPPER, value); mScriptInvoke(&deinitMember, &frame); mScriptFrameDeinit(&frame); } diff --git a/src/tools/docgen.c b/src/tools/docgen.c index cdabb472c..e2c444ed2 100644 --- a/src/tools/docgen.c +++ b/src/tools/docgen.c @@ -362,7 +362,7 @@ bool call(struct mScriptValue* obj, const char* method, struct mScriptFrame* fra if (!mScriptObjectGet(obj, method, &fn)) { return false; } - mSCRIPT_PUSH(&frame->arguments, WRAPPER, obj); + mSCRIPT_PUSH(&frame->stack, WRAPPER, obj); return mScriptInvoke(&fn, frame); } @@ -394,12 +394,12 @@ void explainCore(struct mCore* core) { mScriptFrameInit(&frame); call(value, "base", &frame); - mScriptPopU32(&frame.returnValues, &baseVal); + mScriptPopU32(&frame.stack, &baseVal); mScriptFrameDeinit(&frame); mScriptFrameInit(&frame); call(value, "name", &frame); - shortName = mScriptValueUnwrap(mScriptListGetPointer(&frame.returnValues, 0)); + shortName = mScriptValueUnwrap(mScriptListGetPointer(&frame.stack, 0)); mScriptFrameDeinit(&frame); fprintf(out, " base: 0x%x\n", baseVal);