]> gitweb.factorcode.org Git - factor.git/blob - vm/objects.hpp
Revert "vm: replace line comments // with block comments /**/ for consintency"
[factor.git] / vm / objects.hpp
1 namespace factor {
2
3 // Special object count and identifiers must be kept in sync with:
4 //   core/kernel/kernel.factor
5 //   basis/bootstrap/image/image.factor
6
7 static const cell special_object_count = 85;
8
9 enum special_object {
10   OBJ_WALKER_HOOK = 3, /* non-local exit hook, used by library only */
11   OBJ_CALLCC_1,        /* used to pass the value in callcc1 */
12
13   ERROR_HANDLER_QUOT = 5, /* quotation called when VM throws an error */
14
15   OBJ_CELL_SIZE = 7, /* sizeof(cell) */
16   OBJ_CPU,           /* CPU architecture */
17   OBJ_OS,            /* operating system name */
18
19   OBJ_ARGS = 10, /* command line arguments */
20   OBJ_STDIN,     /* stdin FILE* handle */
21   OBJ_STDOUT,    /* stdout FILE* handle */
22
23   OBJ_IMAGE = 13, /* image path name */
24   OBJ_EXECUTABLE, /* runtime executable path name */
25
26   OBJ_EMBEDDED = 15,  /* are we embedded in another app? */
27   OBJ_EVAL_CALLBACK,  /* used when Factor is embedded in a C app */
28   OBJ_YIELD_CALLBACK, /* used when Factor is embedded in a C app */
29   OBJ_SLEEP_CALLBACK, /* used when Factor is embedded in a C app */
30
31   OBJ_STARTUP_QUOT = 20, /* startup quotation */
32   OBJ_GLOBAL,            /* global namespace */
33   OBJ_SHUTDOWN_QUOT,     /* shutdown quotation */
34
35   /* Quotation compilation in quotations.cpp */
36   JIT_PROLOG = 23,
37   JIT_PRIMITIVE_WORD,
38   JIT_PRIMITIVE,
39   JIT_WORD_JUMP,
40   JIT_WORD_CALL,
41   JIT_IF_WORD,
42   JIT_IF,
43   JIT_SAFEPOINT,
44   JIT_EPILOG,
45   JIT_RETURN,
46   JIT_UNUSED,
47   JIT_PUSH_LITERAL,
48   JIT_DIP_WORD,
49   JIT_DIP,
50   JIT_2DIP_WORD,
51   JIT_2DIP,
52   JIT_3DIP_WORD,
53   JIT_3DIP,
54   JIT_EXECUTE,
55   JIT_DECLARE_WORD,
56
57   /* External entry points. These are defined in the files in
58      bootstrap/assembler/ */
59   C_TO_FACTOR_WORD = 43,
60   LAZY_JIT_COMPILE_WORD,
61   UNWIND_NATIVE_FRAMES_WORD,
62   GET_FPU_STATE_WORD,
63   SET_FPU_STATE_WORD,
64   SIGNAL_HANDLER_WORD,
65   LEAF_SIGNAL_HANDLER_WORD,
66   WIN_EXCEPTION_HANDLER,
67   UNUSED2,
68
69   /* Incremented on every modify-code-heap call; invalidates call( inline
70      caching */
71   REDEFINITION_COUNTER = 52,
72
73   /* Callback stub generation in callbacks.cpp */
74   CALLBACK_STUB = 53,
75
76   /* Polymorphic inline cache generation in inline_cache.cpp */
77   PIC_LOAD = 54,
78   PIC_TAG,
79   PIC_TUPLE,
80   PIC_CHECK_TAG,
81   PIC_CHECK_TUPLE,
82   PIC_HIT,
83   PIC_MISS_WORD,
84   PIC_MISS_TAIL_WORD,
85
86   /* Megamorphic cache generation in dispatch.cpp */
87   MEGA_LOOKUP = 62,
88   MEGA_LOOKUP_WORD,
89   MEGA_MISS_WORD,
90
91   OBJ_UNDEFINED = 65, /* default quotation for undefined words */
92
93   OBJ_STDERR = 66, /* stderr FILE* handle */
94
95   OBJ_STAGE2 = 67, /* have we bootstrapped? */
96
97   OBJ_CURRENT_THREAD = 68,
98
99   OBJ_THREADS = 69,
100   OBJ_RUN_QUEUE = 70,
101   OBJ_SLEEP_QUEUE = 71,
102
103   OBJ_VM_COMPILER = 72, /* version string of the compiler we were built with */
104
105   OBJ_WAITING_CALLBACKS = 73,
106
107   OBJ_SIGNAL_PIPE = 74, /* file descriptor for pipe used to communicate signals
108                            only used on unix */
109   OBJ_VM_COMPILE_TIME = 75, /* when the binary was built */
110   OBJ_VM_VERSION = 76, /* factor version */
111   OBJ_VM_GIT_LABEL = 77, /* git label (git describe --all --long) */
112
113   /* Canonical truth value. In Factor, 't' */
114   OBJ_CANONICAL_TRUE = 78,
115
116   /* Canonical bignums. These needs to be kept in the image in case
117      some heap objects refer to them. */
118   OBJ_BIGNUM_ZERO,
119   OBJ_BIGNUM_POS_ONE,
120   OBJ_BIGNUM_NEG_ONE = 81,
121 };
122
123 /* save-image-and-exit discards special objects that are filled in on startup
124    anyway, to reduce image size */
125 inline static bool save_special_p(cell i) {
126   /* Need to fix the order here. */
127   return (i >= OBJ_STARTUP_QUOT && i <= LEAF_SIGNAL_HANDLER_WORD) ||
128       (i >= REDEFINITION_COUNTER && i <= OBJ_UNDEFINED) ||
129       i == OBJ_STAGE2 ||
130       (i >= OBJ_CANONICAL_TRUE && i <= OBJ_BIGNUM_NEG_ONE);
131 }
132
133 template <typename Iterator> void object::each_slot(Iterator& iter) {
134   cell* start = (cell*)this + 1;
135   cell* end = start + slot_count();
136
137   while (start < end) {
138     iter(start);
139     start++;
140   }
141 }
142
143 }