What's the meaning of "magic" pragma in nim?
Asked Answered
R

1

9

When going through the code in Nim project itself, I find that some proc decorated by "magic" pragma misses proc definition (example). There's no doc to explain the pragma, I guess the proc's definition is somewhere else and is merged while compiling.But I cannot still find the definition by searching the whole project.

Do I misunderstand the "magic" pragma? What's the meaning of it? And how to use it?

Rakeoff answered 31/8, 2015 at 6:39 Comment(0)
E
9

The {.magic.} pragma is used to define built-in operations and types, i.e. anything that requires compiler magic in order to work (hence the name). It is not intended to be used outside the system modules.

Eruptive answered 31/8, 2015 at 7:39 Comment(3)
Where can I get the definitions of these procs?Rakeoff
They are all implemented in the compiler. For example, the procedure that you linked to is eventually implemented in the opcParseStmtToAst branch in the rawExecute() procedure in compiler/vm.nim.Eruptive
In some other languages/VMs, these magic operations are also called intrinsics. See en.wikipedia.org/wiki/Intrinsic_function for additional context.Penumbra

© 2022 - 2024 — McMap. All rights reserved.