all repos — min @ 9d4f6657f39a22f29724f1bcebc4a40b5df4a5f8

A small but practical concatenative programming language.

Fixed module closure capturing problem.
h3rald h3rald@h3rald.com
Mon, 17 Jun 2024 03:39:45 +0000
commit

9d4f6657f39a22f29724f1bcebc4a40b5df4a5f8

parent

d5072e01822187654987916594844ffa1dc71493

2 files changed, 12 insertions(+), 4 deletions(-)

jump to
M minpkg/core/interpreter.nimminpkg/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.nimminpkg/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