Merge remote-tracking branch 'origin/stable-2.0'
[bpt/guile.git] / libguile / instructions.h
1 /* Copyright (C) 2001, 2009, 2012 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_INSTRUCTIONS_H_
20 #define _SCM_INSTRUCTIONS_H_
21
22 #include <libguile.h>
23 #include <libguile/vm-operations.h>
24
25 enum scm_rtl_opcode
26 {
27 #define ENUM(opcode, tag, name, meta) scm_rtl_op_##tag = opcode,
28 FOR_EACH_VM_OPERATION(ENUM)
29 #undef ENUM
30 };
31
32 #define SCM_PACK_RTL_8_8_8(op,a,b,c) ((op) | ((a) << 8) | ((b) << 16) | ((c) << 24))
33 #define SCM_PACK_RTL_8_16(op,a,b) ((op) | ((a) << 8) | ((b) << 16))
34 #define SCM_PACK_RTL_16_8(op,a,b) ((op) | ((a) << 8) | ((b) << 24))
35 #define SCM_PACK_RTL_24(op,a) ((op) | ((a) << 8))
36
37 #define SCM_UNPACK_RTL_8_8_8(op,a,b,c) \
38 do \
39 { \
40 a = (op >> 8) & 0xff; \
41 b = (op >> 16) & 0xff; \
42 c = op >> 24; \
43 } \
44 while (0)
45
46 #define SCM_UNPACK_RTL_8_16(op,a,b) \
47 do \
48 { \
49 a = (op >> 8) & 0xff; \
50 b = op >> 16; \
51 } \
52 while (0)
53
54 #define SCM_UNPACK_RTL_16_8(op,a,b) \
55 do \
56 { \
57 a = (op >> 8) & 0xffff; \
58 b = op >> 24; \
59 } \
60 while (0)
61
62 #define SCM_UNPACK_RTL_12_12(op,a,b) \
63 do \
64 { \
65 a = (op >> 8) & 0xfff; \
66 b = op >> 20; \
67 } \
68 while (0)
69
70 #define SCM_UNPACK_RTL_24(op,a) \
71 do \
72 { \
73 a = op >> 8; \
74 } \
75 while (0)
76
77 #define SCM_VM_NUM_INSTRUCTIONS (1<<8)
78 #define SCM_VM_INSTRUCTION_MASK (SCM_VM_NUM_INSTRUCTIONS-1)
79
80 enum scm_opcode {
81 #define VM_INSTRUCTION_TO_OPCODE 1
82 #include <libguile/vm-expand.h>
83 #include <libguile/vm-i-system.i>
84 #include <libguile/vm-i-scheme.i>
85 #include <libguile/vm-i-loader.i>
86 #undef VM_INSTRUCTION_TO_OPCODE
87 };
88
89 SCM_INTERNAL SCM scm_rtl_instruction_list (void);
90
91 SCM_API SCM scm_instruction_list (void);
92 SCM_API SCM scm_instruction_p (SCM obj);
93 SCM_API SCM scm_instruction_length (SCM inst);
94 SCM_API SCM scm_instruction_pops (SCM inst);
95 SCM_API SCM scm_instruction_pushes (SCM inst);
96 SCM_API SCM scm_instruction_to_opcode (SCM inst);
97 SCM_API SCM scm_opcode_to_instruction (SCM op);
98
99 SCM_INTERNAL void scm_bootstrap_instructions (void);
100 SCM_INTERNAL void scm_init_instructions (void);
101
102 #endif /* _SCM_INSTRUCTIONS_H_ */
103
104 /*
105 Local Variables:
106 c-file-style: "gnu"
107 End:
108 */