compiler/vmops.nim:
registerCallback c, "stdlib.marshal.toVM", proc(a: VmArgs) =
let typ = a.getNode(0).typ
case typ.kind
of tyInt..tyInt64, tyUInt..tyUInt64:
setResult(a, loadAny(a.getString(1), typ, c.cache, c.config,
c.idgen).intVal)
of tyFloat..tyFloat128:
setResult(a, loadAny(a.getString(1), typ, c.cache, c.config,
c.idgen).floatVal)
else:
setResult(a, loadAny(a.getString(1), typ, c.cache, c.config, c.idgen))
registerCallback c, "stdlib.marshal.loadVM", proc(a: VmArgs) =
let typ = a.getNode(0).typ
let p = a.getReg(1)
var res: string
storeAny(res, typ, regToNode(p[]), c.config)
setResult(a, res)
Run
Needs some error handling I suppose but when I designed this I thought, "who
wants the compilation to continue after illformed JSon that you try to eval at
compile time?" ;-)