feat(net) Started implementing net module.
h3rald h3rald@h3rald.com
Sun, 12 Jun 2016 13:43:22 +0200
12 files changed,
87 insertions(+),
9 deletions(-)
M
core/parser.nim
→
core/parser.nim
@@ -396,6 +396,8 @@ of minQuotation:
var q = "(" for i in a.qVal: q = q & $i & " " + if not a.objType.isNil: + q = q & ";" & a.objType q = q.strip & ")" return q@@ -415,6 +417,8 @@ of minQuotation:
var q = "(" for i in a.qVal: q = q & $i & " " + if not a.objType.isNil: + q = q & ";" & a.objType q = q.strip & ")" return q
M
core/types.nim
→
core/types.nim
@@ -35,6 +35,8 @@ of minFloat: floatVal*: float
of minQuotation: qVal*: seq[MinValue] scope*: ref MinScope + objType*: string + obj*: pointer of minString: strVal*: string of minSymbol: symVal*: string of minBool: boolVal*: bool
M
lib/io.nim
→
lib/min_io.nim
@@ -1,4 +1,4 @@
-import tables, os, strutils +import os, strutils import ../core/types, ../core/parser,
A
lib/min_net.nim
@@ -0,0 +1,71 @@
+import net, nativesockets +import + ../core/types, + ../core/parser, + ../core/interpreter, + ../core/utils + +# Network + +define("net") + + .symbol("open") do (i: In): + echo "all good" + var q: MinValue + i.reqQuotation q + # (ipv4 stream tcp) + if q.qVal.len < 3 or not (q.qVal[0].isSymbol and q.qVal[1].isSymbol and q.qVal[2].isSymbol): + raiseInvalid("Quotation must contain three symbols for <domain> <type> <protocol>") + let vals = q.qVal + if not ["ipv4", "ipv6"].contains(vals[0].symVal): + raiseInvalid("Domain symbol must be 'ipv4' or 'ipv6'") + if not ["stream", "dgram"].contains(vals[1].symVal): + raiseInvalid("Type symbol must be 'stream' or 'dgram'") + if not ["tcp", "udp"].contains(vals[2].symVal): + raiseInvalid("Protocol symbol must be 'tcp' or 'udp'") + var + domain: Domain + sockettype: SockType + protocol: Protocol + # Process domain + if vals[0].symVal == "ipv4": + domain = AF_INET + else: + domain = AF_INET6 + if vals[1].symVal == "stream": + sockettype = SOCK_STREAM + else: + sockettype = SOCK_DGRAM + if vals[2].symVal == "tcp": + protocol = IPPROTO_TCP + else: + protocol = IPPROTO_UDP + var socket = newSocket(domain, sockettype, protocol) + echo "all good" + q.objType = "socket" + q.obj = socket.addr + i.push @[q] + + + .symbol("close") do (i: In): + discard + + .symbol("listen") do (i: In): + discard + + .symbol("accept") do (i: In): + discard + + .symbol("connect") do (i: In): + discard + + .symbol("send") do (i: In): + discard + + .symbol("recv") do (i: In): + discard + + .symbol("bind") do (i: In): + discard + + .finalize()
M
minim.nim
→
minim.nim
@@ -5,14 +5,15 @@ core/interpreter,
core/utils, vendor/linenoise import - lib/lang, - lib/stack, - lib/num, - lib/str, - lib/logic, - lib/time, - lib/io, - lib/sys + lib/min_lang, + lib/min_stack, + lib/min_num, + lib/min_str, + lib/min_logic, + lib/min_time, + lib/min_io, + lib/min_sys, + lib/min_net const version* = "1.0.0-preview" var REPL = false