summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/ast.nim2
-rw-r--r--compiler/commands.nim13
-rw-r--r--compiler/condsyms.nim9
-rw-r--r--compiler/semfold.nim6
-rw-r--r--compiler/wordrecg.nim3
5 files changed, 28 insertions, 5 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim
index c3bb7cd62..34ffd6f58 100644
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -610,7 +610,7 @@ type
     mEqIdent, mEqNimrodNode, mSameNodeType, mGetImpl,
     mNHint, mNWarning, mNError,
     mInstantiationInfo, mGetTypeInfo, mNGenSym,
-    mNimvm
+    mNimvm, mIntDefine, mStrDefine
 
 # things that we can evaluate safely at compile time, even if not asked for it:
 const
diff --git a/compiler/commands.nim b/compiler/commands.nim
index b3edb5e14..640e07b1b 100644
--- a/compiler/commands.nim
+++ b/compiler/commands.nim
@@ -122,6 +122,13 @@ proc splitSwitch(switch: string, cmd, arg: var string, pass: TCmdLinePass,
   elif switch[i] in {':', '=', '['}: arg = substr(switch, i + 1)
   else: invalidCmdLineOption(pass, switch, info)
 
+proc hasKeyValuePair(arg: string): bool =
+  for i in 0..arg.high:
+    if arg[i] in {':', '='}:
+      return true
+
+  return false
+
 proc processOnOffSwitch(op: TOptions, arg: string, pass: TCmdLinePass,
                         info: TLineInfo) =
   case whichKeyword(arg)
@@ -342,7 +349,11 @@ proc processSwitch(switch, arg: string, pass: TCmdLinePass, info: TLineInfo) =
     discard "allow for backwards compatibility, but don't do anything"
   of "define", "d":
     expectArg(switch, arg, pass, info)
-    defineSymbol(arg)
+    if hasKeyValuePair(arg):
+      splitSwitch(arg, key, val, pass, info)
+      defineSymbol(key, val)
+    else:
+      defineSymbol(arg)
   of "undef", "u":
     expectArg(switch, arg, pass, info)
     undefSymbol(arg)
diff --git a/compiler/condsyms.nim b/compiler/condsyms.nim
index 60e8f2826..02f7e764d 100644
--- a/compiler/condsyms.nim
+++ b/compiler/condsyms.nim
@@ -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
diff --git a/compiler/semfold.nim b/compiler/semfold.nim
index feea6ce34..26d309cfd 100644
--- a/compiler/semfold.nim
+++ b/compiler/semfold.nim
@@ -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}:
diff --git a/compiler/wordrecg.nim b/compiler/wordrecg.nim
index 3e0e05a94..b5ffd51c2 100644
--- a/compiler/wordrecg.nim
+++ b/compiler/wordrecg.nim
@@ -36,6 +36,7 @@ type
     wColon, wColonColon, wEquals, wDot, wDotDot,
     wStar, wMinus,
     wMagic, wThread, wFinal, wProfiler, wObjChecks,
+    wIntDefine, wStrDefine,
 
     wDestroy,
 
@@ -121,7 +122,7 @@ const
 
     ":", "::", "=", ".", "..",
     "*", "-",
-    "magic", "thread", "final", "profiler", "objchecks",
+    "magic", "thread", "final", "profiler", "objchecks", "intdefine", "strdefine",
 
     "destroy",