factor/vm/primitives.h

43 lines
1.2 KiB
C
Raw Normal View History

2007-09-20 18:09:08 -04:00
extern void *primitives[];
/* Primitives are called with two parameters, the word itself and the current
callstack pointer. The DEFINE_PRIMITIVE() macro takes care of boilerplate to
save the current callstack pointer so that GC and other facilities can proceed
to inspect Factor stack frames below the primitive's C stack frame.
Usage:
DEFINE_PRIMITIVE(name)
{
... CODE ...
}
Becomes
2007-09-27 16:10:37 -04:00
F_FASTCALL void primitive_name(CELL word, F_STACK_FRAME *callstack_top)
2007-09-20 18:09:08 -04:00
{
2007-10-06 22:52:55 -04:00
save_callstack_top(callstack_top);
2007-09-20 18:09:08 -04:00
... CODE ...
}
2007-09-27 16:10:37 -04:00
On x86, F_FASTCALL expands into a GCC declaration which forces the two
parameters to be passed in registers. This simplifies the quotation compiler
2007-10-06 22:52:55 -04:00
and support code in cpu-x86.S.
We do the assignment of stack_chain->callstack_top in a ``noinline'' function
to inhibit assignment re-ordering. */
2007-09-20 18:09:08 -04:00
#define DEFINE_PRIMITIVE(name) \
INLINE void primitive_##name##_impl(void); \
\
2007-09-27 16:10:37 -04:00
F_FASTCALL void primitive_##name(CELL word, F_STACK_FRAME *callstack_top) \
2007-09-20 18:09:08 -04:00
{ \
2007-10-06 22:52:55 -04:00
save_callstack_top(callstack_top); \
2007-09-20 18:09:08 -04:00
primitive_##name##_impl(); \
} \
\
INLINE void primitive_##name##_impl(void) \
/* Prototype for header files */
#define DECLARE_PRIMITIVE(name) \
2007-09-27 16:10:37 -04:00
F_FASTCALL void primitive_##name(CELL word, F_STACK_FRAME *callstack_top)