all repos — min @ 6b09ec7405d5cc3332a67e51c5a3e56533b8ec5c

A small but practical concatenative programming language.

Removed net module, removed object support.
h3rald h3rald@h3rald.com
Wed, 24 Aug 2016 20:58:01 +0200
commit

6b09ec7405d5cc3332a67e51c5a3e56533b8ec5c

parent

e1c31d46563379024dd51cfbee9a75124beeeb5e

M core/parser.nimcore/parser.nim

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

@@ -417,8 +415,6 @@ 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.nimcore/types.nim

@@ -35,8 +35,6 @@ of minFloat: floatVal*: BiggestFloat

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 core/utils.nimcore/utils.nim

@@ -31,12 +31,6 @@

proc isStringLike*(s: MinValue): bool = return s.isSymbol or s.isString or (s.isQuotation and s.qVal.len == 1 and s.qVal[0].isSymbol) -proc isObject*(a: MinValue, t: string): bool = - return a.isQuotation and not a.objType.isNil and a.objType == t - -proc isObject*(a: MinValue): bool = - return a.isQuotation and not a.objType.isNil - proc isDictionary*(q: MinValue): bool = if not q.isQuotation: return false

@@ -191,9 +185,14 @@ return %a.intVal

of minFloat: return %a.floatVal of minQuotation: - result = newJArray() - for i in a.qVal: - result.add %i + if a.isDictionary: + result = newJObject() + for i in a.qVal: + result[$i.qVal[0].symVal] = %i.qVal[1] + else: + result = newJArray() + for i in a.qVal: + result.add %i proc fromJson*(json: JsonNode): MinValue = case json.kind:

@@ -389,16 +388,6 @@ a = i.pop

b = i.pop if not ((a.kind == a.kind or (a.isNumber and a.isNumber)) and not a.isSymbol): raiseInvalid("Two non-symbol values of similar type are required on the stack") - -proc reqObject*(i: var MinInterpreter, t: string, a: var MinValue) = - a = i.pop - if not a.isObject(t): - raiseInvalid("An object of type $1 is required on the stack" % [t]) - -proc reqObject*(i: var MinInterpreter, a: var MinValue) = - a = i.pop - if not a.isObject: - raiseInvalid("An object is required on the stack") proc reqDictionary*(i: In, q: var MinValue) = q = i.pop
M lib/min_lang.nimlib/min_lang.nim

@@ -89,7 +89,6 @@ .symbol("scope") do (i: In):

var code: MinValue i.reqQuotation code code.filename = i.filename - code.objType = "scope" i.unquote("<scope>", code) i.push @[code].newVal

@@ -98,30 +97,9 @@ var code, name: MinValue

i.reqStringLike name i.reqQuotation code code.filename = i.filename - code.objType = "module" i.unquote("<module>", code) i.scope.symbols[name.getString] = proc(i: In) = i.push code - - .symbol("object") do (i: In): - var code, t: MinValue - i.reqStringLike t - i.reqQuotation code - code.filename = i.filename - code.objType = t.getString - i.unquote("<object>", code) - i.push code - - .symbol("type") do (i: In): - var obj: MinValue - i.reqObject obj - i.push obj.objType.newVal - - .symbol("defines?") do (i: In): - var obj, s: MinValue - i.reqStringLike s - i.reqObject obj - i.push obj.scope.symbols.hasKey(s.getString).newVal .symbol("import") do (i: In): var mdl, rawName: MinValue

@@ -419,15 +397,6 @@

.symbol("cdel") do (i: In): var s: MinValue cfgDel(s.getString) - - .symbol("members") do (i: In): - var o: MinValue - i.reqObject o - var res = newSeq[MinValue](0) - for sym in o.scope.symbols.keys: - res.add sym.newSym - i.push o - i.push res.newVal .symbol("dget") do (i: In): var d, k: MinValue
M lib/min_logic.nimlib/min_logic.nim

@@ -139,26 +139,8 @@ i.push true.newVal

else: i.push false.newVal - .symbol("object?") do (i: In): - if i.peek.isObject: - i.push true.newVal - else: - i.push false.newVal - .symbol("dictionary?") do (i: In): if i.peek.isDictionary: - i.push true.newVal - else: - i.push false.newVal - - .symbol("module?") do (i: In): - if i.peek.isObject and i.peek.objType == "module": - i.push true.newVal - else: - i.push false.newVal - - .symbol("scope?") do (i: In): - if i.peek.isObject and i.peek.objType == "scope": i.push true.newVal else: i.push false.newVal
D lib/min_net.nim

@@ -1,130 +0,0 @@

