Skip to content

Commit

Permalink
Initialize repo - 0.620
Browse files Browse the repository at this point in the history
  • Loading branch information
RealEthanPlayzDev committed Apr 6, 2024
0 parents commit 5d1f39f
Show file tree
Hide file tree
Showing 19 changed files with 1,329 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "luau"]
path = luau
url = https://github.com/luau-lang/luau.git
72 changes: 72 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"files.associations": {
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"charconv": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"format": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"semaphore": "cpp",
"span": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp",
"variant": "cpp"
}
}
60 changes: 60 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
cmake_minimum_required(VERSION 3.19)
project(Luau.LuauCeption LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 17)

# Import Luau
option(LUAU_BUILD_CLI "Build CLI" OFF)
option(LUAU_BUILD_TESTS "Build tests" OFF)
option(LUAU_BUILD_WEB "Build Web module" OFF)
option(LUAU_WERROR "Warnings as errors" OFF)
option(LUAU_STATIC_CRT "Link with the static CRT (/MT)" OFF)
option(LUAU_EXTERN_C "Use extern C for all APIs" ON)
add_subdirectory(luau)

# Compiler variant compile & link options
set(COMPILER_CC_OPTS)
list(APPEND COMPILER_CC_OPTS -O3 -flto)
set(COMPILER_LN_OPTS)
list(APPEND COMPILER_LN_OPTS -O3 -flto -sEVAL_CTORS -sEXPORTED_FUNCTIONS=['_luau_compile','_set_flag','_set_all_flags','_reset_flags','_strlen','_malloc','_free'] -sBINARYEN_EXTRA_PASSES='vacuum,simplify-locals,simplify-globals,optimize-instructions,optimize-stack-ir,fast-math,strip-dwarf,code-folding,duplicate-function-elimination,duplicate-import-elimination,rse,type-ssa')

# VM variant compile & link options
set(VM_CC_OPTS)
list(APPEND VM_CC_OPTS -O3 -flto)
set(VM_LN_OPTS)
list(APPEND VM_LN_OPTS -O3 -flto -sEVAL_CTORS -sEXPORTED_FUNCTIONS=['_lua_newstate','_lua_close','_lua_newthread','_lua_mainthread','_lua_resetthread','_lua_isthreadreset','_lua_absindex','_lua_gettop','_lua_settop','_lua_pushvalue','_lua_remove','_lua_insert','_lua_replace','_lua_checkstack','_lua_rawcheckstack','_lua_xmove','_lua_xpush','_lua_isnumber','_lua_isstring','_lua_iscfunction','_lua_isLfunction','_lua_isuserdata','_lua_type','_lua_typename','_lua_equal','_lua_rawequal','_lua_lessthan','_lua_tonumberx','_lua_tointegerx','_lua_tovector','_lua_toboolean','_lua_tolstring','_lua_tostringatom','_lua_namecallatom','_lua_objlen','_lua_tocfunction','_lua_tolightuserdata','_lua_tolightuserdatatagged','_lua_touserdata','_lua_touserdatatagged','_lua_userdatatag','_lua_lightuserdatatag','_lua_tothread','_lua_tobuffer','_lua_topointer','_lua_pushnil','_lua_pushnumber','_lua_pushinteger','_lua_pushunsigned','_lua_pushvector','_lua_pushlstring','_lua_pushstring','_lua_pushvfstring','_lua_pushfstringL','_lua_pushcclosurek','_lua_pushboolean','_lua_pushthread','_lua_pushlightuserdatatagged','_lua_newuserdatatagged','_lua_newuserdatadtor','_lua_newbuffer','_lua_gettable','_lua_getfield','_lua_rawgetfield','_lua_rawget','_lua_rawgeti','_lua_createtable','_lua_setreadonly','_lua_getreadonly','_lua_setsafeenv','_lua_getmetatable','_lua_settable','_lua_setfield','_lua_rawsetfield','_lua_rawset','_lua_rawseti','_lua_setmetatable','_lua_setfenv','_luau_load','_lua_call','_lua_pcall','_lua_yield','_lua_break','_lua_resume','_lua_resumeerror','_lua_status','_lua_isyieldable','_lua_getthreaddata','_lua_setthreaddata','_lua_costatus','_lua_gc','_lua_setmemcat','_lua_totalbytes','_lua_error','_lua_next','_lua_rawiter','_lua_concat','_lua_encodepointer','_lua_clock','_lua_setuserdatatag','_lua_setuserdatadtor','_lua_getuserdatadtor','_lua_setlightuserdataname','_lua_getlightuserdataname','_lua_clonefunction','_lua_cleartable','_lua_getallocf','_lua_ref','_lua_unref','_lua_stackdepth','_lua_getinfo','_lua_getargument','_lua_getlocal','_lua_setlocal','_lua_getupvalue','_lua_setupvalue','_lua_singlestep','_lua_breakpoint','_lua_getcoverage','_lua_debugtrace','_luaL_register','_luaL_getmetafield','_luaL_callmeta','_luaL_typeerrorL','_luaL_argerrorL','_luaL_checklstring','_luaL_optlstring','_luaL_checknumber','_luaL_optnumber','_luaL_checkboolean','_luaL_optboolean','_luaL_checkinteger','_luaL_optinteger','_luaL_checkunsigned','_luaL_optunsigned','_luaL_checkvector','_luaL_optvector','_luaL_checkstack','_luaL_checktype','_luaL_checkany','_luaL_newmetatable','_luaL_checkudata','_luaL_checkbuffer','_luaL_where','_luaL_errorL','_luaL_checkoption','_luaL_tolstring','_luaL_newstate','_luaL_findtable','_luaL_typename','_luaL_buffinitsize','_luaL_prepbuffsize','_luaL_addlstring','_luaL_addvalue','_luaL_addvalueany','_luaL_pushresult','_luaL_pushresultsize','_luaopen_base','_luaopen_coroutine','_luaopen_table','_luaopen_os','_luaopen_string','_luaopen_bit32','_luaopen_buffer','_luaopen_utf8','_luaopen_math','_luaopen_debug','_luaL_openlibs','_luaL_sandbox','_luaL_sandboxthread','_set_flag','_set_all_flags','_reset_flags','_strlen','_malloc','_free'] -sBINARYEN_EXTRA_PASSES='vacuum,simplify-locals,simplify-globals,optimize-instructions,optimize-stack-ir,fast-math,strip-dwarf,code-folding,duplicate-function-elimination,duplicate-import-elimination,rse,type-ssa')

