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