mirror of
https://github.com/Adorable-Catgirl/LuaComp.git
synced 2024-12-23 08:48:05 +11:00
luaposix time, way faster now
This commit is contained in:
parent
e4741cd571
commit
9b4a7932b6
@ -8,6 +8,9 @@ local function dprint(...)
|
||||
end
|
||||
end
|
||||
|
||||
local stat = require("posix.sys.stat")
|
||||
local dirent = require("posix.dirent")
|
||||
|
||||
--#include "src/shell_var.lua"
|
||||
--#include "src/luacomp_vars.lua"
|
||||
--#include "src/libluacomp.lua"
|
||||
@ -51,11 +54,9 @@ local file = args.input
|
||||
_sv("LUACOMP_MINIFIER", args.minifier)
|
||||
local f
|
||||
if (file ~= "-") then
|
||||
local sr, er = stat.stat(file)
|
||||
if not sr then lc_error("luacomp", er) end
|
||||
f = io.open(file, "r")
|
||||
if not f then
|
||||
io.stderr:write("ERROR: File `"..file.."' does not exist!\n")
|
||||
os.exit(1)
|
||||
end
|
||||
else
|
||||
f = io.stdin
|
||||
end
|
||||
@ -64,16 +65,18 @@ local ocode = luacomp.process_file(f, (file == "-") and "stdin" or file, args.ge
|
||||
local minifier = providers[args.minifier]
|
||||
dprint("Minifier: "..args.minifier, minifier)
|
||||
if not minifier then
|
||||
io.stderr:write("ERROR: Postprocessor `"..args.minifier.."' not found!\n")
|
||||
os.exit(1)
|
||||
lc_error("luacomp", "Postprocessor "..args.minifier.." not found!")
|
||||
--io.stderr:write("ERROR: Postprocessor `"..args.minifier.."' not found!\n")
|
||||
--os.exit(1)
|
||||
end
|
||||
dprint("Running...")
|
||||
local rcode, err = minifier(ocode)
|
||||
|
||||
if (not rcode) then
|
||||
io.stderr:write("ERROR: Error for postprocessor `"..args.minifier.."': \n")
|
||||
io.stderr:write(err)
|
||||
os.exit(1)
|
||||
--io.stderr:write("ERROR: Error for postprocessor `"..args.minifier.."': \n")
|
||||
--io.stderr:write(err)
|
||||
--os.exit(1)
|
||||
lc_error(args.minifier, "Postprocessor error:\n"..err)
|
||||
end
|
||||
|
||||
local of
|
||||
|
@ -87,8 +87,7 @@ do
|
||||
function ast.parser_error(str, err)
|
||||
local y, x = str:get_yx()
|
||||
--print(y, x)
|
||||
io.stderr:write(string.format("%s(%d:%d): %s\n", str.file, y or 0, x or 0, err))
|
||||
os.exit(1)
|
||||
lc_error(@[{_GENERATOR.fname}], string.format("%s(%d:%d): %s\n", str.file, y or 0, x or 0, err))
|
||||
end
|
||||
|
||||
function ast.unescape(escaped_string)
|
||||
@ -306,7 +305,7 @@ do
|
||||
local c = str:peek()
|
||||
if c ~= " " and c ~= "\n" and c ~= "" then
|
||||
str:set(apos)
|
||||
ast.parser_error(str, "malformed string, got "..c)
|
||||
ast.parser_error(str, "malformed string")
|
||||
end
|
||||
table.insert(args, sval)
|
||||
elseif str:peek() == "\'" then
|
||||
@ -333,7 +332,7 @@ do
|
||||
local c = str:peek()
|
||||
if c ~= " " and c ~= "\n" and c ~= "" then
|
||||
str:set(apos)
|
||||
ast.parser_error(str, "malformed code block, got "..c)
|
||||
ast.parser_error(str, "malformed code block")
|
||||
end
|
||||
table.insert(args, {type="lua_span", val=sval})
|
||||
elseif str:peek() == "\n" then
|
||||
|
@ -108,7 +108,7 @@ end
|
||||
|
||||
setmetatable(providers, {__index=function(t, i)
|
||||
for i=1, #postproc_paths do
|
||||
if (os.execute("stat "..postproc_paths[i].."/"..i..".lua 1>/dev/null 2>&1")) then
|
||||
if stat.stat(postproc_paths[i].."/"..i..".lua") then
|
||||
providers[i] = loadfile(postproc_paths[i].."/"..i..".lua")()
|
||||
return providers[i]
|
||||
end
|
||||
@ -118,11 +118,10 @@ end})
|
||||
local function preload_providers()
|
||||
--Do this in the best way possible
|
||||
for i=1, #postproc_paths do
|
||||
if (os.execute("stat "..postproc_paths[i].."1>/dev/null 2>&1")) then
|
||||
local fh = io.popen("ls "..postproc_paths[i], "r")
|
||||
for line in fh:lines() do
|
||||
if (line:match("%.lua$")) then
|
||||
providers[line:sub(1, #line-4)] = loadfile(postproc_paths[i].."/"..line)()
|
||||
if stat.stat(postproc_paths[i]) then
|
||||
for ent in dirent.files(postproc_paths[i]) do
|
||||
if ent:match("%.lua$") then
|
||||
providers[ent:sub(1, #ent-4)] = loadfile(postproc_paths[i].."/"..ent)()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -24,9 +24,9 @@
|
||||
|
||||
setmetatable(directives, {__index=function(t, i)
|
||||
for i=1, #directive_paths do
|
||||
if (os.execute("stat "..directive_paths[i].."/"..i..".lua 1>/dev/null 2>&1")) then
|
||||
directives[i] = loadfile(directive_paths[i].."/"..i..".lua")()
|
||||
return directives[i]
|
||||
if stat.stat(directive_paths[i].."/"..i..".lua") then
|
||||
providers[i] = loadfile(directive_paths[i].."/"..i..".lua")()
|
||||
return providers[i]
|
||||
end
|
||||
end
|
||||
end})
|
||||
@ -34,11 +34,10 @@ end})
|
||||
local function preload_directives()
|
||||
--Do this in the best way possible
|
||||
for i=1, #directive_paths do
|
||||
if (os.execute("stat "..directive_paths[i].." 1>/dev/null 2>&1")) then
|
||||
local fh = io.popen("ls "..directive_paths[i], "r")
|
||||
for line in fh:lines() do
|
||||
if (line:match("%.lua$")) then
|
||||
directives[line:sub(1, #line-4)] = loadfile(directive_paths[i].."/"..line)()
|
||||
if stat.stat(directive_paths[i]) then
|
||||
for ent in dirent.files(directive_paths[i]) do
|
||||
if ent:match("%.lua$") then
|
||||
providers[ent:sub(1, #ent-4)] = loadfile(directive_paths[i].."/"..ent)()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,7 +1,6 @@
|
||||
function directives.include(env, file)
|
||||
if (not os.execute("stat "..file..">/dev/null")) then
|
||||
return false, "File `"..file.."' does not exist!"
|
||||
end
|
||||
local sr, err = stat.stat(file)
|
||||
if not sr then return false, err end
|
||||
--[[local f = io.open(file, "r")
|
||||
local fast = mkast(f, file)
|
||||
fast.file = file
|
||||
|
@ -38,7 +38,7 @@ do
|
||||
end
|
||||
|
||||
function generator.run_gcode(fname, gcode)
|
||||
local env = {code = ""}
|
||||
local env = {code = "", fname=fname}
|
||||
local fenv = {}
|
||||
for k, v in pairs(_G) do
|
||||
fenv[k] = v
|
||||
@ -46,9 +46,9 @@ do
|
||||
fenv._G = fenv
|
||||
fenv._GENERATOR = env
|
||||
function fenv.call_directive(dname, ...)
|
||||
if not directives[dname] then error("invalid directive "..dname) end
|
||||
if not directives[dname] then lc_error(@[{_GENERATOR.fname}], "invalid directive "..dname) end
|
||||
local r, er = directives[dname](env, ...)
|
||||
assert(r, er)
|
||||
if not r then lc_error(@[{_GENERATOR.fname}], er) end
|
||||
end
|
||||
|
||||
function fenv.write_out(code)
|
||||
|
@ -3,6 +3,37 @@ local luacomp = {}
|
||||
|
||||
local directives = {}
|
||||
|
||||
local unistd = require("posix.unistd")
|
||||
|
||||
local function lc_error(name, msg)
|
||||
if unistd.isatty(2) then
|
||||
io.stderr:write(string.format("\27[90;1m(%s) \27[31;22m%s\27[0m\n", name, msg))
|
||||
else
|
||||
io.stderr:write(string.format("(%s) %s\n", name, msg))
|
||||
end
|
||||
os.exit(1)
|
||||
end
|
||||
|
||||
local function lc_warning(name, msg)
|
||||
if unistd.isatty(2) then
|
||||
io.stderr:write(string.format("\27[90;1m(%s) \27[33;22m%s\27[0m\n", name, msg))
|
||||
else
|
||||
io.stderr:write(string.format("(%s) %s\n", name, msg))
|
||||
end
|
||||
end
|
||||
|
||||
function luacomp.error(msg)
|
||||
local inf = debug.getinfo(1)
|
||||
local name = (inf and inf.short_src:match("[^/]+$"):gsub("^[=@]", "")) or "luacomp"
|
||||
lc_error(name, msg)
|
||||
end
|
||||
|
||||
function luacomp.warning(msg)
|
||||
local inf = debug.getinfo(1)
|
||||
local name = (inf and inf.short_src:match("[^/]+$"):gsub("^[=@]", "")) or "luacomp"
|
||||
lc_warning(name, msg)
|
||||
end
|
||||
|
||||
--#include "src/ast2.lua"
|
||||
--#include "src/generator2.lua"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user