From dbf3de3d8efc0d150e1f439c4fc15fc09fea7d27 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 23 Jun 2018 00:57:31 -0700 Subject: Added versioning system. --- core/collections.nom | 11 ++++++----- core/metaprogramming.nom | 39 +++++++++++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 13 deletions(-) (limited to 'core') diff --git a/core/collections.nom b/core/collections.nom index abd4a3a..0f53679 100644 --- a/core/collections.nom +++ b/core/collections.nom @@ -150,13 +150,14 @@ action [%items sorted, sorted %items] %copy <- (% for % in %items) sort %copy return %copy -action [..] +parse [..] %items sorted by %item = %key %items sorted by %item -> %key -.. - %copy <- (% for % in %items) - sort %copy by %item = %key - return %copy +..as + result of + %copy <- (% for % in %items) + sort %copy by %item = %key + return %copy action [unique %items] %unique <- [] diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom index 068513a..4e3e99a 100644 --- a/core/metaprogramming.nom +++ b/core/metaprogramming.nom @@ -2,6 +2,8 @@ This File contains actions for making actions and compile-time actions and some helper functions to make that easier. +lua> "NOMSU_CORE_VERSION = 1" + lua> ".." nomsu.COMPILE_ACTIONS["% -> %"] = function(nomsu, tree, \%args, \%body) local lua = LuaCode.Value(tree.source, "function(") @@ -52,6 +54,13 @@ lua> ".." ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +compile [call %fn with %args] to + lua> ".." + local lua = LuaCode.Value(tree.source, nomsu:compile(\%fn), "(") + lua:concat_append(table.map(\%args, function(a) return nomsu:compile(a) end), ", ") + lua:append(")") + return lua + compile [using %defs compile %body] to lua> ".." local lua = LuaCode(tree.source) @@ -124,8 +133,9 @@ compile [parse %actions as %body] to local \%new_body = LuaCode(\%body.source, "__MANGLE_INDEX = (__MANGLE_INDEX or 0) + 1", "\nlocal tree = ", make_tree(\%body), - "\nreturn nomsu:compile(tree)") - return \(compile as: compile %actions to %new_body) + "\nlocal lua = nomsu:compile(tree); return lua") + local ret = \(compile as: compile %actions to %new_body) + return ret ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -171,6 +181,15 @@ compile [%tree with %t -> %replacement] to \(%replacement as lua return) end) +compile [%tree with vars %v] to + Lua value ".." + \(%tree as lua expr):map(function(t) + local replacements = \(%v as lua expr) + if t.type == "Var" then + return replacements[t[1]] + end + end) + compile [declare locals in %code] to Lua value "\(%code as lua expr):declare_locals()" @@ -190,7 +209,7 @@ compile [quote %s] to ('"'..\(%s as lua expr):gsub("\\\\", "\\\\\\\\"):gsub("\n","\\\\n"):gsub('"', '\\\\"')..'"') compile [type of %obj] to: Lua value "type(\(%obj as lua expr))" -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ compile [parse %text] to Lua value ".." @@ -201,11 +220,7 @@ compile [run %nomsu_code] to action [run tree %tree, %tree as value] lua> ".." - if \%tree.type == 'Text' and #\%tree == 1 and type(\%tree[1]) == 'string' then - return \%tree[1] - end - local lua = LuaCode(\%tree.source, "return ",nomsu:compile(\%tree)) - return nomsu:run_lua(lua) + return nomsu:run(\%tree) compile [compile %block, compiled %block, %block compiled] to Lua value "nomsu:compile(\(%block as lua))" @@ -219,4 +234,12 @@ compile [return %return_value] to: Lua "do return \(%return_value as lua expr); compile [yes] to: Lua value "true" compile [no] to: Lua value "false" compile [nothing, nil, null] to: Lua value "nil" +compile [Nomsu syntax version] to: Lua value "NOMSU_SYNTAX_VERSION" +compile [Nomsu compiler version] to: Lua value "NOMSU_COMPILER_VERSION" +compile [core version] to: Lua value "NOMSU_CORE_VERSION" +compile [lib version] to: Lua value "NOMSU_LIB_VERSION" +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +action [Nomsu version] + use "lib/version.nom" + return "\(Nomsu syntax version).\(Nomsu compiler version).\(core version).\(lib version)" -- cgit v1.2.3