Commit | Line | Data |
---|---|---|
8f5cfc81 | 1 | /* Copyright (C) 2001 Free Software Foundation, Inc. |
17e90c5e KN |
2 | * |
3 | * This program is free software; you can redistribute it and/or modify | |
4 | * it under the terms of the GNU General Public License as published by | |
5 | * the Free Software Foundation; either version 2, or (at your option) | |
6 | * any later version. | |
7 | * | |
8 | * This program is distributed in the hope that it will be useful, | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | * GNU General Public License for more details. | |
12 | * | |
13 | * You should have received a copy of the GNU General Public License | |
14 | * along with this software; see the file COPYING. If not, write to | |
15 | * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, | |
16 | * Boston, MA 02111-1307 USA | |
17 | * | |
18 | * As a special exception, the Free Software Foundation gives permission | |
19 | * for additional uses of the text contained in its release of GUILE. | |
20 | * | |
21 | * The exception is that, if you link the GUILE library with other files | |
22 | * to produce an executable, this does not by itself cause the | |
23 | * resulting executable to be covered by the GNU General Public License. | |
24 | * Your use of that executable is in no way restricted on account of | |
25 | * linking the GUILE library code into it. | |
26 | * | |
27 | * This exception does not however invalidate any other reasons why | |
28 | * the executable file might be covered by the GNU General Public License. | |
29 | * | |
30 | * This exception applies only to the code released by the | |
31 | * Free Software Foundation under the name GUILE. If you copy | |
32 | * code from other Free Software Foundation releases into a copy of | |
33 | * GUILE, as the General Public License permits, the exception does | |
34 | * not apply to the code that you add in this way. To avoid misleading | |
35 | * anyone as to the status of such modified files, you must delete | |
36 | * this exception notice from them. | |
37 | * | |
38 | * If you write modifications of your own for GUILE, it is your choice | |
39 | * whether to permit this exception to apply to your modifications. | |
40 | * If you do not wish that, delete this exception notice. */ | |
41 | ||
42 | /* This file is included in vm_engine.c */ | |
43 | ||
3616e9e9 | 44 | VM_DEFINE_LOADER (load_integer, "load-integer") |
17e90c5e KN |
45 | { |
46 | size_t len; | |
ea9b4b29 | 47 | |
17e90c5e | 48 | FETCH_LENGTH (len); |
ea9b4b29 KN |
49 | if (len <= 4) |
50 | { | |
51 | long val = 0; | |
52 | while (len-- > 0) | |
53 | val = (val << 8) + FETCH (); | |
f41cb00c | 54 | PUSH (scm_from_ulong (val)); |
ea9b4b29 KN |
55 | NEXT; |
56 | } | |
57 | else | |
58 | SCM_MISC_ERROR ("load-integer: not implemented yet", SCM_EOL); | |
17e90c5e KN |
59 | } |
60 | ||
3616e9e9 | 61 | VM_DEFINE_LOADER (load_number, "load-number") |
17e90c5e KN |
62 | { |
63 | size_t len; | |
f9e8c09d | 64 | |
17e90c5e | 65 | FETCH_LENGTH (len); |
b6368dbb | 66 | PUSH (scm_string_to_number (scm_from_locale_stringn ((char *)ip, len), |
f9e8c09d LC |
67 | SCM_UNSPECIFIED /* radix = 10 */)); |
68 | /* Was: scm_istring2number (ip, len, 10)); */ | |
17e90c5e KN |
69 | ip += len; |
70 | NEXT; | |
71 | } | |
72 | ||
3616e9e9 | 73 | VM_DEFINE_LOADER (load_string, "load-string") |
17e90c5e KN |
74 | { |
75 | size_t len; | |
76 | FETCH_LENGTH (len); | |
b6368dbb | 77 | PUSH (scm_from_locale_stringn ((char *)ip, len)); |
f9e8c09d | 78 | /* Was: scm_makfromstr (ip, len, 0) */ |
17e90c5e KN |
79 | ip += len; |
80 | NEXT; | |
81 | } | |
82 | ||
3616e9e9 | 83 | VM_DEFINE_LOADER (load_symbol, "load-symbol") |
a80be762 KN |
84 | { |
85 | size_t len; | |
86 | FETCH_LENGTH (len); | |
b6368dbb | 87 | PUSH (scm_from_locale_symboln ((char *)ip, len)); |
a80be762 KN |
88 | ip += len; |
89 | NEXT; | |
90 | } | |
91 | ||
3616e9e9 | 92 | VM_DEFINE_LOADER (load_keyword, "load-keyword") |
17e90c5e | 93 | { |
17e90c5e KN |
94 | size_t len; |
95 | FETCH_LENGTH (len); | |
a52b96a7 | 96 | PUSH (scm_from_locale_keywordn ((char *)ip, len)); |
17e90c5e KN |
97 | ip += len; |
98 | NEXT; | |
99 | } | |
100 | ||
3616e9e9 | 101 | VM_DEFINE_LOADER (load_module, "load-module") |
17e90c5e KN |
102 | { |
103 | size_t len; | |
104 | FETCH_LENGTH (len); | |
b6368dbb | 105 | PUSH (scm_c_lookup_env (scm_from_locale_symboln ((char *)ip, len))); |
17e90c5e KN |
106 | ip += len; |
107 | NEXT; | |
108 | } | |
109 | ||
3616e9e9 | 110 | VM_DEFINE_LOADER (load_program, "load-program") |
17e90c5e KN |
111 | { |
112 | size_t len; | |
113 | SCM prog, x; | |
ac99cb0c | 114 | struct scm_program *p; |
17e90c5e KN |
115 | |
116 | FETCH_LENGTH (len); | |
117 | prog = scm_c_make_program (ip, len, program); | |
ac99cb0c | 118 | p = SCM_PROGRAM_DATA (prog); |
206a0622 | 119 | ip += len; |
17e90c5e | 120 | |
ac99cb0c KN |
121 | POP (x); |
122 | ||
123 | /* init meta data */ | |
124 | if (SCM_CONSP (x)) | |
125 | { | |
126 | p->meta = x; | |
127 | POP (x); | |
128 | } | |
129 | ||
206a0622 | 130 | /* init object table */ |
238e7a11 | 131 | if (scm_is_vector (x)) |
206a0622 | 132 | { |
a52b2d3d LC |
133 | #if 0 |
134 | if (scm_is_simple_vector (x)) | |
135 | printf ("is_simple_vector!\n"); | |
136 | else | |
137 | printf ("NOT is_simple_vector\n"); | |
138 | #endif | |
ac99cb0c KN |
139 | p->objs = x; |
140 | POP (x); | |
206a0622 KN |
141 | } |
142 | ||
143 | /* init parameters */ | |
4bfb26f5 | 144 | /* NOTE: format defined in system/vm/assemble.scm */ |
2d80426a | 145 | if (SCM_I_INUMP (x)) |
17e90c5e | 146 | { |
2d80426a | 147 | int i = SCM_I_INUM (x); |
3d5ee0cd KN |
148 | if (-128 <= i && i <= 127) |
149 | { | |
150 | /* 8-bit representation */ | |
ac99cb0c KN |
151 | p->nargs = (i >> 6) & 0x03; /* 7-6 bits */ |
152 | p->nrest = (i >> 5) & 0x01; /* 5 bit */ | |
153 | p->nlocs = (i >> 2) & 0x07; /* 4-2 bits */ | |
154 | p->nexts = i & 0x03; /* 1-0 bits */ | |
3d5ee0cd KN |
155 | } |
156 | else | |
157 | { | |
158 | /* 16-bit representation */ | |
ac99cb0c KN |
159 | p->nargs = (i >> 12) & 0x07; /* 15-12 bits */ |
160 | p->nrest = (i >> 11) & 0x01; /* 11 bit */ | |
161 | p->nlocs = (i >> 4) & 0x7f; /* 10-04 bits */ | |
162 | p->nexts = i & 0x0f; /* 03-00 bits */ | |
3d5ee0cd | 163 | } |
17e90c5e KN |
164 | } |
165 | else | |
166 | { | |
3d5ee0cd | 167 | /* Other cases */ |
3616e9e9 | 168 | sp -= 4; |
2d80426a LC |
169 | p->nargs = SCM_I_INUM (sp[0]); |
170 | p->nrest = SCM_I_INUM (sp[1]); | |
171 | p->nlocs = SCM_I_INUM (sp[2]); | |
172 | p->nexts = SCM_I_INUM (sp[3]); | |
17e90c5e KN |
173 | } |
174 | ||
ac99cb0c | 175 | PUSH (prog); |
17e90c5e KN |
176 | NEXT; |
177 | } | |
178 | ||
1b8abe55 | 179 | /* this seems to be a bit too much processing for one instruction.. */ |
6167de4f | 180 | VM_DEFINE_INSTRUCTION (link, "link", 0, 2, 1) |
17e90c5e | 181 | { |
6167de4f AW |
182 | SCM modname, mod, sym; |
183 | POP (sym); | |
184 | POP (modname); | |
185 | if (SCM_NFALSEP (modname)) | |
186 | { | |
1b8abe55 AW |
187 | mod = scm_resolve_module (modname); |
188 | ||
189 | if (mod != scm_current_module ()) | |
190 | { | |
191 | mod = scm_c_module_lookup (mod, "%module-public-interface"); | |
192 | if (SCM_FALSEP (mod)) | |
193 | SCM_MISC_ERROR ("Could not load module", SCM_LIST1 (modname)); | |
194 | mod = SCM_VARIABLE_REF (mod); | |
195 | } | |
6167de4f | 196 | |
1b8abe55 | 197 | PUSH (scm_module_lookup (mod, sym)); |
6167de4f AW |
198 | } |
199 | else | |
200 | PUSH (scm_lookup (sym)); | |
201 | ||
cd9d95d7 AW |
202 | NEXT; |
203 | } | |
204 | ||
205 | VM_DEFINE_LOADER (define, "define") | |
206 | { | |
207 | SCM sym; | |
208 | size_t len; | |
209 | ||
210 | FETCH_LENGTH (len); | |
211 | sym = scm_from_locale_symboln ((char *)ip, len); | |
212 | ip += len; | |
213 | ||
214 | PUSH (scm_sym2var (sym, scm_current_module_lookup_closure (), SCM_BOOL_T)); | |
215 | NEXT; | |
fdcedea6 KN |
216 | } |
217 | ||
17e90c5e KN |
218 | /* |
219 | Local Variables: | |
220 | c-file-style: "gnu" | |
221 | End: | |
222 | */ |