# Full variant compile & link options
set(FULL_CC_OPTS)
list(APPEND FULL_CC_OPTS -O3 -flto)
set(FULL_LN_OPTS)
list(APPEND FULL_LN_OPTS -O3 -flto -sEVAL_CTORS -sEXPORTED_FUNCTIONS=['_luau_compile','_lua_newstate','_lua_close','_lua_newthread','_lua_mainthread','_lua_resetthread','_lua_isthreadreset','_lua_absindex','_lua_gettop','_lua_settop','_lua_pushvalue','_lua_remove','_lua_insert','_lua_replace','_lua_checkstack','_lua_rawcheckstack','_lua_xmove','_lua_xpush','_lua_isnumber','_lua_isstring','_lua_iscfunction','_lua_isLfunction','_lua_isuserdata','_lua_type','_lua_typename','_lua_equal','_lua_rawequal','_lua_lessthan','_lua_tonumberx','_lua_tointegerx','_lua_tovector','_lua_toboolean','_lua_tolstring','_lua_tostringatom','_lua_namecallatom','_lua_objlen','_lua_tocfunction','_lua_tolightuserdata','_lua_tolightuserdatatagged','_lua_touserdata','_lua_touserdatatagged','_lua_userdatatag','_lua_lightuserdatatag','_lua_tothread','_lua_tobuffer','_lua_topointer','_lua_pushnil','_lua_pushnumber','_lua_pushinteger','_lua_pushunsigned','_lua_pushvector','_lua_pushlstring','_lua_pushstring','_lua_pushvfstring','_lua_pushfstringL','_lua_pushcclosurek','_lua_pushboolean','_lua_pushthread','_lua_pushlightuserdatatagged','_lua_newuserdatatagged','_lua_newuserdatadtor','_lua_newbuffer','_lua_gettable','_lua_getfield','_lua_rawgetfield','_lua_rawget','_lua_rawgeti','_lua_createtable','_lua_setreadonly','_lua_getreadonly','_lua_setsafeenv','_lua_getmetatable','_lua_settable','_lua_setfield','_lua_rawsetfield','_lua_rawset','_lua_rawseti','_lua_setmetatable','_lua_setfenv','_luau_load','_lua_call','_lua_pcall','_lua_yield','_lua_break','_lua_resume','_lua_resumeerror','_lua_status','_lua_isyieldable','_lua_getthreaddata','_lua_setthreaddata','_lua_costatus','_lua_gc','_lua_setmemcat','_lua_totalbytes','_lua_error','_lua_next','_lua_rawiter','_lua_concat','_lua_encodepointer','_lua_clock','_lua_setuserdatatag','_lua_setuserdatadtor','_lua_getuserdatadtor','_lua_setlightuserdataname','_lua_getlightuserdataname','_lua_clonefunction','_lua_cleartable','_lua_getallocf','_lua_ref','_lua_unref','_lua_stackdepth','_lua_getinfo','_lua_getargument','_lua_getlocal','_lua_setlocal','_lua_getupvalue','_lua_setupvalue','_lua_singlestep','_lua_breakpoint','_lua_getcoverage','_lua_debugtrace','_luaL_register','_luaL_getmetafield','_luaL_callmeta','_luaL_typeerrorL','_luaL_argerrorL','_luaL_checklstring','_luaL_optlstring','_luaL_checknumber','_luaL_optnumber','_luaL_checkboolean','_luaL_optboolean','_luaL_checkinteger','_luaL_optinteger','_luaL_checkunsigned','_luaL_optunsigned','_luaL_checkvector','_luaL_optvector','_luaL_checkstack','_luaL_checktype','_luaL_checkany','_luaL_newmetatable','_luaL_checkudata','_luaL_checkbuffer','_luaL_where','_luaL_errorL','_luaL_checkoption','_luaL_tolstring','_luaL_newstate','_luaL_findtable','_luaL_typename','_luaL_buffinitsize','_luaL_prepbuffsize','_luaL_addlstring','_luaL_addvalue','_luaL_addvalueany','_luaL_pushresult','_luaL_pushresultsize','_luaopen_base','_luaopen_coroutine','_luaopen_table','_luaopen_os','_luaopen_string','_luaopen_bit32','_luaopen_buffer','_luaopen_utf8','_luaopen_math','_luaopen_debug','_luaL_openlibs','_luaL_sandbox','_luaL_sandboxthread','_set_flag','_set_all_flags','_reset_flags','_strlen','_malloc','_free'] -sBINARYEN_EXTRA_PASSES='vacuum,simplify-locals,simplify-globals,optimize-instructions,optimize-stack-ir,fast-math,strip-dwarf,code-folding,duplicate-function-elimination,duplicate-import-elimination,rse,type-ssa')

