Revert "lists: Add list literal doc example."
[factor.git] / vm / contexts.hpp
blob945b9cda7d50ae9d5fd1f9ecbb3bb36aa25be61f
1 namespace factor {
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;
7 enum context_object {
8 OBJ_NAMESTACK,
9 OBJ_CATCHSTACK,
10 OBJ_CONTEXT,
11 OBJ_IN_CALLBACK_P,
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;
20 struct context {
22 // First 5 fields accessed directly by compiler. See basis/vm/vm.factor
24 // Factor callstack pointers
25 cell callstack_top;
26 cell callstack_bottom;
28 // current datastack top pointer
29 cell datastack;
31 // current retain stack top pointer
32 cell retainstack;
34 // C callstack pointer
35 cell callstack_save;
37 segment* datastack_seg;
38 segment* retainstack_seg;
39 segment* callstack_seg;
41 // context-specific special objects, accessed by context-object and
42 // set-context-object primitives
43 cell context_objects[context_object_count];
45 context(cell ds_size, cell rs_size, cell cs_size);
46 ~context();
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);
57 cell peek() { return *(cell*)datastack; }
59 void replace(cell tagged) { *(cell*)datastack = tagged; }
61 cell pop() {
62 cell value = peek();
63 datastack -= sizeof(cell);
64 return value;
67 void push(cell tagged) {
68 datastack += sizeof(cell);
69 replace(tagged);
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);