diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-02-10 14:52:20 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2020-02-10 14:52:20 +0000 |
| commit | c0ab54600e29a2b8ba318df8c9b76e89897db7fe (patch) | |
| tree | e6608dcb131429ae1d606156d5e5897a3962e74b | |
| parent | reorganization (diff) | |
| download | alive-c0ab54600e29a2b8ba318df8c9b76e89897db7fe.tar.gz alive-c0ab54600e29a2b8ba318df8c9b76e89897db7fe.zip | |
finally implement function diffing
| -rw-r--r-- | core/cell.moon | 11 | ||||
| -rw-r--r-- | core/const.moon | 2 | ||||
| -rw-r--r-- | core/init.moon | 2 | ||||
| -rw-r--r-- | core/invoke.moon | 2 | ||||
| -rw-r--r-- | init.moon | 1 | ||||
| -rw-r--r-- | lib/builtin.moon | 1 | ||||
| -rw-r--r-- | registry.moon | 8 | ||||
| -rw-r--r-- | spec/registry_spec.moon | 2 |
8 files changed, 25 insertions, 4 deletions
diff --git a/core/cell.moon b/core/cell.moon index 199c4c3..1a25c0a 100644 --- a/core/cell.moon +++ b/core/cell.moon @@ -30,8 +30,14 @@ class Cell action\eval scope, @tail! quote: (scope, registry) => - tag = registry\register @, @tag 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 + + clone: (prefix) => + tag = Const.sym prefix\getc! .. @tag\getc! + children = [child\clone prefix for child in *@children] Cell tag, children, @white stringify: (depth=-1) => @@ -82,4 +88,7 @@ class RootCell extends Cell buf + @parse: (...) => + @__parent.parse @, (Const.num 0), ... + :Cell, :RootCell diff --git a/core/const.moon b/core/const.moon index 564ab53..e1d19d9 100644 --- a/core/const.moon +++ b/core/const.moon @@ -53,6 +53,8 @@ class Const stringify: => @raw + clone: (prefix) => Const @type, @value, @raw + -- static __tostring: => value = if @type == 'opdef' or @type == 'builtin' then @value.__name else @value diff --git a/core/init.moon b/core/init.moon index 713f326..ed385fe 100644 --- a/core/init.moon +++ b/core/init.moon @@ -1,3 +1,5 @@ +L or= setmetatable {}, __index: => -> + import Op, Action from require 'core.base' import Const, load_ from require 'core.const' diff --git a/core/invoke.moon b/core/invoke.moon index 78c40a2..6458f2b 100644 --- a/core/invoke.moon +++ b/core/invoke.moon @@ -58,6 +58,8 @@ class fn_invoke extends Action argm = tail[i] fn_scope\set name, L\push argm\eval, scope, @registry + body = body\clone @tag + body\eval fn_scope, @registry class do_expr extends Action @@ -25,6 +25,7 @@ delta = do if last target, current = (last + period), monotime! if current > target + print current, target L\warn 'Frame Skipped!' else sleep target - current diff --git a/lib/builtin.moon b/lib/builtin.moon index b4d6dc7..f6cde1a 100644 --- a/lib/builtin.moon +++ b/lib/builtin.moon @@ -82,7 +82,6 @@ class fn extends Action assert #tail == 2, "'fn' takes exactly two arguments" { params, body } = tail - assert params.__class == Cell, "'fn's first argument has to be an expression" param_symbols = for param in *params.children assert param.type == 'sym', "function parameter declaration has to be a symbol" diff --git a/registry.moon b/registry.moon index 51fa187..7c03e1b 100644 --- a/registry.moon +++ b/registry.moon @@ -19,11 +19,15 @@ class Registry register: (expr, tag) => tag or= @gentag! - @map[tag\getc 'num'] = expr + L\trace "registering #{expr} for tag #{tag}" + num = tag\getc! + if old = @map[num] + error "double registration: #{num}\n(old: #{old}, new: #{expr})" + @map[num] = expr tag prev: (tag) => - @prev_map[tag\getc 'num'] + @prev_map[tag\getc!] gentag: => num = (math.max #@map, #@prev_map) + 1 diff --git a/spec/registry_spec.moon b/spec/registry_spec.moon index de79744..8fdfdb9 100644 --- a/spec/registry_spec.moon +++ b/spec/registry_spec.moon @@ -1,5 +1,7 @@ import Registry from require 'registry' import Const from require 'core' +import Logger from require 'logger' +Logger.init 'silent' mk = -> mock destroy: => |
