all repos — min @ f31fbc321013683fb8c723ef79dff9fbf9d535e5

A small but practical concatenative programming language.

feat(scope): Started to implement support for scopes.
h3rald h3rald@h3rald.com
Fri, 20 May 2016 22:11:10 +0200
commit

f31fbc321013683fb8c723ef79dff9fbf9d535e5

parent

8bddc431d3ce4113641ff4bb0d32de6086e468f4

2 files changed, 25 insertions(+), 1 deletions(-)

jump to
M core/interpreter.nimcore/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]