Merge remote-tracking branch 'origin/stable-2.0'
[bpt/guile.git] / libguile / vm.h
CommitLineData
9ede013f 1/* Copyright (C) 2001, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
560b9c25
AW
2 *
3 * This library is free software; you can redistribute it and/or
53befeb7
NJ
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.
a98cef7e 7 *
53befeb7
NJ
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
560b9c25
AW
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
a98cef7e 12 *
560b9c25
AW
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
53befeb7
NJ
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 * 02110-1301 USA
560b9c25 17 */
a98cef7e 18
8f5cfc81
KN
19#ifndef _SCM_VM_H_
20#define _SCM_VM_H_
a98cef7e
KN
21
22#include <libguile.h>
22f4ee48 23#include <libguile/programs.h>
a98cef7e 24
c45d4d77
AW
25enum {
26 SCM_VM_APPLY_HOOK,
27 SCM_VM_PUSH_CONTINUATION_HOOK,
28 SCM_VM_POP_CONTINUATION_HOOK,
29 SCM_VM_NEXT_HOOK,
f3120251
AW
30 SCM_VM_ABORT_CONTINUATION_HOOK,
31 SCM_VM_RESTORE_CONTINUATION_HOOK,
c45d4d77
AW
32 SCM_VM_NUM_HOOKS,
33};
a98cef7e 34
6d14383e
AW
35struct scm_vm;
36
7656f194 37typedef SCM (*scm_t_vm_engine) (SCM vm, SCM program, SCM *argv, int nargs);
6d14383e
AW
38
39#define SCM_VM_REGULAR_ENGINE 0
40#define SCM_VM_DEBUG_ENGINE 1
41#define SCM_VM_NUM_ENGINES 2
42
17e90c5e 43struct scm_vm {
2fb924f6 44 scm_t_uint8 *ip; /* instruction pointer */
17e90c5e
KN
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 */
6d14383e 50 int engine; /* which vm engine we're using */
17e90c5e 51 SCM hooks[SCM_VM_NUM_HOOKS]; /* hooks */
7656f194 52 int trace_level; /* traces enabled if trace_level > 0 */
17e90c5e 53};
a98cef7e 54
560b9c25 55SCM_API SCM scm_the_vm_fluid;
7bbed518 56
dc7da0be 57#define SCM_VM_P(x) (SCM_HAS_TYP7 (x, scm_tc7_vm))
6f3b0cc2 58#define SCM_VM_DATA(vm) ((struct scm_vm *) SCM_CELL_WORD_1 (vm))
17e90c5e 59#define SCM_VALIDATE_VM(pos,x) SCM_MAKE_VALIDATE (pos, x, VM_P)
a98cef7e 60
b339459e 61SCM_API SCM scm_the_vm (void);
560b9c25 62SCM_API SCM scm_make_vm (void);
560b9c25 63
560b9c25 64SCM_API SCM scm_the_vm (void);
ea9f4f4b
AW
65SCM_API SCM scm_call_with_vm (SCM vm, SCM proc, SCM args);
66
560b9c25
AW
67SCM_API SCM scm_vm_p (SCM obj);
68SCM_API SCM scm_vm_ip (SCM vm);
69SCM_API SCM scm_vm_sp (SCM vm);
70SCM_API SCM scm_vm_fp (SCM vm);
560b9c25 71SCM_API SCM scm_vm_apply_hook (SCM vm);
c45d4d77
AW
72SCM_API SCM scm_vm_push_continuation_hook (SCM vm);
73SCM_API SCM scm_vm_pop_continuation_hook (SCM vm);
f3120251
AW
74SCM_API SCM scm_vm_abort_continuation_hook (SCM vm);
75SCM_API SCM scm_vm_restore_continuation_hook (SCM vm);
c45d4d77 76SCM_API SCM scm_vm_next_hook (SCM vm);
7656f194
AW
77SCM_API SCM scm_vm_trace_level (SCM vm);
78SCM_API SCM scm_set_vm_trace_level_x (SCM vm, SCM level);
ea9f4f4b
AW
79SCM_API SCM scm_vm_engine (SCM vm);
80SCM_API SCM scm_set_vm_engine_x (SCM vm, SCM engine);
81SCM_API SCM scm_set_default_vm_engine_x (SCM engine);
82SCM_API void scm_c_set_vm_engine_x (SCM vm, int engine);
83SCM_API void scm_c_set_default_vm_engine_x (int engine);
b1b942b7 84
cee1d22c
AW
85#define SCM_F_VM_CONT_PARTIAL 0x1
86#define SCM_F_VM_CONT_REWINDABLE 0x2
87
b1b942b7 88struct scm_vm_cont {
7aa6f86b
AW
89 SCM *sp;
90 SCM *fp;
d8873dfe 91 scm_t_uint8 *ra, *mvra;
b1b942b7
AW
92 scm_t_ptrdiff stack_size;
93 SCM *stack_base;
94 scm_t_ptrdiff reloc;
9ede013f 95 scm_t_dynstack *dynstack;
cee1d22c 96 scm_t_uint32 flags;
b1b942b7
AW
97};
98
dc7da0be 99#define SCM_VM_CONT_P(OBJ) (SCM_HAS_TYP7 (OBJ, scm_tc7_vm_cont))
6f3b0cc2 100#define SCM_VM_CONT_DATA(CONT) ((struct scm_vm_cont *) SCM_CELL_WORD_1 (CONT))
b3950ad6
AW
101#define SCM_VM_CONT_PARTIAL_P(CONT) (SCM_VM_CONT_DATA (CONT)->flags & SCM_F_VM_CONT_PARTIAL)
102#define SCM_VM_CONT_REWINDABLE_P(CONT) (SCM_VM_CONT_DATA (CONT)->flags & SCM_F_VM_CONT_REWINDABLE)
fcd4901b 103
560b9c25 104SCM_API SCM scm_load_compiled_with_vm (SCM file);
07e56b27 105
ea9f4f4b
AW
106SCM_INTERNAL SCM scm_c_vm_run (SCM vm, SCM program, SCM *argv, int nargs);
107
6f3b0cc2
AW
108SCM_INTERNAL void scm_i_vm_print (SCM x, SCM port,
109 scm_print_state *pstate);
9ede013f 110SCM_INTERNAL SCM scm_i_capture_current_stack (void);
cee1d22c
AW
111SCM_INTERNAL SCM scm_i_vm_capture_stack (SCM *stack_base, SCM *fp, SCM *sp,
112 scm_t_uint8 *ra, scm_t_uint8 *mvra,
9ede013f 113 scm_t_dynstack *dynstack,
cee1d22c 114 scm_t_uint32 flags);
6f3b0cc2
AW
115SCM_INTERNAL void scm_i_vm_cont_print (SCM x, SCM port,
116 scm_print_state *pstate);
a6029b97 117SCM_INTERNAL void scm_bootstrap_vm (void);
560b9c25 118SCM_INTERNAL void scm_init_vm (void);
a98cef7e 119
8f5cfc81 120#endif /* _SCM_VM_H_ */
a98cef7e 121
17e90c5e
KN
122/*
123 Local Variables:
124 c-file-style: "gnu"
125 End:
126*/