From ddef8be3df626d63f6e575d4c1416295a22371ad Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 14 Jan 2019 17:14:34 -0800 Subject: Moved compatibility to lib/ and fixed path searching for .peg files. --- lib/compatibility/2.3.nom | 20 ++++++ lib/compatibility/2.4.nom | 85 +++++++++++++++++++++++ lib/compatibility/2.5.5.5.nom | 17 +++++ lib/compatibility/2.5.nom | 13 ++++ lib/compatibility/2.nom | 38 +++++++++++ lib/compatibility/3.5.5.6.nom | 11 +++ lib/compatibility/3.6.nom | 30 ++++++++ lib/compatibility/3.7.nom | 41 +++++++++++ lib/compatibility/3.8.nom | 23 +++++++ lib/compatibility/3.nom | 15 ++++ lib/compatibility/4.10.12.7.nom | 85 +++++++++++++++++++++++ lib/compatibility/4.11.nom | 97 ++++++++++++++++++++++++++ lib/compatibility/4.12.nom | 18 +++++ lib/compatibility/4.8.10.nom | 68 +++++++++++++++++++ lib/compatibility/4.9.nom | 11 +++ lib/compatibility/5.13.nom | 24 +++++++ lib/compatibility/6.14.nom | 41 +++++++++++ lib/compatibility/compatibility.nom | 132 ++++++++++++++++++++++++++++++++++++ lib/compatibility/init.nom | 19 ++++++ 19 files changed, 788 insertions(+) create mode 100644 lib/compatibility/2.3.nom create mode 100644 lib/compatibility/2.4.nom create mode 100644 lib/compatibility/2.5.5.5.nom create mode 100644 lib/compatibility/2.5.nom create mode 100644 lib/compatibility/2.nom create mode 100644 lib/compatibility/3.5.5.6.nom create mode 100644 lib/compatibility/3.6.nom create mode 100644 lib/compatibility/3.7.nom create mode 100644 lib/compatibility/3.8.nom create mode 100644 lib/compatibility/3.nom create mode 100644 lib/compatibility/4.10.12.7.nom create mode 100644 lib/compatibility/4.11.nom create mode 100644 lib/compatibility/4.12.nom create mode 100644 lib/compatibility/4.8.10.nom create mode 100644 lib/compatibility/4.9.nom create mode 100644 lib/compatibility/5.13.nom create mode 100644 lib/compatibility/6.14.nom create mode 100644 lib/compatibility/compatibility.nom create mode 100644 lib/compatibility/init.nom (limited to 'lib/compatibility') diff --git a/lib/compatibility/2.3.nom b/lib/compatibility/2.3.nom new file mode 100644 index 0000000..67870ac --- /dev/null +++ b/lib/compatibility/2.3.nom @@ -0,0 +1,20 @@ +#!/usr/bin/env nomsu -V6.14 +# + This file defines upgrades from Nomsu <2.3 to Nomsu 2.3 + +use "compatibility/compatibility" + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +upgrade action ($a = $b) to "2.3" as ($a == $b) +upgrade action (<- $) to "2.3" as (set $) +upgrade action (assign $) to "2.3" as (set $) +upgrade action ($a <- $b) to "2.3" as ($a = $b) +upgrade action (external $a <- $b) to "2.3" as (external $a = $b) +upgrade action ($a +<- $b) to "2.3" as ($a += $b) +upgrade action ($a -<- $b) to "2.3" as ($a -= $b) +upgrade action ($a *<- $b) to "2.3" as ($a *= $b) +upgrade action ($a /<- $b) to "2.3" as ($a /= $b) +upgrade action ($a ^<- $b) to "2.3" as ($a ^= $b) +upgrade action ($a and<- $b) to "2.3" as ($a and= $b) +upgrade action ($a or<- $b) to "2.3" as ($a or= $b) diff --git a/lib/compatibility/2.4.nom b/lib/compatibility/2.4.nom new file mode 100644 index 0000000..e0d2e02 --- /dev/null +++ b/lib/compatibility/2.4.nom @@ -0,0 +1,85 @@ +#!/usr/bin/env nomsu -V6.14 +# + This file defines upgrades from Nomsu <2.4 to Nomsu 2.4 + +use "compatibility/compatibility" + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +upgrade $tree to "2.4" as: + unless ($tree is "Action" syntax tree): return + if $tree.stub is: + "when" "if": + if ((size of $tree) == 3): return $tree + $conditions = [] + $new_lines = [] + $body = + ($tree.2 upgraded) if ($tree.2 is "Block" syntax tree) else [$tree.2 upgraded] + + for $line in $body: + when: + (not ($line is "Action" syntax tree)): + $new_lines, add $line + + ($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}) + + else: + $conditions, add $line.2 + $action = $line.3 + unless ($action is "Block" syntax tree): + $action = (=lua "SyntaxTree{type='Block', source=\$action.source, \$action}") + $conditions, add $action + $new_lines, add + =lua (" + SyntaxTree{type='Action', source=\$conditions[1].source, unpack(\$conditions)} + ") + $conditions = [] + + return + \(when $body) with vars { + .body = + =lua "SyntaxTree{type='Block', source=\$tree[2].source, unpack(\$new_lines)}" + } + + "if 1 is ?" "if 1 = ?": + $values = [] + $new_lines = [] + $body = + ($tree.5 upgraded) if ($tree.5 is "Block" syntax tree) else [$tree.5 upgraded] + + for $line in $body: + when: + (not ($line is "Action" syntax tree)): + $new_lines, add $line + + ($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}) + + else: + $values, add $line.2 + $action = $line.3 + unless ($action is "Block" syntax tree): $action = \(: $action) + $values, add $action + $new_lines, add + =lua "SyntaxTree{type='Action', source=\$values[1].source, unpack(\$values)}" + $values = [] + + return + \(if $var is $body) with vars { + .var = ($tree.2 upgraded) + .body = + =lua "SyntaxTree{type='Block', source=\$tree[5].source, unpack(\$new_lines)}" + } diff --git a/lib/compatibility/2.5.5.5.nom b/lib/compatibility/2.5.5.5.nom new file mode 100644 index 0000000..c026a42 --- /dev/null +++ b/lib/compatibility/2.5.5.5.nom @@ -0,0 +1,17 @@ +#!/usr/bin/env nomsu -V6.14 +# + This file defines upgrades from Nomsu <2.5.5.5 to Nomsu 2.5.5.5 + +use "compatibility/compatibility" + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +upgrade action [hash $, sha1 $] to "2.5.5.5" as + =lua (" + \(base64 decode (hash $)):gsub('.', function(c) return ('%x02'):format(c) end) + ") + +upgrade action [file with hash $] to "2.5.5.5" as + file with hash + base64 + =lua "\$:gsub('..', function(xx) return string.char(tonumber(xx, 16)) end)" diff --git a/lib/compatibility/2.5.nom b/lib/compatibility/2.5.nom new file mode 100644 index 0000000..03b3f61 --- /dev/null +++ b/lib/compatibility/2.5.nom @@ -0,0 +1,13 @@ +#!/usr/bin/env nomsu -V6.14 +# + This file defines upgrades from Nomsu <2.5 to Nomsu 2.5 + +use "compatibility/compatibility" + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +upgrade action (for $1 where $2 matches $3 $4) to "2.5" as + for $1 in $2 matching $3 $4 + +upgrade action ($1 for $2 where $3 matches $4) to "2.5" as + $1 for $2 in $3 matching $4 diff --git a/lib/compatibility/2.nom b/lib/compatibility/2.nom new file mode 100644 index 0000000..caf7a86 --- /dev/null +++ b/lib/compatibility/2.nom @@ -0,0 +1,38 @@ +#!/usr/bin/env nomsu -V6.14 +# + This file defines upgrades from Nomsu 1 to Nomsu 2 + +use "compatibility/compatibility" + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +upgrade $tree to "2" as: + unless ($tree is "Action" syntax tree): return + if ($tree.stub is "if 1 2 else"): + $true_body = ($tree.3 upgraded) + unless ($true_body is "Block" syntax tree): + $true_body = \(: $true_body) + $false_body = ($tree.5 upgraded) + unless ($false_body is "Block" syntax tree): + $false_body = (=lua "Block(\$false_body.source, \$false_body)") + + return + \(if $cond $true_body else $false_body) with vars { + .cond = ($tree.2 upgraded), .true_body = $true_body, .false_body = $false_body + } + + $need_blocks = [ + "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" + "when" + ] + + for $n in $need_blocks: + if ($tree.stub is $n): + $bits = [: for $ in $tree: add (($ upgraded) if ($ is syntax tree) else $)] + unless (($bits, last) is "Block" syntax tree): + $body = ($bits, last) + $bits.(size of $bits) = + =lua "SyntaxTree{type='Block', source=\$body.source, \$body}" + return (=lua "SyntaxTree{type='Action', source=\$tree.source, unpack(\$bits)}") diff --git a/lib/compatibility/3.5.5.6.nom b/lib/compatibility/3.5.5.6.nom new file mode 100644 index 0000000..6528526 --- /dev/null +++ b/lib/compatibility/3.5.5.6.nom @@ -0,0 +1,11 @@ +#!/usr/bin/env nomsu -V6.14 +# + This file defines upgrades from Nomsu <3.5.5.6 to Nomsu 3.5.5.6 + +use "compatibility/compatibility" + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +upgrade action "traceback" to "3.5.5.6" via + for $tree: + compile error at $tree "'traceback' has been deprecated." diff --git a/lib/compatibility/3.6.nom b/lib/compatibility/3.6.nom new file mode 100644 index 0000000..5db2aae --- /dev/null +++ b/lib/compatibility/3.6.nom @@ -0,0 +1,30 @@ +#!/usr/bin/env nomsu -V6.14 +# + This file defines upgrades from Nomsu <3.6 to 3.6 + +use "compatibility/compatibility" + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +upgrade action [ + append $item to $list, add $item to $list, to $list add $item, to $list append $item +] to "3.6" as ($list, add $item) + +upgrade action [add $item to $list at index $i] to "3.6" as + $list, at index $i add $item + +upgrade action [pop from $list, remove last from $list] to "3.6" as ($list, pop) +upgrade action [remove index $index from $list] to "3.6" as + $list, remove index $index +upgrade action [to $1 write $2, $1 <-write $2] to "3.6" as ($1, add $2) +upgrade action [to $1 write $2 joined by $3] to "3.6" as + $1, add $2 joined by $3 +upgrade action [declare locals in $lua] to "3.6" as ($lua, declare locals) +upgrade action [declare locals $locs in $lua] to "3.6" as + $lua, declare locals $locs + +upgrade action [add free vars $vars to $lua] to "3.6" as + $lua, add free vars $vars + +upgrade action [remove free vars $vars from $lua] to "3.6" as + $lua, remove free vars $vars diff --git a/lib/compatibility/3.7.nom b/lib/compatibility/3.7.nom new file mode 100644 index 0000000..ed877a6 --- /dev/null +++ b/lib/compatibility/3.7.nom @@ -0,0 +1,41 @@ +#!/usr/bin/env nomsu -V6.14 +# + This file defines upgrades from Nomsu <3.7 to 3.7 + +use "compatibility/compatibility" + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +upgrade action [$index st to last in $list] to "3.7" as + $list, $index st to last + +upgrade action [$index nd to last in $list] to "3.7" as + $list, $index nd to last + +upgrade action [$index rd to last in $list] to "3.7" as + $list, $index rd to last + +upgrade action [$index th to last in $list] to "3.7" as + $list, $index rd th last + +upgrade action [last in $list] to "3.7" as ($list, last) +upgrade action [first in $list] to "3.7" as ($list, first) +upgrade action [$item is in $list, $list contains $item, $list has $item] to +.."3.7" as ($list, has $item) + +upgrade action [ + $item isn't in $list, $item is not in $list, $list doesn't contain $item + $list does not contain $item, $list doesn't have $item, $list does not have $item +] to "3.7" as (not ($list, has $item)) + +upgrade action [$list has key $index, $list has index $index] to "3.7" as + $list.$index != (nil) + +upgrade action [ + $list doesn't have key $index, $list does not have key $index + $list doesn't have index $index, $list does not have index $index +] to "3.7" as ($list.$index == (nil)) + +upgrade action [ + number of keys in $list, len $list, || $list ||, length $list, length of $list +] to "3.7" as (size of $list) diff --git a/lib/compatibility/3.8.nom b/lib/compatibility/3.8.nom new file mode 100644 index 0000000..398e3bb --- /dev/null +++ b/lib/compatibility/3.8.nom @@ -0,0 +1,23 @@ +#!/usr/bin/env nomsu -V6.14 +# + This file defines upgrades from Nomsu <3.8 to 3.8 (Text method changes) + +use "compatibility/compatibility" + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +upgrade action [$texts joined with $glue] to "3.8" as ($texts, joined with $glue) +upgrade action [$texts joined, joined $texts] to "3.8" as ($texts, joined) +upgrade action [byte $i of $text] to "3.8" as ($text, byte $i) +upgrade action [bytes $start to $stop of $text] to "3.8" as + $text, bytes $start to $stop +upgrade action [bytes of $text] to "3.8" as ($text, bytes) +upgrade action [capitalized $text, $text capitalized] to "3.8" as + $text, capitalized +upgrade action [uppercase $text, $text uppercase] to "3.8" as ($text, uppercase) +upgrade action [ + $text with $sub instead of $patt, $text with $patt replaced by $sub + $text s/ $patt / $sub +] to "3.8" as ($text, with $patt -> $sub) +upgrade action [$text matches $pattern] to "3.8" as ($text, matches $pattern) +upgrade action [$text matching $pattern] to "3.8" as ($text, matching $pattern).1 diff --git a/lib/compatibility/3.nom b/lib/compatibility/3.nom new file mode 100644 index 0000000..af5c2fd --- /dev/null +++ b/lib/compatibility/3.nom @@ -0,0 +1,15 @@ +#!/usr/bin/env nomsu -V6.14 +# + This file defines upgrades from Nomsu <=2 to Nomsu 3 + +use "compatibility/compatibility" + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +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" to "3" via + for $tree: + compile error at $tree "Object API has changed and 'as' is no longer supported." + "Use ($obj, action ...) instead of (as $obj: action ...)" diff --git a/lib/compatibility/4.10.12.7.nom b/lib/compatibility/4.10.12.7.nom new file mode 100644 index 0000000..c241898 --- /dev/null +++ b/lib/compatibility/4.10.12.7.nom @@ -0,0 +1,85 @@ +#!/usr/bin/env nomsu -V6.14 +# + This file defines upgrades from Nomsu <4.10.12.7 to 4.10.12.7 +use "compatibility/compatibility" + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +upgrade action ($ as lua statements) to "4.10.12.7" as ($ as lua) +upgrade action ($ as lua return) to "4.10.12.7" as + =lua "\$.type == 'Block' and \($ as lua) or 'return '..\($ as lua expr)" + +upgrade action (Lua value $) to "4.10.12.7" as (Lua $) + +upgrade action ($e for $ in $items) to "4.10.12.7" as [: for $ in $items: add $e] +upgrade action ($e for $k = $v in $items) to "4.10.12.7" as + [: for $k = $v in $items: add $e] + +upgrade action ($e for $i in $start to $stop) to "4.10.12.7" as + [: for $i in $start to $stop: add $e] + +upgrade action ($e for $i in $start to $stop by $step) to "4.10.12.7" as + [: for $i in $start to $stop by $step: add $e] + +upgrade action ($e for $i in $start to $stop via $step) to "4.10.12.7" as + [: for $i in $start to $stop by $step: add $e] + +upgrade action ($k = $v for $ in $items) to "4.10.12.7" as { + : for $ in $items: + add $k = $v +} + +upgrade action ($k = $v for $k0 = $v0 in $items) to "4.10.12.7" as + {: for $k0 = $v0 in $items: add $k = $v} + +upgrade action ($k = $v for $i in $start to $stop) to "4.10.12.7" as + {: for $i in $start to $stop: add $k = $v} + +upgrade action ($k = $v for $i in $start to $stop by $step) to "4.10.12.7" as + {: for $i in $start to $stop by $step: add $k = $v} + +upgrade action ($k = $v for $i in $start to $stop via $step) to "4.10.12.7" as + {: for $i in $start to $stop by $step: add $k = $v} + +upgrade action (parse $text from $filename) to "4.10.12.7" as + (NomsuCode from (Source $filename 1 (size of $text)) $text) parsed + +upgrade action ($ as lua statements) to "4.10.12.7" as ($ as lua) +upgrade action (compile error at $pos $err hint $hint) to "4.10.12.7" as + compile error at $pos $err $hint + +# In old code, it was okay to have imports at the top of the file in the same chunk, + but changes to the API now require imports to be in their own file chunk in order + for compilation to work properly. +upgrade $tree to "4.10.12.7" as: + if ($tree.type == "FileChunks"): + $first_chunk = $tree.1 + $i = 1 + $has_use = (no) + repeat while ($i <= (size of $first_chunk)): + if (($first_chunk.$i.type == "Action") and ($first_chunk.$i.stub == "use")): + $has_use = (yes) + ..else: + if $has_use: + go to (insert chunk) + $i += 1 + return + --- (insert chunk) --- + [$chunk1, $chunk2] = [ + SyntaxTree {.type = "Block", .source = $first_chunk.source} + SyntaxTree {.type = "Block", .source = $first_chunk.source} + ] + + for $j in 1 to ($i - 1): + $chunk1.$j = $first_chunk.$j + + for $j in $i to (size of $first_chunk): + $chunk2.($j - $i + 1) = $first_chunk.$j + + $new_tree = + SyntaxTree {.source = $tree.source, .type = "FileChunks"} $chunk1 $chunk2 + + for $i in 2 to (size of $tree): + $new_tree.($i + 1) = $tree.$i + + return $new_tree diff --git a/lib/compatibility/4.11.nom b/lib/compatibility/4.11.nom new file mode 100644 index 0000000..24dbbdc --- /dev/null +++ b/lib/compatibility/4.11.nom @@ -0,0 +1,97 @@ +#!/usr/bin/env nomsu -V6.14 +# + This file defines upgrades from Nomsu <4.11 to Nomsu 4.11 + (overhaul of function literals, deleting (if all of ...), etc. shorthand) + +use "compatibility/compatibility" + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Overhaul of function literals: +upgrade action "call 1 with" to "4.11" via + for ($tree $end_version): + $tree2 = {.type = "Action", .source = $tree.source, .1 = $tree.2} + for $arg in $tree.4 at $i: + $tree2.($i + 1) = $arg + return (SyntaxTree $tree2) +upgrade action (-> $yield_value) to "4.11" as (yield $yield_value) + +# Replace set {$x:1, $y:2} with [$x, $y] = [1, 2] +upgrade action "set" to "4.11" via + for ($tree $end_version): + [$lhs, $rhs] = [\[], \[]] + $lhs.source = $tree.2.source + $rhs.source = $tree.2.source + for $entry in $tree.2 at $i: + $lhs.$i = $entry.1 + $rhs.$i = $entry.2 + + return + SyntaxTree {.type = "Action", .source = $tree.source} $lhs "=" $rhs + +upgrade action "1 with 2 ~>" to "4.11" via + for $tree: + compile error at $tree "This method has been deprecated." + "Perhaps this could be use ($tree, map ...) instead." + +# Changing filesystem API: +upgrade action (for file $f in $path $body) to "4.11" as + for $f in (files for $path) $body + +upgrade action ($expr for file $f in $path) to "4.11" as + [: for $f in (files for $path): add $expr] + +upgrade action (line $n in $text) to "4.11" as ($text, line $n) +upgrade action (line number of $pos in $text) to "4.11" as + $text, line number at $pos + +# Deduplicating goto labels: +upgrade action [=== $label ===, *** $label ***] to "4.11" as (--- $label ---) +upgrade action [===stop $label ===, ***stop $label ***] to "4.11" as + ---stop $label --- + +upgrade action [===next $label ===, ***next $label ***] to "4.11" as + ---next $label --- + +# Deprecating shorthand functions: +upgrade action [if all of $items $body, if all of $items then $body] to "4.11" as + if (all of $items) $body + +upgrade action [unless all of $items $body, unless all of $items then $body] to +.."4.11" as (if (not (all of $items)) $body) + +upgrade action [if any of $items $body, if any of $items then $body] to "4.11" as + if (any of $items) $body + +upgrade action [unless any of $items $body, unless any of $items then $body] to +.."4.11" as (if (not (any of $items)) $body) + +upgrade action [if none of $items $body, if none of $items then $body] to "4.11" +..as (if (not (any of $items)) $body) + +upgrade action [unless none of $items $body, unless none of $items then $body] to +.."4.11" as (if (any of $items) $body) + +upgrade action [ + if all of $items $body else $else, if all of $items then $body else $else +] to "4.11" as (if (all of $items) $body else $else) + +upgrade action [ + unless all of $items $body else $else, unless all of $items then $body else $else +] to "4.11" as (if (not (all of $items)) $body else $else) + +upgrade action [ + if any of $items $body else $else, if any of $items then $body else $else +] to "4.11" as (if (any of $items) $body else $else) + +upgrade action [ + unless any of $items $body else $else, unless any of $items then $body else $else +] to "4.11" as (if (not (any of $items)) $body else $else) + +upgrade action [ + if none of $items $body else $else, if none of $items then $body else $else +] to "4.11" as (if (not (any of $items)) $body else $else) + +upgrade action [ + unless none of $items $body else $else, unless none of $items then $body else $else +] to "4.11" as (if (any of $items) $body else $else) diff --git a/lib/compatibility/4.12.nom b/lib/compatibility/4.12.nom new file mode 100644 index 0000000..a76e7df --- /dev/null +++ b/lib/compatibility/4.12.nom @@ -0,0 +1,18 @@ +#!/usr/bin/env nomsu -V6.14 +# + This file defines upgrades from Nomsu <4.11 to Nomsu 4.11 + (overhaul of function literals, deleting (if all of ...), etc. shorthand) + +use "compatibility/compatibility" + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +upgrade action "do next repeat" to "4.12" via + for $tree: + compile error at $tree "This method has been deprecated." + "Use either (do next) or (go to (label)) instead." + +upgrade action "stop repeating" to "4.12" via + for $tree: + compile error at $tree "This method has been deprecated." + "Use either (stop) or (go to (label)) instead." diff --git a/lib/compatibility/4.8.10.nom b/lib/compatibility/4.8.10.nom new file mode 100644 index 0000000..250dc4a --- /dev/null +++ b/lib/compatibility/4.8.10.nom @@ -0,0 +1,68 @@ +#!/usr/bin/env nomsu -V6.14 +# + This file defines upgrades from Nomsu <4.8.10 to 4.8.10 (renaming "action" -> "means") +use "compatibility/compatibility" + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +upgrade action "local action" to "4.8.10" via + for ($tree $end_version): + $spec = $tree.3 + $body = $tree.4 + if $spec.type is: + "List": + if ((size of $spec) == 1): + return \($spec.1 means $body) + ..else: + return \($spec all mean $body) + + else: + return \($spec means $body) + +upgrade action "action" to "4.8.10" via + for ($tree $end_version): + $spec = $tree.2 + $body = $tree.3 + 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" to "4.8.10" via + for ($tree $end_version): + $spec = $tree.2 + $body = $tree.4 + if $spec.type is: + "List": + if ((size of $spec) == 1): + return \($spec.1 compiles to $body) + ..else: + return \($spec all compile to $body) + + else: + return \($spec compiles to $body) + +upgrade action "parse 1 as" to "4.8.10" via + for ($tree $end_version): + $spec = $tree.2 + $body = $tree.4 + if $spec.type is: + "List": + if ((size of $spec) == 1): + return \($spec.1 parses as $body) + ..else: + return \($spec all parse as $body) + + else: + return \($spec parse as $body) + +upgrade action (compile as $) to "4.8.10" as (what $ compiles to) +upgrade action (remove action $) to "4.8.10" as (($'s meaning) = (nil)) diff --git a/lib/compatibility/4.9.nom b/lib/compatibility/4.9.nom new file mode 100644 index 0000000..14b5dd6 --- /dev/null +++ b/lib/compatibility/4.9.nom @@ -0,0 +1,11 @@ +#!/usr/bin/env nomsu -V6.14 +# + This file defines upgrades from Nomsu <4.9 to 4.9 +use "compatibility/compatibility" + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +upgrade action "if" to "4.9" via + for ($tree $end_version): + if ((size of $tree) > 2): return $tree + return \(when $tree.2) diff --git a/lib/compatibility/5.13.nom b/lib/compatibility/5.13.nom new file mode 100644 index 0000000..1e0db6d --- /dev/null +++ b/lib/compatibility/5.13.nom @@ -0,0 +1,24 @@ +#!/usr/bin/env nomsu -V5.13 +# + This file defines upgrades from Nomsu <5.13 to 5.13 +use "compatibility/compatibility" + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +upgrade action (size of $) to "5.13" as (#$) + +upgrade action "with" to "5.13" via (..) + for $tree: + $assignments = $tree.2 + $body = $tree.3 + if ($assignments.type != "Dict"): + return $tree + $new_assignments = \[] + for $a in $assignments at $i: + when: + (($a.type == "DictEntry") and ((#$a) == 1)): + $a = $a.1 + (all of [$a.type == "DictEntry", (#$a) == 2]): + $a = \($a.1 = $a.2) + $new_assignments.$i = $a + return \(with $new_assignments $body) diff --git a/lib/compatibility/6.14.nom b/lib/compatibility/6.14.nom new file mode 100644 index 0000000..8443157 --- /dev/null +++ b/lib/compatibility/6.14.nom @@ -0,0 +1,41 @@ +#!/usr/bin/env nomsu -V6.14 +# + This file defines upgrades from Nomsu <6.14 to 6.14 +use "compatibility/compatibility" + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +upgrade action + try $action and if it succeeds $success or if it barfs $msg $fallback +..to "6.14" as (try $action if it succeeds $success if it fails $msg $fallback) + +upgrade action + try $action and if it barfs $msg $fallback or if it succeeds $success +..to "6.14" as (try $action if it fails $msg $fallback if it succeeds $success) + +upgrade action (try $action and if it barfs $fallback or if it succeeds $success) +..to "6.14" as (try $action if it fails $fallback if it succeeds $success) + +upgrade action (try $action and if it barfs $msg $fallback) to "6.14" as + try $action if it fails $msg $fallback + +upgrade action (try $action and if it succeeds $success) to "6.14" as + try $action if it succeeds $success + +upgrade action (assume $assumption or barf $err) to "6.14" as + unless $assumption: fail $err + +upgrade action (barf $msg) to "6.14" as (fail $msg) + +upgrade action (\(1's meaning)).stub to "6.14" via + $tree -> (SyntaxTree {.source = $tree.source, .type = "Var", $tree.1}) + +upgrade action (log base $b of $n) to "6.14" as (log $n base $b) + +upgrade action "use" to "6.14" via + for $tree: + $path = $tree.2.1 + $path = ($path, with "%.nom$" -> "") + $path = ($path, with "^lib/" -> "") + return \(use (SyntaxTree {.source = $tree.2.source, .type="Text"} $path)) + diff --git a/lib/compatibility/compatibility.nom b/lib/compatibility/compatibility.nom new file mode 100644 index 0000000..444be11 --- /dev/null +++ b/lib/compatibility/compatibility.nom @@ -0,0 +1,132 @@ +#!/usr/bin/env nomsu -V6.14 +# + This file contains code for defining ways to upgrade code between different versions + of Nomsu. + +use "filesystem" + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +$UPGRADES = {} +externally (upgrade to $version via $upgrade_fn) means: + $UPGRADES.$version = $upgrade_fn +$ACTION_UPGRADES = ({} with fallback $ -> {}) +externally (upgrade action $stub to $version via $upgrade_fn) means: + $ACTION_UPGRADES.$version.$stub = $upgrade_fn + +(upgrade $tree to $version as $body) parses as + upgrade to $version via (($ $end_version) -> ($ with $tree -> $body)) + +(upgrade action $actions to $version as $body) compiles to: + if ($actions is "Action" syntax tree): + $actions = \[$actions] + $lua = (Lua "") + for $action in $actions: + $replacements = {} + for $i in 1 to (size of $action): + if ($action.$i is "Var" syntax tree): + $replacements.($action.$i.1) = "\(\$tree as lua id)[\$i]" + define mangler + (make tree $t) means: + when: + ($t is "Var" syntax tree): + if $replacements.($t.1): + return $replacements.($t.1) + ..else: + external $needs_mangle = (yes) + return (" + SyntaxTree{type=\(quote $t.type), source=\(quote "\($t.source)"), \(quote (mangle $t.1))} + ") + + ($t is syntax tree): + $args = [] + for $k = $v in $t: + if ((type of $k) == "number"): + $args, add (make tree $v) + ..else: + $args, add "\($k)=\(make tree $v)" + return "SyntaxTree{\($args, joined with ", ")}" + + else: + return (quote $t) + + unless ("\$lua" == ""): + $lua, add "\n" + + $retval = (make tree $body) + $lua, add + Lua (" + upgrade_action_1_to_2_via(\(quote $action.stub), \($version as lua expr), function(\ + ..\(\$tree as lua id)) + return \$retval + end) + ") + return $lua + +externally [ + $tree upgraded from $start_version to $end_version + $tree upgraded to $end_version from $start_version +] all mean: + unless ($tree is syntax tree): return $tree + + ($ver as list) means (($ as number) for $ in $ver matching "[0-9]+") + + (Ver $) means: + [$lib, $ver] = ($, match "(.*)/([0-9.]+)") + if $lib: + return {.lib = $lib, .version = ($ver as list)} + return {.version = ($ as list)} + + $start = (Ver $start_version) + $end = (Ver $end_version) + assume $start.lib == $end.lib + + $seen = {} + $versions = {} + for $v = $ in $UPGRADES: $versions.$v = (yes) + for $v = $ in $ACTION_UPGRADES: $versions.$v = (yes) + $versions = [ + :for $v = $ in $versions: + if ((Ver $v).lib == $start.lib): + add $v + ] + + sort $versions by $ -> ($ as list) + for $ver in $versions: + if (($ver as list) <= $start.version): do next $ver + if (($ver as list) > $end.version): stop $ver + if $ACTION_UPGRADES.$ver: + $tree = + $tree with $ ->: + if (($ is "Action" syntax tree) and $ACTION_UPGRADES.$ver.($.stub)): + $with_upgraded_args = { + : for $k = $v in $: + add $k = ($v upgraded from $start_version to $end_version) + } + set $with_upgraded_args's metatable to ($'s metatable) + return ($ACTION_UPGRADES.$ver.($.stub) $with_upgraded_args $end_version) + + if $UPGRADES.$ver: + $with_upgraded_args = { + : for $k = $v in $tree: + add $k = ($v upgraded from $start_version to $end_version) + } + set $with_upgraded_args's metatable to ($tree's metatable) + $tree = ($UPGRADES.$ver $with_upgraded_args $end_version) + + if ($tree.version != $end_version): + $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" + + return $tree + +externally ($tree upgraded from $start_version) means + $tree upgraded from $start_version to (Nomsu version) + +externally ($tree upgraded to $end_version) means + $tree upgraded from ($tree.version or (Nomsu version)) to $end_version + +externally ($tree upgraded) means + $tree upgraded from ($tree.version or (Nomsu version)) to (Nomsu version) diff --git a/lib/compatibility/init.nom b/lib/compatibility/init.nom new file mode 100644 index 0000000..40cafff --- /dev/null +++ b/lib/compatibility/init.nom @@ -0,0 +1,19 @@ +#!/usr/bin/env nomsu -V6.14.13.8 +export "compatibility/compatibility" +export "compatibility/2" +export "compatibility/2.3" +export "compatibility/2.4" +export "compatibility/2.5" +export "compatibility/2.5.5.5" +export "compatibility/3" +export "compatibility/3.5.5.6" +export "compatibility/3.6" +export "compatibility/3.7" +export "compatibility/3.8" +export "compatibility/4.8.10" +export "compatibility/4.9" +export "compatibility/4.10.12.7" +export "compatibility/4.11" +export "compatibility/4.12" +export "compatibility/5.13" +export "compatibility/6.14" -- cgit v1.2.3