# Compiler variant
add_executable(Luau.LuauCeption.Compiler)
target_sources(Luau.LuauCeption.Compiler PRIVATE src/Compiler.cpp src/LuauCeptionFlags.cpp src/LuauCeptionFlags.h)
target_link_libraries(Luau.LuauCeption.Compiler PUBLIC Luau.Compiler)

# VM variant
add_executable(Luau.LuauCeption.VM)
target_sources(Luau.LuauCeption.VM PRIVATE src/VM.cpp src/LuauCeptionFlags.cpp src/LuauCeptionFlags.h)
target_link_libraries(Luau.LuauCeption.VM PUBLIC Luau.VM)

# Full variant
add_executable(Luau.LuauCeption.Full)
target_sources(Luau.LuauCeption.Full PRIVATE src/Full.cpp src/LuauCeptionFlags.cpp src/LuauCeptionFlags.h)
target_link_libraries(Luau.LuauCeption.Full PUBLIC Luau.Compiler Luau.VM)

# Compiler variant configuration
target_compile_features(Luau.LuauCeption.Compiler PUBLIC cxx_std_17)
target_compile_options(Luau.LuauCeption.Compiler PUBLIC ${COMPILER_CC_OPTS})
target_link_options(Luau.LuauCeption.Compiler PUBLIC ${COMPILER_LN_OPTS})

# VM variant configuration
target_compile_features(Luau.LuauCeption.VM PUBLIC cxx_std_17)
target_compile_options(Luau.LuauCeption.VM PUBLIC ${VM_CC_OPTS})
target_link_options(Luau.LuauCeption.VM PUBLIC ${VM_LN_OPTS})

