]> gitweb.factorcode.org Git - factor.git/blob - vm/contexts.hpp
VM: fixing small style issues
[factor.git] / vm / contexts.hpp
1 namespace factor {
2
3 /* Context object count and identifiers must be kept in sync with:
4      core/kernel/kernel.factor */
5 static const cell context_object_count = 4;
6
7 enum context_object {
8   OBJ_NAMESTACK,
9   OBJ_CATCHSTACK,
10   OBJ_CONTEXT,
11   OBJ_IN_CALLBACK_P,
12 };
13
14 /* When the callstack fills up (e.g by to deep recursion), a callstack
15    overflow error is triggered. So before continuing executing on it
16    in general_error(), we chop off this many bytes to have some space
17    to work with. Mac OSX 64 bit needs more than 8192. See issue #1419. */
18 static const cell stack_reserved = 16384;
19
20 struct context {
21
22   /* First 5 fields accessed directly by compiler. See basis/vm/vm.factor */
23
24   /* Factor callstack pointers */
25   cell callstack_top;
26   cell callstack_bottom;
27
28   /* current datastack top pointer */
29   cell datastack;
30
31   /* current retain stack top pointer */
32   cell retainstack;
33
34   /* C callstack pointer */
35   cell callstack_save;
36
37   segment* datastack_seg;
38   segment* retainstack_seg;
39   segment* callstack_seg;
40
41   /* context-specific special objects, accessed by context-object and
42      set-context-object primitives */
43   cell context_objects[context_object_count];
44
45   context(cell ds_size, cell rs_size, cell cs_size);
46   ~context();
47
48   void reset_datastack();
49   void reset_retainstack();
50   void reset_callstack();
51   void reset_context_objects();
52   void reset();
53   void fix_stacks();
54   void fill_stack_seg(cell top_ptr, segment* seg, cell pattern);
55   vm_error_type address_to_error(cell addr);
56
57   cell peek() { return *(cell*)datastack; }
58
59   void replace(cell tagged) { *(cell*)datastack = tagged; }
60
61   cell pop() {
62     cell value = peek();
63     datastack -= sizeof(cell);
64     return value;
65   }
66
67   void push(cell tagged) {
68     datastack += sizeof(cell);
69     replace(tagged);
70   }
71 };
72
73 VM_C_API context* new_context(factor_vm* parent);
74 VM_C_API void delete_context(factor_vm* parent);
75 VM_C_API void reset_context(factor_vm* parent);
76 VM_C_API cell begin_callback(factor_vm* parent, cell quot);
77 VM_C_API void end_callback(factor_vm* parent);
78
79 }