lang enhancements.
h3rald h3rald@h3rald.com
Sat, 17 Sep 2016 16:58:42 +0200
2 files changed,
21 insertions(+),
4 deletions(-)
M
lib/min_lang.nim
→
lib/min_lang.nim
@@ -107,7 +107,15 @@ i.reqQuotation code
code.filename = i.filename i.unquote("<module>", code) i.scope.symbols[name.getString] = MinOperator(kind: minValOp, val: @[code].newVal) - + + .symbol("scope?") do (i: In): + var q: MinValue + i.reqQuotation q + if not q.scope.isNil: + i.push true.newVal + else: + i.push false.newVal + .symbol("import") do (i: In): var mdl, rawName: MinValue var name: string@@ -173,9 +181,12 @@ .symbol("inspect") do (i: In):
var scope: MinValue i.reqQuotation scope var symbols = newSeq[MinValue](0) - for s in scope.scope.symbols.keys: - symbols.add s.newVal - i.push symbols.newVal + if scope.scope.isNil: + i.push symbols.newVal + else: + for s in scope.scope.symbols.keys: + symbols.add s.newVal + i.push symbols.newVal # ("SomeError" "message") .symbol("raise") do (i: In):
M
tests/lang.min
→
tests/lang.min
@@ -37,6 +37,12 @@ ) :defmod
(defmod symbols "mymath" contains) assert + (defmod mymath scope?) assert + + (() scope? false ==) assert + + (() inspect () ==) assert + (defmod 'mymath import symbols "myplus" contains) assert (defmod 'mymath import 2 3 myplus 5 ==) assert