all repos — min @ 87aae2120723652e324af891a56582ac20a8c162

A small but practical concatenative programming language.

Refactored prelude into .minimrc.
h3rald h3rald@h3rald.com
Fri, 02 Sep 2016 17:37:00 +0200
commit

87aae2120723652e324af891a56582ac20a8c162

parent

45c671a3c03219949c48701cbadae38f75da1e0d

M core/types.nimcore/types.nim

@@ -91,4 +91,6 @@ MinRuntimeError* = ref object of SystemError

qVal*: seq[MinValue] proc isNotNil*[T](obj: T): bool = - return not obj.isNil+ return not obj.isNil + +const version* = "1.0.0-dev"
M core/utils.nimcore/utils.nim

@@ -416,6 +416,12 @@ q = i.pop

if not a.isStringLike or not q.isQuotation: raiseInvalid("A string or symbol and a quotation are required on the stack") +proc reqQuotationAndString*(i: var MinInterpreter, q, a: var MinValue) = + q = i.pop + a = i.pop + if not a.isString or not q.isQuotation: + raiseInvalid("A string and a quotation are required on the stack") + proc reqStringOrQuotation*(i: var MinInterpreter, a: var MinValue) = a = i.pop if not a.isQuotation and not a.isString:

@@ -424,7 +430,7 @@

proc reqStringLike*(i: var MinInterpreter, a: var MinValue) = a = i.pop if not a.isStringLike: - raiseInvalid("A symbol or a string is required on the stack") + raiseInvalid("A quoted symbol or a string is required on the stack") proc reqTwoStrings*(i: var MinInterpreter, a, b: var MinValue) = a = i.pop
M lib/min_lang.nimlib/min_lang.nim

@@ -114,17 +114,6 @@ for sym, val in mdl.scope.symbols.pairs:

i.debug "[import] $1:$2" % [i.scope.name, sym] i.scope.symbols[sym] = val - .sigil("'") do (i: In): - var s: MinValue - i.reqString s - i.push(@[MinValue(kind: minSymbol, symVal: s.strVal)].newVal) - - .sigil("#") do (i: In): - var s: MinValue - i.reqString s - i.push s - i.push "import".newSym - .symbol("sigil") do (i: In): var q1, q2: MinValue i.reqTwoQuotations q1, q2

@@ -429,7 +418,58 @@ i.reqDictionary d

i.push d i.push d.values + .symbol("interpolate") do (i: In): + var s, q: MinValue + i.reqQuotationAndString q, s + var strings = newSeq[string](0) + for el in q.qVal: + if el.isSymbol: + i.push el + strings.add $$i.pop + else: + strings.add $$el + let res = s.strVal % strings + i.push res.newVal + + .symbol("version") do (i: In): + i.push version.newVal + .symbol("clear") do (i: In): linenoiseClearScreen() + + .sigil("'") do (i: In): + var s: MinValue + i.reqString s + i.push(@[s.strVal.newSym].newVal) + + .sigil(":") do (i: In): + i.push("define".newSym) + + .sigil("~") do (i: In): + i.push("delete".newSym) + + .sigil("$") do (i: In): + i.push("getenv".newSym) + + .sigil("!") do (i: In): + i.push("system".newSym) + + .sigil("&") do (i: In): + i.push("run".newSym) + + .sigil("@") do (i: In): + i.push("bind".newSym) + + .sigil("=") do (i: In): + i.push("module".newSym) + + .sigil("%") do (i: In): + i.push("call".newSym) + + .sigil("/") do (i: In): + i.push("dget".newSym) + + .sigil("-") do (i: In): + i.push("ddel".newSym) .finalize()
M lib/prelude.min.minimrc

@@ -1,32 +1,18 @@

; Imports -#str -#io -#logic -#num -#stack -#sys -#time -#fs -#crypto - -; Common sigils -(bind) (.) sigil -(define) (:) sigil -(delete) (~) sigil -(getenv) ($) sigil -(system) (!) sigil -(run) (&) sigil -(load) (@) sigil -(call) (%) sigil -(module) (=) sigil -(dget) (/) sigil -(ddel) (-) sigil +'str import +'io import +'logic import +'num import +'stack import +'sys import +'time import +'fs import +'crypto import ; Aliases 'define :: -'bind :. -'import :# +'bind :@ 'exit :quit '== :eq '!= :noteq

@@ -46,7 +32,6 @@ 'unquote :apply

'unquote :-> 'scope :=> 'filter :select -'clear :empty 'cons :prepend 'size :length

@@ -80,3 +65,6 @@ (dprint pop) :dprint!

(put pop) :put! (:ms :q :check (check) (ms sleep q) while) :interval (call pop) :call! + +"MiNiM Shell v$1" (version) interpolate put! +"-> Type 'exit' or 'quit' to exit." put!
M minim.nimminim.nim

@@ -22,10 +22,9 @@ when USE_LINENOISE:

