diff options
Diffstat (limited to 'compiler/vmconv.nim')
-rw-r--r-- | compiler/vmconv.nim | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/compiler/vmconv.nim b/compiler/vmconv.nim index 7db3906c2..45d925df0 100644 --- a/compiler/vmconv.nim +++ b/compiler/vmconv.nim @@ -1,4 +1,7 @@ -import ast +import ast except elementType +import idents, lineinfos, astalgo +import vmdef +import std/times template elementType*(T: typedesc): typedesc = typeof(block: @@ -14,7 +17,7 @@ proc fromLit*(a: PNode, T: typedesc): auto = for ai in a: result.incl Ti(ai.intVal) else: - static: doAssert false, "not yet supported: " & $T # add as needed + static: raiseAssert "not yet supported: " & $T # add as needed proc toLit*[T](a: T): PNode = ## generic type => PNode @@ -28,6 +31,10 @@ proc toLit*[T](a: T): PNode = elif T is tuple: result = newTree(nkTupleConstr) for ai in fields(a): result.add toLit(ai) + elif T is seq: + result = newNode(nkBracket) + for ai in a: + result.add toLit(ai) elif T is object: result = newTree(nkObjConstr) result.add(newNode(nkEmpty)) @@ -37,5 +44,14 @@ proc toLit*[T](a: T): PNode = reti.add ai.toLit result.add reti else: - static: doAssert false, "not yet supported: " & $T # add as needed + static: raiseAssert "not yet supported: " & $T # add as needed +proc toTimeLit*(a: Time, c: PCtx, obj: PNode, info: TLineInfo): PNode = + # probably refactor it into `toLit` in the future + result = newTree(nkObjConstr) + result.add(newNode(nkEmpty)) # can be changed to a symbol according to PType + for k, ai in fieldPairs(a): + let reti = newNode(nkExprColonExpr) + reti.add newSymNode(lookupInRecord(obj, getIdent(c.cache, k)), info) + reti.add ai.toLit + result.add reti |