compile lexical variable access and closure creation to the new ops
[bpt/guile.git] / libguile / vm-i-loader.c
CommitLineData
53e28ed9 1/* Copyright (C) 2001,2008,2009 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
a5cfddd5 23VM_DEFINE_LOADER (80, load_unsigned_integer, "load-unsigned-integer")
b912a1cd
LC
24{
25 size_t len;
26
27 FETCH_LENGTH (len);
586cfdec 28 if (SCM_LIKELY (len <= 8))
b912a1cd 29 {
586cfdec 30 scm_t_uint64 val = 0;
b912a1cd
LC
31 while (len-- > 0)
32 val = (val << 8U) + FETCH ();
33 SYNC_REGISTER ();
586cfdec 34 PUSH (scm_from_uint64 (val));
b912a1cd
LC
35 NEXT;
36 }
37 else
38 SCM_MISC_ERROR ("load-unsigned-integer: not implemented yet", SCM_EOL);
39}
40
a5cfddd5 41VM_DEFINE_LOADER (81, load_integer, "load-integer")
17e90c5e
KN
42{
43 size_t len;
ea9b4b29 44
17e90c5e 45 FETCH_LENGTH (len);
b912a1cd 46 if (SCM_LIKELY (len <= 4))
ea9b4b29 47 {
53e28ed9 48 int val = 0;
ea9b4b29
KN
49 while (len-- > 0)
50 val = (val << 8) + FETCH ();
1865ad56 51 SYNC_REGISTER ();
53e28ed9 52 PUSH (scm_from_int (val));
ea9b4b29
KN
53 NEXT;
54 }
55 else
56 SCM_MISC_ERROR ("load-integer: not implemented yet", SCM_EOL);
17e90c5e
KN
57}
58
a5cfddd5 59VM_DEFINE_LOADER (82, load_number, "load-number")
17e90c5e
KN
60{
61 size_t len;
f9e8c09d 62
17e90c5e 63 FETCH_LENGTH (len);
1865ad56 64 SYNC_REGISTER ();
b6368dbb 65 PUSH (scm_string_to_number (scm_from_locale_stringn ((char *)ip, len),
9cc649b8 66 SCM_UNDEFINED /* radix = 10 */));
f9e8c09d 67 /* Was: scm_istring2number (ip, len, 10)); */
17e90c5e
KN
68 ip += len;
69 NEXT;
70}
71
a5cfddd5 72VM_DEFINE_LOADER (83, load_string, "load-string")
17e90c5e
KN
73{
74 size_t len;
75 FETCH_LENGTH (len);
1865ad56 76 SYNC_REGISTER ();
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
a5cfddd5 83VM_DEFINE_LOADER (84, load_symbol, "load-symbol")
a80be762
KN
84{
85 size_t len;
86 FETCH_LENGTH (len);
1865ad56 87 SYNC_REGISTER ();
b6368dbb 88 PUSH (scm_from_locale_symboln ((char *)ip, len));
a80be762
KN
89 ip += len;
90 NEXT;
91}
92
a5cfddd5 93VM_DEFINE_LOADER (85, load_keyword, "load-keyword")
17e90c5e 94{
17e90c5e
KN
95 size_t len;
96 FETCH_LENGTH (len);
1865ad56 97 SYNC_REGISTER ();
a52b96a7 98 PUSH (scm_from_locale_keywordn ((char *)ip, len));
17e90c5e
KN
99 ip += len;
100 NEXT;
101}
102
a5cfddd5 103VM_DEFINE_LOADER (86, load_program, "load-program")
17e90c5e 104{
53e28ed9
AW
105 scm_t_uint32 len;
106 SCM objs, objcode;
17e90c5e 107
53e28ed9
AW
108 POP (objs);
109 SYNC_REGISTER ();
ac99cb0c 110
53e28ed9
AW
111 if (scm_is_vector (objs) && scm_is_false (scm_c_vector_ref (objs, 0)))
112 scm_c_vector_set_x (objs, 0, scm_current_module ());
ac99cb0c 113
53e28ed9 114 objcode = scm_c_make_objcode_slice (SCM_PROGRAM_OBJCODE (fp[-1]), ip);
ac47d5f6 115 len = sizeof (struct scm_objcode) + SCM_OBJCODE_TOTAL_LEN (objcode);
206a0622 116
53e28ed9 117 PUSH (scm_make_program (objcode, objs, SCM_EOL));
2fda0242 118
53e28ed9 119 ip += len;
17e90c5e 120
17e90c5e
KN
121 NEXT;
122}
123
a5cfddd5 124VM_DEFINE_INSTRUCTION (87, link_now, "link-now", 0, 1, 1)
17e90c5e 125{
fd358575
AW
126 SCM what;
127 POP (what);
1865ad56 128 SYNC_REGISTER ();
b7393ea1 129 PUSH (resolve_variable (what, scm_current_module ()));
6297d229
AW
130 NEXT;
131}
132
a5cfddd5 133VM_DEFINE_LOADER (88, define, "define")
cd9d95d7
AW
134{
135 SCM sym;
136 size_t len;
137
138 FETCH_LENGTH (len);
1865ad56 139 SYNC_REGISTER ();
cd9d95d7
AW
140 sym = scm_from_locale_symboln ((char *)ip, len);
141 ip += len;
142
1865ad56 143 SYNC_REGISTER ();
cd9d95d7
AW
144 PUSH (scm_sym2var (sym, scm_current_module_lookup_closure (), SCM_BOOL_T));
145 NEXT;
fdcedea6
KN
146}
147
a5cfddd5 148VM_DEFINE_LOADER (89, load_array, "load-array")
782a82ee
AW
149{
150 SCM type, shape;
151 size_t len;
152 FETCH_LENGTH (len);
153 POP (shape);
154 POP (type);
155 SYNC_REGISTER ();
156 PUSH (scm_from_contiguous_typed_array (type, shape, ip, len));
157 ip += len;
158 NEXT;
159}
160
53e28ed9
AW
161/*
162(defun renumber-ops ()
163 "start from top of buffer and renumber 'VM_DEFINE_FOO (\n' sequences"
164 (interactive "")
165 (save-excursion
a5cfddd5 166 (let ((counter 79)) (goto-char (point-min))
53e28ed9
AW
167 (while (re-search-forward "^VM_DEFINE_[^ ]+ (\\([^,]+\\)," (point-max) t)
168 (replace-match
169 (number-to-string (setq counter (1+ counter)))
170 t t nil 1)))))
171*/
172
17e90c5e
KN
173/*
174 Local Variables:
175 c-file-style: "gnu"
176 End:
177*/