Commit | Line | Data |
---|---|---|
4a655e50 | 1 | /* Copyright (C) 2001,2008,2009,2010,2011 Free Software Foundation, Inc. |
17e90c5e | 2 | * |
53e28ed9 | 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. | |
17e90c5e | 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 | |
53e28ed9 AW |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
11 | * Lesser General Public License for more details. | |
17e90c5e | 12 | * |
53e28ed9 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 | |
53e28ed9 AW |
17 | */ |
18 | ||
782a82ee | 19 | /* FIXME! Need to check that the fetch is within the current program */ |
17e90c5e KN |
20 | |
21 | /* This file is included in vm_engine.c */ | |
22 | ||
827dc8dc | 23 | VM_DEFINE_LOADER (101, load_number, "load-number") |
17e90c5e KN |
24 | { |
25 | size_t len; | |
f9e8c09d | 26 | |
17e90c5e | 27 | FETCH_LENGTH (len); |
1865ad56 | 28 | SYNC_REGISTER (); |
b6368dbb | 29 | PUSH (scm_string_to_number (scm_from_locale_stringn ((char *)ip, len), |
9cc649b8 | 30 | SCM_UNDEFINED /* radix = 10 */)); |
f9e8c09d | 31 | /* Was: scm_istring2number (ip, len, 10)); */ |
17e90c5e KN |
32 | ip += len; |
33 | NEXT; | |
34 | } | |
35 | ||
827dc8dc | 36 | VM_DEFINE_LOADER (102, load_string, "load-string") |
17e90c5e KN |
37 | { |
38 | size_t len; | |
94ff26b9 | 39 | char *buf; |
9c44cd45 | 40 | |
17e90c5e | 41 | FETCH_LENGTH (len); |
1865ad56 | 42 | SYNC_REGISTER (); |
190d4b0d | 43 | PUSH (scm_i_make_string (len, &buf, 1)); |
94ff26b9 AW |
44 | memcpy (buf, (char *) ip, len); |
45 | ip += len; | |
17e90c5e KN |
46 | NEXT; |
47 | } | |
48 | ||
827dc8dc | 49 | VM_DEFINE_LOADER (103, load_symbol, "load-symbol") |
a80be762 KN |
50 | { |
51 | size_t len; | |
17e90c5e | 52 | FETCH_LENGTH (len); |
1865ad56 | 53 | SYNC_REGISTER (); |
94ff26b9 | 54 | /* FIXME: should be scm_from_latin1_symboln */ |
4a655e50 | 55 | PUSH (scm_from_latin1_symboln ((const char*)ip, len)); |
94ff26b9 | 56 | ip += len; |
17e90c5e KN |
57 | NEXT; |
58 | } | |
59 | ||
827dc8dc | 60 | VM_DEFINE_LOADER (104, load_program, "load-program") |
17e90c5e | 61 | { |
53e28ed9 AW |
62 | scm_t_uint32 len; |
63 | SCM objs, objcode; | |
17e90c5e | 64 | |
53e28ed9 AW |
65 | POP (objs); |
66 | SYNC_REGISTER (); | |
ac99cb0c | 67 | |
53e28ed9 AW |
68 | if (scm_is_vector (objs) && scm_is_false (scm_c_vector_ref (objs, 0))) |
69 | scm_c_vector_set_x (objs, 0, scm_current_module ()); | |
ac99cb0c | 70 | |
53e28ed9 | 71 | objcode = scm_c_make_objcode_slice (SCM_PROGRAM_OBJCODE (fp[-1]), ip); |
ac47d5f6 | 72 | len = sizeof (struct scm_objcode) + SCM_OBJCODE_TOTAL_LEN (objcode); |
206a0622 | 73 | |
20d47c39 | 74 | PUSH (scm_make_program (objcode, objs, SCM_BOOL_F)); |
2fda0242 | 75 | |
53e28ed9 | 76 | ip += len; |
17e90c5e | 77 | |
17e90c5e KN |
78 | NEXT; |
79 | } | |
80 | ||
827dc8dc | 81 | VM_DEFINE_INSTRUCTION (105, link_now, "link-now", 0, 1, 1) |
17e90c5e | 82 | { |
fd358575 AW |
83 | SCM what; |
84 | POP (what); | |
1865ad56 | 85 | SYNC_REGISTER (); |
b7393ea1 | 86 | PUSH (resolve_variable (what, scm_current_module ())); |
6297d229 AW |
87 | NEXT; |
88 | } | |
89 | ||
827dc8dc | 90 | VM_DEFINE_LOADER (106, load_array, "load-array") |
cd9d95d7 | 91 | { |
94ff26b9 | 92 | SCM type, shape; |
cd9d95d7 | 93 | size_t len; |
cd9d95d7 | 94 | FETCH_LENGTH (len); |
eae2438d | 95 | POP2 (shape, type); |
1865ad56 | 96 | SYNC_REGISTER (); |
94ff26b9 AW |
97 | PUSH (scm_from_contiguous_typed_array (type, shape, ip, len)); |
98 | ip += len; | |
cd9d95d7 | 99 | NEXT; |
fdcedea6 KN |
100 | } |
101 | ||
827dc8dc | 102 | VM_DEFINE_LOADER (107, load_wide_string, "load-wide-string") |
782a82ee | 103 | { |
782a82ee | 104 | size_t len; |
94ff26b9 AW |
105 | scm_t_wchar *wbuf; |
106 | ||
782a82ee | 107 | FETCH_LENGTH (len); |
94ff26b9 | 108 | if (SCM_UNLIKELY (len % 4)) |
71fc6438 AW |
109 | { |
110 | finish_args = scm_list_1 (scm_from_size_t (len)); | |
94ff26b9 AW |
111 | goto vm_error_bad_wide_string_length; |
112 | } | |
113 | ||
782a82ee | 114 | SYNC_REGISTER (); |
190d4b0d | 115 | PUSH (scm_i_make_wide_string (len / 4, &wbuf, 1)); |
94ff26b9 | 116 | memcpy ((char *) wbuf, (char *) ip, len); |
782a82ee AW |
117 | ip += len; |
118 | NEXT; | |
119 | } | |
120 | ||
53e28ed9 AW |
121 | /* |
122 | (defun renumber-ops () | |
123 | "start from top of buffer and renumber 'VM_DEFINE_FOO (\n' sequences" | |
124 | (interactive "") | |
125 | (save-excursion | |
827dc8dc | 126 | (let ((counter 100)) (goto-char (point-min)) |
53e28ed9 AW |
127 | (while (re-search-forward "^VM_DEFINE_[^ ]+ (\\([^,]+\\)," (point-max) t) |
128 | (replace-match | |
129 | (number-to-string (setq counter (1+ counter))) | |
130 | t t nil 1))))) | |
131 | */ | |
132 | ||
17e90c5e KN |
133 | /* |
134 | Local Variables: | |
135 | c-file-style: "gnu" | |
136 | End: | |
137 | */ |