all repos — min @ 7a905b94e3f5077698fd515c64b265b07c4b866e

A small but practical concatenative programming language.

test(scope) Testing scope extension.
h3rald h3rald@h3rald.com
Fri, 03 Jun 2016 10:50:32 +0200
commit

7a905b94e3f5077698fd515c64b265b07c4b866e

parent

b480a47a8322a4c927749e793fc3725c4821f566

4 files changed, 18 insertions(+), 21 deletions(-)

jump to
M lib/lang.nimlib/lang.nim

@@ -76,7 +76,6 @@ # echo "BIND $1 - fn: $2" % [symbol, i.filename]

# q1.filename = i.filename # Save filename for diagnostic purposes let res = i.scope.setSymbol(symbol) do (i: In): #i.evaluating = true - let fn = i.filename #if not q1.filename.isNil: # i.filename = q1.filename #echo "BIND '$1' FN: $2" % [symbol, i.filename]

@@ -94,28 +93,21 @@ let res = i.scope.delSymbol(sym.getString)

if not res: i.error errRuntime, "Attempting to delete undefined symbol: " & sym.getString - .symbol("module") do (i: In): - let name = i.pop + .symbol("scope") do (i: In): var code = i.pop - if not name.isString or not code.isQuotation: - i.error(errIncorrect, "A string and a quotation are require on the stack") + if not code.isQuotation: + i.error errNoQuotation return - let id = name.strVal - let scope = i.scope - let stack = i.copystack code.filename = i.filename - i.unquote(id, code) - let p = proc(i: In) = - i.evaluating = true - i.push code - i.evaluating = false - i.scope.symbols[id] = p - i.stack = stack + i.unquote("<scope>", code) + i.push @[code].newVal .symbol("import") do (i: In): var mdl: MinValue + var name: string try: - i.scope.getSymbol(i.pop.strVal)(i) + name = i.pop.strVal + i.scope.getSymbol(name)(i) mdl = i.pop except: echo getCurrentExceptionMsg()
M lib/prelude.minlib/prelude.min

@@ -16,14 +16,12 @@ (delete) (~) sigil

(getenv) ($) sigil (system) (!) sigil (run) (&) sigil -(module) (=) sigil (load) (@) sigil (":" split call) (%) sigil ; Aliases 'define :: 'bind :. -'module := 'import :# 'exit :quit '== :eq

@@ -42,6 +40,7 @@ 'quote :'

'unquote :i 'unquote :apply 'unquote :-> +'scope :=> 'filter :select 'clear :empty 'cons :prepend
M tests/lang.mintests/lang.min

@@ -5,7 +5,7 @@ "lang" describe

(symbols size 156 ==) assert - (sigils size 11 ==) assert + (sigils size 10 ==) assert (debug? false ==) assert

@@ -23,12 +23,18 @@

( ( (+) :myplus - ) =mymath + ) => :mymath ) :defmod (defmod symbols "mymath" contains) assert (defmod #mymath 2 3 myplus 5 ==) assert + + ; Extend an existing scope + (defmod + (#mymath + (-) :myminus) => .mymath + 5 2 %mymath:myminus 3 ==) assert ((":mysigil" concat) ', sigil ,test "test:mysigil" ==) assert
M tests/test.mintests/test.min

@@ -50,4 +50,4 @@ )

map ) :report -) =test +) => :test