Export <slot> from GOOPS
[bpt/guile.git] / libguile / vm.h
CommitLineData
7dba1c2f 1/* Copyright (C) 2001, 2009, 2010, 2011, 2012, 2013, 2014 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 30 SCM_VM_ABORT_CONTINUATION_HOOK,
c45d4d77
AW
31 SCM_VM_NUM_HOOKS,
32};
a98cef7e 33
6d14383e
AW
34#define SCM_VM_REGULAR_ENGINE 0
35#define SCM_VM_DEBUG_ENGINE 1
36#define SCM_VM_NUM_ENGINES 2
37
17e90c5e 38struct scm_vm {
9121d9f1 39 scm_t_uint32 *ip; /* instruction pointer */
17e90c5e
KN
40 SCM *sp; /* stack pointer */
41 SCM *fp; /* frame pointer */
17e90c5e 42 SCM *stack_limit; /* stack limit address */
7656f194 43 int trace_level; /* traces enabled if trace_level > 0 */
7dba1c2f
AW
44 SCM *sp_max_since_gc; /* highest sp since last gc */
45 size_t stack_size; /* stack size */
46 SCM *stack_base; /* stack base address */
f764e259 47 SCM overflow_handler_stack; /* alist of max-stack-size -> thunk */
a3da4498
AW
48 SCM hooks[SCM_VM_NUM_HOOKS]; /* hooks */
49 int engine; /* which vm engine we're using */
17e90c5e 50};
a98cef7e 51
e7f9abab 52SCM_INTERNAL struct scm_vm *scm_the_vm (void);
972275ee 53SCM_API SCM scm_call_with_vm (SCM proc, SCM args);
ea9f4f4b 54
f764e259
AW
55SCM_API SCM scm_call_with_stack_overflow_handler (SCM limit, SCM thunk,
56 SCM handler);
57
972275ee
AW
58SCM_API SCM scm_vm_apply_hook (void);
59SCM_API SCM scm_vm_push_continuation_hook (void);
60SCM_API SCM scm_vm_pop_continuation_hook (void);
61SCM_API SCM scm_vm_abort_continuation_hook (void);
972275ee
AW
62SCM_API SCM scm_vm_next_hook (void);
63SCM_API SCM scm_vm_trace_level (void);
64SCM_API SCM scm_set_vm_trace_level_x (SCM level);
65SCM_API SCM scm_vm_engine (void);
66SCM_API SCM scm_set_vm_engine_x (SCM engine);
ea9f4f4b 67SCM_API SCM scm_set_default_vm_engine_x (SCM engine);
972275ee 68SCM_API void scm_c_set_vm_engine_x (int engine);
ea9f4f4b 69SCM_API void scm_c_set_default_vm_engine_x (int engine);
b1b942b7 70
5f18bc84
AW
71struct GC_ms_entry;
72SCM_INTERNAL struct GC_ms_entry * scm_i_vm_mark_stack (struct scm_vm *,
73 struct GC_ms_entry *,
74 struct GC_ms_entry *);
75SCM_INTERNAL void scm_i_vm_free_stack (struct scm_vm *vp);
76
cee1d22c
AW
77#define SCM_F_VM_CONT_PARTIAL 0x1
78#define SCM_F_VM_CONT_REWINDABLE 0x2
79
b1b942b7 80struct scm_vm_cont {
7aa6f86b
AW
81 SCM *sp;
82 SCM *fp;
9121d9f1 83 scm_t_uint32 *ra;
b1b942b7
AW
84 scm_t_ptrdiff stack_size;
85 SCM *stack_base;
86 scm_t_ptrdiff reloc;
9ede013f 87 scm_t_dynstack *dynstack;
cee1d22c 88 scm_t_uint32 flags;
b1b942b7
AW
89};
90
dc7da0be 91#define SCM_VM_CONT_P(OBJ) (SCM_HAS_TYP7 (OBJ, scm_tc7_vm_cont))
6f3b0cc2 92#define SCM_VM_CONT_DATA(CONT) ((struct scm_vm_cont *) SCM_CELL_WORD_1 (CONT))
b3950ad6
AW
93#define SCM_VM_CONT_PARTIAL_P(CONT) (SCM_VM_CONT_DATA (CONT)->flags & SCM_F_VM_CONT_PARTIAL)
94#define SCM_VM_CONT_REWINDABLE_P(CONT) (SCM_VM_CONT_DATA (CONT)->flags & SCM_F_VM_CONT_REWINDABLE)
fcd4901b 95
560b9c25 96SCM_API SCM scm_load_compiled_with_vm (SCM file);
07e56b27 97
486013d6 98SCM_INTERNAL SCM scm_i_call_with_current_continuation (SCM proc);
9ede013f 99SCM_INTERNAL SCM scm_i_capture_current_stack (void);
cee1d22c 100SCM_INTERNAL SCM scm_i_vm_capture_stack (SCM *stack_base, SCM *fp, SCM *sp,
9121d9f1 101 scm_t_uint32 *ra,
9ede013f 102 scm_t_dynstack *dynstack,
cee1d22c 103 scm_t_uint32 flags);
4cfa92d6 104SCM_INTERNAL int scm_i_vm_cont_to_frame (SCM cont, struct scm_frame *frame);
6f3b0cc2
AW
105SCM_INTERNAL void scm_i_vm_cont_print (SCM x, SCM port,
106 scm_print_state *pstate);
a6029b97 107SCM_INTERNAL void scm_bootstrap_vm (void);
560b9c25 108SCM_INTERNAL void scm_init_vm (void);
a98cef7e 109
8f5cfc81 110#endif /* _SCM_VM_H_ */
a98cef7e 111
17e90c5e
KN
112/*
113 Local Variables:
114 c-file-style: "gnu"
115 End:
116*/