all repos — min @ 3129bdf37f225e90cafec83515c95ae1a70604b4

A small but practical concatenative programming language.

Modified printing procs to support typed dictionaries.
h3rald h3rald@h3rald.com
Sun, 19 Nov 2017 11:35:16 +0100
commit

3129bdf37f225e90cafec83515c95ae1a70604b4

parent

2b8b47f811b7bdb3f2c44f27af06cfbff4fc3be0

5 files changed, 44 insertions(+), 35 deletions(-)

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

@@ -530,6 +530,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

@@ -549,6 +551,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 lib/min_net.nimlib/min_net.nim

@@ -14,46 +14,47 @@

def.symbol("socket") do (i: In): let vals = i.expect "dict" var q = vals[0] - # (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 values = q.qVal - if not ["ipv4", "ipv6"].contains(values[0].symVal): - raiseInvalid("Domain symbol must be 'ipv4' or 'ipv6'") - if not ["stream", "dgram"].contains(values[1].symVal): - raiseInvalid("Type symbol must be 'stream' or 'dgram'") - if not ["tcp", "udp"].contains(values[2].symVal): - raiseInvalid("Protocol symbol must be 'tcp' or 'udp'") + # ((domain ipv4) (type stream) (protocol tcp)) var - domain: Domain - sockettype: SockType - protocol: Protocol - sDomain, sSockType, sProtocol: string - # Process domain - if values[0].symVal == "ipv4": + domain = AF_INET + sockettype = SOCK_STREAM + protocol = IPPROTO_TCP sDomain = "ipv4" - domain = AF_INET - else: - sDomain = "ipv6" - domain = AF_INET6 - if values[1].symVal == "stream": sSockType = "stream" - sockettype = SOCK_STREAM - else: - sSockType = "dgram" - sockettype = SOCK_DGRAM - if values[2].symVal == "tcp": sProtocol = "tcp" - protocol = IPPROTO_TCP - else: - sProtocol = "udp" - protocol = IPPROTO_UDP + if q.dhas("domain".newVal): + sDomain = q.dget("domain".newVal).getString + if (sDomain == "unix"): + domain = AF_UNIX + elif (sDomain == "ipv6"): + domain = AF_INET6 + if q.dhas("type".newVal): + sSockType = q.dget("type".newVal).getString + if (sSockType == "dgram"): + sockettype = SOCK_DGRAM + elif (sSockType == "raw"): + sockettype = SOCK_RAW + elif (sSockType == "seqpacket"): + sockettype = SOCK_SEQPACKET + if q.dhas("protocol".newVal): + sProtocol = q.dget("protocol".newVal).getstring + if (sProtocol == "udp"): + protocol = IPPROTO_UDP + elif (sProtocol == "ipv4"): + protocol = IPPROTO_IP + elif (sProtocol == "ipv6"): + protocol = IPPROTO_IPV6 + elif (sProtocol == "raw"): + protocol = IPPROTO_RAW + elif (sProtocol == "icmp"): + protocol = IPPROTO_ICMP var socket = newSocket(domain, sockettype, protocol) var skt = newSeq[MinValue](0).newVal(i.scope) - i.dset(skt, "domain".newSym, sDomain.newVal) - i.dset(skt, "type".newSym, sSockType.newVal) - i.dset(skt, "protocol".newSym, sProtocol.newVal) + skt = i.dset(skt, "domain".newSym, sDomain.newVal) + skt = i.dset(skt, "type".newSym, sSockType.newVal) + skt = i.dset(skt, "protocol".newSym, sProtocol.newVal) skt.objType = "socket" skt.obj = socket[].addr + i.push skt def.finalize("net")
M min.nimmin.nim

@@ -212,7 +212,11 @@ if res.isQuotation and res.qVal.len > 1:

echo "{$1} -> (" % n for item in res.qVal: echo " " & $item - echo " ".repeat(n.len) & " )" + if res.objType.isNil: + echo " ".repeat(n.len) & " )" + else: + echo " ".repeat(n.len) & " ;" & res.objType + echo " ".repeat(n.len) & " )" else: echo "{$1} -> $2" % [$i.stack.len, $i.stack[i.stack.len - 1]]
M mindyn.nimmindyn.nim

@@ -178,7 +178,6 @@ proc reqQuotationOfSymbols*(i: var MinInterpreter, a: var MinValue) {.importc, extern:"min_exported_symbol_$1".}

proc reqTwoNumbersOrStrings*(i: var MinInterpreter, a, b: var MinValue) {.importc, extern:"min_exported_symbol_$1".} proc reqStringOrQuotation*(i: var MinInterpreter, a: var MinValue) {.importc, extern:"min_exported_symbol_$1".} proc reqTwoQuotationsOrStrings*(i: var MinInterpreter, a, b: var MinValue) {.importc, extern:"min_exported_symbol_$1".} -proc reqTwoSimilarTypesNonSymbol*(i: var MinInterpreter, a, b: var MinValue) {.importc, extern:"min_exported_symbol_$1".} # scope.nim proc copy*(s: ref MinScope): ref MinScope {.importc, extern:"min_exported_symbol_$1".}
M prelude.minprelude.min

@@ -10,3 +10,4 @@ 'time import

'fs import 'crypto import 'math import +'net import