diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2021-04-09 16:41:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-09 16:41:49 +0200 |
commit | 1822ed384abdbbb5d385b1ad24e23e66936dbf74 (patch) | |
tree | 272e9c20bd9464867ec25cba060468a671dacbe0 | |
parent | 8aa5991beaa01f25a90d4115ed2495c92221f603 (diff) | |
download | Nim-1822ed384abdbbb5d385b1ad24e23e66936dbf74.tar.gz |
IC: added converter test case (#17688)
* IC: added converter test case * IC: make converter example work
-rw-r--r-- | compiler/importer.nim | 9 | ||||
-rw-r--r-- | compiler/modulegraphs.nim | 4 | ||||
-rw-r--r-- | tests/ic/mdefconverter.nim | 2 | ||||
-rw-r--r-- | tests/ic/tconverter.nim | 18 |
4 files changed, 30 insertions, 3 deletions
diff --git a/compiler/importer.nim b/compiler/importer.nim index cb529795a..f8ee0d483 100644 --- a/compiler/importer.nim +++ b/compiler/importer.nim @@ -163,14 +163,17 @@ proc addImport(c: PContext; im: sink ImportedModule) = c.imports.add im 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: + loadPackedSym(c.graph, 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: + loadPackedSym(c.graph, 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: + loadPackedSym(c.graph, it) importPureEnumFields(c, it.sym, it.sym.typ) proc importAllSymbolsExcept(c: PContext, fromMod: PSym, exceptSet: IntSet) = diff --git a/compiler/modulegraphs.nim b/compiler/modulegraphs.nim index 4430e3baa..02c745018 100644 --- a/compiler/modulegraphs.nim +++ b/compiler/modulegraphs.nim @@ -326,6 +326,10 @@ proc loadCompilerProc*(g: ModuleGraph; name: string): PSym = strTableAdd(g.compilerprocs, 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 = toBase64a(cast[cstring](unsafeAddr u), sizeof(u)) diff --git a/tests/ic/mdefconverter.nim b/tests/ic/mdefconverter.nim new file mode 100644 index 000000000..d0a23f801 --- /dev/null +++ b/tests/ic/mdefconverter.nim @@ -0,0 +1,2 @@ + +converter toBool*(x: int): bool = x != 0 diff --git a/tests/ic/tconverter.nim b/tests/ic/tconverter.nim new file mode 100644 index 000000000..aecdf4b48 --- /dev/null +++ b/tests/ic/tconverter.nim @@ -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" |