all repos — min @ 72fe18d527b65e73605c84e3bfce8603b41f9230

A small but practical concatenative programming language.

Implemented JSON interop.
h3rald h3rald@h3rald.com
Sat, 02 Jun 2018 14:51:42 +0200
commit

72fe18d527b65e73605c84e3bfce8603b41f9230

parent

c3ee6627ab5424669b01bc28f355f9a251804b94

2 files changed, 11 insertions(+), 15 deletions(-)

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

@@ -130,10 +130,7 @@ return r.newVal(i.scope)

# JSON interop -proc `%`*(p: MinOperatorProc): JsonNode {.extern:"min_exported_symbol_percent_1".}= - return %nil - -proc `%`*(a: MinValue): JsonNode {.extern:"min_exported_symbol_percent_2".}= +proc `%`*(i: In, a: MinValue): JsonNode {.extern:"min_exported_symbol_percent_2".}= case a.kind: of minBool: return %a.boolVal

@@ -147,12 +144,12 @@ of minFloat:

return %a.floatVal of minQuotation: result = newJArray() - for i in a.qVal: - result.add %i + for it in a.qVal: + result.add(i%it) of minDictionary: result = newJObject() - for i in a.dVal.pairs: - result[$i.key] = %i.val + for it in a.dVal.pairs: + result[it.key] = i%i.dget(a, it.key) proc fromJson*(i: In, json: JsonNode): MinValue {.extern:"min_exported_symbol_$1".}= case json.kind:

@@ -171,11 +168,10 @@ result = sgregex.replace(s, "^;sym:", "").newSym

else: result = json.getStr.newVal of JObject: - var res = newSeq[MinValue](0) + var res = newDict(i.scope) for key, value in json.pairs: - #TODO - res.add @[key.newVal, i.fromJson(value)].newVal(i.scope) - return res.newVal(i.scope) + discard i.dset(res, key, i.fromJson(value)) + return res of JArray: var res = newSeq[MinValue](0) for value in json.items:
M lib/min_lang.nimlib/min_lang.nim

@@ -76,9 +76,9 @@ let s = vals[0]

i.push i.fromJson(s.getString.parseJson) def.symbol("to-json") do (i: In): - let vals = i.expect "quot" + let vals = i.expect "a" let q = vals[0] - i.push(($((%q).pretty)).newVal) + i.push(($((i%q).pretty)).newVal) def.symbol("loglevel") do (i: In): let vals = i.expect("'sym")

@@ -485,7 +485,7 @@ let op = i.scope.getSymbol(sym)

if op.kind == minProcOp: raiseInvalid("Symbol '$1' cannot be serialized." % sym) let json = MINSYMBOLS.readFile.parseJson - json[sym] = %op.val + json[sym] = i%op.val MINSYMBOLS.writeFile(json.pretty) def.symbol("load-symbol") do (i: In):