IC: added converter test case (#17688)

* IC: added converter test case

* IC: make converter example work
This commit is contained in:
Andreas Rumpf 2021-04-09 16:41:49 +02:00 • committed by GitHub
commit 1822ed384a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 3 deletions

View file

@ -163,14 +163,17 @@ proc addImport(c: PContext; im: sink ImportedModule) =
c.imports.add im c.imports.add im
template addUnnamedIt(c: PContext, fromMod: PSym; filter: untyped) {.dirty.} = template addUnnamedIt(c: PContext, fromMod: PSym; filter: untyped) {.dirty.} =
for it in c.graph.ifaces[fromMod.position].converters: for it in mitems c.graph.ifaces[fromMod.position].converters:
if filter: if filter:
loadPackedSym(c.graph, it)
addConverter(c, it) addConverter(c, it)
for it in c.graph.ifaces[fromMod.position].patterns: for it in mitems c.graph.ifaces[fromMod.position].patterns:
if filter: if filter:
loadPackedSym(c.graph, it)
addPattern(c, it) addPattern(c, it)
for it in c.graph.ifaces[fromMod.position].pureEnums: for it in mitems c.graph.ifaces[fromMod.position].pureEnums:
if filter: if filter:
loadPackedSym(c.graph, it)
importPureEnumFields(c, it.sym, it.sym.typ) importPureEnumFields(c, it.sym, it.sym.typ)
proc importAllSymbolsExcept(c: PContext, fromMod: PSym, exceptSet: IntSet) = proc importAllSymbolsExcept(c: PContext, fromMod: PSym, exceptSet: IntSet) =

View file

@ -326,6 +326,10 @@ proc loadCompilerProc*(g: ModuleGraph; name: string): PSym =
strTableAdd(g.compilerprocs, result) strTableAdd(g.compilerprocs, result)
return result return result
proc loadPackedSym*(g: ModuleGraph; s: var LazySym) =
if s.sym == nil:
s.sym = loadSymFromId(g.config, g.cache, g.packed, s.id.module, s.id.packed)
proc `$`*(u: SigHash): string = proc `$`*(u: SigHash): string =
toBase64a(cast[cstring](unsafeAddr u), sizeof(u)) toBase64a(cast[cstring](unsafeAddr u), sizeof(u))

View file

@ -0,0 +1,2 @@
converter toBool*(x: int): bool = x != 0

18
tests/ic/tconverter.nim Normal file
View file

@ -0,0 +1,18 @@
discard """
output: "yes"
"""
import mdefconverter
echo "yes"
#!EDIT!#
discard """
output: "converted int to bool"
"""
import mdefconverter
if 4:
echo "converted int to bool"