all repos — min @ 2ab52b22ec2b9240e7367ed25d0e7d0236ac7636

A small but practical concatenative programming language.

Added set-type symbol; added types for errors and timeinfos.
h3rald h3rald@h3rald.com
Sun, 03 Jun 2018 12:41:48 +0200
commit

2ab52b22ec2b9240e7367ed25d0e7d0236ac7636

parent

0755480db9d686d8b9b799428081841566ecc0c2

6 files changed, 16 insertions(+), 6 deletions(-)

jump to
M core/interpreter.nimcore/interpreter.nim

@@ -17,6 +17,7 @@ MinRuntimeError* = ref object of SystemError

data*: MinValue proc raiseRuntime*(msg: string, data: MinValue) {.extern:"min_exported_symbol_$1".}= + data.objType = "error" raise MinRuntimeError(msg: msg, data: data) proc dump*(i: MinInterpreter): string {.extern:"min_exported_symbol_$1".}=
M core/utils.nimcore/utils.nim

@@ -239,9 +239,7 @@ for t in split:

if validate(value, t): res = true break - if res: - valid.add element - else: + if not res: raiseInvalid(message(value.typeName)) elif not validate(value, element): raiseInvalid(message(value.typeName))
M lib/min_lang.nimlib/min_lang.nim

@@ -240,6 +240,13 @@ let sym = i.scope.getSymbol(s)

i.apply(sym) i.scope = origScope + def.symbol("set-type") do (i: In): + let vals = i.expect("'sym", "dict") + let symbol = vals[0] + var d = vals[1] + d.objType = symbol.getString + i.push d + def.symbol("raise") do (i: In): let vals = i.expect("dict") let err = vals[0]

@@ -249,7 +256,7 @@ else:

raiseInvalid("Invalid error dictionary") def.symbol("format-error") do (i: In): - let vals = i.expect("dict") + let vals = i.expect("dict:error") let err = vals[0] if err.dhas("error".newVal) and err.dhas("message".newVal): var msg: string

@@ -302,6 +309,7 @@ return

let e = getCurrentException() var res = newDict(i.scope) let err = sgregex.replace($e.name, ":.+$", "") + res.objType = "error" i.dset(res, "error", err.newVal) i.dset(res, "message", e.msg.newVal) i.dset(res, "symbol", i.currSym)
M lib/min_time.nimlib/min_time.nim

@@ -29,6 +29,7 @@ else:

time = t.floatVal.int64.fromUnix let tinfo = time.local var info = newDict(i.scope) + info.objType = "timeinfo" i.dset info, "year", tinfo.year.newVal i.dset info, "month", (tinfo.month.int+1).newVal i.dset info, "day", tinfo.monthday.newVal

@@ -42,7 +43,7 @@ i.dset info, "timezone", tinfo.utcOffset.newVal

i.push info def.symbol("to-timestamp") do (i: In): - let vals = i.expect("dict") + let vals = i.expect("dict:timeinfo") let dict = vals[0] try: let year = i.dget(dict, "year").intVal.int
M min.vimmin.vim

@@ -11,7 +11,7 @@

setl iskeyword=@,36-39,+,-,*,.,/,:,~,!,48-57,60-65,94-95,192-255 setl iskeyword+=^ -syntax keyword minDefaultSymbol ! != $ & ' * + # - % ^ -> . .. / § : = # < <= == => =~ > >= @ -inf ROOT accept acos aes all? and any? append apply args asin ask atan atime bind bool boolean? call call! capitalize case cd ceil chmod choose clear-stack cleave close column-print concat confirm connect cons cos cosh cp cpu crypto ctime d2r datetime ddel ddup debug decode define defined? delete dequote dequote-and dequote-or dget dhas? dkeys dict dictionary? dip dir? dirname div download dpick dprint dprint! drop dset dup dvalues e encode env? error eval even? exists? exit expect fappend fatal find file? filename filter first flatten float float? floor foreach fperms fread from-json format-error fs fsize fstats ftype fwrite get get-content gets get-env get-stack hardlink harvest hidden? http id if import in? indent indexof inf info insert int integer? interpolate interval io join keep last length linrec listen ln load load-symbol log2 log10 logic loglevel loglevel? lowercase ls ls-r map map-reduce match math md5 mkdir mod module mtime mv nan newline net nip not notice now num number? odd? opts os over parse partition password pi pick pop popd pow pred prepend print print! prompt publish puts puts! put-env q quotation? quote quote-bind quote-define quote-map r2d random randomize raise read recv recv-line reduce regex reject remove remove-symbol repeat replace request rest reverse rm rmdir round run save-symbol scope scope? scope-symbols scope-sigils seal search send seq set set-stack sha1 sha224 sha256 sha384 sha512 shorten sigils sin sinh sip size sleep slice socket sort source split spread sqrt stack start-server startup stop-server stored-symbols str string string? strip succ sum swap swons symbols symlink symlink? sys system take tan tanh tap tap! tau tformat time timeinfo times timestamp titleize to-json to-timestamp try trunc unless substr unseal unzip uppercase version warn when which while with xor zip +syntax keyword minDefaultSymbol ! != $ & ' * + # - % ^ -> . .. / § : = # < <= == => =~ > >= @ -inf ROOT accept acos aes all? and any? append apply args asin ask atan atime bind bool boolean? call call! capitalize case cd ceil chmod choose clear-stack cleave close column-print concat confirm connect cons cos cosh cp cpu crypto ctime d2r datetime ddel ddup debug decode define defined? delete dequote dequote-and dequote-or dget dhas? dkeys dict dictionary? dip dir? dirname div download dpick dprint dprint! drop dset dup dvalues e encode env? error eval even? exists? exit expect fappend fatal find file? filename filter first flatten float float? floor foreach fperms fread from-json format-error fs fsize fstats ftype fwrite get get-content gets get-env get-stack hardlink harvest hidden? http id if import in? indent indexof inf info insert int integer? interpolate interval io join keep last length linrec listen lite? ln load load-symbol log2 log10 logic loglevel loglevel? lowercase ls ls-r map map-reduce match math md5 mkdir mod module mtime mv nan newline net nip not notice now num number? odd? opts os over parse partition password pi pick pop popd pow pred prepend print print! prompt publish puts puts! put-env q quotation? quote quote-bind quote-define quote-map r2d random randomize raise read recv recv-line reduce regex reject remove remove-symbol repeat replace request rest reverse rm rmdir round run save-symbol scope scope? scope-symbols scope-sigils seal search send seq set set-stack set-type sha1 sha224 sha256 sha384 sha512 shorten sigils sin sinh sip size sleep slice socket sort source split spread sqrt stack start-server startup stop-server stored-symbols str string string? strip succ sum swap swons symbols symlink symlink? sys system take tan tanh tap tap! tau tformat time timeinfo times timestamp titleize to-json to-timestamp try trunc type? unless substr unseal unzip uppercase version warn when which while with xor zip syntax match minDefaultSigil ;\<[/:@'~!?$%&$=<>#^*#+]; contained syntax match minQuote ;\<['];
M tests/lang.mintests/lang.min

@@ -213,6 +213,8 @@ ("aaa bbb ccc 2 2 + (2 3 4)" parse (aaa bbb ccc 2 2 + (2 3 4)) ==) assert

(lite? false ==) assert + ({3 :x 5 :y} "point" set-type 'point type?) assert + report ; Tidy up clear-stack