add vm-abort-continuation-hook, vm-restore-continuation-hook
[bpt/guile.git] / libguile / vm.h
... / ...
CommitLineData
1/* Copyright (C) 2001, 2009, 2010 Free Software Foundation, Inc.
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public License
5 * as published by the Free Software Foundation; either version 3 of
6 * the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 * 02110-1301 USA
17 */
18
19#ifndef _SCM_VM_H_
20#define _SCM_VM_H_
21
22#include <libguile.h>
23#include <libguile/programs.h>
24
25enum {
26 SCM_VM_APPLY_HOOK,
27 SCM_VM_PUSH_CONTINUATION_HOOK,
28 SCM_VM_POP_CONTINUATION_HOOK,
29 SCM_VM_NEXT_HOOK,
30 SCM_VM_ABORT_CONTINUATION_HOOK,
31 SCM_VM_RESTORE_CONTINUATION_HOOK,
32 SCM_VM_NUM_HOOKS,
33};
34
35struct scm_vm;
36
37typedef SCM (*scm_t_vm_engine) (SCM vm, SCM program, SCM *argv, int nargs);
38
39#define SCM_VM_REGULAR_ENGINE 0
40#define SCM_VM_DEBUG_ENGINE 1
41#define SCM_VM_NUM_ENGINES 2
42
43struct scm_vm {
44 scm_t_uint8 *ip; /* instruction pointer */
45 SCM *sp; /* stack pointer */
46 SCM *fp; /* frame pointer */
47 size_t stack_size; /* stack size */
48 SCM *stack_base; /* stack base address */
49 SCM *stack_limit; /* stack limit address */
50 int engine; /* which vm engine we're using */
51 SCM hooks[SCM_VM_NUM_HOOKS]; /* hooks */
52 SCM options; /* options */
53 int trace_level; /* traces enabled if trace_level > 0 */
54 scm_t_int64 cookie; /* used to detect unrewindable continuations */
55};
56
57SCM_API SCM scm_the_vm_fluid;
58
59#define SCM_VM_P(x) (SCM_NIMP (x) && SCM_TYP7 (x) == scm_tc7_vm)
60#define SCM_VM_DATA(vm) ((struct scm_vm *) SCM_CELL_WORD_1 (vm))
61#define SCM_VALIDATE_VM(pos,x) SCM_MAKE_VALIDATE (pos, x, VM_P)
62
63SCM_API SCM scm_the_vm ();
64SCM_API SCM scm_make_vm (void);
65SCM_API SCM scm_vm_apply (SCM vm, SCM program, SCM args);
66SCM_API SCM scm_c_vm_run (SCM vm, SCM program, SCM *argv, int nargs);
67SCM_API SCM scm_vm_option_ref (SCM vm, SCM key);
68SCM_API SCM scm_vm_option_set_x (SCM vm, SCM key, SCM val);
69
70SCM_API SCM scm_vm_version (void);
71SCM_API SCM scm_the_vm (void);
72SCM_API SCM scm_vm_p (SCM obj);
73SCM_API SCM scm_vm_ip (SCM vm);
74SCM_API SCM scm_vm_sp (SCM vm);
75SCM_API SCM scm_vm_fp (SCM vm);
76SCM_API SCM scm_vm_apply_hook (SCM vm);
77SCM_API SCM scm_vm_push_continuation_hook (SCM vm);
78SCM_API SCM scm_vm_pop_continuation_hook (SCM vm);
79SCM_API SCM scm_vm_abort_continuation_hook (SCM vm);
80SCM_API SCM scm_vm_restore_continuation_hook (SCM vm);
81SCM_API SCM scm_vm_next_hook (SCM vm);
82SCM_API SCM scm_vm_option (SCM vm, SCM key);
83SCM_API SCM scm_set_vm_option_x (SCM vm, SCM key, SCM val);
84SCM_API SCM scm_vm_trace_level (SCM vm);
85SCM_API SCM scm_set_vm_trace_level_x (SCM vm, SCM level);
86
87#define SCM_F_VM_CONT_PARTIAL 0x1
88#define SCM_F_VM_CONT_REWINDABLE 0x2
89
90struct scm_vm_cont {
91 SCM *sp;
92 SCM *fp;
93 scm_t_uint8 *ra, *mvra;
94 scm_t_ptrdiff stack_size;
95 SCM *stack_base;
96 scm_t_ptrdiff reloc;
97 scm_t_uint32 flags;
98};
99
100#define SCM_VM_CONT_P(OBJ) (SCM_NIMP (OBJ) && SCM_TYP7 (OBJ) == scm_tc7_vm_cont)
101#define SCM_VM_CONT_DATA(CONT) ((struct scm_vm_cont *) SCM_CELL_WORD_1 (CONT))
102#define SCM_VM_CONT_PARTIAL_P(CONT) (SCM_VM_CONT_DATA (CONT)->flags & SCM_F_VM_CONT_PARTIAL)
103#define SCM_VM_CONT_REWINDABLE_P(CONT) (SCM_VM_CONT_DATA (CONT)->flags & SCM_F_VM_CONT_REWINDABLE)
104
105SCM_API SCM scm_load_compiled_with_vm (SCM file);
106
107SCM_INTERNAL void scm_i_vm_print (SCM x, SCM port,
108 scm_print_state *pstate);
109SCM_INTERNAL SCM scm_i_vm_capture_continuation (SCM vm);
110SCM_INTERNAL SCM scm_i_vm_capture_stack (SCM *stack_base, SCM *fp, SCM *sp,
111 scm_t_uint8 *ra, scm_t_uint8 *mvra,
112 scm_t_uint32 flags);
113SCM_INTERNAL void scm_i_vm_cont_print (SCM x, SCM port,
114 scm_print_state *pstate);
115SCM_INTERNAL void scm_bootstrap_vm (void);
116SCM_INTERNAL void scm_init_vm (void);
117
118#endif /* _SCM_VM_H_ */
119
120/*
121 Local Variables:
122 c-file-style: "gnu"
123 End:
124*/