]> gitweb.factorcode.org Git - factor.git/blob - vm/contexts.hpp
Merge Phil Dawes' VM work
[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 #define ds_bot (stack_chain->datastack_region->start)
40 #define ds_top (stack_chain->datastack_region->end)
41 #define rs_bot (stack_chain->retainstack_region->start)
42 #define rs_top (stack_chain->retainstack_region->end)
43
44 DEFPUSHPOP(d,ds)
45 DEFPUSHPOP(r,rs)
46
47 PRIMITIVE(datastack);
48 PRIMITIVE(retainstack);
49 PRIMITIVE(set_datastack);
50 PRIMITIVE(set_retainstack);
51 PRIMITIVE(check_datastack);
52
53 struct factorvm;
54 VM_C_API void nest_stacks(factorvm *vm);
55 VM_C_API void unnest_stacks(factorvm *vm);
56
57 }
58