-import net, nativesockets, strutils, critbits -import - ../core/types, - ../core/parser, - ../core/interpreter, - ../core/utils - -# Network - -proc net_module*(i: In)= - - i.define("net") - - .symbol("^socket") do (i: In): - 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 - sDomain, sSockType, sProtocol: string - # Process domain - if vals[0].symVal == "ipv4": - sDomain = "ipv4" - domain = AF_INET - else: - sDomain = "ipv6" - domain = AF_INET6 - if vals[1].symVal == "stream": - sSockType = "stream" - sockettype = SOCK_STREAM - else: - sSockType = "dgram" - sockettype = SOCK_DGRAM - if vals[2].symVal == "tcp": - sProtocol = "tcp" - protocol = IPPROTO_TCP - else: - sProtocol = "udp" - protocol = IPPROTO_UDP - var socket = newSocket(domain, sockettype, protocol) - var qs = @[ - @["domain".newSym, sDomain.newVal].newVal, - @["type".newSym, sSockType.newVal].newVal, - @["protocol".newSym, sProtocol.newVal].newVal - ].newVal - qs.objType = "socket" - qs.obj = socket[].addr - i.newScope("<socket>", qs) - - var sAddress: string - var sPort: BiggestInt - - qs.scope - .symbol("close") do (i: In): - qs.to(Socket).close() - - .symbol("listen") do (i: In): - var port: MinValue - i.reqInt port - var socket = qs.to(Socket) - sAddress = "0.0.0.0" - sPort = port.intVal - socket.bindAddr(Port(sPort)) - qs.qVal.add @["address".newSym, sAddress.newVal].newVal - qs.qVal.add @["port".newSym, sPort.newVal].newVal - socket.listen() - i.push qs - - .symbol("accept") do (i: In): - # Open same socket type as server - i.eval "($1 $2 $3) net %^socket" % [sDomain, sSockType, sProtocol] - var clientVal: MinValue - i.reqObject "socket", clientVal - var client = clientVal.to(Socket) - var address = "" - qs.to(Socket).acceptAddr(client, address) - clientVal.qVal.add address.newSym - i.push clientVal - - .symbol("connect") do (i: In): - var address, port: MinValue - i.reqInt port - i.reqStringLike address - qs.to(Socket).connect(address.strVal, Port(port.intVal)) - #var qc = @[ - # @["domain".newSym, sDomain.newVal].newVal, - # @["type".newSym, sSockType.newVal].newVal, - # @["protocol".newSym, sProtocol.newVal].newVal - #].newVal - qs.qVal.add @["address".newSym, address.getString.newVal].newVal - qs.qVal.add @["port".newSym, port].newVal - i.push qs - - .symbol("send") do (i: In): - echo "sending" - var s: MinValue - i.reqString s - qs.to(Socket).send s.strVal - i.push qs - - .symbol("recv") do (i: In): - var size: MinValue - i.reqInt size - var s = "" - discard qs.to(Socket).recv(s, size.intVal.int) - i.push qs - i.push s.newVal - - .symbol("recv-line") do (i: In): - var s = "" - qs.to(Socket).readLine(s) - i.push @[qs] - i.push s.newVal - - .finalize() - - i.push qs - - .finalize()
M lib/prelude.minlib/prelude.min

@@ -8,7 +8,6 @@ #num

#stack #sys #time -#net #comm ; Common sigils

@@ -21,7 +20,6 @@ (run) (&) sigil

(load) (@) sigil (call) (%) sigil (module) (=) sigil -(object) (^) sigil (to-host) (>) sigil (dget) (/) sigil (ddel) (-) sigil

@@ -86,11 +84,3 @@ (put pop) :put!

(:ms :q :check (check) (ms sleep q) while) :interval (call pop) :call! (host print! ":" print! " (OK)" put! ('OK) >* dprint!) :hostcheck - -; Socket constructors -((ipv4 stream tcp) ^socket) :tcp-socket -((ipv6 stream tcp) ^socket) :tcp6-socket -((ipv4 dgram tcp) ^socket) :udp-socket -((ipv6 dgram tcp) ^socket) :udp6-socket - -
M minim.nimminim.nim

@@ -15,7 +15,6 @@ lib/min_logic,

lib/min_time, lib/min_io, lib/min_sys, -# lib/min_net, lib/min_comm const version* = "1.0.0-dev"

@@ -72,7 +71,6 @@ proc stdLib(i: In) =

i.lang_module i.io_module i.logic_module - #i.net_module i.num_module i.stack_module i.str_module
M tests/lang.mintests/lang.min

@@ -110,16 +110,6 @@ ) try 1 ==) assert

((a b +) (4 :a 5 :b) with 9 ==) assert - ((4 :four 5 :five) ^myobject type "myobject" ==) assert - - ((4 :four 7 :seven) ^myobject2 'seven defines?) assert - - ((4 :four 7 :seven) ^myobject2 members (four seven) ==) assert - - (("test" :test) =test1 test1 object?) assert - - (("test" :test) =test2 test2 module?) assert - ("{\"a\": 1, \"b\": 2.3}" from-json ((a 1) (b 2.3)) ==) assert ((1 2 3 "aaa" 'q q true) to-json "[1,2,3,\"aaa\",\";sym:'q\",\";sym:q\",true]" ==) assert