all repos — min @ 357e64778f62097876a9061c3f02b205f0640ab2

A small but practical concatenative programming language.

Implemented case operator.
h3rald h3rald@h3rald.com
Sun, 02 Oct 2016 14:08:11 +0200
commit

357e64778f62097876a9061c3f02b205f0640ab2

parent

4c0fcf7d4e3ff921a8ea04a1e25aba8191862f28

3 files changed, 42 insertions(+), 2 deletions(-)

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

@@ -506,10 +506,42 @@ var stack = i.copystack

i.unquote("<ifte-check>", check) let res = i.pop i.stack = stack - if res.isBool and res.boolVal == true: + if not res.isBool: + raiseInvalid("Result of check is not a boolean value") + if res.boolVal == true: i.unquote("<ifte-true>", tpath) else: i.unquote("<ifte-false>", fpath) + + # 4 ( + # ((> 3) ("Greater than 3" put!)) + # ((< 3) ("Smaller than 3" put!)) + # ('true ("Exactly 3" put!)) + # ) case + .symbol("case") do (i: In): + var cases: MinValue + i.reqQuotation cases + let last = cases.qVal.len-1 + if last == 0: + raiseInvalid("Empty case operator") + var k = 0 + let stack = i.stack + for c in cases.qVal: + i.stack = stack + if not c.isQuotation: + raiseInvalid("A quotation of quotations is required") + k.inc + if c.qVal.len != 2 or not c.qVal[0].isQuotation or not c.qVal[1].isQuotation: + raiseInvalid("Inner quotations in case operator must contain two quotations") + var q = c.qVal[0] + i.unquote("<case-$1-check>" % $k, q) + let res = i.pop + if not res.isBool(): + raiseInvalid("Result of case #$1 is not a boolean value" % $k) + if res.boolVal == true: + var t = c.qVal[1] + i.unquote("<case-$1-true>" % $k, t) + .symbol("while") do (i: In): var d, b: MinValue
M minim.vimminim.vim

@@ -10,7 +10,7 @@ endif

setl iskeyword+=?,$,+,*,/,%,=,>,<,&,-,',.,:,@,~,! -syntax keyword minimDefaultSymbol ! != $ & ' * + - -> . .. / : < <= == => =~ > >= @ ROOT aes and append apply at atime b bind bool bool? bury1 bury2 bury3 c call call! capitalize cd chmod clear-stack column-print concat cons cp cpu crypto ctime datetime ddel debug debug? decode decrypt define delete dget dictionary? dig1 dig2 dig3 dip dir? dirname div dprint dprint! dset dump-stack dup dupd echo encode encrypt env? eq eval even? exit fappend file? filename filter first float float? foreach fperms fread from-json fs fsize fstats ftype fwrite get get-stack getenv gt gte hardlink hidden? i id ifte import indent inspect int int? interpolate interval io join k keys length linrec load load-symbol logic lowercase ls ls-r lt lte map match md5 mkdir mod module mtime mv newline not noteq now num number? odd? or os password pop popd pred prepend print print! put put! putenv q quit quotation? quote raise regex remove-symbol repeat replace rest rm rmdir run save-symbol scope scope? seal search select set-stack sha1 sha224 sha256 sha384 sha512 sigil sigils sip size sleep source split stored-symbols str string string? strip succ swap swapd swons symbols symlink symlink? sys system take tformat time timeinfo times timestamp titleize to-json try unit unquote uppercase values version which while with xor zap contains +syntax keyword minimDefaultSymbol ! != $ & ' * + - -> . .. / : < <= == => =~ > >= @ ROOT aes and append apply at atime b bind bool bool? bury1 bury2 bury3 c call call! capitalize case cd chmod choose clear-stack column-print concat confirm cons cp cpu crypto ctime datetime ddel debug debug? decode decrypt define delete dget dictionary? dig1 dig2 dig3 dip dir? dirname div dprint dprint! dset dump-stack dup dupd echo encode encrypt env? eq eval even? exit fappend file? filename filter first float float? foreach fperms fread from-json fs fsize fstats ftype fwrite get get-stack getenv gt gte hardlink hidden? i id ifte import indent inspect int int? interpolate interval io join k keys length linrec load load-symbol logic lowercase ls ls-r lt lte map match md5 mkdir mod module mtime mv newline not noteq now num number? odd? or os password pop popd pred prepend print print! prompt put put! putenv q quit quotation? quote raise regex remove-symbol repeat replace rest rm rmdir run save-symbol scope scope? seal search select set-stack sha1 sha224 sha256 sha384 sha512 sigil sigils sip size sleep source split stored-symbols str string string? strip succ swap swapd swons symbols symlink symlink? sys system take tformat time timeinfo times timestamp titleize to-json try unit unquote uppercase values version which while with xor zap contains syntax match minimDefaultSigil ;\<[:@'~!$%&$=<>*]; contained
M tests/lang.mintests/lang.min

@@ -161,6 +161,14 @@ (0 :temp (1 2 3) (temp + @temp) foreach 6 temp ==) assert

('succ source (1 +) ==) assert + (6 + ( + ((3 ==) (false)) + ((3 <) (false)) + ((3 >) (true)) + ) case + ) assert + report ; Tidy up ~defmod