This commit is contained in:
parent
362c8964bf
commit
018e297d66
4 changed files with 32 additions and 6 deletions
|
|
@ -1166,16 +1166,38 @@ proc requestConstImpl(p: BProc, sym: PSym) =
|
||||||
useHeader(m, sym)
|
useHeader(m, sym)
|
||||||
if sym.loc.k == locNone:
|
if sym.loc.k == locNone:
|
||||||
fillLoc(sym.loc, locData, sym.ast, mangleName(p.module, sym), OnStatic)
|
fillLoc(sym.loc, locData, sym.ast, mangleName(p.module, sym), OnStatic)
|
||||||
|
if m.hcrOn: incl(sym.loc.flags, lfIndirect)
|
||||||
|
|
||||||
if lfNoDecl in sym.loc.flags: return
|
if lfNoDecl in sym.loc.flags: return
|
||||||
# declare implementation:
|
# declare implementation:
|
||||||
var q = findPendingModule(m, sym)
|
var q = findPendingModule(m, sym)
|
||||||
if q != nil and not containsOrIncl(q.declaredThings, sym.id):
|
if q != nil and not containsOrIncl(q.declaredThings, sym.id):
|
||||||
assert q.initProc.module == q
|
assert q.initProc.module == q
|
||||||
|
# add a suffix for hcr - will later init the global pointer with this data
|
||||||
|
let actualConstName = if m.hcrOn: sym.loc.r & "_const" else: sym.loc.r
|
||||||
q.s[cfsData].addf("N_LIB_PRIVATE NIM_CONST $1 $2 = $3;$n",
|
q.s[cfsData].addf("N_LIB_PRIVATE NIM_CONST $1 $2 = $3;$n",
|
||||||
[getTypeDesc(q, sym.typ), sym.loc.r, genBracedInit(q.initProc, sym.ast, isConst = true)])
|
[getTypeDesc(q, sym.typ), actualConstName, genBracedInit(q.initProc, sym.ast, isConst = true)])
|
||||||
|
if m.hcrOn:
|
||||||
|
# generate the global pointer with the real name
|
||||||
|
q.s[cfsVars].addf("static $1* $2;$n", [getTypeDesc(m, sym.loc.t), sym.loc.r])
|
||||||
|
# register it (but ignore the boolean result of hcrRegisterGlobal)
|
||||||
|
q.initProc.procSec(cpsLocals).addf(
|
||||||
|
"\thcrRegisterGlobal($1, \"$2\", sizeof($3), NULL, (void**)&$2);$n",
|
||||||
|
[getModuleDllPath(q, sym), sym.loc.r, rdLoc(sym.loc)])
|
||||||
|
# always copy over the contents of the actual constant with the _const
|
||||||
|
# suffix ==> this means that the constant is reloadable & updatable!
|
||||||
|
q.initProc.procSec(cpsLocals).add(ropecg(q,
|
||||||
|
"\t#nimCopyMem((void*)$1, (NIM_CONST void*)&$2, sizeof($3));$n",
|
||||||
|
[sym.loc.r, actualConstName, rdLoc(sym.loc)]))
|
||||||
# declare header:
|
# declare header:
|
||||||
if q != m and not containsOrIncl(m.declaredThings, sym.id):
|
if q != m and not containsOrIncl(m.declaredThings, sym.id):
|
||||||
assert(sym.loc.r != nil)
|
assert(sym.loc.r != nil)
|
||||||
|
if m.hcrOn:
|
||||||
|
m.s[cfsVars].addf("static $1* $2;$n", [getTypeDesc(m, sym.loc.t), sym.loc.r]);
|
||||||
|
m.initProc.procSec(cpsLocals).addf(
|
||||||
|
"\t$1 = ($2*)hcrGetGlobal($3, \"$1\");$n", [sym.loc.r,
|
||||||
|
getTypeDesc(m, sym.loc.t), getModuleDllPath(q, sym)])
|
||||||
|
else:
|
||||||
let headerDecl = "extern NIM_CONST $1 $2;$n" %
|
let headerDecl = "extern NIM_CONST $1 $2;$n" %
|
||||||
[getTypeDesc(m, sym.loc.t), sym.loc.r]
|
[getTypeDesc(m, sym.loc.t), sym.loc.r]
|
||||||
m.s[cfsData].add(headerDecl)
|
m.s[cfsData].add(headerDecl)
|
||||||
|
|
|
||||||
|
|
@ -14,5 +14,6 @@ let c = makeCounter()
|
||||||
afterCodeReload:
|
afterCodeReload:
|
||||||
echo " 0: after - closure iterator: ", c()
|
echo " 0: after - closure iterator: ", c()
|
||||||
echo " 0: after - closure iterator: ", c()
|
echo " 0: after - closure iterator: ", c()
|
||||||
|
echo " 0: after - c_2 = ", c_2
|
||||||
|
|
||||||
proc getInt*(): int = return g_1 + g_2.len
|
proc getInt*(): int = return g_1 + g_2.len
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ type
|
||||||
|
|
||||||
let g_2* = @[Type2(data: 2), Type2(data: 3)][1..^1] # should have a length of 1
|
let g_2* = @[Type2(data: 2), Type2(data: 3)][1..^1] # should have a length of 1
|
||||||
|
|
||||||
|
const c_2* = [1, 2, 3] # testing that a complext const object is properly exported
|
||||||
|
|
||||||
var a: tuple[str: string, i: int]
|
var a: tuple[str: string, i: int]
|
||||||
a.str = " 2: random string"
|
a.str = " 2: random string"
|
||||||
echo a.str
|
echo a.str
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ max mutual recursion reached!
|
||||||
bar
|
bar
|
||||||
0: after - closure iterator: 0
|
0: after - closure iterator: 0
|
||||||
0: after - closure iterator: 1
|
0: after - closure iterator: 1
|
||||||
|
0: after - c_2 = [1, 2, 3]
|
||||||
main: after
|
main: after
|
||||||
The answer is: 9
|
The answer is: 9
|
||||||
main: hasAnyModuleChanged? true
|
main: hasAnyModuleChanged? true
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue