nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.62k stars 1.47k forks source link

Exportc variable: codegen regression #12081

Open mratsim opened 5 years ago

mratsim commented 5 years ago

My workaround for https://github.com/nim-lang/Nim/issues/9365 relied on stable Nim->C symbols and needed to be updated after https://github.com/nim-lang/Nim/pull/11985.

I would use {.exportc.} in the affected place to ensure Nim->C symbol mapping.

Unfortunately, {.exportc.} variables are not properly generated anymore after https://github.com/nim-lang/Nim/pull/11985

Test case:

template foo(): untyped =
  let ompsize{.exportc.} = 123
  echo ompsize

proc main() =
  foo()

main()
/home/beta/.cache/nim/expc_d/expc.nim.c:103:12: error: stray ‘`’ in program
  103 |  NI ompsize`gensym178008;
      |            ^
/home/beta/.cache/nim/expc_d/expc.nim.c:103:13: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘gensym178008’
  103 |  NI ompsize`gensym178008;
      |             ^~~~~~~~~~~~
/home/beta/.cache/nim/expc_d/expc.nim.c:103:13: error: ‘gensym178008’ undeclared (first use in this function)
/home/beta/.cache/nim/expc_d/expc.nim.c:103:13: note: each undeclared identifier is reported only once for each function it appears in
/home/beta/.cache/nim/expc_d/expc.nim.c:107:9: error: stray ‘`’ in program
  107 |  ompsize`gensym178008 = ((NI) 123);
      |         ^
/home/beta/.cache/nim/expc_d/expc.nim.c:107:2: error: unknown type name ‘ompsize’
  107 |  ompsize`gensym178008 = ((NI) 123);
      |  ^~~~~~~
/home/beta/.cache/nim/expc_d/expc.nim.c:111:30: error: stray ‘`’ in program
  111 |  T1_[0] = nimIntToStr(ompsize`gensym178008);
      |                              ^
/home/beta/.cache/nim/expc_d/expc.nim.c:111:23: error: ‘ompsize’ undeclared (first use in this function)
  111 |  T1_[0] = nimIntToStr(ompsize`gensym178008);
      |                       ^~~~~~~
/home/beta/.cache/nim/expc_d/expc.nim.c:111:30: error: expected ‘)’ before ‘gensym178008’
  111 |  T1_[0] = nimIntToStr(ompsize`gensym178008);
      |                              ^~~~~~~~~~~~~
      |                              )
mratsim commented 5 years ago

Tagging low-priority as there is an easy workaround by specifying the name explicitly

template foo(): untyped =
  let ompsize{.exportc: "ompsize".} = 123
  echo ompsize

proc main() =
  foo()

main(