all repos — min @ 0d73c8590831d2b9223b61d5ebc4f39207ad8060

A small but practical concatenative programming language.

Added checks for swap and pop operators
h3rald h3rald@h3rald.com
Sun, 26 Jun 2016 22:19:52 +0200
commit

0d73c8590831d2b9223b61d5ebc4f39207ad8060

parent

b1b5055a1a0fa6fb52d104f396ed58672f5b16ca

4 files changed, 8 insertions(+), 3 deletions(-)

jump to
M core/utils.nimcore/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.nimlib/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.minlib/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.mintests/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