all repos — min @ 568d793dca984d3e6735c9a6845f5fe9a31ec1be

A small but practical concatenative programming language.

Refactoring.
h3rald h3rald@h3rald.com
Sun, 17 Jul 2016 17:15:55 +0200
commit

568d793dca984d3e6735c9a6845f5fe9a31ec1be

parent

a4d2e4d77fe6969229dffae565b085484e1458c1

6 files changed, 42 insertions(+), 28 deletions(-)

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

@@ -201,6 +201,11 @@ i.execute:

val = i.parser.parseMinValue i.push val +#proc interpretString*(i: In, s, ctxname: string) = +# i.open(newStringStream(s), ctxname) +# discard i.parser.getToken() +# i.interpret() + proc unquote*(i: In, name: string, q: var MinValue) = i.createScope(name, q): for v in q.qVal:
M core/server.nimcore/server.nim

@@ -89,13 +89,26 @@ for key, val in i.link.hosts.pairs:

if key != i.link.name: result[key] = i.remoteExec(key, cmd) -proc executeOnHost*(i: var MinInterpreter, host: string, q: MinValue) = +proc checkHost*(link: ref MinLink) = + let host = link.address & ":" & $link.port + try: + link.hosts = cfgGet("hosts").critbit + except: + discard + var name: string + for key, value in link.hosts.pairs: + if host == value: + name = key + break + if not name.isNil: + link.hosts.excl name + link.hosts[link.name] = host + discard link.interpreter.syncHosts() + +proc executeOnHost*(i: var MinInterpreter, host: string, q: MinValue): string = if not i.link.hosts.hasKey(host): raiseInvalid("Unknown host: " & host) - let res = i.remoteExec(host, $q & " unquote") - i.open(newStringStream(res), "remote-exec") - discard i.parser.getToken() - i.interpret() + return i.remoteExec(host, $q & " unquote") proc newMinLink*(name, address: string, port: int, i: var MinInterpreter): ref MinLink = var link: ref MinLink = new MinLink
M lib/min_comm.nimlib/min_comm.nim

@@ -52,14 +52,16 @@ .symbol("to-host") do (i: In):

var h, q: MinValue i.reqStringLikeAndQuotation(h, q) let host = h.getString - i.executeOnHost(host, q) + i.eval i.executeOnHost(host, q) .symbol("to-all-hosts") do (i: In): var q: MinValue i.reqQuotation(q) + var res = "" for host in i.link.hosts.keys: if host != i.link.name: - i.executeOnHost(host, q) + res = res & " " & i.executeOnHost(host, q) + i.eval("($1)" % res) .finalize()
M lib/min_lang.nimlib/min_lang.nim

@@ -456,12 +456,6 @@ for v in d.qVal:

echo "$1: $2" % [$v.qVal[0], $v.qVal[1]] i.push d - .symbol("dprint!") do (i: In): - var d: MinValue - i.reqDictionary d - for v in d.qVal: - echo "$1: $2" % [$v.qVal[0], $v.qVal[1]] - .symbol("keys") do (i: In): var d: MinValue i.reqDictionary d
M lib/prelude.minlib/prelude.min

@@ -80,11 +80,12 @@ ((() cons cons) dip swap i) :bury2

((() cons cons cons) dip swap i) :bury3 ; Other -(print pop) :print! -(put pop) :put! -(:ms :q :check (check) (ms sleep q) while) :interval -(call pop) :call! -(('OK) >*) :linkcheck +(print pop) :print! +(dprint pop) :dprint! +(put pop) :put! +(:ms :q :check (check) (ms sleep q) while) :interval +(call pop) :call! +(host print! ":" print! " (OK)" put! ('OK) >* dprint!) :linkcheck ; Socket constructors ((ipv4 stream tcp) ^socket) :tcp-socket
M minim.nimminim.nim

@@ -112,7 +112,7 @@ proc minimRepl*(i: var MinInterpreter) =

i.stdLib() var s = newStringStream("") i.open(s, "") - echo "MiNiM v"&version&" - REPL initialized." + echo "Terminal initialized." echo "-> Type 'exit' or 'quit' to exit." var line: string while true:

@@ -174,23 +174,22 @@ discard

if not cfgfile().existsFile: cfgfile().writeFile("{}") - + +if REPL or SERVER: + echo "MiNiM v"&version + if s != "": minimString(s, DEBUGGING) elif file != "": minimFile file, DEBUGGING elif SERVER: var i = newMinInterpreter(DEBUGGING) + let host = ADDRESS & ":" & $PORT if HOSTNAME == "": - HOSTNAME = ADDRESS & ":" & $PORT + HOSTNAME = host var link = newMinLink(HOSTNAME, ADDRESS, PORT, i) - # Load hosts - try: - link.hosts = cfgGet("hosts").critbit - except: - discard - link.hosts[HOSTNAME] = ADDRESS & ":" & $PORT - echo "MiNiM v"&version&" - Host '", HOSTNAME,"' started on ", ADDRESS, ":", PORT + i.link.checkHost() + echo "Host '", HOSTNAME,"' started on ", HOSTNAME proc srv(link: ref MinLink) = link.init() runForever()