aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile65
-rw-r--r--nomsu.lua2
-rwxr-xr-xnomsu.moon3
-rw-r--r--nomsu_compiler.lua2
-rw-r--r--nomsu_compiler.moon2
-rw-r--r--parser.lua5
-rw-r--r--parser.moon5
7 files changed, 78 insertions, 6 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..c08b495
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,65 @@
+# Nomsu makefile
+# To build, run `make`
+# To install,
+
+# ========= User-controlled variables ========
+LUA= lua
+LUA_BIN= /usr/local/bin/$(LUA)
+
+PREFIX=/usr/local
+BIN_DIR= $(PREFIX)/bin
+NOMSU_DIR= $(PREFIX)/lib/nomsu
+
+# ========= You shouldn't need to mess with any of these variables below ================
+
+MOON_FILES= code_obj.moon error_handling.moon nomsu.moon nomsu_compiler.moon nomsu_tree.moon parser.moon
+LUA_FILES= code_obj.lua consolecolors.lua error_handling.lua nomsu.lua nomsu_compiler.lua \
+ nomsu_tree.lua parser.lua utils.lua uuid.lua
+CORE_NOM_FILES= $(wildcard core/*.nom)
+CORE_LUA_FILES= $(patsubst %.nom,%.lua,$(CORE_NOM_FILES))
+LIB_NOM_FILES= $(wildcard lib/*.nom)
+LIB_LUA_FILES= $(patsubst %.nom,%.lua,$(LIB_NOM_FILES))
+PEG_FILE= nomsu.peg
+
+NOMSU_HEADER=\#!$(LUA_BIN)\npackage.path = [[$(realpath $(NOMSU_DIR))/?.lua;]]..package.path\npackage.nomsupath = [[$(realpath $(NOMSU_DIR))]]
+
+all: build optimize
+
+.PHONY: test
+test: build optimize
+ ./nomsu tests
+
+%.lua: %.moon
+ @moonc $<
+
+%.lua: %.nom
+ @./nomsu -c $<
+
+.PHONY: check_header
+check_header:
+ @if [ "`head -n 3 nomsu 2>/dev/null`" != "`echo '$(NOMSU_HEADER)'`" ]; then rm -f nomsu core/*.lua lib/*.lua; fi
+
+nomsu: nomsu.lua
+ @echo '$(NOMSU_HEADER)' | cat - nomsu.lua > nomsu
+ @chmod +x nomsu
+ @echo "Built nomsu binary"
+
+build: $(LUA_FILES) check_header nomsu
+
+.PHONY: optimize
+optimize: build $(CORE_LUA_FILES) $(LIB_LUA_FILES)
+
+.PHONY: clean
+clean:
+ rm -rf nomsu core/*.lua lib/*.lua $(BIN_DIR)/nomsu $(NOMSU_DIR)
+
+.PHONY: install
+install: all
+ mkdir -p $(BIN_DIR) && cp nomsu $(BIN_DIR)
+ mkdir -p $(NOMSU_DIR) && cp -r $(LUA_FILES) $(PEG_FILE) core lib $(NOMSU_DIR)
+
+.PHONY: uninstall
+uninstall: all
+ rm -rf $(NOMSU_DIR) $(BIN_DIR)/nomsu
+
+# eof
diff --git a/nomsu.lua b/nomsu.lua
index b561eb9..7239d44 100644
--- a/nomsu.lua
+++ b/nomsu.lua
@@ -169,7 +169,6 @@ run = function()
else
print_file = io.stdout
end
- nomsu.skip_precompiled = not args.optimized
if print_file == nil then
nomsu.print = function() end
elseif print_file ~= io.stdout then
@@ -195,6 +194,7 @@ run = function()
to_run[f] = true
end
end
+ nomsu.skip_precompiled = to_run
if args.compile or args.verbose then
nomsu.on_compile = function(code, from_file)
if not (to_run[from_file]) then
diff --git a/nomsu.moon b/nomsu.moon
index 86097a7..780e8bc 100755
--- a/nomsu.moon
+++ b/nomsu.moon
@@ -135,7 +135,6 @@ run = ->
elseif args.print_file then io.open(args.print_file, 'w')
else io.stdout
- nomsu.skip_precompiled = not args.optimized
if print_file == nil
nomsu.print = ->
elseif print_file != io.stdout
@@ -155,6 +154,8 @@ run = ->
input_files[#input_files+1] = f
to_run[f] = true
+ nomsu.skip_precompiled = to_run
+
if args.compile or args.verbose
nomsu.on_compile = (code, from_file)->
return unless to_run[from_file]
diff --git a/nomsu_compiler.lua b/nomsu_compiler.lua
index d093ff5..0e3a27c 100644
--- a/nomsu_compiler.lua
+++ b/nomsu_compiler.lua
@@ -465,7 +465,7 @@ do
ret = self:run_lua(file, Source(filename, 1, #file))
elseif match(filename, "%.nom$") or match(filename, "^/dev/fd/[012]$") then
local ran_lua
- if not self.skip_precompiled then
+ if not self.skip_precompiled or not self.skip_precompiled[filename] then
local lua_filename = gsub(filename, "%.nom$", ".lua")
do
local file = FILE_CACHE[lua_filename]
diff --git a/nomsu_compiler.moon b/nomsu_compiler.moon
index 8226db4..d214380 100644
--- a/nomsu_compiler.moon
+++ b/nomsu_compiler.moon
@@ -319,7 +319,7 @@ with NomsuCompiler
file = assert(FILE_CACHE[filename], "Could not find file: #{filename}")
ret = @run_lua file, Source(filename, 1, #file)
elseif match(filename, "%.nom$") or match(filename, "^/dev/fd/[012]$")
- ran_lua = if not @skip_precompiled -- Look for precompiled version
+ ran_lua = if not @skip_precompiled or not @skip_precompiled[filename] -- Look for precompiled version
lua_filename = gsub(filename, "%.nom$", ".lua")
if file = FILE_CACHE[lua_filename]
ret = @run_lua file, Source(lua_filename, 1, #file)
diff --git a/parser.lua b/parser.lua
index e685d56..7b734c3 100644
--- a/parser.lua
+++ b/parser.lua
@@ -127,7 +127,10 @@ do
ident <- [a-zA-Z_][a-zA-Z0-9_]*
comment <- "--" [^%nl]*
]])
- local nomsu_peg = peg_tidier:match(io.open((package.nomsupath or '.') .. "/nomsu.peg"):read('*a'))
+ local peg_file = io.open("nomsu.peg") or (package.nomsupath and io.open(package.nomsupath .. "/nomsu.peg"))
+ assert(peg_file, "could not find nomsu.peg file")
+ local nomsu_peg = peg_tidier:match(peg_file:read('*a'))
+ peg_file:close()
NOMSU_PATTERN = re.compile(nomsu_peg, NOMSU_DEFS)
end
local parse
diff --git a/parser.moon b/parser.moon
index 51538cc..1d62364 100644
--- a/parser.moon
+++ b/parser.moon
@@ -98,7 +98,10 @@ NOMSU_PATTERN = do
ident <- [a-zA-Z_][a-zA-Z0-9_]*
comment <- "--" [^%nl]*
]]
- nomsu_peg = peg_tidier\match(io.open((package.nomsupath or '.').."/nomsu.peg")\read('*a'))
+ peg_file = io.open("nomsu.peg") or (package.nomsupath and io.open(package.nomsupath.."/nomsu.peg"))
+ assert(peg_file, "could not find nomsu.peg file")
+ nomsu_peg = peg_tidier\match(peg_file\read('*a'))
+ peg_file\close!
re.compile(nomsu_peg, NOMSU_DEFS)
parse = (nomsu_code, source=nil)->