aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-01-10 13:52:41 -0800
committerBruce Hill <bitbucket@bruce-hill.com>2018-01-10 13:52:41 -0800
commitea05cc155ee2327be824e0619486b3c4c66d5550 (patch)
tree45b428342b38575bc4a6a14494d4c98e191e94c2
parent787c7c5a6ce4ac6ba19890faf1afa067ea167104 (diff)
Switched back to using precompiled lua files instead of lua> "..",
because it's noticeably faster.
-rw-r--r--.gitignore3
-rwxr-xr-xcompile_lib.sh4
-rw-r--r--nomsu.lua11
-rwxr-xr-xnomsu.moon10
4 files changed, 16 insertions, 12 deletions
diff --git a/.gitignore b/.gitignore
index d1b393c..1753e55 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1 @@
-*.nomc
-*/*.nomc
+lib/*.lua
diff --git a/compile_lib.sh b/compile_lib.sh
index 5d6c19d..6e4e78a 100755
--- a/compile_lib.sh
+++ b/compile_lib.sh
@@ -11,13 +11,13 @@ while getopts ":f" opt; do
esac
done
if [ "$FLUSH" = true ] ; then
- for file in $(find lib/ -name "*.nomc") ; do
+ for file in $(find lib/ -name "*.lua") ; do
rm $file
done
fi
for file in $(cat lib/core.nom | lua -e "for filename in io.read('*a'):gmatch('require \"([^\"]*)\"') do print(filename) end") ; do
- compilefile="${file/\.nom/.nomc}"
+ compilefile="${file/\.nom/.lua}"
if [ ! -e "$compilefile" ] || [ "$file" -nt "$compilefile" ] ; then
echo "Compiling $file into $compilefile"
./nomsu.moon -c $file
diff --git a/nomsu.lua b/nomsu.lua
index 2900590..cf057be 100644
--- a/nomsu.lua
+++ b/nomsu.lua
@@ -1324,7 +1324,7 @@ end]]):format(lua_code))
lua_code = "-- Immediately:\n" .. lua_code
self:run_lua(lua_code, vars)
return {
- statements = ""
+ statements = lua_code
}
end)
self:defmacro("lua> %code", function(self, vars)
@@ -1351,7 +1351,10 @@ end]]):format(lua_code))
end
if vars.filename:match(".*%.nom") then
if not self.skip_precompiled then
- local file = io.open(vars.filename:gsub("%.nom", ".nomc"), "r")
+ local file = io.open(vars.filename:gsub("%.nom", ".lua"), "r")
+ if file then
+ return self:run_lua(file:read("*a"), vars)
+ end
end
local file = file or io.open(vars.filename)
if not file then
@@ -1483,7 +1486,7 @@ if arg then
c.skip_precompiled = not args.flags["-O"]
if args.input then
if args.flags["-c"] and not args.output then
- args.output = args.input:gsub("%.nom", ".nomc")
+ args.output = args.input:gsub("%.nom", ".lua")
end
local compiled_output = nil
if args.flags["-p"] then
@@ -1505,7 +1508,7 @@ if arg then
local vars = { }
local retval, code = c:run(input, args.input, vars)
if args.output then
- compiled_output:write("lua> \"..\"\n " .. c:indent(code:gsub("\\", "\\\\"), 1))
+ compiled_output:write(code)
end
end
if args.flags["-p"] then
diff --git a/nomsu.moon b/nomsu.moon
index 40350d9..49922fa 100755
--- a/nomsu.moon
+++ b/nomsu.moon
@@ -839,7 +839,7 @@ end]]\format(lua_code))
lua_code = lua.statements or (lua.expr..";")
lua_code = "-- Immediately:\n"..lua_code
@run_lua(lua_code, vars)
- return statements:""
+ return statements:lua_code
@defmacro "lua> %code", (vars)=>
lua = nomsu_string_as_lua(@, vars.code)
@@ -857,7 +857,9 @@ end]]\format(lua_code))
return dofile(vars.filename)(@, vars)
if vars.filename\match(".*%.nom")
if not @skip_precompiled -- Look for precompiled version
- file = io.open(vars.filename\gsub("%.nom", ".nomc"), "r")
+ file = io.open(vars.filename\gsub("%.nom", ".lua"), "r")
+ if file
+ return @run_lua(file\read("*a"), vars)
file = file or io.open(vars.filename)
if not file
@error "File does not exist: #{vars.filename}"
@@ -901,7 +903,7 @@ if arg
if args.input
-- Read a file or stdin and output either the printouts or the compiled lua
if args.flags["-c"] and not args.output
- args.output = args.input\gsub("%.nom", ".nomc")
+ args.output = args.input\gsub("%.nom", ".lua")
compiled_output = nil
if args.flags["-p"]
_write = c.write
@@ -919,7 +921,7 @@ if arg
vars = {}
retval, code = c\run(input, args.input, vars)
if args.output
- compiled_output\write("lua> \"..\"\n "..c\indent(code\gsub("\\","\\\\"), 1))
+ compiled_output\write(code)
if args.flags["-p"]
c.write = _write