mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-06 15:29:11 +00:00
IC: remember toplevel .emits
This commit is contained in:
2
tests/ic/mdefconverter.nim
Normal file
2
tests/ic/mdefconverter.nim
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
converter toBool*(x: int): bool = x != 0
|
||||
14
tests/ic/memit.nim
Normal file
14
tests/ic/memit.nim
Normal file
@@ -0,0 +1,14 @@
|
||||
# Helper for temit.nim: a NON-main module with a module-scope `{.emit.}` that
|
||||
# introduces a C macro consumed by an `{.importc, nodecl.}` const. The IC backend
|
||||
# reload used to drop top-level emit pragmas — writeToplevelNode wrote them to the
|
||||
# by-symbol-index implementation section, where a symbol-less pragma is never
|
||||
# reloaded — so the generated C lost the `#define` and failed to compile with
|
||||
# "use of undeclared identifier". Mirrors lib/pure/concurrency/cpuinfo.nim's
|
||||
# `#include <sys/sysctl.h>` + `CTL_HW`/`HW_NCPU` importc pattern.
|
||||
{.emit: """/*TYPESECTION*/
|
||||
#define NIM_IC_EMIT_ANSWER 42
|
||||
""".}
|
||||
|
||||
let icEmitAnswer {.importc: "NIM_IC_EMIT_ANSWER", nodecl.}: cint
|
||||
|
||||
proc emitAnswer*(): int = int(icEmitAnswer)
|
||||
7
tests/ic/temit.nim
Normal file
7
tests/ic/temit.nim
Normal file
@@ -0,0 +1,7 @@
|
||||
# Regression: a module-scope `{.emit.}` in an imported module must survive the
|
||||
# `nim ic` backend reload (see memit.nim). Before the fix the dropped `#define`
|
||||
# made the generated C fail to compile, so `nim ic` exited non-zero.
|
||||
import memit
|
||||
|
||||
doAssert emitAnswer() == 42
|
||||
echo emitAnswer()
|
||||
Reference in New Issue
Block a user