This commit is contained in:
Araq 2019-05-10 19:50:11 +02:00
commit f03391d477

View file

@ -1575,6 +1575,9 @@ proc genTypeLit(c: PCtx; t: PType; dest: var TDest) =
n.typ = t n.typ = t
genLit(c, n, dest) genLit(c, n, dest)
proc importcCond(s: PSym): bool {.inline.} =
sfImportc in s.flags and (lfDynamicLib notin s.loc.flags or s.ast == nil)
proc importcSym(c: PCtx; info: TLineInfo; s: PSym) = proc importcSym(c: PCtx; info: TLineInfo; s: PSym) =
when hasFFI: when hasFFI:
if compiletimeFFI in c.config.features: if compiletimeFFI in c.config.features:
@ -1584,7 +1587,7 @@ proc importcSym(c: PCtx; info: TLineInfo; s: PSym) =
localError(c.config, info, "VM is not allowed to 'importc'") localError(c.config, info, "VM is not allowed to 'importc'")
else: else:
localError(c.config, info, localError(c.config, info,
"cannot 'importc' variable at compile time") "cannot 'importc' variable at compile time; " & s.name.s)
proc getNullValue*(typ: PType, info: TLineInfo; conf: ConfigRef): PNode proc getNullValue*(typ: PType, info: TLineInfo; conf: ConfigRef): PNode
@ -1612,7 +1615,7 @@ proc genRdVar(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags) =
elif s.position == 0: elif s.position == 0:
cannotEval(c, n) cannotEval(c, n)
if s.position == 0: if s.position == 0:
if sfImportc in s.flags: c.importcSym(n.info, s) if importcCond(s): c.importcSym(n.info, s)
else: genGlobalInit(c, n, s) else: genGlobalInit(c, n, s)
if dest < 0: dest = c.getTemp(n.typ) if dest < 0: dest = c.getTemp(n.typ)
assert s.typ != nil assert s.typ != nil
@ -1815,7 +1818,7 @@ proc genVarSection(c: PCtx; n: PNode) =
checkCanEval(c, a.sons[0]) checkCanEval(c, a.sons[0])
if s.isGlobal: if s.isGlobal:
if s.position == 0: if s.position == 0:
if sfImportc in s.flags: c.importcSym(a.info, s) if importcCond(s): c.importcSym(a.info, s)
else: else:
let sa = getNullValue(s.typ, a.info, c.config) let sa = getNullValue(s.typ, a.info, c.config)
#if s.ast.isNil: getNullValue(s.typ, a.info) #if s.ast.isNil: getNullValue(s.typ, a.info)
@ -1972,7 +1975,7 @@ proc gen(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags = {}) =
of skProc, skFunc, skConverter, skMacro, skTemplate, skMethod, skIterator: of skProc, skFunc, skConverter, skMacro, skTemplate, skMethod, skIterator:
# 'skTemplate' is only allowed for 'getAst' support: # 'skTemplate' is only allowed for 'getAst' support:
if procIsCallback(c, s): discard if procIsCallback(c, s): discard
elif sfImportc in s.flags: c.importcSym(n.info, s) elif importcCond(s): c.importcSym(n.info, s)
genLit(c, n, dest) genLit(c, n, dest)
of skConst: of skConst:
let constVal = if s.ast != nil: s.ast else: s.typ.n let constVal = if s.ast != nil: s.ast else: s.typ.n