all repos — min @ 69e704199f863f058128e5375131ec0c2cc6d9a1

A small but practical concatenative programming language.

Implemented to-host
h3rald h3rald@h3rald.com
Fri, 15 Jul 2016 22:16:54 +0200
commit

69e704199f863f058128e5375131ec0c2cc6d9a1

parent

3d1459a90e6ebb13dd9bd60dab55531ab85f36a1

3 files changed, 21 insertions(+), 1 deletions(-)

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

@@ -184,6 +184,12 @@ a = i.pop

if not a.isString: raiseInvalid("A string is required on the stack") +proc reqStringLikeAndQuotation*(i: var MinInterpreter, a, q: var MinValue) = + a = i.pop + 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 reqStringOrQuotation*(i: var MinInterpreter, a: var MinValue) = a = i.pop if not a.isQuotation and not a.isString:
M lib/min_comm.nimlib/min_comm.nim

@@ -1,4 +1,4 @@

-import strutils, critbits +import strutils, critbits, streams import ../core/types, ../core/parser,

@@ -44,5 +44,18 @@ i.push q

.symbol("host") do (i: In): i.push i.link.name.newSym + + .symbol("to-host") do (i: In): + var h, q: MinValue + i.reqStringLikeAndQuotation(h, q) + let host = h.getString + if not i.link.hosts.hasKey(host): + raiseInvalid("Unknown host: " & host) + let res = i.remoteExec(host, $q & " unquote") + echo res + i.open(newStringStream(res), "to-host") + discard i.parser.getToken() + i.interpret() + .finalize()
M lib/prelude.minlib/prelude.min

@@ -22,6 +22,7 @@ (load) (@) sigil

(call) (%) sigil (module) (=) sigil (object) (^) sigil +(to-host) (>) sigil ; Aliases 'define ::