Skip to content

Commit 8f94a62

Browse files
committed
Add support for disassembly and support debug debugger
- Add support for disassembly - Support debug debugger - Support auto download luamake - Update luajit build script
1 parent 57de61e commit 8f94a62

36 files changed

+918
-67
lines changed

.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ NamespaceIndentation: All
1515
PackConstructorInitializers: Never
1616
QualifierAlignment: Left
1717
SpaceBeforeCpp11BracedList: true
18+
SortIncludes: false

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
/build/
66
/extension/package.json
77
.DS_Store
8-
.idea/
8+
.idea/
9+
luamake/

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
url = https://github.com/actboy168/bee.lua.git
44
[submodule "3rd/lua/luajit"]
55
path = 3rd/lua/luajit
6-
url = https://github.com/fesily/luajit2
6+
url = https://github.com/fesily/luajit
77
[submodule "3rd/json.lua"]
88
path = 3rd/json.lua
99
url = https://github.com/actboy168/json.lua

.luarc.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,9 @@
3737
"trailing-space": "Warning"
3838
}
3939
},
40-
"workspace.checkThirdParty": false
40+
"workspace.checkThirdParty": false,
41+
"type.inferParamType": true,
42+
"workspace.library": [
43+
"${addons}/bee/module/library"
44+
]
4145
}

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
{
22
"C_Cpp.autoAddFileAssociations": false,
3+
"terminal.integrated.env.linux": {
4+
"PATH": "${workspaceFolder}/luamake;${env:PATH}"
5+
},
6+
"terminal.integrated.env.windows": {
7+
"PATH": "${workspaceFolder}/luamake;${env:PATH}"
8+
},
9+
"terminal.integrated.env.osx": {
10+
"PATH": "${workspaceFolder}/luamake;${env:PATH}"
11+
}
312
}

3rd/lua/luajit

Makefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
.PHONY: all download_deps build_luamake init_luamake install
3+
4+
all: download_deps build_luamake
5+
luamake/luamake build --release
6+
7+
build_luamake: init_luamake
8+
@echo "Building luamake..."
9+
git submodule update --init --recursive
10+
cd luamake && compile/build.sh
11+
12+
download_deps: build_luamake
13+
luamake/luamake lua compile/download_deps.lua
14+
15+
init_luamake:
16+
@if [ -d "luamake" ]; then \
17+
if [ -d "luamake/.git" ]; then \
18+
echo "Updating luamake repository..."; \
19+
(cd luamake && git pull && git submodule update --remote); \
20+
else \
21+
echo "Error: 'luamake' exists but is not a Git repository."; \
22+
fi; \
23+
else \
24+
echo "Cloning luamake repository..."; \
25+
git clone --recurse-submodules https://github.com/actboy168/luamake.git; \
26+
fi
27+
28+
install: all
29+
@echo "Installing Lua Debugger..."
30+
luamake/luamake lua compile/install.lua

compile/install.lua

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
local fs = require 'bee.filesystem'
2+
local home = assert(os.getenv("HOME") or os.getenv("HOMEPATH"), "HOME environment variable is not set")
3+
4+
local vscode_dir = {
5+
".vscode",
6+
".vscode-server",
7+
}
8+
9+
local sourceDir = ...
10+
11+
for i, v in ipairs(vscode_dir) do
12+
local vscode_dir = fs.path(home) / v / "extensions"
13+
if not fs.exists(vscode_dir) or not fs.is_directory(vscode_dir) then
14+
goto continue
15+
end
16+
local extensions_json = vscode_dir / "extensions.json"
17+
if not fs.exists(extensions_json) or not fs.is_regular_file(extensions_json) then
18+
goto continue
19+
end
20+
local fp = io.open(extensions_json:string(), "r")
21+
local content = fp:read("*a")
22+
fp:close()
23+
if not content:find("lua-debug", 1, true) then
24+
goto continue
25+
end
26+
for dir in fs.pairs(vscode_dir) do
27+
if dir:string():find("lua-debug", 1, true) then
28+
local fn = assert(loadfile('compile/copy.lua'))
29+
fn(sourceDir or 'publish', dir:string())
30+
os.exit(0)
31+
end
32+
end
33+
::continue::
34+
end
35+
os.exit(1)

compile/luajit/defined.lua

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local lm = require "luamake"
2+
local fs = require 'bee.filesystem'
23

34
local arch = lm.runtime_platform:sub(lm.runtime_platform:find("-") + 1)
45
if arch == "ia32" then
@@ -9,12 +10,34 @@ local luaver = "luajit"
910
local LUAJIT_ENABLE_LUA52COMPAT = "LUAJIT_ENABLE_LUA52COMPAT"
1011
local LUAJIT_NUMMODE = "LUAJIT_NUMMODE=2"
1112
local luajitDir = '3rd/lua/' .. luaver .. "/src"
13+
local is_old_version_luajit = fs.exists(fs.path(luajitDir) / 'lj_init.c')
1214

