2022-10-13 23:59:53 +01:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
#include "NativeState.h"
|
|
|
|
|
|
|
|
#include "Luau/UnwindBuilder.h"
|
|
|
|
|
2022-10-27 23:22:49 +01:00
|
|
|
#include "CodeGenUtils.h"
|
2022-10-13 23:59:53 +01:00
|
|
|
|
|
|
|
#include "lbuiltins.h"
|
|
|
|
#include "lgc.h"
|
|
|
|
#include "ltable.h"
|
2022-10-21 18:33:43 +01:00
|
|
|
#include "lfunc.h"
|
2022-10-13 23:59:53 +01:00
|
|
|
#include "lvm.h"
|
|
|
|
|
|
|
|
#include <math.h>
|
2022-10-27 23:22:49 +01:00
|
|
|
#include <string.h>
|
2022-10-13 23:59:53 +01:00
|
|
|
|
2023-09-15 17:27:45 +01:00
|
|
|
LUAU_FASTINTVARIABLE(LuauCodeGenBlockSize, 4 * 1024 * 1024)
|
|
|
|
LUAU_FASTINTVARIABLE(LuauCodeGenMaxTotalSize, 256 * 1024 * 1024)
|
|
|
|
|
2022-10-13 23:59:53 +01:00
|
|
|
namespace Luau
|
|
|
|
{
|
|
|
|
namespace CodeGen
|
|
|
|
{
|
|
|
|
|
|
|
|
NativeState::NativeState()
|
2023-08-11 13:55:30 +01:00
|
|
|
: NativeState(nullptr, nullptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NativeState::NativeState(AllocationCallback* allocationCallback, void* allocationCallbackContext)
|
2023-09-15 17:27:45 +01:00
|
|
|
: codeAllocator{size_t(FInt::LuauCodeGenBlockSize), size_t(FInt::LuauCodeGenMaxTotalSize), allocationCallback, allocationCallbackContext}
|
2022-10-13 23:59:53 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NativeState::~NativeState() = default;
|
|
|
|
|
2023-05-19 19:59:59 +01:00
|
|
|
void initFunctions(NativeState& data)
|
2022-10-13 23:59:53 +01:00
|
|
|
{
|
2022-10-27 23:22:49 +01:00
|
|
|
static_assert(sizeof(data.context.luauF_table) == sizeof(luauF_table), "fastcall tables are not of the same length");
|
|
|
|
memcpy(data.context.luauF_table, luauF_table, sizeof(luauF_table));
|
2022-10-13 23:59:53 +01:00
|
|
|
|
|
|
|
data.context.luaV_lessthan = luaV_lessthan;
|
|
|
|
data.context.luaV_lessequal = luaV_lessequal;
|
|
|
|
data.context.luaV_equalval = luaV_equalval;
|
|
|
|
data.context.luaV_doarith = luaV_doarith;
|
|
|
|
data.context.luaV_dolen = luaV_dolen;
|
|
|
|
data.context.luaV_gettable = luaV_gettable;
|
|
|
|
data.context.luaV_settable = luaV_settable;
|
2022-10-21 18:33:43 +01:00
|
|
|
data.context.luaV_getimport = luaV_getimport;
|
|
|
|
data.context.luaV_concat = luaV_concat;
|
2022-10-13 23:59:53 +01:00
|
|
|
|
|
|
|
data.context.luaH_getn = luaH_getn;
|
2022-10-21 18:33:43 +01:00
|
|
|
data.context.luaH_new = luaH_new;
|
|
|
|
data.context.luaH_clone = luaH_clone;
|
|
|
|
data.context.luaH_resizearray = luaH_resizearray;
|
2023-09-01 17:38:53 +01:00
|
|
|
data.context.luaH_setnum = luaH_setnum;
|
2022-10-13 23:59:53 +01:00
|
|
|
|
|
|
|
data.context.luaC_barriertable = luaC_barriertable;
|
2022-10-21 18:33:43 +01:00
|
|
|
data.context.luaC_barrierf = luaC_barrierf;
|
|
|
|
data.context.luaC_barrierback = luaC_barrierback;
|
|
|
|
data.context.luaC_step = luaC_step;
|
2022-10-13 23:59:53 +01:00
|
|
|
|
2022-10-21 18:33:43 +01:00
|
|
|
data.context.luaF_close = luaF_close;
|
2023-07-28 12:37:00 +01:00
|
|
|
data.context.luaF_findupval = luaF_findupval;
|
|
|
|
data.context.luaF_newLclosure = luaF_newLclosure;
|
2022-10-13 23:59:53 +01:00
|
|
|
|
2023-01-13 20:36:28 +00:00
|
|
|
data.context.luaT_gettm = luaT_gettm;
|
2023-03-17 14:59:30 +00:00
|
|
|
data.context.luaT_objtypenamestr = luaT_objtypenamestr;
|
2023-01-13 20:36:28 +00:00
|
|
|
|
2023-01-03 17:33:19 +00:00
|
|
|
data.context.libm_exp = exp;
|
2022-10-21 18:33:43 +01:00
|
|
|
data.context.libm_pow = pow;
|
2023-01-03 17:33:19 +00:00
|
|
|
data.context.libm_fmod = fmod;
|
|
|
|
data.context.libm_log = log;
|
|
|
|
data.context.libm_log2 = log2;
|
|
|
|
data.context.libm_log10 = log10;
|
2023-02-03 12:34:12 +00:00
|
|
|
data.context.libm_ldexp = ldexp;
|
|
|
|
data.context.libm_round = round;
|
|
|
|
data.context.libm_frexp = frexp;
|
|
|
|
data.context.libm_modf = modf;
|
2023-01-03 17:33:19 +00:00
|
|
|
|
|
|
|
data.context.libm_asin = asin;
|
|
|
|
data.context.libm_sin = sin;
|
|
|
|
data.context.libm_sinh = sinh;
|
|
|
|
data.context.libm_acos = acos;
|
|
|
|
data.context.libm_cos = cos;
|
|
|
|
data.context.libm_cosh = cosh;
|
|
|
|
data.context.libm_atan = atan;
|
|
|
|
data.context.libm_atan2 = atan2;
|
|
|
|
data.context.libm_tan = tan;
|
|
|
|
data.context.libm_tanh = tanh;
|
2022-10-27 23:22:49 +01:00
|
|
|
|
2023-04-14 13:05:27 +01:00
|
|
|
data.context.forgLoopTableIter = forgLoopTableIter;
|
2022-10-27 23:22:49 +01:00
|
|
|
data.context.forgLoopNodeIter = forgLoopNodeIter;
|
|
|
|
data.context.forgLoopNonTableFallback = forgLoopNonTableFallback;
|
|
|
|
data.context.forgPrepXnextFallback = forgPrepXnextFallback;
|
2022-11-04 17:02:37 +00:00
|
|
|
data.context.callProlog = callProlog;
|
|
|
|
data.context.callEpilogC = callEpilogC;
|
2023-03-31 13:21:14 +01:00
|
|
|
|
|
|
|
data.context.callFallback = callFallback;
|
2023-05-19 19:59:59 +01:00
|
|
|
|
|
|
|
data.context.executeGETGLOBAL = executeGETGLOBAL;
|
|
|
|
data.context.executeSETGLOBAL = executeSETGLOBAL;
|
|
|
|
data.context.executeGETTABLEKS = executeGETTABLEKS;
|
|
|
|
data.context.executeSETTABLEKS = executeSETTABLEKS;
|
|
|
|
|
|
|
|
data.context.executeNAMECALL = executeNAMECALL;
|
|
|
|
data.context.executeFORGPREP = executeFORGPREP;
|
2023-08-04 18:01:35 +01:00
|
|
|
data.context.executeGETVARARGSMultRet = executeGETVARARGSMultRet;
|
|
|
|
data.context.executeGETVARARGSConst = executeGETVARARGSConst;
|
2023-05-19 19:59:59 +01:00
|
|
|
data.context.executeDUPCLOSURE = executeDUPCLOSURE;
|
|
|
|
data.context.executePREPVARARGS = executePREPVARARGS;
|
|
|
|
data.context.executeSETLIST = executeSETLIST;
|
2022-10-13 23:59:53 +01:00
|
|
|
}
|
|
|
|
|
2024-03-30 22:49:03 +00:00
|
|
|
void initFunctions(NativeContext& context)
|
|
|
|
{
|
|
|
|
static_assert(sizeof(context.luauF_table) == sizeof(luauF_table), "fastcall tables are not of the same length");
|
|
|
|
memcpy(context.luauF_table, luauF_table, sizeof(luauF_table));
|
|
|
|
|
|
|
|
context.luaV_lessthan = luaV_lessthan;
|
|
|
|
context.luaV_lessequal = luaV_lessequal;
|
|
|
|
context.luaV_equalval = luaV_equalval;
|
|
|
|
context.luaV_doarith = luaV_doarith;
|
|
|
|
context.luaV_dolen = luaV_dolen;
|
|
|
|
context.luaV_gettable = luaV_gettable;
|
|
|
|
context.luaV_settable = luaV_settable;
|
|
|
|
context.luaV_getimport = luaV_getimport;
|
|
|
|
context.luaV_concat = luaV_concat;
|
|
|
|
|
|
|
|
context.luaH_getn = luaH_getn;
|
|
|
|
context.luaH_new = luaH_new;
|
|
|
|
context.luaH_clone = luaH_clone;
|
|
|
|
context.luaH_resizearray = luaH_resizearray;
|
|
|
|
context.luaH_setnum = luaH_setnum;
|
|
|
|
|
|
|
|
context.luaC_barriertable = luaC_barriertable;
|
|
|
|
context.luaC_barrierf = luaC_barrierf;
|
|
|
|
context.luaC_barrierback = luaC_barrierback;
|
|
|
|
context.luaC_step = luaC_step;
|
|
|
|
|
|
|
|
context.luaF_close = luaF_close;
|
|
|
|
context.luaF_findupval = luaF_findupval;
|
|
|
|
context.luaF_newLclosure = luaF_newLclosure;
|
|
|
|
|
|
|
|
context.luaT_gettm = luaT_gettm;
|
|
|
|
context.luaT_objtypenamestr = luaT_objtypenamestr;
|
|
|
|
|
|
|
|
context.libm_exp = exp;
|
|
|
|
context.libm_pow = pow;
|
|
|
|
context.libm_fmod = fmod;
|
|
|
|
context.libm_log = log;
|
|
|
|
context.libm_log2 = log2;
|
|
|
|
context.libm_log10 = log10;
|
|
|
|
context.libm_ldexp = ldexp;
|
|
|
|
context.libm_round = round;
|
|
|
|
context.libm_frexp = frexp;
|
|
|
|
context.libm_modf = modf;
|
|
|
|
|
|
|
|
context.libm_asin = asin;
|
|
|
|
context.libm_sin = sin;
|
|
|
|
context.libm_sinh = sinh;
|
|
|
|
context.libm_acos = acos;
|
|
|
|
context.libm_cos = cos;
|
|
|
|
context.libm_cosh = cosh;
|
|
|
|
context.libm_atan = atan;
|
|
|
|
context.libm_atan2 = atan2;
|
|
|
|
context.libm_tan = tan;
|
|
|
|
context.libm_tanh = tanh;
|
|
|
|
|
|
|
|
context.forgLoopTableIter = forgLoopTableIter;
|
|
|
|
context.forgLoopNodeIter = forgLoopNodeIter;
|
|
|
|
context.forgLoopNonTableFallback = forgLoopNonTableFallback;
|
|
|
|
context.forgPrepXnextFallback = forgPrepXnextFallback;
|
|
|
|
context.callProlog = callProlog;
|
|
|
|
context.callEpilogC = callEpilogC;
|
|
|
|
|
|
|
|
context.callFallback = callFallback;
|
|
|
|
|
|
|
|
context.executeGETGLOBAL = executeGETGLOBAL;
|
|
|
|
context.executeSETGLOBAL = executeSETGLOBAL;
|
|
|
|
context.executeGETTABLEKS = executeGETTABLEKS;
|
|
|
|
context.executeSETTABLEKS = executeSETTABLEKS;
|
|
|
|
|
|
|
|
context.executeNAMECALL = executeNAMECALL;
|
|
|
|
context.executeFORGPREP = executeFORGPREP;
|
|
|
|
context.executeGETVARARGSMultRet = executeGETVARARGSMultRet;
|
|
|
|
context.executeGETVARARGSConst = executeGETVARARGSConst;
|
|
|
|
context.executeDUPCLOSURE = executeDUPCLOSURE;
|
|
|
|
context.executePREPVARARGS = executePREPVARARGS;
|
|
|
|
context.executeSETLIST = executeSETLIST;
|
|
|
|
}
|
|
|
|
|
2022-10-13 23:59:53 +01:00
|
|
|
} // namespace CodeGen
|
|
|
|
} // namespace Luau
|