all repos — min @ 802092c1abaea2ae7433164f644c75390722df76

A small but practical concatenative programming language.

Additional fixes.
h3rald h3rald@h3rald.com
Sun, 12 Aug 2018 13:00:42 +0200
commit

802092c1abaea2ae7433164f644c75390722df76

parent

d002e94452f4120988b0b9d60159c1415219592f

2 files changed, 30 insertions(+), 2 deletions(-)

jump to
M core/interpreter.nimcore/interpreter.nim

@@ -151,11 +151,22 @@ i.trace = i2.trace

raise return i2.stack[0] -proc applyDict*(i: In, val: MinValue): MinValue {.gcsafe, extern:"min_exported_symbol_$1".}= +proc copyDict*(i: In, val: MinValue): MinValue {.gcsafe, extern:"min_exported_symbol_$1".}= # Assuming val is a dictionary var v = newDict(i.scope) for item in val.scope.symbols.pairs: v.scope.symbols[item.key] = item.val + for item in val.scope.sigils.pairs: + v.scope.sigils[item.key] = item.val + if not val.objType.isNil: + v.objType = val.objType + if not val.obj.isNil: + v.obj = val.obj + return v + +proc applyDict*(i: In, val: MinValue): MinValue {.gcsafe, extern:"min_exported_symbol_$1".}= + # Assuming val is a dictionary + var v = i.copyDict(val) for item in v.dVal.pairs: var value = item.val.val v.scope.symbols[item.key] = MinOperator(kind: minValOp, val: i.callValue(value), sealed: false)

@@ -216,6 +227,10 @@ i.apply(i.scope.getSigil(sigil))

else: raiseUndefined("Undefined symbol '$1'" % [val.symVal]) discard i.trace.pop + elif val.kind == minDictionary and val.objType != "module": + # Dictionary must be copied every time they are interpreted, otherwise when they are used in cycles they reference each other. + var v = i.copyDict(val) + i.stack.add(v) else: i.stack.add(val)
M tests/dict.mintests/dict.min

@@ -9,7 +9,7 @@ ({1 :a 2 :b 3 :c} dictionary?) assert

({1 :a 2 :b 3 :c} 'b dget 2 ==) assert - ({1 :a 2 :b 3 :c} :dict1 dict1 5 'b dset 7 %d :newdict newdict {1 :a 5 :b 3 :c 7 :d} == dict1 newdict == and) assert + ({1 :a 2 :b 3 :c} :dict1 dict1 5 'b dset 7 %d :newdict newdict {1 :a 5 :b 3 :c 7 :d} == dict1 newdict != and) assert ({1 :a 2 :b 3 :c} :dict1 dict1 ddup 5 'b dset 7 %d :newdict newdict {1 :a 5 :b 3 :c 7 :d} == dict1 {1 :a 2 :b 3 :c} == and) assert

@@ -33,6 +33,19 @@ :article

article /a :code {code :code} => archives swap code dset @archives + ) foreach + archives {{"a" :code} :a {"aa" :code} :aa {"aaa" :code} :aaa} ==) assert + + ( + {} :archives + ({"a" :a 2 :b} {"aa" :a 4 :b} {"aaa" :a 6 :b}) + ( + :article + article /a :code + {} + code %code + :archive + archives archive code dset @archives ) foreach archives {{"a" :code} :a {"aa" :code} :aa {"aaa" :code} :aaa} ==) assert