diff options
author | Araq <rumpf_a@web.de> | 2013-08-22 19:28:34 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2013-08-22 19:28:34 +0200 |
commit | cf38d635bf8e94abbc68cca55fd6deb6ebc3da5d (patch) | |
tree | 35d19cdf05ed9eff3cf6732d9d942a87c1df2698 | |
parent | 3940bd5b84ec41f91f784573c0b0e02bfa2f8bc9 (diff) | |
download | Nim-cf38d635bf8e94abbc68cca55fd6deb6ebc3da5d.tar.gz |
implemented opcTypeTrait
-rw-r--r-- | compiler/vm.nim | 6 | ||||
-rw-r--r-- | compiler/vmdeps.nim | 30 | ||||
-rw-r--r-- | compiler/vmgen.nim | 7 |
3 files changed, 26 insertions, 17 deletions
diff --git a/compiler/vm.nim b/compiler/vm.nim index c0ce047ea..e13d91e77 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -833,6 +833,12 @@ proc execute(c: PCtx, start: int) = regs[ra] = newSymNode(newSym(k.TSymKind, name.getIdent, c.module, c.debug[pc])) incl(regs[ra].sym.flags, sfGenSym) + of opcTypeTrait: + # XXX only supports 'name' for now; we can use regC to encode the + # type trait operation + decodeB(nkStrLit) + let typ = regs[rb].sym.typ.skipTypes({tyTypeDesc}) + regs[ra].strVal = typ.typeToString(preferExported) inc pc proc evalStmt*(c: PCtx, n: PNode) = diff --git a/compiler/vmdeps.nim b/compiler/vmdeps.nim index 919cd5f9d..0e90a9b14 100644 --- a/compiler/vmdeps.nim +++ b/compiler/vmdeps.nim @@ -35,6 +35,21 @@ proc opSlurp*(file: string, info: TLineInfo, module: PSym): string = result = "" LocalError(info, errCannotOpenFile, file) +proc opTypeTrait*(n: PNode, context: PSym): PNode = + ## XXX: This should be pretty much guaranteed to be true + # by the type traits procs' signatures, but until the + # code is more mature it doesn't hurt to be extra safe + internalAssert n.len >= 2 and n.sons[1].kind == nkSym + + let typ = n.sons[1].sym.typ.skipTypes({tyTypeDesc}) + case n.sons[0].sym.name.s.normalize + of "name": + result = newStrNode(nkStrLit, typ.typeToString(preferExported)) + result.typ = newType(tyString, context) + result.info = n.info + else: + internalAssert false + when false: proc opExpandToAst*(c: PEvalContext, original: PNode): PNode = var @@ -64,21 +79,6 @@ when false: "ExpandToAst: expanded symbol is no macro or template") result = emptyNode - proc opTypeTrait*(n: PNode, context: PSym): PNode = - ## XXX: This should be pretty much guaranteed to be true - # by the type traits procs' signatures, but until the - # code is more mature it doesn't hurt to be extra safe - internalAssert n.len >= 2 and n.sons[1].kind == nkSym - - let typ = n.sons[1].sym.typ.skipTypes({tyTypeDesc}) - case n.sons[0].sym.name.s.normalize - of "name": - result = newStrNode(nkStrLit, typ.typeToString(preferExported)) - result.typ = newType(tyString, context) - result.info = n.info - else: - internalAssert false - proc opIs*(n: PNode): PNode = InternalAssert n.sonsLen == 3 and n[1].kind == nkSym and n[1].sym.kind == skType and diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index fc356018a..84d82e117 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -699,8 +699,11 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest) = of mExpandToAst: InternalError(n.info, "cannot generate code for: " & $m) of mTypeTrait: - - InternalError(n.info, "cannot generate code for: " & $m) + let tmp = c.genx(n.sons[1]) + if dest < 0: dest = c.getTemp(n.typ) + c.gABx(n, opcSetType, tmp, c.genType(n.sons[1])) + c.gABC(n, opcTypeTrait, dest, tmp) + c.freeTemp(tmp) of mIs: InternalError(n.info, "cannot generate code for: " & $m) of mSlurp: genUnaryABC(c, n, dest, opcSlurp) |