Add the ability to pass a value with the -d flag

This allows the end user to use the {.magic: "IntDefine"/"StrDefine"}
pragmas to pass values into code at compile time.  This has a nice side
effect of also allowing/requiring a default value to be assigned in the
code (see osalloc.nim/StandaloneHeapSize for an example)
This commit is contained in:
Jeff Ciesielski 2016-07-04 18:11:25 -04:00
commit 94d1aa5109
7 changed files with 32 additions and 7 deletions

View file

@ -640,6 +640,12 @@ proc getConstExpr(m: PSym, n: PNode): PNode =
of mNaN: result = newFloatNodeT(NaN, n)
of mInf: result = newFloatNodeT(Inf, n)
of mNegInf: result = newFloatNodeT(NegInf, n)
of mIntDefine:
if isDefined(s.name):
result = newIntNodeT(lookupSymbol(s.name).parseInt, n)
of mStrDefine:
if isDefined(s.name):
result = newStrNodeT(lookupSymbol(s.name), n)
else:
if sfFakeConst notin s.flags: result = copyTree(s.ast)
of {skProc, skMethod}: