2018-11-11 15:50:46 -08:00
|
|
|
#!/usr/bin/env nomsu -V4.10.12.7
|
2018-07-23 15:56:59 -07:00
|
|
|
#
|
|
|
|
This file contains code for defining ways to upgrade code between different versions
|
|
|
|
of Nomsu.
|
2018-11-11 15:50:46 -08:00
|
|
|
|
2018-07-17 17:53:07 -07:00
|
|
|
use "lib/os.nom"
|
|
|
|
|
2018-11-08 15:23:22 -08:00
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2018-07-18 01:27:56 -07:00
|
|
|
%UPGRADES = {}
|
2018-10-30 23:42:04 -07:00
|
|
|
externally (upgrade to %version via %upgrade_fn) means:
|
2018-07-18 01:27:56 -07:00
|
|
|
%UPGRADES.%version = %upgrade_fn
|
2018-08-30 14:06:41 -07:00
|
|
|
%ACTION_UPGRADES = ({} with fallback % -> {})
|
2018-10-30 23:42:04 -07:00
|
|
|
externally (upgrade action %stub to %version via %upgrade_fn) means:
|
2018-07-18 01:27:56 -07:00
|
|
|
%ACTION_UPGRADES.%version.%stub = %upgrade_fn
|
2018-07-18 01:04:16 -07:00
|
|
|
|
2018-10-30 23:42:04 -07:00
|
|
|
(upgrade %tree to %version as %body) parses as (..)
|
2018-11-17 14:38:05 -08:00
|
|
|
upgrade to %version via ((% %end_version) -> (% with %tree -> %body))
|
2018-07-17 17:53:07 -07:00
|
|
|
|
2018-10-30 23:42:04 -07:00
|
|
|
(upgrade action %actions to %version as %body) compiles to:
|
2018-07-30 19:39:32 -07:00
|
|
|
if (%actions is "Action" syntax tree):
|
2018-08-30 14:06:41 -07:00
|
|
|
%actions = \[%actions]
|
2018-07-30 19:39:32 -07:00
|
|
|
%lua = (Lua "")
|
|
|
|
for %action in %actions:
|
|
|
|
%replacements = {}
|
2018-08-30 14:06:41 -07:00
|
|
|
for %i in 1 to (size of %action):
|
2018-07-30 19:39:32 -07:00
|
|
|
if (%action.%i.type is "Var"):
|
|
|
|
%replacements.(%action.%i.1) = "\(\%tree as lua id)[\%i]"
|
2018-09-10 16:26:08 -07:00
|
|
|
define mangler
|
2018-10-30 23:42:04 -07:00
|
|
|
(make tree %t) means:
|
2018-07-30 19:39:32 -07:00
|
|
|
when:
|
|
|
|
(%t is "Var" syntax tree):
|
|
|
|
if %replacements.(%t.1):
|
|
|
|
return %replacements.(%t.1)
|
|
|
|
..else:
|
2018-08-30 14:06:41 -07:00
|
|
|
external %needs_mangle = (yes)
|
2018-11-09 17:02:39 -08:00
|
|
|
return "SyntaxTree{type=\(quote %t.type), source=\(quote "\(%t.source)"), \(quote (mangle %t.1))}"
|
2018-07-30 19:39:32 -07:00
|
|
|
|
|
|
|
(%t is syntax tree):
|
2018-08-30 14:06:41 -07:00
|
|
|
%args = []
|
|
|
|
for %k = %v in %t:
|
|
|
|
if ((type of %k) == "number"):
|
|
|
|
%args::add (make tree %v)
|
|
|
|
..else:
|
2018-08-30 14:16:09 -07:00
|
|
|
%args::add "\(%k)=\(make tree %v)"
|
2018-11-09 17:02:39 -08:00
|
|
|
return "SyntaxTree{\(%args::joined with ", ")}"
|
2018-07-30 19:39:32 -07:00
|
|
|
|
2018-11-11 15:50:46 -08:00
|
|
|
else:
|
|
|
|
return (quote %t)
|
|
|
|
|
|
|
|
unless ("\%lua" == ""):
|
|
|
|
%lua::append "\n"
|
2018-07-30 19:39:32 -07:00
|
|
|
|
2018-08-30 14:06:41 -07:00
|
|
|
%retval = (make tree %body)
|
2018-08-29 15:02:36 -07:00
|
|
|
%lua::append (..)
|
2018-09-14 19:17:09 -07:00
|
|
|
Lua "\
|
2018-11-11 15:50:46 -08:00
|
|
|
..upgrade_action_1_to_2_via(\(quote %action.stub), \(%version as lua expr), function(\(\%tree as lua id))
|
2018-09-10 16:26:08 -07:00
|
|
|
return \%retval
|
2018-09-14 19:17:09 -07:00
|
|
|
end)"
|
2018-07-30 19:39:32 -07:00
|
|
|
return %lua
|
2018-07-18 01:04:16 -07:00
|
|
|
|
2018-10-30 23:42:04 -07:00
|
|
|
externally [..]
|
2018-07-18 01:04:16 -07:00
|
|
|
%tree upgraded from %start_version to %end_version
|
|
|
|
%tree upgraded to %end_version from %start_version
|
2018-10-30 23:42:04 -07:00
|
|
|
..all mean:
|
|
|
|
unless (%tree is syntax tree): return %tree
|
|
|
|
(%ver as list) means ((% as number) for % in %ver matching "[0-9]+")
|
2018-07-18 01:27:56 -07:00
|
|
|
%versions = {}
|
2018-07-20 20:27:15 -07:00
|
|
|
for %v = % in %UPGRADES:
|
|
|
|
%versions.%v = (yes)
|
2018-11-11 15:50:46 -08:00
|
|
|
|
2018-07-20 20:27:15 -07:00
|
|
|
for %v = % in %ACTION_UPGRADES:
|
|
|
|
%versions.%v = (yes)
|
2018-11-11 15:50:46 -08:00
|
|
|
|
2018-07-18 01:27:56 -07:00
|
|
|
%versions = ((keys in %versions) sorted by % -> (% as list))
|
2018-07-18 01:04:16 -07:00
|
|
|
for %ver in %versions:
|
|
|
|
if ((%ver as list) <= (%start_version as list)): do next %ver
|
|
|
|
if ((%ver as list) > (%end_version as list)): stop %ver
|
|
|
|
if %ACTION_UPGRADES.%ver:
|
2018-07-18 01:27:56 -07:00
|
|
|
%tree = (..)
|
2018-11-09 16:40:36 -08:00
|
|
|
%tree with % ->:
|
2018-07-18 01:04:16 -07:00
|
|
|
if ((% is "Action" syntax tree) and %ACTION_UPGRADES.%ver.(%.stub)):
|
2018-11-11 15:50:46 -08:00
|
|
|
%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)
|
2018-07-20 20:27:15 -07:00
|
|
|
|
2018-07-18 01:04:16 -07:00
|
|
|
if %UPGRADES.%ver:
|
2018-11-11 15:50:46 -08:00
|
|
|
%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)
|
2018-11-17 14:38:05 -08:00
|
|
|
%tree = (%UPGRADES.%ver %with_upgraded_args %end_version)
|
2018-11-11 18:11:17 -08:00
|
|
|
%tree.shebang = "#!/usr/bin/env nomsu -V\%end_version\n"
|
2018-07-17 17:53:07 -07:00
|
|
|
return %tree
|
|
|
|
|
2018-10-30 23:42:04 -07:00
|
|
|
externally (%tree upgraded from %start_version) means (..)
|
2018-07-18 01:04:16 -07:00
|
|
|
%tree upgraded from %start_version to (Nomsu version)
|
|
|
|
|
2018-10-30 23:42:04 -07:00
|
|
|
externally (%tree upgraded to %end_version) means (..)
|
2018-07-20 20:19:07 -07:00
|
|
|
%tree upgraded from (%tree.version or (Nomsu version)) to %end_version
|
2018-07-18 01:04:16 -07:00
|
|
|
|
2018-10-30 23:42:04 -07:00
|
|
|
externally (%tree upgraded) means (..)
|
2018-07-20 20:27:15 -07:00
|
|
|
%tree upgraded from (%tree.version or (Nomsu version)) to (Nomsu version)
|
|
|
|
|
2018-10-30 23:42:04 -07:00
|
|
|
externally (use %path from version %version) means:
|
2018-07-18 01:04:16 -07:00
|
|
|
for file %filename in %path:
|
2018-11-11 15:50:46 -08:00
|
|
|
if (=lua "LOADED[\%filename]"):
|
|
|
|
do next %filename
|
2018-07-18 01:27:56 -07:00
|
|
|
%file = (read file %filename)
|
|
|
|
%tree = (parse %file from %filename)
|
|
|
|
%tree = (upgrade %tree from %version)
|
2018-07-22 15:01:05 -07:00
|
|
|
run tree %tree
|