diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-03-18 17:50:33 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2020-03-18 18:03:04 +0000 |
| commit | a49382c7b46c7bdf1c105c0783c7bdcd0bb70e4a (patch) | |
| tree | c1f800736e1905514aa913630ee31a720e770c9e /core | |
| parent | docs/internal: add builtins and invoke modules (diff) | |
| download | alive-a49382c7b46c7bdf1c105c0783c7bdcd0bb70e4a.tar.gz alive-a49382c7b46c7bdf1c105c0783c7bdcd0bb70e4a.zip | |
fork ops before eval cycle
Diffstat (limited to 'core')
| -rw-r--r-- | core/base/op.moon | 12 | ||||
| -rw-r--r-- | core/invoke.moon | 4 | ||||
| -rw-r--r-- | core/value.moon | 9 |
3 files changed, 24 insertions, 1 deletions
diff --git a/core/base/op.moon b/core/base/op.moon index f338673..08c47ab 100644 --- a/core/base/op.moon +++ b/core/base/op.moon @@ -19,6 +19,17 @@ class Op -- @treturn iterator iterator over `inputs` all_inputs: => coroutine.wrap -> do_yield @inputs + --- create a mutable copy of this Op. + -- + -- Used to wrap insulate eval-cycles from each other. The copy does not have + -- `inputs` set, since it is expected that this is (re)set in `setup`. + -- + -- @treturn Value + fork: => + with setmetatable {}, getmetatable @ + .state = {k,v for k,v in pairs @state} if @state + .out = @out\fork! if @out + --- `Value` instance representing this Op's computed output value. -- -- Must be set to a `Value` instance once `setup` finishes. Must not change @@ -92,6 +103,7 @@ class Op -- @tparam[opt] string type the type-name for `out` -- @tparam[optchain] any init the initial value for `out` new: (type, init) => + @state = {} if type @out = Value type, init diff --git a/core/invoke.moon b/core/invoke.moon index 8d63962..23207b7 100644 --- a/core/invoke.moon +++ b/core/invoke.moon @@ -13,7 +13,9 @@ import Scope from require 'core.scope' class op_invoke extends Action --- `Action:patch` implementation. patch: (head) => - return true if head == @head + if head == @head + @op = @op\fork! + return true @op\destroy! if @op diff --git a/core/value.moon b/core/value.moon index 0f40ef3..bda6127 100644 --- a/core/value.moon +++ b/core/value.moon @@ -36,6 +36,15 @@ class Value assert type == @type, msg or "#{@} is not a #{type}" if type @value + --- create a mutable copy of this Value. + -- + -- Used to wrap insulate eval-cycles from each other. + -- + -- @treturn Value + fork: => + with Value @type, @value, @raw + .updated = @updated + --- alias for `unwrap`. __call: (...) => @unwrap ... |
