all repos — min @ bd4b5d0ccd875f3f303dd9cfc6142c7fc4840630

A small but practical concatenative programming language.

Implemented with operator.
h3rald h3rald@h3rald.com
Sat, 18 Jun 2016 19:38:57 +0200
commit

bd4b5d0ccd875f3f303dd9cfc6142c7fc4840630

parent

5c59b795fbb3d5b65a7e244e8744a09f3e8465de

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

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

@@ -68,7 +68,7 @@ q.scope = new MinScope

q.scope.name = id q.scope.parent = i.scope -template withScope*(i: In, id: string, q: MinValue, body: stmt): stmt {.immediate.}= +template createScope*(i: In, id: string, q: MinValue, body: stmt): stmt {.immediate.} = q.scope = new MinScope q.scope.name = id q.scope.parent = i.scope

@@ -78,6 +78,14 @@ i.scope = q.scope

body #i.debug "[scope] " & scope.fullname i.scope = scope + +template withScope*(i: In, q: MinValue, body: stmt): stmt {.immediate.} = + #i.debug "[scope] " & q.scope.fullname + let origScope = i.scope + i.scope = q.scope + body + #i.debug "[scope] " & scope.fullname + i.scope = origScope proc copystack*(i: MinInterpreter): MinStack = var s = newSeq[MinValue](0)

@@ -196,7 +204,7 @@ val = i.parser.parseMinValue

i.push val proc unquote*(i: In, name: string, q: var MinValue) = - i.withScope(name, q): + i.createScope(name, q): for v in q.qVal: i.push v
M lib/min_lang.nimlib/min_lang.nim

@@ -135,6 +135,13 @@ if not file.endsWith(".min"):

file = file & ".min" i.load i.pwd.joinPath(file) + .symbol("with") do (i: In): + var qscope, qprog: Minvalue + i.reqTwoQuotations qscope, qprog + i.unquote("<with-scope>", qscope) + i.withScope(qscope): + i.unquote("<with-program>", qprog) + .symbol("call") do (i: In): var symbols, target: MinValue i.reqTwoQuotations symbols, target
M lib/prelude.minlib/prelude.min

@@ -84,3 +84,4 @@ ((ipv6 stream tcp) socket) :tcp6-socket

((ipv4 dgram tcp) socket) :udp-socket ((ipv6 dgram tcp) socket) :udp6-socket +
M tests/lang.mintests/lang.min

@@ -3,7 +3,7 @@ #test

"lang" describe - (symbols size 178 ==) assert + (symbols size 179 ==) assert (sigils size 10 ==) assert

@@ -116,6 +116,8 @@ (8 factorial)

(12 factorial) (9 factorial) ) ->> (40320 479001600 362880) ==) assert + + ((a b +) (4 :a 5 :b) with 9 ==) assert report ; Tidy up