]> gitweb.factorcode.org Git - factor.git/blob - vm/objects.hpp
threads: delete old contexts immediately instead of handing them off to a 'context...
[factor.git] / vm / objects.hpp
1 namespace factor
2 {
3
4 static const cell special_object_count = 70;
5
6 enum special_object {
7         OBJ_WALKER_HOOK = 3,       /* non-local exit hook, used by library only */
8         OBJ_CALLCC_1,              /* used to pass the value in callcc1 */
9
10         ERROR_HANDLER_QUOT = 5,    /* quotation called when VM throws an error */
11         OBJ_ERROR,                 /* a marker consed onto kernel errors */
12
13         OBJ_CELL_SIZE = 7,         /* sizeof(cell) */
14         OBJ_CPU,                   /* CPU architecture */
15         OBJ_OS,                    /* operating system name */
16
17         OBJ_ARGS = 10,             /* command line arguments */
18         OBJ_STDIN,                 /* stdin FILE* handle */
19         OBJ_STDOUT,                /* stdout FILE* handle */
20
21         OBJ_IMAGE = 13,            /* image path name */
22         OBJ_EXECUTABLE,            /* runtime executable path name */
23
24         OBJ_EMBEDDED = 15,         /* are we embedded in another app? */
25         OBJ_EVAL_CALLBACK,         /* used when Factor is embedded in a C app */
26         OBJ_YIELD_CALLBACK,        /* used when Factor is embedded in a C app */
27         OBJ_SLEEP_CALLBACK,        /* used when Factor is embedded in a C app */
28
29         OBJ_COCOA_EXCEPTION = 19,  /* Cocoa exception handler quotation */
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.c */
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_EPILOG,
44         JIT_RETURN,
45         JIT_PROFILING,
46         JIT_PUSH_IMMEDIATE,
47         JIT_DIP_WORD,
48         JIT_DIP,
49         JIT_2DIP_WORD,
50         JIT_2DIP,
51         JIT_3DIP_WORD,
52         JIT_3DIP,
53         JIT_EXECUTE,
54         JIT_DECLARE_WORD,
55
56         /* External entry points */
57         C_TO_FACTOR_WORD,
58         LAZY_JIT_COMPILE_WORD,
59         UNWIND_NATIVE_FRAMES_WORD,
60
61         /* Incremented on every modify-code-heap call; invalidates call( inline
62         caching */
63         REDEFINITION_COUNTER = 47,
64
65         /* Callback stub generation in callbacks.c */
66         CALLBACK_STUB = 48,
67         
68         /* Polymorphic inline cache generation in inline_cache.c */
69         PIC_LOAD = 49,
70         PIC_TAG,
71         PIC_TUPLE,
72         PIC_CHECK_TAG,
73         PIC_CHECK_TUPLE,
74         PIC_HIT,
75         PIC_MISS_WORD,
76         PIC_MISS_TAIL_WORD,
77
78         /* Megamorphic cache generation in dispatch.c */
79         MEGA_LOOKUP = 57,
80         MEGA_LOOKUP_WORD,
81         MEGA_MISS_WORD,
82
83         OBJ_UNDEFINED = 60,       /* default quotation for undefined words */
84
85         OBJ_STDERR = 61,          /* stderr FILE* handle */
86
87         OBJ_STAGE2 = 62,          /* have we bootstrapped? */
88
89         OBJ_CURRENT_THREAD = 63,
90
91         OBJ_THREADS = 64,
92         OBJ_RUN_QUEUE = 65,
93         OBJ_SLEEP_QUEUE = 66,
94
95         OBJ_VM_COMPILER = 67,     /* version string of the compiler we were built with */
96 };
97
98 /* save-image-and-exit discards special objects that are filled in on startup
99 anyway, to reduce image size */
100 #define OBJ_FIRST_SAVE OBJ_STARTUP_QUOT
101 #define OBJ_LAST_SAVE OBJ_STAGE2
102
103 inline static bool save_special_p(cell i)
104 {
105         return (i >= OBJ_FIRST_SAVE && i <= OBJ_LAST_SAVE);
106 }
107
108 template<typename Iterator> void object::each_slot(Iterator &iter)
109 {
110         cell scan = (cell)this;
111         cell payload_start = binary_payload_start();
112         cell end = scan + payload_start;
113
114         scan += sizeof(cell);
115
116         while(scan < end)
117         {
118                 iter((cell *)scan);
119                 scan += sizeof(cell);
120         }
121 }
122
123 }