all repos — min @ bfeb9ac8f8ebeed7f4986babbb1019c8d4be5c7f

A small but practical concatenative programming language.

Added internal symbols on socket scopes.
h3rald h3rald@h3rald.com
Sat, 18 Jun 2016 14:55:06 +0200
commit

bfeb9ac8f8ebeed7f4986babbb1019c8d4be5c7f

parent

edf32d56aee2790df0584d1a8099b1c1e454a4d2

2 files changed, 23 insertions(+), 3 deletions(-)

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

@@ -63,7 +63,12 @@ proc debug*(i: In, value: string) =

if i.debugging: stderr.writeLine("-- " & value) -template newScope*(i: In, id: string, q: MinValue, body: stmt): stmt {.immediate.}= +proc newScope*(i: In, id: string, q: var MinValue) = + 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.}= q.scope = new MinScope q.scope.name = id q.scope.parent = i.scope

@@ -178,7 +183,7 @@ val = i.parser.parseMinValue

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

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

-import net, nativesockets, strutils +import net, nativesockets, strutils, critbits import ../core/types, ../core/parser,

@@ -46,6 +46,13 @@ protocol = IPPROTO_UDP

var socket = newSocket(domain, sockettype, protocol) q.objType = "socket" q.obj = socket[].addr + i.newScope("<socket>", q) + q.scope.symbols["protocol"] = proc (i:In) = + i.push vals[2].symVal.newVal + q.scope.symbols["type"] = proc (i:In) = + i.push vals[1].symVal.newVal + q.scope.symbols["domain"] = proc (i:In) = + i.push vals[0].symVal.newVal i.push @[q] .symbol("tcp-socket") do (i: In):

@@ -73,6 +80,10 @@ var socket = q.to(Socket)

socket.bindAddr(Port(port.intVal)) q.qVal.add "0.0.0.0".newSym q.qVal.add port + q.scope.symbols["address"] = proc (i:In) = + i.push "0.0.0.0".newVal + q.scope.symbols["port"] = proc (i:In) = + i.push port socket.listen() i.push @[q]

@@ -98,6 +109,10 @@ i.reqObject "socket", q

q.to(Socket).connect(address.strVal, Port(port.intVal)) q.qVal.add address.strVal.newSym q.qVal.add port + q.scope.symbols["client-address"] = proc (i:In) = + i.push address.strVal.newVal + q.scope.symbols["client-port"] = proc (i:In) = + i.push port i.push @[q] .symbol("send") do (i: In):