summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2012-08-11 13:00:13 +0300
committerMarius <mariausol@gmail.com>2012-08-11 13:00:13 +0300
commit9b98b3cf26c450f19e763e9908468afc9ced029e (patch)
treeb675737b5448c502db068db0699ff83c80a5c6ee /scripts
parentc8c0121153c97ab80ac87ba275e530c632306eef (diff)
downloadcontext-9b98b3cf26c450f19e763e9908468afc9ced029e.tar.gz
beta 2012.08.11 11:43
Diffstat (limited to 'scripts')
-rw-r--r--scripts/context/lua/mtxrun.lua53
-rw-r--r--scripts/context/stubs/mswin/mtxrun.lua53
-rw-r--r--scripts/context/stubs/unix/mtxrun53
3 files changed, 117 insertions, 42 deletions
diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua
index 3045b6866..f65c8c0ac 100644
--- a/scripts/context/lua/mtxrun.lua
+++ b/scripts/context/lua/mtxrun.lua
@@ -2962,6 +2962,11 @@ end
file.isreadable = file.is_readable -- depricated
file.iswritable = file.is_writable -- depricated
+function file.size(name)
+ local a = attributes(name)
+ return a and a.size or 0
+end
+
-- todo: lpeg \\ / .. does not save much
local checkedsplit = string.checkedsplit
@@ -4877,6 +4882,7 @@ utilities.report = logs and logs.reporter("system") or print
local tracestripping = false
local forcestupidcompile = true
luautilities.stripcode = true
+luautilities.alwaysstripcode = false -- saves 1 meg on 7 meg compressed format file (2012.08.12)
luautilities.nofstrippedchunks = 0
luautilities.nofstrippedbytes = 0
@@ -4962,7 +4968,7 @@ end
-- ... end of borrowed code.
local function strippedbytecode(code,forcestrip,name)
- if forcestrip and luautilities.stripcode then
+ if (forcestrip and luautilities.stripcode) or luautilities.alwaysstripcode then
return strip_code_pc(code,name)
else
return code, 0
@@ -4972,8 +4978,16 @@ end
luautilities.stripbytecode = strip_code_pc
luautilities.strippedbytecode = strippedbytecode
+local function fatalerror(name)
+ utilities.report(format("fatal error in %q",name or "unknown"))
+end
+
+-- quite subtle ... doing this wrong incidentally can give more bytes
+
+
function luautilities.loadedluacode(fullname,forcestrip,name)
-- quite subtle ... doing this wrong incidentally can give more bytes
+ name = name or fullname
local code = loadfile(fullname)
if code then
code()
@@ -4983,34 +4997,45 @@ function luautilities.loadedluacode(fullname,forcestrip,name)
forcestrip = forcestrip(fullname)
end
if forcestrip then
- local code, n = strip_code_pc(dump(code,name or fullname))
+ local code, n = strip_code_pc(dump(code,name))
return loadstring(code), n
+ elseif luautilities.alwaysstripcode then
+ return loadstring(strip_code_pc(dump(code),name))
else
return code, 0
end
+ elseif luautilities.alwaysstripcode then
+ return loadstring(strip_code_pc(dump(code),name))
else
return code, 0
end
end
-function luautilities.strippedloadstring(str,forcestrip,name) -- better inline
- if forcestrip and luautilities.stripcode then
- local code, n = strip_code_pc(dump(loadstring(str)),name)
- return loadstring(code), n
- else
- return loadstring(str)
+function luautilities.strippedloadstring(code,forcestrip,name) -- not executed
+ local n = 0
+ if (forcestrip and luautilities.stripcode) or luautilities.alwaysstripcode then
+ code = loadstring(code)
+ if not code then
+ fatalerror(name)
+ end
+ code, n = strip_code_pc(dump(code),name)
end
+ return loadstring(code), n
end
local function stupidcompile(luafile,lucfile,strip)
- local data = io.loaddata(luafile)
- if data and data ~= "" then
- data = dump(loadstring(data))
+ local code = io.loaddata(luafile)
+ if code and code ~= "" then
+ code = loadstring(code)
+ if not code then
+ fatalerror()
+ end
+ code = dump(code)
if strip then
- data = strippedbytecode(data,true,luafile) -- last one is reported
+ code = strippedbytecode(code,true,luafile) -- last one is reported
end
- if data and data ~= "" then
- io.savedata(lucfile,data)
+ if code and code ~= "" then
+ io.savedata(lucfile,code)
end
end
end
diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua
index 3045b6866..f65c8c0ac 100644
--- a/scripts/context/stubs/mswin/mtxrun.lua
+++ b/scripts/context/stubs/mswin/mtxrun.lua
@@ -2962,6 +2962,11 @@ end
file.isreadable = file.is_readable -- depricated
file.iswritable = file.is_writable -- depricated
+function file.size(name)
+ local a = attributes(name)
+ return a and a.size or 0
+end
+
-- todo: lpeg \\ / .. does not save much
local checkedsplit = string.checkedsplit
@@ -4877,6 +4882,7 @@ utilities.report = logs and logs.reporter("system") or print
local tracestripping = false
local forcestupidcompile = true
luautilities.stripcode = true
+luautilities.alwaysstripcode = false -- saves 1 meg on 7 meg compressed format file (2012.08.12)
luautilities.nofstrippedchunks = 0
luautilities.nofstrippedbytes = 0
@@ -4962,7 +4968,7 @@ end
-- ... end of borrowed code.
local function strippedbytecode(code,forcestrip,name)
- if forcestrip and luautilities.stripcode then
+ if (forcestrip and luautilities.stripcode) or luautilities.alwaysstripcode then
return strip_code_pc(code,name)
else
return code, 0
@@ -4972,8 +4978,16 @@ end
luautilities.stripbytecode = strip_code_pc
luautilities.strippedbytecode = strippedbytecode
+local function fatalerror(name)
+ utilities.report(format("fatal error in %q",name or "unknown"))
+end
+
+-- quite subtle ... doing this wrong incidentally can give more bytes
+
+
function luautilities.loadedluacode(fullname,forcestrip,name)
-- quite subtle ... doing this wrong incidentally can give more bytes
+ name = name or fullname
local code = loadfile(fullname)
if code then
code()
@@ -4983,34 +4997,45 @@ function luautilities.loadedluacode(fullname,forcestrip,name)
forcestrip = forcestrip(fullname)
end
if forcestrip then
- local code, n = strip_code_pc(dump(code,name or fullname))
+ local code, n = strip_code_pc(dump(code,name))
return loadstring(code), n
+ elseif luautilities.alwaysstripcode then
+ return loadstring(strip_code_pc(dump(code),name))
else
return code, 0
end
+ elseif luautilities.alwaysstripcode then
+ return loadstring(strip_code_pc(dump(code),name))
else
return code, 0
end
end
-function luautilities.strippedloadstring(str,forcestrip,name) -- better inline
- if forcestrip and luautilities.stripcode then
- local code, n = strip_code_pc(dump(loadstring(str)),name)
- return loadstring(code), n
- else
- return loadstring(str)
+function luautilities.strippedloadstring(code,forcestrip,name) -- not executed
+ local n = 0
+ if (forcestrip and luautilities.stripcode) or luautilities.alwaysstripcode then
+ code = loadstring(code)
+ if not code then
+ fatalerror(name)
+ end
+ code, n = strip_code_pc(dump(code),name)
end
+ return loadstring(code), n
end
local function stupidcompile(luafile,lucfile,strip)
- local data = io.loaddata(luafile)
- if data and data ~= "" then
- data = dump(loadstring(data))
+ local code = io.loaddata(luafile)
+ if code and code ~= "" then
+ code = loadstring(code)
+ if not code then
+ fatalerror()
+ end
+ code = dump(code)
if strip then
- data = strippedbytecode(data,true,luafile) -- last one is reported
+ code = strippedbytecode(code,true,luafile) -- last one is reported
end
- if data and data ~= "" then
- io.savedata(lucfile,data)
+ if code and code ~= "" then
+ io.savedata(lucfile,code)
end
end
end
diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun
index 3045b6866..f65c8c0ac 100644
--- a/scripts/context/stubs/unix/mtxrun
+++ b/scripts/context/stubs/unix/mtxrun
@@ -2962,6 +2962,11 @@ end
file.isreadable = file.is_readable -- depricated
file.iswritable = file.is_writable -- depricated
+function file.size(name)
+ local a = attributes(name)
+ return a and a.size or 0
+end
+
-- todo: lpeg \\ / .. does not save much
local checkedsplit = string.checkedsplit
@@ -4877,6 +4882,7 @@ utilities.report = logs and logs.reporter("system") or print
local tracestripping = false
local forcestupidcompile = true
luautilities.stripcode = true
+luautilities.alwaysstripcode = false -- saves 1 meg on 7 meg compressed format file (2012.08.12)
luautilities.nofstrippedchunks = 0
luautilities.nofstrippedbytes = 0
@@ -4962,7 +4968,7 @@ end
-- ... end of borrowed code.
local function strippedbytecode(code,forcestrip,name)
- if forcestrip and luautilities.stripcode then
+ if (forcestrip and luautilities.stripcode) or luautilities.alwaysstripcode then
return strip_code_pc(code,name)
else
return code, 0
@@ -4972,8 +4978,16 @@ end
luautilities.stripbytecode = strip_code_pc
luautilities.strippedbytecode = strippedbytecode
+local function fatalerror(name)
+ utilities.report(format("fatal error in %q",name or "unknown"))
+end
+
+-- quite subtle ... doing this wrong incidentally can give more bytes
+
+
function luautilities.loadedluacode(fullname,forcestrip,name)
-- quite subtle ... doing this wrong incidentally can give more bytes
+ name = name or fullname
local code = loadfile(fullname)
if code then
code()
@@ -4983,34 +4997,45 @@ function luautilities.loadedluacode(fullname,forcestrip,name)
forcestrip = forcestrip(fullname)
end
if forcestrip then
- local code, n = strip_code_pc(dump(code,name or fullname))
+ local code, n = strip_code_pc(dump(code,name))
return loadstring(code), n
+ elseif luautilities.alwaysstripcode then
+ return loadstring(strip_code_pc(dump(code),name))
else
return code, 0
end
+ elseif luautilities.alwaysstripcode then
+ return loadstring(strip_code_pc(dump(code),name))
else
return code, 0
end
end
-function luautilities.strippedloadstring(str,forcestrip,name) -- better inline
- if forcestrip and luautilities.stripcode then
- local code, n = strip_code_pc(dump(loadstring(str)),name)
- return loadstring(code), n
- else
- return loadstring(str)
+function luautilities.strippedloadstring(code,forcestrip,name) -- not executed
+ local n = 0
+ if (forcestrip and luautilities.stripcode) or luautilities.alwaysstripcode then
+ code = loadstring(code)
+ if not code then
+ fatalerror(name)
+ end
+ code, n = strip_code_pc(dump(code),name)
end
+ return loadstring(code), n
end
local function stupidcompile(luafile,lucfile,strip)
- local data = io.loaddata(luafile)
- if data and data ~= "" then
- data = dump(loadstring(data))
+ local code = io.loaddata(luafile)
+ if code and code ~= "" then
+ code = loadstring(code)
+ if not code then
+ fatalerror()
+ end
+ code = dump(code)
if strip then
- data = strippedbytecode(data,true,luafile) -- last one is reported
+ code = strippedbytecode(code,true,luafile) -- last one is reported
end
- if data and data ~= "" then
- io.savedata(lucfile,data)
+ if code and code ~= "" then
+ io.savedata(lucfile,code)
end
end
end