From a49382c7b46c7bdf1c105c0783c7bdcd0bb70e4a Mon Sep 17 00:00:00 2001 From: s-ol Date: Wed, 18 Mar 2020 18:50:33 +0100 Subject: fork ops before eval cycle --- core/base/op.moon | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'core/base') 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 -- cgit v1.2.3