# Full variant configuration
target_compile_features(Luau.LuauCeption.Full PUBLIC cxx_std_17)
target_compile_options(Luau.LuauCeption.Full PUBLIC ${FULL_CC_OPTS})
target_link_options(Luau.LuauCeption.Full PUBLIC ${FULL_LN_OPTS})
1 change: 1 addition & 0 deletions luau
Submodule luau added at 67e16c
84 changes: 84 additions & 0 deletions snippets/Compiler.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
--// LuauCeption - Compiler variant
--// Luau 0.620 (67e16cba1826351e28d0bd193cedea14d01cbbee)

local STUB_WARN = true

local cfns = {
["luau_compile"] = FUNC_LIST[241],
["set_flag"] = FUNC_LIST[534],
["set_all_flags"] = FUNC_LIST[541],
["reset_flags"] = FUNC_LIST[543],
["strlen"] = FUNC_LIST[504],
["malloc"] = FUNC_LIST[513],
["free"] = FUNC_LIST[515],
}

run_init_code()
memory_at_0 = MEMORY_LIST[0]

--// __cxa_throw
FUNC_LIST[0] = function(except, _info, _dtor)
assert(false, "exception occured in c")
end

--// emscripten_memcpy_js (emscripten_memcpy_big)
FUNC_LIST[1] = function(destination, source, size)
rt.store.copy(memory_at_0, destination, memory_at_0, source, size)
end

--// emscripten_resize_heap
FUNC_LIST[2] = function(_requestedSize)
assert(false, "OOM")
end

--// abort
FUNC_LIST[3] = function(reason)
assert(false, `Aborted({reason})`)
end

local function luau_compile(src: string, optLevel: number?, dbgLevel: number?, covLevel: number?)
--// Source string
local srcLen = #src
local srcPtr = cfns.malloc(srcLen + 1)
rt.store.string(memory_at_0, srcPtr, src)
rt.store.i32_n8(memory_at_0, srcPtr + srcLen, 0)

--// Struct lua_CompileOptions (see luau/Compiler/include/luacode.h)
local compileOptsPtr = cfns.malloc(28)
rt.store.i32(memory_at_0, compileOptsPtr + 0, optLevel or 1) --// int optimizationLevel
rt.store.i32(memory_at_0, compileOptsPtr + 4, dbgLevel or 1) --// int debugLevel
rt.store.i32(memory_at_0, compileOptsPtr + 8, covLevel or 0) --// int coverageLevel
rt.store.i32(memory_at_0, compileOptsPtr + 12, 0) --// const char* vectorLib
rt.store.i32(memory_at_0, compileOptsPtr + 16, 0) --// const char* vectorCtor
rt.store.i32(memory_at_0, compileOptsPtr + 20, 0) --// const char* vectorType
rt.store.i32(memory_at_0, compileOptsPtr + 24, 0) --// const char* const* mutableGlobals

--// Bytecode size
local bcSizePtr = cfns.malloc(8)

--// Compile
local bcPtr = cfns.luau_compile(srcPtr, srcLen, compileOptsPtr, bcSizePtr)
local bcSize = rt.load.i32(memory_at_0, bcSizePtr)
local bc = rt.load.string(memory_at_0, bcPtr, bcSize)

--// Cleanup
cfns.free(srcPtr)
cfns.free(bcPtr)
cfns.free(bcSizePtr)
cfns.free(compileOptsPtr)

return bc, bcSize
end

return {
luau_compile = luau_compile,
luau_setflag = luau_setflag,
luau_setallflags = luau_setallflags,
luau_resetflags = luau_resetflags,
wasm = {
rt = rt,
cfns = cfns,
indirect_function_table = TABLE_LIST[0],
memory = MEMORY_LIST[0]
}
}
22 changes: 22 additions & 0 deletions snippets/Flags.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
local function luau_setflag(name: string, state: boolean)
--// Flag name
local flagNamePtr = cfns.malloc(#name)
rt.store.string(memory_at_0, flagNamePtr, name)

--// Set the flag
cfns.set_flag(flagNamePtr, if (state) then 1 else 0)

--// Cleanup
cfns.free(flagNamePtr)
return
end

local function luau_setallflags(state: boolean)
cfns.set_all_flags(if (state) then 1 else 0)
return
end

local function luau_resetflags()
cfns.reset_flags()
return
end
Loading

0 comments on commit 5d1f39f

Please sign in to comment.