aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-07-18 01:04:16 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-07-18 01:04:57 -0700
commitc7c657d38f999901225b33482ef3a15994526feb (patch)
treea4c2b843b31bd7d573a479b43512bf8dec99187b
parent88df5c72a317cc011f221627a2c3082078237cc1 (diff)
Prep work for next big upgrade, including adding a shorthand for
upgrading actions similarly to 'parse % as %'
-rw-r--r--compatibility/compatibility.nom90
-rw-r--r--core/collections.nom3
-rw-r--r--core/metaprogramming.nom2
3 files changed, 69 insertions, 26 deletions
diff --git a/compatibility/compatibility.nom b/compatibility/compatibility.nom
index 303c05b..1e68f35 100644
--- a/compatibility/compatibility.nom
+++ b/compatibility/compatibility.nom
@@ -1,38 +1,78 @@
-#!/usr/bin/env nomsu -V1
+#!/usr/bin/env nomsu -V2.2.4.3
use "core"
use "lib/os.nom"
%UPGRADES <- {}
-
-action [upgrade to %version via %upgrade_fn]
+action [upgrade to %version via %upgrade_fn]:
%UPGRADES.%version <- %upgrade_fn
-parse [upgrade %tree to %version as %body] as
+%ACTION_UPGRADES <- {}
+action [upgrade action %stub to %version via %upgrade_fn]:
+ unless (%ACTION_UPGRADES.%version): %ACTION_UPGRADES.%version <- []
+ %ACTION_UPGRADES.%version.%stub <- %upgrade_fn
+
+parse [upgrade %tree to %version as %body] as (..)
upgrade to %version via ([%] -> (% with %tree -> %body))
-action [%tree upgraded from %start_version to %end_version, %tree upgraded to %end_version from %start_version]
- local action [%ver as list]
- (% as number) for % where %ver matches "[0-9]+"
+compile [upgrade action %action to %version as %body] to:
+ %replacements <- {}
+ for %i in 1 to (length of %action):
+ if (%action.%i.type is "Var"):
+ %replacements.(%action.%i.1) <- "\(\%tree as lua id)[\%i]"
+ local action [make tree %t]:
+ when:
+ * (%t is "Var" syntax tree):
+ if (%replacements.(%t.1)):
+ return %replacements.(%t.1)
+ ..else:
+ return "\(%t.type)(\(quote "\(%t.source)"), \(quote "\(%t.1) \0\(=lua "string.format('%X', __MANGLE_INDEX)")"))"
+ * (%t is syntax tree):
+ %args <- ((make tree %) for % in %t)
+ add "\(\%tree as lua id).source" to %args at index 1
+ return "\(%t.type)(\(%args joined with ", "))"
+ *else: return (quote "\%t")
+ return (..)
+ Lua ".."
+ A_upgrade_action_1_to_2_via_3(\(quote %action.stub), \(%version as lua expr), function(\(\%tree as lua id))
+ __MANGLE_INDEX = (__MANGLE_INDEX or 0) + 1
+ return \(make tree %body)
+ end)
+
+action [..]
+ %tree upgraded from %start_version to %end_version
+ %tree upgraded to %end_version from %start_version
+..:
+ local action [%ver as list] ((% as number) for % where %ver matches "[0-9]+")
+ %versions <- {}
+ for %v = % in %UPGRADES: %versions.%v <- (yes)
+ for %v = % in %ACTION_UPGRADES: %versions.%v <- (yes)
+ %versions <- ((keys in %versions) sorted by % -> (% as list))
+ 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:
+ %tree <- (..)
+ %tree with % -> (..)
+ if ((% is "Action" syntax tree) and %ACTION_UPGRADES.%ver.(%.stub)):
+ return (call %ACTION_UPGRADES.%ver.(%.stub) with [%])
+ if %UPGRADES.%ver:
+ %tree <- (call %UPGRADES.%ver with [%tree])
- %versions <-: (keys in %UPGRADES) sorted by % -> (% as list)
- 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
- %tree <- (call %UPGRADES.%ver with [%tree])
return %tree
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-parse [%tree upgraded from %start_version] as: %tree upgraded from %start_version to (Nomsu version)
-parse [%tree upgraded to %end_version] as: %tree upgraded from %tree.version to %end_version
-parse [%tree upgraded] as: %tree upgraded from %tree.version to (Nomsu version)
-
-action [use %path from version %version]
- for file %filename in %path
- if (=lua "LOADED[\%filename]")
- do next %filename
- %file <-: read file %filename
- %tree <-: parse %file from %filename
- %tree <-: upgrade %tree from %version
+
+parse [%tree upgraded from %start_version] as (..)
+ %tree upgraded from %start_version to (Nomsu version)
+
+parse [%tree upgraded to %end_version] as (..)
+ %tree upgraded from %tree.version to %end_version
+
+parse [%tree upgraded] as (%tree upgraded from %tree.version to (Nomsu version))
+action [use %path from version %version] (..)
+ for file %filename in %path:
+ if (=lua "LOADED[\%filename]"): do next %filename
+ %file <- (read file %filename)
+ %tree <- (parse %file from %filename)
+ %tree <- (upgrade %tree from %version)
run tree %tree
diff --git a/core/collections.nom b/core/collections.nom
index 100781b..d99ae49 100644
--- a/core/collections.nom
+++ b/core/collections.nom
@@ -62,6 +62,9 @@ compile [..]
to %list append %item
..to (Lua "table.insert(\(%list as lua expr), \(%item as lua expr))")
+compile [add %item to %list at index %i] to (..)
+ Lua "table.insert(\(%list as lua expr), \(%i as lua expr), \(%item as lua expr))"
+
compile [pop from %list, remove last from %list] to (..)
Lua value "table.remove(\(%list as lua expr))"
diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom
index f78ab50..c81eb74 100644
--- a/core/metaprogramming.nom
+++ b/core/metaprogramming.nom
@@ -3,7 +3,7 @@
This File contains actions for making actions and compile-time actions and some helper
functions to make that easier.
-lua> "NOMSU_CORE_VERSION = 2"
+lua> "NOMSU_CORE_VERSION = 3"
lua> ".."
nomsu.COMPILE_ACTIONS["% -> %"] = function(nomsu, tree, \%args, \%body)
local lua = LuaCode.Value(tree.source, "function(")