import vendor/linenoise -const version* = "1.0.0-dev" var REPL = false var DEBUGGING = false -const PRELUDE* = "lib/prelude.min".slurp.strip +const PRELUDE* = ".minimrc".slurp.strip let usage* = " MiNiM v" & version & " - a tiny concatenative programming language" & """

@@ -109,8 +108,6 @@ proc minimRepl*(i: var MinInterpreter) =

i.stdLib() var s = newStringStream("") i.open(s, "") - echo "MiNiM Shell v" & version - echo "-> Type 'exit' or 'quit' to exit." var line: string while true: when USE_LINENOISE:
M tests/all.mintests/all.min

@@ -1,10 +1,10 @@

-@io -@lang -@logic -@num -@stack -@str -@sys -@fs -@crypto -@time +'io load +'lang load +'logic load +'num load +'stack load +'str load +'sys load +'time load +'fs load +'crypto load
M tests/crypto.mintests/crypto.min

@@ -1,5 +1,5 @@

-@test -#test +'test load +'test import "crypto" describe

@@ -20,5 +20,5 @@

("test" "test" aes "test" aes strip "test" ==) assert report - clear + clear-stack "test.txt" rm
M tests/fs.mintests/fs.min

@@ -1,5 +1,5 @@

-@test -#test +'test load +'test import "fs" describe

@@ -16,5 +16,5 @@

("test.txt" fstats 'type dget "file" ==) assert report - clear + clear-stack "test.txt" rm
M tests/io.mintests/io.min

@@ -1,5 +1,5 @@

-@test -#test +'test load +'test import "io" describe

@@ -11,4 +11,4 @@ "test.txt" fread "TEST - TEST" ==) assert

"test.txt" rm report - clear + clear-stack
M tests/lang.mintests/lang.min

@@ -1,6 +1,5 @@

-@test -#test - +'test load +'test import "lang" describe

@@ -28,12 +27,14 @@ ) :defmod

(defmod symbols "mymath" contains) assert - (defmod #mymath 2 3 myplus 5 ==) assert + (defmod 'mymath import symbols "myplus" contains) assert + + (defmod 'mymath import 2 3 myplus 5 ==) assert ; Extend an existing scope (defmod - (#mymath - (-) :myminus) => .mymath + ('mymath import + (-) :myminus) => @mymath 5 2 mymath %myminus 3 ==) assert (defmod mymath inspect ("myplus") ==) assert

@@ -42,7 +43,7 @@ ((":mysigil" concat) ', sigil ,test "test:mysigil" ==) assert

("3 4 +" eval 7 ==) assert - ("2 2 +" "tests/testload.min" fwrite @testload 4 ==) assert + ("2 2 +" "tests/testload.min" fwrite 'testload load 4 ==) assert "tests/testload.min" rm (defmod 2 2 mymath %myplus 4 ==) assert

@@ -79,7 +80,7 @@ ((2 3 >) ("YES") ("NO") ifte "NO" ==) assert

((2 3 <) ("YES") ("NO") ifte "YES" ==) assert (0 :c - (c 10 <) (c succ .c) while + (c 10 <) (c succ @c) while c 10 ==) assert ((1 2 3 4 5) (even?) filter (2 4) ==) assert

@@ -128,7 +129,9 @@ (((a 1)(b 2)(c 3)) keys (a b c) ==) assert

(((a 1)(b 2)(c 3)) values (1 2 3) ==) assert + ("$1 - $2 - $3" (1 true "test") interpolate "1 - true - test" ==) assert + report ; Tidy up ~defmod - clear + clear-stack
M tests/logic.mintests/logic.min

@@ -1,5 +1,5 @@

-@test -#test +'test load +'test import "logic" describe

@@ -133,4 +133,4 @@ (false quotation? false ==) assert

(("a" 2 c) quotation?) assert report - clear + clear-stack
M tests/num.mintests/num.min

@@ -1,5 +1,5 @@

-@test -#test +'test load +'test import "num" describe

@@ -29,4 +29,4 @@ (4 2 mod 0 ==) assert

(-3 2 mod -1 ==) assert report - clear + clear-stack
M tests/stack.mintests/stack.min

@@ -1,5 +1,5 @@

-@test -#test +'test load +'test import "stack" describe

@@ -14,4 +14,4 @@

((1) (2 swap append) sip concat (1 2 1) ==) assert report - clear + clear-stack
M tests/str.mintests/str.min

@@ -1,5 +1,5 @@

-@test -#test +'test load +'test import "str" describe

@@ -22,4 +22,4 @@

("This is a DIFFICULT\n test" "s/difficult/simple/mis" =~ ("This is a simple\n test") ==) assert report - clear + clear-stack
M tests/sys.mintests/sys.min

@@ -1,5 +1,5 @@

-@test -#test +'test load +'test import "sys" describe

@@ -33,5 +33,5 @@

("systest" rmdir pwd ls "systest" contains false ==) assert report - clear + clear-stack "systest" rmdir
M tests/test.mintests/test.min

@@ -17,11 +17,11 @@ ' :check ; save the check quotation to validate

' :results ; save the result symbol to update (check -> true ==) ( - ok results append quote .results + ok results append quote @results "." print! ) ( - check results append quote .results + check results append quote @results "x" print! ) ifte

@@ -35,8 +35,8 @@ ' :results ; save the results collected so far

0 :total 0 :failed results ( - total succ .total - (ok !=) (failed succ .failed) () ifte + total succ @total + (ok !=) (failed succ @failed) () ifte ) map padding total print! " tests executed - " print! failed print! " failed." put! (
M tests/time.mintests/time.min

@@ -1,5 +1,5 @@

-@test -#test +'test load +'test import "time" describe

@@ -14,4 +14,4 @@

(1464951736 timeinfo 'second dget 16 ==) assert report - clear + clear-stack