Fixed module closure capturing problem.
h3rald h3rald@h3rald.com
Mon, 17 Jun 2024 03:39:45 +0000
2 files changed,
12 insertions(+),
4 deletions(-)
M
minpkg/core/interpreter.nim
→
minpkg/core/interpreter.nim
@@ -195,13 +195,14 @@ return v
proc apply*(i: In, op: MinOperator, sym = "") {.effectsOf: op.} = if op.kind == minProcOp: - if not op.mdl.isNil and not op.mdl.scope.isNil: + if not op.mdl.isNil and not op.mdl.scope.isNil and not i.scope.hasParent op.mdl.scope: # Capture closures at module level let origScope = i.scope let origParentScope = i.scope.parent let origMdlParentScope = op.mdl.scope.parent - i.scope.parent = op.mdl.scope - i.scope.parent.parent = origParentScope + i.scope = op.mdl.scope + i.scope.parent = origScope + i.scope.parent.parent = origParentScope op.prc(i) i.scope = origScope i.scope.parent = origParentScope
M
minpkg/core/scope.nim
→
minpkg/core/scope.nim
@@ -1,5 +1,5 @@
import - std/[strutils, critbits, logging, sequtils] + std/[strutils, critbits, logging] import parser@@ -209,3 +209,10 @@ if scope.parent.isNil:
return scope else: return scope.parent + +proc hasParent*(scope: ref MinScope, parent: ref MinScope): bool = + if scope.parent.isNil: + return false + if scope.parent == parent: + return true + return scope.parent.hasParent parent