1315
local _M = {
1416
arch = arch,
1517
LUAJIT_ENABLE_LUA52COMPAT = LUAJIT_ENABLE_LUA52COMPAT,
1618
LUAJIT_NUMMODE = LUAJIT_NUMMODE,
17-
luajitDir = luajitDir
19+
luajitDir = luajitDir,
20+
is_old_version_luajit = is_old_version_luajit
1821
}
1922

23+
if not is_old_version_luajit then
24+
local sp = require 'bee.subprocess'
25+
local sys = require 'bee.sys'
26+
sp.spawn({
27+
sys.exe_path(),
28+
"lua",
29+
'compile/luajit/relver.lua',
30+
luajitDir.."/..",
31+
luajitDir.."/luajit_relver.txt"
32+
}):wait()
33+
sp.spawn({
34+
sys.exe_path(),
35+
"lua",
36+
luajitDir.."/host/genversion.lua",
37+
luajitDir.."/luajit_rolling.h",
38+
luajitDir.."/luajit_relver.txt",
39+
luajitDir.."/luajit.h"
40+
}):wait()
41+
end
42+
2043
return _M

compile/luajit/make.lua

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local lm = require "luamake"
2+
local fs = require 'bee.filesystem'
23

34
local bindir = "publish/runtime/" .. lm.runtime_platform
45

@@ -9,6 +10,7 @@ local arch = defined.arch
910
local LUAJIT_ENABLE_LUA52COMPAT = defined.LUAJIT_ENABLE_LUA52COMPAT
1011
local LUAJIT_NUMMODE = defined.LUAJIT_NUMMODE
1112
local luajitDir = defined.luajitDir
13+
local is_old_version_luajit = defined.is_old_version_luajit
1214

1315
local LJLIB_C = {
1416
luajitDir .. "/lib_base.c ",
@@ -98,35 +100,39 @@ lm:build "lj_vm.obj" {
98100
outputs = lm.bindir .. "/lj_vm.obj",
99101
}
100102

101-
local lj_str_hash_flags = {
102-
"-fno-stack-protector",
103-
U_FORTIFY_SOURCE,
104-
"-fPIC",
105-
}
103+
local has_str_hash = fs.exists(luajitDir.. '/lj_str_hash.c')
104+
if has_str_hash then
105+
local lj_str_hash_flags = {
106+
"-fno-stack-protector",
107+
U_FORTIFY_SOURCE,
108+
"-fPIC",
109+
}
106110

107-
if arch == "x64" then
108-
table.insert(lj_str_hash_flags, "-msse4.2")
109-
end
111+
if arch == "x64" then
112+
table.insert(lj_str_hash_flags, "-msse4.2")
113+
end
110114

111-
lm:source_set("lj_str_hash.c") {
112-
rootdir = luajitDir,
113-
sources = { "lj_str_hash.c" },
114-
includes = { '.' },
115-
defines = {
116-
LUAJIT_UNWIND_EXTERNAL,
117-
_FILE_OFFSET_BITS,
118-
_LARGEFILE_SOURCE,
119-
LUA_MULTILIB,
120-
LUAJIT_ENABLE_LUA52COMPAT,
121-
LUAJIT_NUMMODE,
122-
},
123-
linux = {
115+
lm:source_set("lj_str_hash.c") {
116+
rootdir = luajitDir,
117+
sources = { "lj_str_hash.c" },
118+
includes = { '.' },
124119
defines = {
125-
"_GNU_SOURCE",
126-
}
127-
},
128-
flags = lj_str_hash_flags
129-
}
120+
LUAJIT_UNWIND_EXTERNAL,
121+
_FILE_OFFSET_BITS,
122+
_LARGEFILE_SOURCE,
123+
LUA_MULTILIB,
124+
LUAJIT_ENABLE_LUA52COMPAT,
125+
LUAJIT_NUMMODE,
126+
},
127+
linux = {
128+
defines = {
129+
"_GNU_SOURCE",
130+
}
131+
},
132+
flags = lj_str_hash_flags
133+
}
134+
end
135+
130136

131137
lm:executable("luajit/lua") {
132138
rootdir = luajitDir,
@@ -139,12 +145,14 @@ lm:executable("luajit/lua") {
139145
"lj_libdef.h",
140146
"lj_recdef.h",
141147
},
142-
deps = "lj_str_hash.c",
148+
deps = {
149+
has_str_hash and "lj_str_hash.c",
150+
},
143151
sources = {
144152
"luajit.c",
145153
"lj_*.c",
146154
"lib_*.c",
147-
"!lj_str_hash.c",
155+
has_str_hash and "!lj_str_hash.c",
148156
lm.bindir .. "/lj_vm.obj",
149157
},
150158
includes = {

0 commit comments

Comments
 (0)