8

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?

Grzegorz Adam Hankiewicz
  • 7,349
  • 1
  • 36
  • 78
Roger
  • 440
  • 2
  • 13

1 Answers1

8

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.

Reimer Behrends
  • 8,600
  • 15
  • 19
  • 3
    Where can I get the definitions of these procs? – Roger Aug 31 '15 at 09:33
  • 1
    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`. – Reimer Behrends Aug 31 '15 at 14:45
  • 4
    In some other languages/VMs, these `magic` operations are also called `intrinsics`. See https://en.wikipedia.org/wiki/Intrinsic_function for additional context. – Alex Boisvert Sep 01 '15 at 05:14