Doesn't compile
import macros
macro declCTVar(ct_name: static string): untyped =
let ct_node = newIdentNode(ct_name)
quote do:
const `ct_node` {. compileTime .} = 1 # <-- Error: cannot attach a custom pragma to 'ctVar'
declCTVar("ctVar")
Have you tried it outside a macro?
const x{.compile time.} =1
Gives the same error.
const is inherently compile time, the only purpose for the compiletime pragma is only meaningful for let and var
Having said that, Im sure a PR supporting const x{.compiletime.} would be accepted, @japplegame and if you bought me a cup of coffee I'd even submit it 😄
const is inherently compile time, the compiletime pragma is only meaningful for let and var
Then why does the compiler place const data in the .rodata section?
And why did the compiler generate such terrible code?
800002e: 4b05 ldr r3, [pc, #20] ; (8000044 <NimMain+0x28>)
8000030: 9300 str r3, [sp, #0]
8000032: 9b00 ldr r3, [sp, #0]
8000034: f000 f808 bl 8000048 <NimMain+0x2c>
...
8000048: 4718 bx r3
800004a: 46c0 nop ; (mov r8, r8)
Hey there fellow human, pls forgive any unintended insult.
.rodata seems like a great place to keep a const, what's the problem?
That certainly looks like unoptimal asm, is that a related issue? If it's on your hot path an causing a big slowdown, you can submit a bug to gcc-arm or use inline assembly to get the machine code you need.