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:
parent
38de553b86
commit
94d1aa5109
7 changed files with 32 additions and 7 deletions
|
|
@ -19,8 +19,8 @@ var gSymbols: StringTableRef
|
|||
const
|
||||
catNone = "false"
|
||||
|
||||
proc defineSymbol*(symbol: string) =
|
||||
gSymbols[symbol] = "true"
|
||||
proc defineSymbol*(symbol: string, value: string = "true") =
|
||||
gSymbols[symbol] = value
|
||||
|
||||
proc undefSymbol*(symbol: string) =
|
||||
gSymbols[symbol] = catNone
|
||||
|
|
@ -62,6 +62,11 @@ proc isDefined*(symbol: string): bool =
|
|||
|
||||
proc isDefined*(symbol: PIdent): bool = isDefined(symbol.s)
|
||||
|
||||
proc lookupSymbol*(symbol: string): string =
|
||||
result = if isDefined(symbol): gSymbols[symbol] else: nil
|
||||
|
||||
proc lookupSymbol*(symbol: PIdent): string = lookupSymbol(symbol.s)
|
||||
|
||||
iterator definedSymbolNames*: string =
|
||||
for key, val in pairs(gSymbols):
|
||||
if val != catNone: yield key
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue