14.2 Primitives

If you locate +, you see the following source code from the file prim:

+       ( n1 n2 -- n )          core    plus
n = n1+n2;

This code is written in a variant of the vmgen language. The first line provides the primitive Forth name, stack effect (including stack item names), wordset name, and pronounciation (which also serves as the C name of the primitive), while the remaining lines are C code that refer to the stack items by name.

Our vmgen variant extracts a lot of information from the stack effect notations: The number of items popped from and pushed on the stack, their type, and by what name they are referred to in the C code. It generates a C code from this, incorporating the C code given explicitly. For more details See Vmgen in Vmgen.

When you see +, you see the variant of the primitive that’s used in threaded code: starting in the canonical state and ending in the canonical state, with NEXT (including IP update):

see + 
Code +  
   $55DE56E88427: add    $0x8,%rbx
   $55DE56E8842B: add    $0x8,%r10
   $55DE56E8842F: add    (%r10),%r13
   $55DE56E88432: mov    (%rbx),%rax
   $55DE56E88435: jmp    *%rax
end-code

You can see the source and disassembled code of other primitives in the same way.