]> gitweb.factorcode.org Git - factor.git/blob - vm/contexts.hpp
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / vm / contexts.hpp
1 namespace factor
2 {
3
4 /* Assembly code makes assumptions about the layout of this struct:
5    - callstack_top field is 0
6    - callstack_bottom field is 1
7    - datastack field is 2
8    - retainstack field is 3 */
9 struct context {
10         /* C stack pointer on entry */
11         stack_frame *callstack_top;
12         stack_frame *callstack_bottom;
13
14         /* current datastack top pointer */
15         cell datastack;
16
17         /* current retain stack top pointer */
18         cell retainstack;
19
20         /* saved contents of ds register on entry to callback */
21         cell datastack_save;
22
23         /* saved contents of rs register on entry to callback */
24         cell retainstack_save;
25
26         /* memory region holding current datastack */
27         segment *datastack_region;
28
29         /* memory region holding current retain stack */
30         segment *retainstack_region;
31
32         /* saved userenv slots on entry to callback */
33         cell catchstack_save;
34         cell current_callback_save;
35
36         context *next;
37 };
38
39 extern cell ds_size, rs_size;
40
41 #define ds_bot (stack_chain->datastack_region->start)
42 #define ds_top (stack_chain->datastack_region->end)
43 #define rs_bot (stack_chain->retainstack_region->start)
44 #define rs_top (stack_chain->retainstack_region->end)
45
46 DEFPUSHPOP(d,ds)
47 DEFPUSHPOP(r,rs)
48
49 void reset_datastack();
50 void reset_retainstack();
51 void fix_stacks();
52 void init_stacks(cell ds_size, cell rs_size);
53
54 PRIMITIVE(datastack);
55 PRIMITIVE(retainstack);
56 PRIMITIVE(set_datastack);
57 PRIMITIVE(set_retainstack);
58 PRIMITIVE(check_datastack);
59
60 VM_C_API void save_stacks();
61 VM_C_API void nest_stacks();
62 VM_C_API void unnest_stacks();
63
64 }
65
66 VM_C_API factor::context *stack_chain;