From 0091f2ad3bfa57aa1d5bdd1a1062975135a2a6d9 Mon Sep 17 00:00:00 2001 From: Oscar NihlgÄrd <oscarnihlgard@gmail.com> Date: Sun, 3 Feb 2019 09:06:00 +0100 Subject: Implement {.booldefine.} (#10533) --- compiler/semfold.nim | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'compiler/semfold.nim') diff --git a/compiler/semfold.nim b/compiler/semfold.nim index 0bdd0b64c..2a2942191 100644 --- a/compiler/semfold.nim +++ b/compiler/semfold.nim @@ -569,10 +569,20 @@ proc getConstExpr(m: PSym, n: PNode; g: ModuleGraph): PNode = try: result = newIntNodeT(g.config.symbols[s.name.s].parseInt, n, g) except ValueError: - localError(g.config, n.info, "expression is not an integer literal") + localError(g.config, s.info, + "{.intdefine.} const was set to an invalid integer: '" & + g.config.symbols[s.name.s] & "'") of mStrDefine: if isDefined(g.config, s.name.s): result = newStrNodeT(g.config.symbols[s.name.s], n, g) + of mBoolDefine: + if isDefined(g.config, s.name.s): + try: + result = newIntNodeT(g.config.symbols[s.name.s].parseBool.int, n, g) + except ValueError: + localError(g.config, s.info, + "{.booldefine.} const was set to an invalid bool: '" & + g.config.symbols[s.name.s] & "'") else: result = copyTree(s.ast) of skProc, skFunc, skMethod: -- cgit 1.4.1-2-gfad0 From d5da450100f35008df06ecf812f1eeabda05d285 Mon Sep 17 00:00:00 2001 From: Araq <rumpf_a@web.de> Date: Thu, 7 Feb 2019 12:12:20 +0100 Subject: helpers2 now has a real name --- compiler/cgen.nim | 2 +- compiler/semfold.nim | 2 +- lib/system/chcks.nim | 2 +- lib/system/helpers2.nim | 7 ------- lib/system/indexerrors.nim | 7 +++++++ 5 files changed, 10 insertions(+), 10 deletions(-) delete mode 100644 lib/system/helpers2.nim create mode 100644 lib/system/indexerrors.nim (limited to 'compiler/semfold.nim') diff --git a/compiler/cgen.nim b/compiler/cgen.nim index d020b1bd7..4abefe463 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -16,7 +16,7 @@ import condsyms, rodutils, renderer, idgen, cgendata, ccgmerge, semfold, aliases, lowerings, tables, sets, ndi, lineinfos, pathutils, transf -import system/helpers2 +import system/indexerrors when not defined(leanCompiler): import semparallel diff --git a/compiler/semfold.nim b/compiler/semfold.nim index 2a2942191..237a5127a 100644 --- a/compiler/semfold.nim +++ b/compiler/semfold.nim @@ -15,7 +15,7 @@ import nversion, platform, math, msgs, os, condsyms, idents, renderer, types, commands, magicsys, modulegraphs, strtabs, lineinfos -import system/helpers2 +import system/indexerrors proc newIntNodeT*(intVal: BiggestInt, n: PNode; g: ModuleGraph): PNode = case skipTypes(n.typ, abstractVarRange).kind diff --git a/lib/system/chcks.nim b/lib/system/chcks.nim index 6f4e8ce37..0840d863a 100644 --- a/lib/system/chcks.nim +++ b/lib/system/chcks.nim @@ -8,7 +8,7 @@ # # Implementation of some runtime checks. -import system/helpers2 +import system/indexerrors proc raiseRangeError(val: BiggestInt) {.compilerproc, noinline.} = when hostOS == "standalone": diff --git a/lib/system/helpers2.nim b/lib/system/helpers2.nim deleted file mode 100644 index 8bd69ad71..000000000 --- a/lib/system/helpers2.nim +++ /dev/null @@ -1,7 +0,0 @@ -# imported by other modules, unlike helpers.nim which is included - -template formatErrorIndexBound*[T](i, a, b: T): string = - "index out of bounds: (a: " & $a & ") <= (i: " & $i & ") <= (b: " & $b & ") " - -template formatErrorIndexBound*[T](i, n: T): string = - "index out of bounds: (i: " & $i & ") <= (n: " & $n & ") " diff --git a/lib/system/indexerrors.nim b/lib/system/indexerrors.nim new file mode 100644 index 000000000..8bd69ad71 --- /dev/null +++ b/lib/system/indexerrors.nim @@ -0,0 +1,7 @@ +# imported by other modules, unlike helpers.nim which is included + +template formatErrorIndexBound*[T](i, a, b: T): string = + "index out of bounds: (a: " & $a & ") <= (i: " & $i & ") <= (b: " & $b & ") " + +template formatErrorIndexBound*[T](i, n: T): string = + "index out of bounds: (i: " & $i & ") <= (n: " & $n & ") " -- cgit 1.4.1-2-gfad0