1
0
forked from osmarks/potatOS

fix SPUDNET bug, and quite possibly other bugs

This commit is contained in:
2022-02-20 14:32:14 +00:00
parent a0702bb775
commit 383991c739
9 changed files with 50 additions and 19 deletions

View File

@@ -62,7 +62,7 @@ if #arg == 1 then
--
print("Minification complete")
elseif #arg == 2 then
elseif #arg == 3 then
--keep the user from accidentally overwriting their non-minified file with
if arg[1]:find("_min") then
print("Did you mix up the argument order?\n"..
@@ -112,9 +112,17 @@ elseif #arg == 2 then
return
end
--
outf:write(Format_Mini(ast))
local text, map = Format_Mini(ast)
outf:write(text)
outf:close()
--
local outf = io.open(arg[3], 'w')
if not outf then
print("Failed to open `"..arg[3].."` for writing")
return
end
outf:write(map)
outf:close()
print("Minification complete")
else

View File

@@ -21,6 +21,14 @@ local UpperChars = lookupify{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
local Digits = lookupify{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}
local Symbols = lookupify{'+', '-', '*', '/', '^', '%', ',', '{', '}', '[', ']', '(', ')', ';', '#'}
local function serialize_debug_symbols(map)
local out = {}
for k, v in pairs(map) do
table.insert(out, k .. "\t" .. v)
end
return table.concat(out, "\n")
end
local function Format_Mini(ast)
local formatStatlist, formatExpr;
local count = 0
@@ -334,10 +342,6 @@ local function Format_Mini(ast)
out = joinStatementsSafe(out, "do")
out = joinStatementsSafe(out, formatStatlist(statement.Body))
out = joinStatementsSafe(out, "end")
elseif statement.AstType == 'LabelStatement' then
out = getIndentation() .. "::" .. statement.Label .. "::"
elseif statement.AstType == 'GotoStatement' then
out = getIndentation() .. "goto " .. statement.Label
elseif statement.AstType == 'Comment' then
-- ignore
elseif statement.AstType == 'Eof' then
@@ -349,9 +353,17 @@ local function Format_Mini(ast)
return out
end
local map = {}
local function insert(t)
for k, v in pairs(t) do
map[k] = v
end
end
formatStatlist = function(statList)
local out = ''
statList.Scope:ObfuscateVariables()
insert(statList.Scope.name_map or {})
for _, stat in pairs(statList.Body) do
out = joinStatementsSafe(out, formatStatement(stat), ';')
end
@@ -359,7 +371,8 @@ local function Format_Mini(ast)
end
ast.Scope:ObfuscateVariables()
return formatStatlist(ast)
insert(ast.Scope.name_map)
return formatStatlist(ast), serialize_debug_symbols(map)
end
return Format_Mini

View File

@@ -86,6 +86,8 @@ local Scope = {
RenameLocal = function(self, oldName, newName)
oldName = type(oldName) == 'string' and oldName or oldName.Name
self.name_map = self.name_map or {}
self.name_map[newName] = oldName
local found = false
local var = self:GetLocal(oldName)
if var then