]> gitweb.factorcode.org Git - factor.git/blob - vm/objects.hpp
Merge branch 'master' of github.com:erg/factor
[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_STARTUP_QUOT = 20,     /* startup quotation */
30         OBJ_GLOBAL,                /* global namespace */
31         OBJ_SHUTDOWN_QUOT,         /* shutdown quotation */
32
33         /* Quotation compilation in quotations.c */
34         JIT_PROLOG = 23,
35         JIT_PRIMITIVE_WORD,
36         JIT_PRIMITIVE,
37         JIT_WORD_JUMP,
38         JIT_WORD_CALL,
39         JIT_IF_WORD,
40         JIT_IF,
41         JIT_EPILOG,
42         JIT_RETURN,
43         JIT_PROFILING,
44         JIT_PUSH_IMMEDIATE,
45         JIT_DIP_WORD,
46         JIT_DIP,
47         JIT_2DIP_WORD,
48         JIT_2DIP,
49         JIT_3DIP_WORD,
50         JIT_3DIP,
51         JIT_EXECUTE,
52         JIT_DECLARE_WORD,
53
54         /* External entry points */
55         C_TO_FACTOR_WORD,
56         LAZY_JIT_COMPILE_WORD,
57         UNWIND_NATIVE_FRAMES_WORD,
58
59         /* Incremented on every modify-code-heap call; invalidates call( inline
60         caching */
61         REDEFINITION_COUNTER = 47,
62
63         /* Callback stub generation in callbacks.c */
64         CALLBACK_STUB = 48,
65         
66         /* Polymorphic inline cache generation in inline_cache.c */
67         PIC_LOAD = 49,
68         PIC_TAG,
69         PIC_TUPLE,
70         PIC_CHECK_TAG,
71         PIC_CHECK_TUPLE,
72         PIC_HIT,
73         PIC_MISS_WORD,
74         PIC_MISS_TAIL_WORD,
75
76         /* Megamorphic cache generation in dispatch.c */
77         MEGA_LOOKUP = 57,
78         MEGA_LOOKUP_WORD,
79         MEGA_MISS_WORD,
80
81         OBJ_UNDEFINED = 60,       /* default quotation for undefined words */
82
83         OBJ_STDERR = 61,          /* stderr FILE* handle */
84
85         OBJ_STAGE2 = 62,          /* have we bootstrapped? */
86
87         OBJ_CURRENT_THREAD = 63,
88
89         OBJ_THREADS = 64,
90         OBJ_RUN_QUEUE = 65,
91         OBJ_SLEEP_QUEUE = 66,
92
93         OBJ_VM_COMPILER = 67,     /* version string of the compiler we were built with */
94 };
95
96 /* save-image-and-exit discards special objects that are filled in on startup
97 anyway, to reduce image size */
98 #define OBJ_FIRST_SAVE OBJ_STARTUP_QUOT
99 #define OBJ_LAST_SAVE OBJ_STAGE2
100
101 inline static bool save_special_p(cell i)
102 {
103         return (i >= OBJ_FIRST_SAVE && i <= OBJ_LAST_SAVE);
104 }
105
106 template<typename Iterator> void object::each_slot(Iterator &iter)
107 {
108         cell scan = (cell)this;
109         cell payload_start = binary_payload_start();
110         cell end = scan + payload_start;
111
112         scan += sizeof(cell);
113
114         while(scan < end)
115         {
116                 iter((cell *)scan);
117                 scan += sizeof(cell);
118         }
119 }
120
121 }