aboutsummaryrefslogtreecommitdiffstats
path: root/core/cell.moon
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-02-11 17:35:26 +0000
committers-ol <s-ol@users.noreply.github.com>2020-02-13 08:39:03 +0000
commit85df7feacac36f5cd058e86ff81b3f4aa9f0ded8 (patch)
treeadf72d8d77016eb8e9d211f256dbdc52d5f14350 /core/cell.moon
parentadd edge and pilot/* (diff)
downloadalive-85df7feacac36f5cd058e86ff81b3f4aa9f0ded8.tar.gz
alive-85df7feacac36f5cd058e86ff81b3f4aa9f0ded8.zip
new Registry tagging mechanism
Diffstat (limited to 'core/cell.moon')
-rw-r--r--core/cell.moon29
1 files changed, 17 insertions, 12 deletions
diff --git a/core/cell.moon b/core/cell.moon
index 8f31f27..65273d8 100644
--- a/core/cell.moon
+++ b/core/cell.moon
@@ -1,5 +1,6 @@
import Const from require 'core.const'
import op_invoke, fn_invoke from require 'core.invoke'
+import Tag from require 'core.registry'
class Cell
-- common
@@ -7,6 +8,9 @@ class Cell
if not @white
@white = ['' for i=1,#@children+1]
+ if not @tag
+ @tag = Tag.blank!
+
head: => @children[1]
tail: => [c for c in *@children[2,]]
@@ -25,21 +29,23 @@ class Cell
when 'builtin'
head\getc!
else
+ print head
+ for k,v in pairs head
+ print k,v
+ print head.__class.__name
error "cannot evaluate expr with head #{head}"
- action = Action\get_or_create head, @tag, registry
- @tag or= action.tag
+ @tag.registry = registry
+ action = Action\get_or_create head, @tag
action\eval scope, @tail!
quote: (scope, registry) =>
children = [child\quote scope, registry for child in *@children]
- with cell = Cell nil, children, @white
- cell.tag = registry\register cell, @tag
- @tag = cell.tag -- for writing back to file
+ Cell @tag, children, @white
- clone: (prefix) =>
- tag = Const.sym prefix\getc! .. '.' .. @tag\getc!
- children = [child\clone prefix for child in *@children]
+ clone: (parent) =>
+ tag = @tag\clone parent
+ children = [child\clone parent for child in *@children]
Cell tag, children, @white
stringify: (depth=-1) =>
@@ -53,10 +59,9 @@ class Cell
buf ..= if depth > 0 then ' ' else @white[i]
if depth > 0
- buf = buf\sub 1, #buf - 1
+ buf = buf\sub 1, #b@uf - 1
- tag = if @tag then "[#{@tag\stringify!}]" else ''
- '(' .. tag .. buf .. ')'
+ '(' .. @tag\stringify! .. buf .. ')'
-- static
__tostring: => @stringify 2
@@ -91,6 +96,6 @@ class RootCell extends Cell
buf
@parse: (...) =>
- @__parent.parse @, (Const.num 0), ...
+ @__parent.parse @, (Tag\parse '0'), ...
:Cell, :RootCell