Add feature flag capability

This commit is contained in:
Ganesh Viswanathan 2020-03-09 21:20:24 -05:00
commit 1b63a125c5
4 changed files with 22 additions and 8 deletions

View file

@ -9,4 +9,11 @@ when defined(Windows):
switch("gc", "markAndSweep") switch("gc", "markAndSweep")
# Retain stackTrace for clear errors # Retain stackTrace for clear errors
switch("stackTrace", "on") switch("stackTrace", "on")
# Path to compiler
switch("path", "$nim")
# Case objects
when not defined(danger):
switch("define", "nimOldCaseObjects")

View file

@ -25,7 +25,7 @@ proc execTest(test: string) =
execCmd "nim cpp -r " & test execCmd "nim cpp -r " & test
task buildToast, "build toast": task buildToast, "build toast":
execCmd("nim c -f -d:danger nimterop/toast.nim") execCmd("nim c -f nimterop/toast.nim")
task bt, "build toast": task bt, "build toast":
execCmd("nim c -d:danger nimterop/toast.nim") execCmd("nim c -d:danger nimterop/toast.nim")

View file

@ -59,6 +59,8 @@ type
code*, dynlib*, mode*, nim*, overrides*, pluginSource*, pluginSourcePath*: string code*, dynlib*, mode*, nim*, overrides*, pluginSource*, pluginSourcePath*: string
feature*: seq[Feature]
onSymbol*, onSymbolOverride*: OnSymbol onSymbol*, onSymbolOverride*: OnSymbol
onSymbolOverrideFinal*: OnSymbolOverrideFinal onSymbolOverrideFinal*: OnSymbolOverrideFinal
@ -77,6 +79,12 @@ type
nodeBranch*: seq[string] nodeBranch*: seq[string]
CompileMode = enum
c, cpp
Feature* = enum
ast2
var var
gStateCT {.compiletime, used.} = new(State) gStateCT {.compiletime, used.} = new(State)
@ -86,12 +94,7 @@ template nBl(s: typed): untyped {.used.} =
template Bl(s: typed): untyped {.used.} = template Bl(s: typed): untyped {.used.} =
(s.len == 0) (s.len == 0)
type CompileMode = enum const modeDefault {.used.} = $cpp
c,
cpp,
# TODO: can cligen accept enum instead of string?
const modeDefault {.used.} = $cpp # TODO: USE this everywhere relevant
when not declared(CIMPORT): when not declared(CIMPORT):
export gAtoms, gExpressions, gEnumVals, Kind, Ast, AstTable, State, NimState, export gAtoms, gExpressions, gEnumVals, Kind, Ast, AstTable, State, NimState,

View file

@ -103,6 +103,7 @@ proc main(
debug = false, debug = false,
defines: seq[string] = @[], defines: seq[string] = @[],
dynlib: string = "", dynlib: string = "",
feature: seq[Feature] = @[],
includeDirs: seq[string] = @[], includeDirs: seq[string] = @[],
mode = modeDefault, mode = modeDefault,
nim: string = "nim", nim: string = "nim",
@ -126,6 +127,7 @@ proc main(
debug: debug, debug: debug,
defines: defines, defines: defines,
dynlib: dynlib, dynlib: dynlib,
feature: feature,
includeDirs: includeDirs, includeDirs: includeDirs,
mode: mode, mode: mode,
nim: nim, nim: nim,
@ -235,6 +237,7 @@ when isMainModule:
"debug": "enable debug output", "debug": "enable debug output",
"defines": "definitions to pass to preprocessor", "defines": "definitions to pass to preprocessor",
"dynlib": "Import symbols from library in specified Nim string", "dynlib": "Import symbols from library in specified Nim string",
"feature": "flags to enable experimental features",
"includeDirs": "include directory to pass to preprocessor", "includeDirs": "include directory to pass to preprocessor",
"mode": "language parser: c or cpp", "mode": "language parser: c or cpp",
"nim": "use a particular Nim executable (default: $PATH/nim)", "nim": "use a particular Nim executable (default: $PATH/nim)",
@ -256,6 +259,7 @@ when isMainModule:
"debug": 'd', "debug": 'd',
"defines": 'D', "defines": 'D',
"dynlib": 'l', "dynlib": 'l',
"feature": 'f',
"includeDirs": 'I', "includeDirs": 'I',
"nocomments": 'c', "nocomments": 'c',
"output": 'o', "output": 'o',