Merged stack module into lang module.
h3rald h3rald@h3rald.com
Sun, 11 Sep 2016 12:49:28 +0200
7 files changed,
44 insertions(+),
77 deletions(-)
M
lib/min_lang.nim
→
lib/min_lang.nim
@@ -106,9 +106,6 @@ i.reqStringLike name
i.reqQuotation code code.filename = i.filename i.unquote("<module>", code) - #let p = proc(i: In) = - # i.push code - #i.scope.symbols[name.getString] = MinOperator(kind: minProcOp, prc: p) i.scope.symbols[name.getString] = MinOperator(kind: minValOp, val: @[code].newVal) .symbol("import") do (i: In):@@ -132,10 +129,6 @@ var symbol = q1.qVal[0].symVal
if symbol.len == 1: if i.scope.hasSigil(symbol): raiseInvalid("Sigil '$1' already exists" % [symbol]) - #let p = proc(i: In) = - # i.evaluating = true - # i.push q2.qVal - # i.evaluating = false i.scope.sigils[symbol] = MinOperator(kind: minValOp, val: q2) else: raiseInvalid("A sigil can only have one character")@@ -227,8 +220,41 @@ i.unquote("<try-catch>", catch)
finally: if hasFinally: i.unquote("<try-finally>", final) - + # Operations on the whole stack + + .symbol("id") do (i: In): + discard + + .symbol("pop") do (i: In): + if i.stack.len < 1: + raiseEmptyStack() + discard i.pop + + .symbol("dup") do (i: In): + i.push i.peek + + .symbol("dip") do (i: In): + var q: MinValue + i.reqQuotation q + let v = i.pop + i.unquote("<dip>", q) + i.push v + + .symbol("swap") do (i: In): + if i.stack.len < 2: + raiseEmptyStack() + let a = i.pop + let b = i.pop + i.push a + i.push b + + .symbol("sip") do (i: In): + var a, b: MinValue + i.reqTwoQuotations a, b + i.push b + i.unquote("<sip>", a) + i.push b .symbol("clear-stack") do (i: In): while i.stack.len > 0:
D
lib/min_stack.nim
@@ -1,48 +0,0 @@
-import tables -import - ../core/types, - ../core/parser, - ../core/interpreter, - ../core/utils - - # Common stack operations - - -proc stack_module*(i: In) = - i.define("stack") - - .symbol("id") do (i: In): - discard - - .symbol("pop") do (i: In): - if i.stack.len < 1: - raiseEmptyStack() - discard i.pop - - .symbol("dup") do (i: In): - i.push i.peek - - .symbol("dip") do (i: In): - var q: MinValue - i.reqQuotation q - let v = i.pop - i.unquote("<dip>", q) - i.push v - - .symbol("swap") do (i: In): - if i.stack.len < 2: - raiseEmptyStack() - let a = i.pop - let b = i.pop - i.push a - i.push b - - .symbol("sip") do (i: In): - var a, b: MinValue - i.reqTwoQuotations a, b - i.push b - i.unquote("<sip>", a) - i.push b - - .finalize() -
M
prelude.min
→
prelude.min
@@ -3,7 +3,6 @@ 'str import
'io import 'logic import 'num import -'stack import 'sys import 'time import 'fs import
M
tests/all.min
→
tests/all.min
@@ -2,7 +2,6 @@ 'lang load
'io load 'logic load 'num load -'stack load 'str load 'sys load 'time load
M
tests/lang.min
→
tests/lang.min
@@ -8,6 +8,16 @@ " Total Sigils: " print! sigils size put!
(debug? false ==) assert + (1 id 1 ==) assert + + (1 pop get-stack () ==) assert + + (1 dup get-stack (1 1) ==) assert + + (3 2 (1 +) dip + 6 ==) assert + + ((1) (2 swap append) sip concat (1 2 1) ==) assert + (2 'a define (3 a + (5 'a define a) -> +) -> a + 12 ==) assert
D
tests/stack.min
@@ -1,17 +0,0 @@
-'test load -'test import - -"stack" describe - - (1 id 1 ==) assert - - (1 pop get-stack () ==) assert - - (1 dup get-stack (1 1) ==) assert - - (3 2 (1 +) dip + 6 ==) assert - - ((1) (2 swap append) sip concat (1 2 1) ==) assert - - report - clear-stack