aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-04-18 16:25:42 +0000
committers-ol <s-ol@users.noreply.github.com>2020-04-18 16:25:42 +0000
commit80d568c025bb5b5cf0e3e9b4b7a8a191f71095bc (patch)
tree6e19e2c9084a6ba18c240019bbfc2c721a1a20a6
parentoutput to different streams at eval/runtime (diff)
downloadalive-80d568c025bb5b5cf0e3e9b4b7a8a191f71095bc.tar.gz
alive-80d568c025bb5b5cf0e3e9b4b7a8a191f71095bc.zip
reassign duplicate tags (and print a warning)
Close #14
-rw-r--r--alv/registry.moon29
-rw-r--r--alv/tag.moon19
2 files changed, 22 insertions, 26 deletions
diff --git a/alv/registry.moon b/alv/registry.moon
index c41e684..a39a1d7 100644
--- a/alv/registry.moon
+++ b/alv/registry.moon
@@ -17,22 +17,22 @@ class Registry
--- set the current registration.
--
- -- @tparam string\number index the registration index
+ -- @tparam Tag tag the Tag to register
-- @tparam any expr the registration value
-- @tparam[default=false] boolean ignore_dup ignore duplicate registrations
- register: (index, expr, ignore_dup=false) =>
- L\trace "reg: setting #{index} to #{expr}"
- if not ignore_dup and @map[index]
- error Error 'tag', "duplicate tags [#{index}]!"
- @map[index] = expr
-
- --- request identity and registration for blank tag.
- --
- -- @tparam Tag tag the blank tag
- -- @tparam any expr the registration value
- init: (tag, expr) =>
- L\trace "reg: init pending to #{expr}"
- table.insert @pending, { :tag, :expr }
+ register: (tag, expr, ignore_dup=false) =>
+ index = tag\index!
+
+ if index and (not @map[index] or ignore_dup)
+ L\trace "reg: setting #{index} to #{expr}"
+ @map[index] = expr
+ else
+ if index
+ L\warn "duplicate tag [#{index}], reassigning repeated occurance"
+ tag\set nil
+ else
+ L\trace "reg: init #{tag} to #{expr}"
+ table.insert @pending, { :tag, :expr }
--- members
-- @section members
@@ -45,7 +45,6 @@ class Registry
-- All calls go `begin_eval` must be matched with either a call to
-- `end_eval` or `rollback_eval`.
begin_eval: =>
- @latest_map = @last_map
@begin_tick!
@map, @pending = {}, {}
diff --git a/alv/tag.moon b/alv/tag.moon
index 904cd20..d7becab 100644
--- a/alv/tag.moon
+++ b/alv/tag.moon
@@ -37,11 +37,7 @@ class Tag
-- Will mark blank tags for auto-assignment at the end of the eval cycle.
--
-- @tparam any expr the value to register
- register: (expr) =>
- if index = @index!
- Registry.active!\register index, expr
- else
- Registry.active!\init @, expr
+ register: (expr) => Registry.active!\register @, expr
--- create a copy of this tag scoped to a `parent` tag.
--
@@ -52,10 +48,7 @@ class Tag
clone: (parent) =>
-- ensure this tag is registered for the current eval cycle,
-- even if it is blank and has no associated value
- if index = @index!
- Registry.active!\register index, dummy, true
- else
- Registry.active!\init @, dummy
+ Registry.active!\register @, dummy, true
assert parent, "need parent to clone!"
ClonedTag @, parent
@@ -77,9 +70,13 @@ class Tag
index: => @value
--- callback to set value for blank tags.
- -- @tparam number value
+ --
+ -- `value` may be blank to reassign duplicate tags.
+ --
+ -- @tparam ?number value
set: (value) =>
- assert not @value, "#{@} is not blank"
+ either_or = (@value or value) and not (@value and value)
+ assert either_or, "unexpected :set #{value} on #{@}"
@value = value
--- static functions