all repos — min @ af33d407898c118f58d7013c428fd3f3c0b3c73a

A small but practical concatenative programming language.

Modified type procs to manage type dictionaries as well.
h3rald h3rald@h3rald.com
Sun, 19 Nov 2017 12:00:36 +0100
commit

af33d407898c118f58d7013c428fd3f3c0b3c73a

parent

3129bdf37f225e90cafec83515c95ae1a70604b4

5 files changed, 37 insertions(+), 3 deletions(-)

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

@@ -595,6 +595,16 @@ if not val.isQuotation or val.qVal.len != 2 or not val.qVal[0].isString:

return false return true +proc isTypedDictionary*(q: MinValue): bool {.extern:"min_exported_symbol_$1".}= + if q.isDictionary: + return not q.objType.isNil + return false + +proc isTypedDictionary*(q: MinValue, t: string): bool {.extern:"min_exported_symbol_$1_2".}= + if q.isTypedDictionary: + return q.objType == t + return false + proc `==`*(a: MinValue, b: MinValue): bool {.extern:"min_exported_symbol_eqeq".}= if not (a.kind == b.kind or (a.isNumber and b.isNumber)): return false

@@ -621,7 +631,12 @@ if item == b.qVal[c]:

c.inc else: return false - return true + if a.objType.isNil and b.objType.isNil: + return true + elif not a.objType.isNil and not b.objType.isNil: + return a.objType == b.objType + else: + return false else: return false else:
M core/utils.nimcore/utils.nim

@@ -207,7 +207,12 @@ raiseInvalid(message(value.typeName))

of "a": discard # any type else: - raiseInvalid("Invalid type description: " & element) + var split = element.split(":") + if split[0] == "dict": + if not value.isTypedDictionary(split[1]): + raiseInvalid(message(value.typeName)) + else: + raiseInvalid("Invalid type description: " & element) valid.add element proc reqQuotationOfQuotations*(i: var MinInterpreter, a: var MinValue) {.extern:"min_exported_symbol_$1".}=
M core/value.nimcore/value.nim

@@ -11,7 +11,12 @@ return "int"

of minFloat: return "float" of minQuotation: - return "quot" + if v.isTypedDictionary: + return "dict:" & v.objType + elif v.isDictionary: + return "dict" + else: + return "quot" of minString: return "string" of minSymbol:
M lib/min_net.nimlib/min_net.nim

@@ -7,6 +7,9 @@ ../core/utils

# Time +proc toSocket(q: MinValue): Socket = + return cast[Socket](q.obj) + proc net_module*(i: In)= let def = i.define()

@@ -56,5 +59,9 @@ skt = i.dset(skt, "protocol".newSym, sProtocol.newVal)

skt.objType = "socket" skt.obj = socket[].addr i.push skt + + def.symbol("socket-close") do (i: In): + let vals = i.expect("dict:socket") + vals[0].toSocket.close() def.finalize("net")
M mindyn.nimmindyn.nim

@@ -145,6 +145,8 @@ proc isNumber*(s: MinValue): bool {.importc, extern:"min_exported_symbol_$1".}

proc isBool*(s: MinValue): bool {.importc, extern:"min_exported_symbol_$1".} proc isStringLike*(s: MinValue): bool {.importc, extern:"min_exported_symbol_$1".} proc isDictionary*(q: MinValue): bool {.importc, extern:"min_exported_symbol_$1".} +proc isTypedDictionary*(q: MinValue): bool {.extern:"min_exported_symbol_$1".}= +proc isTypedDictionary*(q: MinValue, t: string): bool {.extern:"min_exported_symbol_$1_2".}= proc newVal*(s: string): MinValue {.importc, extern:"min_exported_symbol_$1".} proc newVal*(s: cstring): MinValue {.importc, extern:"min_exported_symbol_$1_2".} proc newVal*(q: seq[MinValue], parentScope: ref MinScope): MinValue {.importc, extern:"min_exported_symbol_$1_3".}