aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2018-11-09 17:02:39 -0800
committerBruce Hill <bruce@bruce-hill.com>2018-11-09 17:02:53 -0800
commitfa3f598fc3b91d92665fda293460944f75c95b67 (patch)
treea5d19eac16d81873ab51171bdd5670793baa4ff8
parent69aaea030e08e083151aa25b8080eddd0d4c1683 (diff)
Fixing the upgrade pipeline, plus some misc. fixes.
-rw-r--r--compatibility/2.4.nom34
-rw-r--r--compatibility/2.nom10
-rw-r--r--compatibility/3.nom4
-rw-r--r--compatibility/4.8.10.nom28
-rw-r--r--compatibility/4.9.nom28
-rw-r--r--compatibility/compatibility.nom4
-rw-r--r--core/metaprogramming.nom6
-rw-r--r--core/text.nom2
-rw-r--r--lib/object.nom2
-rw-r--r--nomsu_decompiler.lua4
-rw-r--r--nomsu_decompiler.moon4
-rwxr-xr-xtools/upgrade.nom6
12 files changed, 70 insertions, 62 deletions
diff --git a/compatibility/2.4.nom b/compatibility/2.4.nom
index f26bf0d..1f87a98 100644
--- a/compatibility/2.4.nom
+++ b/compatibility/2.4.nom
@@ -9,23 +9,22 @@ use "compatibility/compatibility.nom"
upgrade %tree to "2.4" as:
unless (%tree is "Action" syntax tree): return
if %tree.stub is:
- "when %":
+ "when":
%conditions = []
%new_lines = []
%body = (..)
(%tree.2 upgraded) if (%tree.2 is "Block" syntax tree) else [%tree.2 upgraded]
for %line in %body:
- if:
- (not (%line is syntax tree)):
- compile error at %tree.source "WUT: %s"
+ when:
(not (%line is "Action" syntax tree)):
%new_lines::add %line
- (%line.stub is "* %"):
- %conditions::add %line.2
- (%line.stub == "* else %"):
+ (%line.stub is "*"):
+ if ((size of %line) == 2):
+ %conditions::add %line.2
+ ..else:
+ %new_lines::add %line
+ (%line.stub == "* else"):
%new_lines::add (\(else %block) with vars {block:%line.3})
- (%line.stub != "* % %"):
- %new_lines::add %line
else:
%conditions::add %line.2
%action = %line.3
@@ -36,23 +35,24 @@ upgrade %tree to "2.4" as:
%conditions = []
return (..)
- \(if %body) with vars {body:=lua "Block(\%tree[2].source, unpack(\%new_lines))"}
+ \(when %body) with vars {body:=lua "Block(\%tree[2].source, unpack(\%new_lines))"}
- "when % is ? %" "when % = ? %":
+ "when 1 is ?" "when 1 = ?":
%values = []
%new_lines = []
%body = (..)
(%tree.5 upgraded) if (%tree.5 is "Block" syntax tree) else [%tree.5 upgraded]
for %line in %body:
- if:
+ when:
(not (%line is "Action" syntax tree)):
%new_lines::add %line
- (%line.stub is "* %"):
- %values::add %line.2
- (%line.stub == "* else %"):
+ (%line.stub is "*"):
+ if ((size of %line) == 2):
+ %values::add %line.2
+ ..else:
+ %new_lines::add %line
+ (%line.stub == "* else"):
%new_lines::add (\(else %block) with vars {block:%line.3})
- (%line.stub != "* % %"):
- %new_lines::add %line
else:
%values::add %line.2
%action = %line.3
diff --git a/compatibility/2.nom b/compatibility/2.nom
index eb4060a..5c78e29 100644
--- a/compatibility/2.nom
+++ b/compatibility/2.nom
@@ -8,7 +8,7 @@ use "compatibility/compatibility.nom"
upgrade %tree to "2" as:
unless (%tree is "Action" syntax tree): return
- if (%tree.stub is "if % % else %"):
+ if (%tree.stub is "if 1 2 else"):
%true_body = (%tree.3 upgraded)
unless (%true_body is "Block" syntax tree):
%true_body = \(: %true_body)
@@ -20,10 +20,10 @@ upgrade %tree to "2" as:
cond:%tree.2 upgraded, true_body:%true_body, false_body:%false_body
%need_blocks = [..]
- "if % %", "unless % %", "for % in % %", "for % = % in % %", "repeat while % %"
- "repeat % times %", "repeat %", "repeat until % %", "for % in % to % by % %"
- "for % in % to % via % %", "for % in % to % %", "for % % in % %"
- "do %", "for % in recursive % %", "test %", "with % %", "result of %"
+ "if", "unless", "for 1 in", "for 1 = 2 in", "repeat while 1"
+ "repeat 1 times", "repeat", "repeat until 1", "for 1 in 2 to 3 by"
+ "for 1 in 2 to 3 via", "for 1 in 2 to", "for 1 2 in"
+ "do", "for 1 in recursive", "test", "with", "result of"
for %n in %need_blocks:
if (%tree.stub is %n):
diff --git a/compatibility/3.nom b/compatibility/3.nom
index a4840ca..f97bb8b 100644
--- a/compatibility/3.nom
+++ b/compatibility/3.nom
@@ -9,7 +9,7 @@ use "compatibility/compatibility.nom"
upgrade action (method %spec %body) to "3" as (my action %spec %body)
upgrade action (me) to "3" as %me
upgrade action (@) to "3" as %me
-upgrade action "as 1 2" to "3" via (..)
+upgrade action "as" to "3" via (..)
[] -> (..)
barf "\
- ..Object API has changed. Use (%obj::action 1 2) instead of (as %obj: action 1 2)"
+ ..Object API has changed. Use (%obj::action ...) instead of (as %obj: action ...)"
diff --git a/compatibility/4.8.10.nom b/compatibility/4.8.10.nom
index d62efa1..7ea95b0 100644
--- a/compatibility/4.8.10.nom
+++ b/compatibility/4.8.10.nom
@@ -5,7 +5,7 @@ use "compatibility/compatibility.nom"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-upgrade action "local action 1 2" to "4.8.10" via (..)
+upgrade action "local action" to "4.8.10" via (..)
[%tree, %end_version] ->:
%spec = %tree.3
%body = %tree.4
@@ -18,20 +18,23 @@ upgrade action "local action 1 2" to "4.8.10" via (..)
else:
return \(%spec means %body)
-upgrade action "action 1 2" to "4.8.10" via (..)
+upgrade action "action" to "4.8.10" via (..)
[%tree, %end_version] ->:
%spec = %tree.2
%body = %tree.3
- if %spec.type is:
- "List":
- if ((size of %spec) == 1):
- return \(externally %spec.1 means %body)
- ..else:
- return \(externally %spec all mean %body)
- else:
- return \(externally %spec means %body)
+ if %body:
+ if %spec.type is:
+ "List":
+ if ((size of %spec) == 1):
+ return \(externally %spec.1 means %body)
+ ..else:
+ return \(externally %spec all mean %body)
+ else:
+ return \(externally %spec means %body)
+ ..else:
+ return \(%spec's meaning)
-upgrade action "compile 1 to 2" to "4.8.10" via (..)
+upgrade action "compile 1 to" to "4.8.10" via (..)
[%tree, %end_version] ->:
%spec = %tree.2
%body = %tree.4
@@ -44,7 +47,7 @@ upgrade action "compile 1 to 2" to "4.8.10" via (..)
else:
return \(%spec compiles to %body)
-upgrade action "parse 1 as 2" to "4.8.10" via (..)
+upgrade action "parse 1 as" to "4.8.10" via (..)
[%tree, %end_version] ->:
%spec = %tree.2
%body = %tree.4
@@ -58,5 +61,4 @@ upgrade action "parse 1 as 2" to "4.8.10" via (..)
return \(%spec parse as %body)
upgrade action (compile as %) to "4.8.10" as (what % compiles to)
-upgrade action (action %) to "4.8.10" as (%'s meaning)
upgrade action (remove action %) to "4.8.10" as ((%'s meaning) = (nil))
diff --git a/compatibility/4.9.nom b/compatibility/4.9.nom
index f84171a..7eb54d4 100644
--- a/compatibility/4.9.nom
+++ b/compatibility/4.9.nom
@@ -3,7 +3,7 @@
This file defines upgrades from Nomsu <4.9 to 4.9
use "compatibility/compatibility.nom"
-upgrade action "local action 1 2" to "4.9" via (..)
+upgrade action "local action" to "4.9" via (..)
[%tree, %end_version] ->:
%spec = %tree.3
%body = %tree.4
@@ -16,20 +16,23 @@ upgrade action "local action 1 2" to "4.9" via (..)
else:
return \(%spec means %body)
-upgrade action "action 1 2" to "4.9" via (..)
+upgrade action "action" to "4.9" via (..)
[%tree, %end_version] ->:
%spec = %tree.2
%body = %tree.3
- if %spec.type is:
- "List":
- if ((size of %spec) == 1):
- return \(externally %spec.1 means %body)
- ..else:
- return \(externally %spec all mean %body)
- else:
- return \(externally %spec means %body)
+ if %body:
+ if %spec.type is:
+ "List":
+ if ((size of %spec) == 1):
+ return \(externally %spec.1 means %body)
+ ..else:
+ return \(externally %spec all mean %body)
+ else:
+ return \(externally %spec means %body)
+ ..else:
+ return \(%spec's meaning)
-upgrade action "compile 1 to 2" to "4.9" via (..)
+upgrade action "compile 1 to" to "4.9" via (..)
[%tree, %end_version] ->:
%spec = %tree.2
%body = %tree.4
@@ -42,7 +45,7 @@ upgrade action "compile 1 to 2" to "4.9" via (..)
else:
return \(%spec compiles to %body)
-upgrade action "parse 1 as 2" to "4.9" via (..)
+upgrade action "parse 1 as" to "4.9" via (..)
[%tree, %end_version] ->:
%spec = %tree.2
%body = %tree.4
@@ -56,6 +59,5 @@ upgrade action "parse 1 as 2" to "4.9" via (..)
return \(%spec parse as %body)
upgrade action (compile as %) to "4.9" as (what % compiles to)
-upgrade action (action %) to "4.9" as (%'s meaning)
upgrade action (remove action %) to "4.9" as ((%'s meaning) = (nil))
upgrade action (if %) to "4.9" as (when %)
diff --git a/compatibility/compatibility.nom b/compatibility/compatibility.nom
index 4e22dbc..09eacc2 100644
--- a/compatibility/compatibility.nom
+++ b/compatibility/compatibility.nom
@@ -36,7 +36,7 @@ externally (upgrade action %stub to %version via %upgrade_fn) means:
return %replacements.(%t.1)
..else:
external %needs_mangle = (yes)
- return "\(%t.type){source=\(quote "\(%t.source)"), \(quote (mangle %t.1))}"
+ return "SyntaxTree{type=\(quote %t.type), source=\(quote "\(%t.source)"), \(quote (mangle %t.1))}"
(%t is syntax tree):
%args = []
@@ -46,7 +46,7 @@ externally (upgrade action %stub to %version via %upgrade_fn) means:
..else:
%args::add "\(%k)=\(make tree %v)"
- return "\(%t.type){\(%args::joined with ", ")}"
+ return "SyntaxTree{\(%args::joined with ", ")}"
else: return (quote %t)
diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom
index fc81e15..b27147d 100644
--- a/core/metaprogramming.nom
+++ b/core/metaprogramming.nom
@@ -365,8 +365,10 @@ test:
# Return statement is wrapped in a do..end block because Lua is unhappy if you
put code after a return statement, unless you wrap it in a block.
-(return) compiles to "do return; end"
-(return %return_value) compiles to "do return \(%return_value as lua expr) end"
+(return %return_value) compiles to "\
+ ..do return \(..)
+ =lua "\%return_value and \(%return_value as lua expr) or ''"
+ .. end"
# Literals
(yes) compiles to "true"
diff --git a/core/text.nom b/core/text.nom
index d4cd227..28944dd 100644
--- a/core/text.nom
+++ b/core/text.nom
@@ -36,7 +36,7 @@ test:
return (..)
Lua "\
..(function()
- local \(mangle "comprehension") = _List{}
+ local \(mangle "comprehension") = List{}
for \(%match as lua expr) in (\(%text as lua expr)):gmatch(\(..)
%patt as lua expr
..) do
diff --git a/lib/object.nom b/lib/object.nom
index bb2de3a..d8c7f5e 100644
--- a/lib/object.nom
+++ b/lib/object.nom
@@ -99,7 +99,7 @@ test:
class.__index = class
class.class = class
class.__tostring = function(inst)
- return inst.name..getmetatable(_Dict{}).__tostring(inst)
+ return inst.name..getmetatable(Dict{}).__tostring(inst)
end
\(%class_body as lua)
for stub,metamethod in pairs(globals.METAMETHOD_MAP) do
diff --git a/nomsu_decompiler.lua b/nomsu_decompiler.lua
index a3d7f41..77905e5 100644
--- a/nomsu_decompiler.lua
+++ b/nomsu_decompiler.lua
@@ -179,7 +179,7 @@ tree_to_inline_nomsu = function(tree)
elseif "FileChunks" == _exp_0 then
return error("Can't inline a FileChunks")
elseif "Comment" == _exp_0 then
- return nil
+ return NomsuCode:from(tree.source)
elseif "Error" == _exp_0 then
return error("Can't compile errors")
else
@@ -397,7 +397,7 @@ tree_to_nomsu = function(tree)
nomsu:append(": ", value_nomsu)
return nomsu
elseif "Comment" == _exp_0 then
- nomsu:append("#", tree[1]:gsub("\n", "\n "))
+ nomsu:append("#", (tree[1]:gsub("\n", "\n ")))
return nomsu
elseif "IndexChain" == _exp_0 or "Number" == _exp_0 or "Var" == _exp_0 or "Comment" == _exp_0 or "Error" == _exp_0 then
return tree_to_inline_nomsu(tree)
diff --git a/nomsu_decompiler.moon b/nomsu_decompiler.moon
index 828df06..1de60ca 100644
--- a/nomsu_decompiler.moon
+++ b/nomsu_decompiler.moon
@@ -137,7 +137,7 @@ tree_to_inline_nomsu = (tree)->
when "Comment"
-- TODO: implement?
- return nil
+ return NomsuCode\from(tree.source)
when "Error"
error("Can't compile errors")
@@ -307,7 +307,7 @@ tree_to_nomsu = (tree)->
return nomsu
when "Comment"
- nomsu\append "#", tree[1]\gsub("\n", "\n ")
+ nomsu\append "#", (tree[1]\gsub("\n", "\n "))
return nomsu
when "IndexChain", "Number", "Var", "Comment", "Error"
diff --git a/tools/upgrade.nom b/tools/upgrade.nom
index 4975aad..a937e46 100755
--- a/tools/upgrade.nom
+++ b/tools/upgrade.nom
@@ -40,14 +40,16 @@ repeat:
for %path in %args:
for file %filename in %path:
unless (%filename::matches "%.nom$"): do next %filename
- %tree = (parse (read file %filename) from %filename)
+ %file = (read file %filename)
+ %code = (%NomsuCode::from (%Source %filename 1 (size of %file)) %file)
+ %tree = (%code parsed)
%uptree = (..)
%tree upgraded from (%start_version or (%tree.version or (Nomsu version))) to %version
%text = "\
..#!/usr/bin/env nomsu -V\%version
\(%uptree as nomsu)"
- if:
+ when:
%inplace:
say "Upgraded \%filename"
write %text to file %filename