aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--README.md9
-rw-r--r--containers.lua6
-rw-r--r--containers.moon2
-rw-r--r--lib/compatibility/7.nom12
-rw-r--r--lib/compatibility/compatibility.nom17
-rw-r--r--lib/compatibility/init.nom3
-rw-r--r--lib/core/metaprogramming.nom12
-rwxr-xr-xlib/tools/repl.nom4
-rwxr-xr-xlib/tools/upgrade.nom4
-rw-r--r--nomsu.lua39
-rwxr-xr-xnomsu.moon29
-rw-r--r--nomsu_environment.lua15
-rw-r--r--nomsu_environment.moon12
14 files changed, 90 insertions, 76 deletions
diff --git a/Makefile b/Makefile
index 0da53ea..9dcdc68 100644
--- a/Makefile
+++ b/Makefile
@@ -84,7 +84,7 @@ install: lua version optimize optimize_extra
fi; \
version="`cat version`"; \
mkdir -pv $$prefix/bin $$prefix/lib/nomsu/$$version $$prefix/share/nomsu/$$version $$prefix/share/man/man1 $$packagepath/nomsu \
- && echo "#!$(LUA_BIN)\\nlocal NOMSU_VERSION, NOMSU_PREFIX, NOMSU_PACKAGEPATH = [[$$version]], [[$$prefix]], [[$$packagepath/nomsu]]" \
+ && echo "#!$(LUA_BIN)\\nlocal NOMSU_PREFIX, NOMSU_PACKAGEPATH = [[$$prefix]], [[$$packagepath/nomsu]]" \
| cat - nomsu.lua > $$prefix/bin/nomsu$$version \
&& chmod +x $$prefix/bin/nomsu$$version \
&& cp -v nomsu $$prefix/bin \
diff --git a/README.md b/README.md
index aba91cf..2b7b01a 100644
--- a/README.md
+++ b/README.md
@@ -72,16 +72,9 @@ All `.moon` files have been precompiled into corresponding `.lua` files, so you
## Versioning
-Nomsu uses the following versioning scheme: `[syntax version].[core library API version].[compiler internal API version].[minor version]`. Which means:
-
-* Any code that parses on `Nomsu X.a.b.c` will also parse on Nomsu `X.p.w.r`
-* Any code that compiles on Nomsu `X.Y.a.b` will also compile on Nomsu `X.Y.p.q` and run without any differences, as long as it only depends on the behavior of the core library functions (i.e. stuff defined in [lib/core/\*.nom](lib/core)), and doesn't mess with the compiler internals at all.
-* Any code that compiles on Nomsu `X.Y.Z.a` will also compile on Nomsu `X.Y.Z.p` and run without any differences, unless if it messes with the compiler internals.
-* Any code that compiles on Nomsu `X.Y.Z.W` will also compile on any other Nomsu `X.Y.Z.W` and run without any differences.
-
When Nomsu is istalled via `make install`, all of Nomsu's lua files and [lib/](lib) files are stored in `$PREFIX/share/nomsu/$NOMSU_VERSION` and the Nomsu executable is installed to `$PREFIX/bin/nomsu$NOMSU_VERSION`, along with the file `nomsu` (the version-selection script), which goes to `$PREFIX/bin/nomsu`. When `make uninstall` is run, all those files are deleted (except for `nomsu`, if there are other versions installed).
-To run different versions, use the `-V` flag, which will select the latest version matching the specified pattern. For example, if you have v1.0.0.0, v1.0.2.1, and 1.1.0.0 installed, then `nomsu` will run v1.1.0.0, `nomsu -V 1.0` will run v1.0.2.1, and `nomsu -V 1.0.0.0` will run v1.0.0.0.
+To run different versions, use the `-V` flag, which will select the latest version matching the specified pattern. For example, if you have v1.0.0, v1.0.2, and 1.1.0 installed, then `nomsu` will run v1.1.0, `nomsu -V1.0` will run v1.0.2, and `nomsu -V 1.0.0` will run v1.0.0.
## Extra
diff --git a/containers.lua b/containers.lua
index 93a8705..365fa4d 100644
--- a/containers.lua
+++ b/containers.lua
@@ -226,6 +226,12 @@ local _list_mt = {
return _accum_0
end)())
end,
+ from = function(self, start)
+ return self:from_1_to(start, -1)
+ end,
+ up_to = function(self, stop)
+ return self:from_1_to(1, stop)
+ end,
copy = function(self)
return List((function()
local _accum_0 = { }
diff --git a/containers.moon b/containers.moon
index 06fbccc..8bca1c4 100644
--- a/containers.moon
+++ b/containers.moon
@@ -88,6 +88,8 @@ _list_mt =
start = (n+1-start) if start < 0
stop = (n+1-stop) if stop < 0
return List[@[i] for i=start,stop]
+ from: (start)=> @from_1_to(start, -1)
+ up_to: (stop)=> @from_1_to(1, stop)
copy: => List[@[i] for i=1,#@]
reverse: =>
n = #@
diff --git a/lib/compatibility/7.nom b/lib/compatibility/7.nom
index fb313c3..fe31ec6 100644
--- a/lib/compatibility/7.nom
+++ b/lib/compatibility/7.nom
@@ -1,5 +1,5 @@
#!/usr/bin/env nomsu -V7
-#
+###
This file defines upgrades from Nomsu <7 to 7
use "compatibility/compatibility"
@@ -22,3 +22,13 @@ upgrade $tree to "7" as:
return
"Action" tree from $tree.source with ("Text" tree with $e.type) "tree" "with"
unpack $e
+
+upgrade action "Nomsu version" to "7" via ->(`$(NOMSU VERSION))
+upgrade action [
+ "Nomsu syntax version", "Nomsu compiler version", "core version", "lib version"
+] to "7" via:
+ for $:
+ at $.source fail ("
+ Deprecation error: Actions for accessing specific parts of the version number have been deprecated.
+ Hint: Use $(NOMSU VERSION).1, etc. instead.
+ ")
diff --git a/lib/compatibility/compatibility.nom b/lib/compatibility/compatibility.nom
index a7ca0c1..c1c83d3 100644
--- a/lib/compatibility/compatibility.nom
+++ b/lib/compatibility/compatibility.nom
@@ -70,8 +70,15 @@ external:
$tree upgraded to $end_version from $start_version
] all mean:
unless ($tree is syntax tree): return $tree
- ($ver as version list) means (($ as number) for $ in $ver matching "[0-9]+")
+ ($ver as version list) means:
+ if ($ver is "Text"):
+ return (($ as number) for $ in $ver matching "[0-9]+")
+ return $ver
(Ver $) means:
+ if ($ is "a List"):
+ if ($.1 is "Text"):
+ return {.lib = $.1, .version = ($, from 2)}
+ return {.version = $}
[$lib, $ver] = ($, match "(.*)/([0-9.]+)")
if $lib:
return {.lib = $lib, .version = ($ver as version list)}
@@ -117,15 +124,15 @@ external:
$tree = (SyntaxTree {: for $k = $v in $tree: add $k = $v})
$tree.version = $end_version
if $tree.shebang:
- $tree.shebang = "#!/usr/bin/env nomsu -V\$end_version\n"
+ $tree.shebang = "#!/usr/bin/env nomsu -V\($end_version, joined with ".")\n"
return $tree
($tree upgraded from $start_version) means
- $tree upgraded from $start_version to (Nomsu version)
+ $tree upgraded from $start_version to $(NOMSU VERSION)
($tree upgraded to $end_version) means
- $tree upgraded from ($tree.version or (Nomsu version)) to $end_version
+ $tree upgraded from ($tree.version or $(NOMSU VERSION)) to $end_version
($tree upgraded) means
- $tree upgraded from ($tree.version or (Nomsu version)) to (Nomsu version)
+ $tree upgraded from ($tree.version or $(NOMSU VERSION)) to $(NOMSU VERSION)
diff --git a/lib/compatibility/init.nom b/lib/compatibility/init.nom
index 42834bb..90d2ca5 100644
--- a/lib/compatibility/init.nom
+++ b/lib/compatibility/init.nom
@@ -17,3 +17,6 @@ export "compatibility/4.11"
export "compatibility/4.12"
export "compatibility/5.13"
export "compatibility/6.14"
+export "compatibility/6.15"
+export "compatibility/6.15.9"
+export "compatibility/7"
diff --git a/lib/core/metaprogramming.nom b/lib/core/metaprogramming.nom
index c310fdd..55cab2a 100644
--- a/lib/core/metaprogramming.nom
+++ b/lib/core/metaprogramming.nom
@@ -3,8 +3,6 @@
This File contains actions for making actions and compile-time actions and some helper
functions to make that easier.
-lua> "NOMSU_CORE_VERSION = 15"
-lua> "NOMSU_LIB_VERSION = 9"
lua> ("
do
local mangle_index = 0
@@ -462,10 +460,6 @@ test:
(yes) compiles to "(true)"
(no) compiles to "(false)"
[nothing, nil, null] all compile to "(nil)"
-(Nomsu syntax version) compiles to "NOMSU_SYNTAX_VERSION"
-(Nomsu compiler version) compiles to "NOMSU_COMPILER_VERSION"
-(core version) compiles to "NOMSU_CORE_VERSION"
-(lib version) compiles to "NOMSU_LIB_VERSION"
(command line args) compiles to "COMMAND_LINE_ARGS"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -496,12 +490,6 @@ test:
return lua
")
-external:
- (Nomsu version) means:
- return ("
- \(Nomsu syntax version).\(core version).\(Nomsu compiler version).\(lib version)
- ")
-
~~~~
# TODO: Remove shim
($tree with $t -> $replacement) parses as
diff --git a/lib/tools/repl.nom b/lib/tools/repl.nom
index 5e8336f..716c899 100755
--- a/lib/tools/repl.nom
+++ b/lib/tools/repl.nom
@@ -11,7 +11,7 @@ use "commandline"
external:
(help) means:
say ("
- This is the Nomsu v\(Nomsu version) interactive console.
+ This is the Nomsu v\($(NOMSU VERSION), joined with ".") interactive console.
You can type in Nomsu code here and hit 'enter' twice to run it.
To exit, type 'exit' or 'quit' and hit enter twice.
")
@@ -23,7 +23,7 @@ external:
command line program with $args:
say ("
- \(bright)\(underscore)Welcome to the Nomsu v\(Nomsu version) interactive console!\
+ \(bright)\(underscore)Welcome to the Nomsu v\($(NOMSU VERSION), joined with ".") interactive console!\
..\(reset color)
press 'enter' twice to run a command
type 'tutorial' to run the tutorial
diff --git a/lib/tools/upgrade.nom b/lib/tools/upgrade.nom
index 30b6cab..f4a2b8c 100755
--- a/lib/tools/upgrade.nom
+++ b/lib/tools/upgrade.nom
@@ -20,7 +20,7 @@ command line program with $args:
use $start_version
..if it fails:
fail "Could not find upgrade rules for \$start_version"
- $version = ($args."upgrade-to" or (Nomsu version))
+ $version = ($args."upgrade-to" or $(NOMSU VERSION))
$test = ($args.t or $args.test)
for $filename in $args.extras:
$file = (read file $filename)
@@ -30,7 +30,7 @@ command line program with $args:
$code = (NomsuCode from (Source $filename 1 (size of $file)) $file)
$tree = ($code parsed $start_version)
$uptree =
- $tree upgraded from ($start_version or ($tree.version or (Nomsu version))) to
+ $tree upgraded from ($start_version or ($tree.version or $(NOMSU VERSION))) to
$version
$text = "\$leading_indent\($uptree as nomsu, text, with "\n" -> "\n\$leading_indent")"
when:
diff --git a/nomsu.lua b/nomsu.lua
index 86172c4..ee2625c 100644
--- a/nomsu.lua
+++ b/nomsu.lua
@@ -1,4 +1,13 @@
+NOMSU_VERSION = {
+ 7,
+ 0,
+ 0
+}
local clibtype = package.cpath:match("?%.(so)") or package.cpath:match("?%.(dll)")
+if NOMSU_PREFIX then
+ package.path = tostring(NOMSU_PREFIX) .. "/share/nomsu/" .. tostring(table.concat(NOMSU_VERSION, ".")) .. "/?.lua;" .. package.path
+ package.cpath = tostring(NOMSU_PREFIX) .. "/lib/nomsu/" .. tostring(table.concat(NOMSU_VERSION, ".")) .. "/?." .. tostring(clibtype) .. ";" .. package.cpath
+end
COLOR_ENABLED = true
if clibtype == "dll" then
local enable_colors = require('wincolors')
@@ -8,10 +17,14 @@ if clibtype == "dll" then
end
os.execute("chcp 65001>nul")
end
-if NOMSU_VERSION and NOMSU_PREFIX then
- package.path = tostring(NOMSU_PREFIX) .. "/share/nomsu/" .. tostring(NOMSU_VERSION) .. "/?.lua;" .. package.path
- package.cpath = tostring(NOMSU_PREFIX) .. "/lib/nomsu/" .. tostring(NOMSU_VERSION) .. "/?." .. tostring(clibtype) .. ";" .. package.cpath
+local List, Dict
+do
+ local _obj_0 = require('containers')
+ List, Dict = _obj_0.List, _obj_0.Dict
end
+NOMSU_VERSION = List(NOMSU_VERSION)
+local Text = require('text')
+require('builtin_metatables')
local usage = [=[Nomsu Compiler
Usage: (nomsu | lua nomsu.lua | moon nomsu.moon) [-V version] [--help | -h] [--version] [-O optimization level] [-v] [-c] [-s] [-d debugger] [--no-core] [(file | -t tool | -e "nomsu code..." | files... -- ) [nomsu args...]]
@@ -44,13 +57,6 @@ do
local _obj_0 = require("code_obj")
NomsuCode, LuaCode, Source = _obj_0.NomsuCode, _obj_0.LuaCode, _obj_0.Source
end
-local List, Dict
-do
- local _obj_0 = require('containers')
- List, Dict = _obj_0.List, _obj_0.Dict
-end
-local Text = require('text')
-require('builtin_metatables')
local sep = "\3"
local parser = re.compile([[ args <- {| (flag %sep)*
{:files: {|
@@ -98,6 +104,10 @@ if not args or err or args.help then
print(usage)
os.exit(EXIT_FAILURE)
end
+if args.version then
+ print(NOMSU_VERSION:joined_with("."))
+ os.exit(EXIT_SUCCESS)
+end
local nomsu_args = Dict({ })
local _list_0 = args.nomsu_args
for _index_0 = 1, #_list_0 do
@@ -128,8 +138,8 @@ add_path = function(p)
table.insert(nomsupath, p .. "/" .. s)
end
end
-if NOMSU_VERSION and NOMSU_PREFIX then
- add_path(tostring(NOMSU_PREFIX) .. "/share/nomsu/" .. tostring(NOMSU_VERSION) .. "/lib")
+if NOMSU_PREFIX then
+ add_path(tostring(NOMSU_PREFIX) .. "/share/nomsu/" .. tostring(NOMSU_VERSION:joined_with(".")) .. "/lib")
else
add_path("./lib")
end
@@ -139,6 +149,7 @@ add_path(".")
package.nomsupath = table.concat(nomsupath, ";")
package.nomsuloaded = Dict({ })
local nomsu_environment = require('nomsu_environment')
+nomsu_environment.NOMSU_VERSION = NOMSU_VERSION
nomsu_environment.COMMAND_LINE_ARGS = nomsu_args
nomsu_environment.OPTIMIZATION = optimization
nomsu_environment.NOMSU_PACKAGEPATH = NOMSU_PACKAGEPATH
@@ -149,10 +160,6 @@ run = function()
if not (args.no_core) then
nomsu_environment:export("core")
end
- if args.version then
- nomsu_environment:run("say (Nomsu version)")
- os.exit(EXIT_SUCCESS)
- end
local input_files = { }
if args.files then
local _list_1 = args.files
diff --git a/nomsu.moon b/nomsu.moon
index 94b5388..4ffb7c8 100755
--- a/nomsu.moon
+++ b/nomsu.moon
@@ -1,7 +1,14 @@
#!/usr/bin/env moon
-- This file contains the command-line Nomsu runner.
+export NOMSU_VERSION
+NOMSU_VERSION = {7, 0, 0}
clibtype = package.cpath\match("?%.(so)") or package.cpath\match("?%.(dll)")
+
+if NOMSU_PREFIX
+ package.path = "#{NOMSU_PREFIX}/share/nomsu/#{table.concat NOMSU_VERSION, "."}/?.lua;"..package.path
+ package.cpath = "#{NOMSU_PREFIX}/lib/nomsu/#{table.concat NOMSU_VERSION, "."}/?.#{clibtype};"..package.cpath
+
export COLOR_ENABLED
COLOR_ENABLED = true
if clibtype == "dll"
@@ -13,9 +20,10 @@ if clibtype == "dll"
-- Special hack to enable utf8 for windows console applications:
os.execute("chcp 65001>nul")
-if NOMSU_VERSION and NOMSU_PREFIX
- package.path = "#{NOMSU_PREFIX}/share/nomsu/#{NOMSU_VERSION}/?.lua;"..package.path
- package.cpath = "#{NOMSU_PREFIX}/lib/nomsu/#{NOMSU_VERSION}/?.#{clibtype};"..package.cpath
+{:List, :Dict} = require 'containers'
+NOMSU_VERSION = List(NOMSU_VERSION)
+Text = require 'text'
+require 'builtin_metatables'
usage = [=[
Nomsu Compiler
@@ -46,9 +54,6 @@ if not ok
os.exit(EXIT_FAILURE)
Files = require "files"
{:NomsuCode, :LuaCode, :Source} = require "code_obj"
-{:List, :Dict} = require 'containers'
-Text = require 'text'
-require 'builtin_metatables'
sep = "\3"
parser = re.compile([[
@@ -94,6 +99,9 @@ if not args or err or args.help
print("Didn't understand: #{err}")
print usage
os.exit(EXIT_FAILURE)
+if args.version
+ print(NOMSU_VERSION\joined_with("."))
+ os.exit(EXIT_SUCCESS)
nomsu_args = Dict{}
for argpair in *args.nomsu_args
nomsu_args[argpair.key] = argpair.value
@@ -106,8 +114,8 @@ suffixes = if optimization > 0
else {"?.nom", "?/init.nom"}
add_path = (p)->
for s in *suffixes do table.insert(nomsupath, p.."/"..s)
-if NOMSU_VERSION and NOMSU_PREFIX
- add_path "#{NOMSU_PREFIX}/share/nomsu/#{NOMSU_VERSION}/lib"
+if NOMSU_PREFIX
+ add_path "#{NOMSU_PREFIX}/share/nomsu/#{NOMSU_VERSION\joined_with(".")}/lib"
else
add_path "./lib"
NOMSU_PACKAGEPATH or= "/opt/nomsu"
@@ -117,6 +125,7 @@ package.nomsupath = table.concat(nomsupath, ";")
package.nomsuloaded = Dict{}
nomsu_environment = require('nomsu_environment')
+nomsu_environment.NOMSU_VERSION = NOMSU_VERSION
nomsu_environment.COMMAND_LINE_ARGS = nomsu_args
nomsu_environment.OPTIMIZATION = optimization
nomsu_environment.NOMSU_PACKAGEPATH = NOMSU_PACKAGEPATH
@@ -127,10 +136,6 @@ run = ->
unless args.no_core
nomsu_environment\export("core")
- if args.version
- nomsu_environment\run("say (Nomsu version)")
- os.exit(EXIT_SUCCESS)
-
input_files = {}
if args.files
for f in *args.files
diff --git a/nomsu_environment.lua b/nomsu_environment.lua
index 8573179..08993ea 100644
--- a/nomsu_environment.lua
+++ b/nomsu_environment.lua
@@ -23,8 +23,7 @@ make_tree = function(tree, userdata)
return tree
end
local Parsers = { }
-local max_parser_version = 0
-for version = 1, 999 do
+for version = 1, NOMSU_VERSION[1] do
local peg_file
if package.nomsupath then
local pegpath = package.nomsupath:gsub("lib/%?%.nom", "?.peg"):gsub("lib/%?%.lua", "?.peg")
@@ -37,10 +36,7 @@ for version = 1, 999 do
else
peg_file = io.open("nomsu." .. tostring(version) .. ".peg")
end
- if not (peg_file) then
- break
- end
- max_parser_version = version
+ assert(peg_file, "No PEG file found for Nomsu version " .. tostring(version))
local peg_contents = peg_file:read('*a')
peg_file:close()
Parsers[version] = make_parser(peg_contents, make_tree)
@@ -87,8 +83,6 @@ _1_as_list = function(x)
end
local nomsu_environment
nomsu_environment = Importer({
- NOMSU_COMPILER_VERSION = 13,
- NOMSU_SYNTAX_VERSION = max_parser_version,
next = next,
unpack = unpack or table.unpack,
setmetatable = setmetatable,
@@ -171,8 +165,9 @@ nomsu_environment = Importer({
if syntax_version then
syntax_version = tonumber(syntax_version:match("^[0-9]+"))
end
- syntax_version = syntax_version or (version and tonumber(version:match("^[0-9]+")) or max_parser_version)
- local parse = Parsers[syntax_version] or Parsers[max_parser_version]
+ syntax_version = syntax_version or (version and tonumber(version:match("^[0-9]+")) or NOMSU_VERSION[1])
+ local parse = Parsers[syntax_version]
+ assert(parse, "No parser found for Nomsu syntax version " .. tostring(syntax_version))
local tree = parse(nomsu_code, source.filename)
if tree.shebang then
tree.version = tree.version or tree.shebang:match("nomsu %-V[ ]*([%d.]*)")
diff --git a/nomsu_environment.moon b/nomsu_environment.moon
index 3b589dd..7e248c9 100644
--- a/nomsu_environment.moon
+++ b/nomsu_environment.moon
@@ -17,8 +17,7 @@ make_tree = (tree, userdata)->
return tree
Parsers = {}
-max_parser_version = 0
-for version=1,999
+for version=1,NOMSU_VERSION[1]
local peg_file
if package.nomsupath
pegpath = package.nomsupath\gsub("lib/%?%.nom", "?.peg")\gsub("lib/%?%.lua", "?.peg")
@@ -26,8 +25,7 @@ for version=1,999
peg_file = io.open(path)
else
peg_file = io.open("nomsu.#{version}.peg")
- break unless peg_file
- max_parser_version = version
+ assert peg_file, "No PEG file found for Nomsu version #{version}"
peg_contents = peg_file\read('*a')
peg_file\close!
Parsers[version] = make_parser(peg_contents, make_tree)
@@ -53,7 +51,6 @@ _1_as_list = (x)->
local nomsu_environment
nomsu_environment = Importer{
- NOMSU_COMPILER_VERSION: 13, NOMSU_SYNTAX_VERSION: max_parser_version
-- Lua stuff:
:next, unpack: unpack or table.unpack, :setmetatable, :rawequal, :getmetatable, :pcall,
yield:coroutine.yield, resume:coroutine.resume, coroutine_status_of:coroutine.status,
@@ -89,8 +86,9 @@ nomsu_environment = Importer{
version = nomsu_code\match("^#![^\n]*nomsu[ ]+-V[ ]*([0-9.]+)")
if syntax_version
syntax_version = tonumber(syntax_version\match("^[0-9]+"))
- syntax_version or= version and tonumber(version\match("^[0-9]+")) or max_parser_version
- parse = Parsers[syntax_version] or Parsers[max_parser_version]
+ syntax_version or= version and tonumber(version\match("^[0-9]+")) or NOMSU_VERSION[1]
+ parse = Parsers[syntax_version]
+ assert parse, "No parser found for Nomsu syntax version #{syntax_version}"
tree = parse(nomsu_code, source.filename)
if tree.shebang
tree.version or= tree.shebang\match("nomsu %-V[ ]*([%d.]*)")