Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test for define, undef #14443

Merged
merged 1 commit into from
May 25, 2020
Merged

Conversation

timotheecour
Copy link
Member

undef is actually not used at all in nim repo, but I rely on it; so I'm adding a test

@kaushalmodi
Copy link
Contributor

TIL undef exists :)

@timotheecour
Copy link
Member Author

timotheecour commented May 25, 2020

exactly. that's the point :)
btw @Araq I found the following pattern extremely useful when debugging, for example, the compiler:

proc problematicCode =
  {.define(enableMyDebug).}
  codeThatNeedsCompilerDebuggingEnabled()
  {.undef(enableMyDebug).}
# in compiler/debugs.nim
macro myDebug(...) =
  let conf = getConfGlobal() # global var set in newConfigRef(), when debugging enabled
  if isDefined(conf, "enableDebug"):
    # pretty print all arguments, with line numbers etc using https://github.com/nim-lang/RFCs/issues/203#issuecomment-602534906
  else: # do nothing

# somewhere inside compiler
proc semExpr() =
  ...
  myDebug t, n, n2.renderTree # compiler code temporarily littered with these while debugging something
  ...

this allows showing debug logs only for the section you're interested in
it's more useful in particular than msgs.??:

proc `??`* (conf: ConfigRef; info: TLineInfo, filename: string): bool =
  # only for debugging purposes
  result = filename in toFilename(conf, info)

@Araq Araq merged commit a008f59 into nim-lang:devel May 25, 2020
@timotheecour timotheecour deleted the pr_test_undef_define branch May 25, 2020 09:27
EchoPouet pushed a commit to EchoPouet/Nim that referenced this pull request Jun 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants