Added checks for swap and pop operators
h3rald h3rald@h3rald.com
Sun, 26 Jun 2016 22:19:52 +0200
4 files changed,
8 insertions(+),
3 deletions(-)
M
core/utils.nim
→
core/utils.nim
@@ -66,6 +66,9 @@
proc raiseRuntime*(msg: string, qVal: var seq[MinValue]) = raise MinRuntimeError(msg: msg, qVal: qVal) +proc raiseEmptyStack*() = + raise MinEmptyStackError(msg: "Insufficient items on the stack") + proc getString*(v: MinValue): string = if v.isSymbol: return v.symVal
M
lib/min_stack.nim
→
lib/min_stack.nim
@@ -13,6 +13,8 @@ .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):@@ -26,6 +28,8 @@ 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
M
lib/prelude.min
→
lib/prelude.min
@@ -50,7 +50,6 @@ 'filter :select
'clear :empty 'cons :prepend 'size :length -'swap :<> ; Mathematical Operators (1 +) :succ@@ -81,7 +80,6 @@ (print pop) :print!
(put pop) :put! (:ms :q :check (check) (ms sleep q) while) :interval (call pop) :call! -(swap pop) :<!> ; Socket constructors ((ipv4 stream tcp) ^socket) :tcp-socket
M
tests/lang.min
→
tests/lang.min
@@ -7,7 +7,7 @@
"Total Symbols: " print! symbols size put! " Total Sigils: " print! sigils size put! - (symbols size 182 ==) assert + (symbols size 180 ==) assert (sigils size 12 ==) assert