feat(scope): Started to implement support for scopes.
h3rald h3rald@h3rald.com
Fri, 20 May 2016 22:11:10 +0200
2 files changed,
25 insertions(+),
1 deletions(-)
M
core/interpreter.nim
→
core/interpreter.nim
@@ -1,5 +1,9 @@
import streams, strutils, critbits -import types, parser, ../vendor/linenoise +import + types, + parser, + scope, + ../vendor/linenoise const ERRORS: array [MinError, string] = [ "A system error occurred",
A
core/scope.nim
@@ -0,0 +1,20 @@
+import critbits, strutils +import + types + + +proc lookupSymbol*(scope: ref MinScope, key: string): MinOperator = + if scope.symbols.hasKey(key): + return scope.symbols[key] + elif scope.parent != nil: + return scope.parent.lookupSymbol(key) + +proc lookupSigil*(scope: ref MinScope, key: string): MinOperator = + if scope.sigils.hasKey(key): + return scope.sigils[key] + elif scope.parent != nil: + return scope.parent.lookupSigil(key) + +proc lookupLocal*(scope: ref MinScope, key: string): MinValue = + if scope.locals.hasKey(key): + return scope.locals[key]