*** empty log message ***
[bpt/guile.git] / src / vm_loader.c
CommitLineData
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 44VM_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 ();
54 PUSH (scm_long2num (val));
55 NEXT;
56 }
57 else
58 SCM_MISC_ERROR ("load-integer: not implemented yet", SCM_EOL);
17e90c5e
KN
59}
60
3616e9e9 61VM_DEFINE_LOADER (load_number, "load-number")
17e90c5e
KN
62{
63 size_t len;
64 FETCH_LENGTH (len);
a80be762 65 PUSH (scm_istring2number (ip, len, 10));
17e90c5e
KN
66 ip += len;
67 NEXT;
68}
69
3616e9e9 70VM_DEFINE_LOADER (load_string, "load-string")
17e90c5e
KN
71{
72 size_t len;
73 FETCH_LENGTH (len);
74 PUSH (scm_makfromstr (ip, len, 0));
75 ip += len;
76 NEXT;
77}
78
3616e9e9 79VM_DEFINE_LOADER (load_symbol, "load-symbol")
a80be762
KN
80{
81 size_t len;
82 FETCH_LENGTH (len);
83 PUSH (scm_mem2symbol (ip, len));
84 ip += len;
85 NEXT;
86}
87
3616e9e9 88VM_DEFINE_LOADER (load_keyword, "load-keyword")
17e90c5e
KN
89{
90 SCM sym;
91 size_t len;
92 FETCH_LENGTH (len);
93 sym = scm_mem2symbol (ip, len);
94 PUSH (scm_make_keyword_from_dash_symbol (sym));
95 ip += len;
96 NEXT;
97}
98
3616e9e9 99VM_DEFINE_LOADER (load_module, "load-module")
17e90c5e
KN
100{
101 size_t len;
102 FETCH_LENGTH (len);
103 PUSH (scm_c_lookup_env (scm_mem2symbol (ip, len)));
104 ip += len;
105 NEXT;
106}
107
3616e9e9 108VM_DEFINE_LOADER (load_program, "load-program")
17e90c5e
KN
109{
110 size_t len;
111 SCM prog, x;
ac99cb0c 112 struct scm_program *p;
17e90c5e
KN
113
114 FETCH_LENGTH (len);
115 prog = scm_c_make_program (ip, len, program);
ac99cb0c 116 p = SCM_PROGRAM_DATA (prog);
206a0622 117 ip += len;
17e90c5e 118
ac99cb0c
KN
119 POP (x);
120
121 /* init meta data */
122 if (SCM_CONSP (x))
123 {
124 p->meta = x;
125 POP (x);
126 }
127
206a0622 128 /* init object table */
206a0622
KN
129 if (SCM_VECTORP (x))
130 {
ac99cb0c
KN
131 p->objs = x;
132 POP (x);
206a0622
KN
133 }
134
135 /* init parameters */
4bfb26f5 136 /* NOTE: format defined in system/vm/assemble.scm */
17e90c5e
KN
137 if (SCM_INUMP (x))
138 {
139 int i = SCM_INUM (x);
3d5ee0cd
KN
140 if (-128 <= i && i <= 127)
141 {
142 /* 8-bit representation */
ac99cb0c
KN
143 p->nargs = (i >> 6) & 0x03; /* 7-6 bits */
144 p->nrest = (i >> 5) & 0x01; /* 5 bit */
145 p->nlocs = (i >> 2) & 0x07; /* 4-2 bits */
146 p->nexts = i & 0x03; /* 1-0 bits */
3d5ee0cd
KN
147 }
148 else
149 {
150 /* 16-bit representation */
ac99cb0c
KN
151 p->nargs = (i >> 12) & 0x07; /* 15-12 bits */
152 p->nrest = (i >> 11) & 0x01; /* 11 bit */
153 p->nlocs = (i >> 4) & 0x7f; /* 10-04 bits */
154 p->nexts = i & 0x0f; /* 03-00 bits */
3d5ee0cd 155 }
17e90c5e
KN
156 }
157 else
158 {
3d5ee0cd 159 /* Other cases */
3616e9e9 160 sp -= 4;
ac99cb0c
KN
161 p->nargs = SCM_INUM (sp[0]);
162 p->nrest = SCM_INUM (sp[1]);
163 p->nlocs = SCM_INUM (sp[2]);
164 p->nexts = SCM_INUM (sp[3]);
17e90c5e
KN
165 }
166
ac99cb0c 167 PUSH (prog);
17e90c5e
KN
168 NEXT;
169}
170
cb4cca12 171VM_DEFINE_LOADER (link, "link")
17e90c5e 172{
cb4cca12
KN
173 SCM sym;
174 size_t len;
175
176 FETCH_LENGTH (len);
177 sym = scm_mem2symbol (ip, len);
178 ip += len;
179
41f248a8 180#if 0
cb4cca12 181 *sp = scm_c_env_vcell (*sp, sym, 1);
41f248a8 182#endif
cb4cca12
KN
183 {
184 /* Temporary hack that supports the current module system */
185 SCM mod = scm_current_module ();
186 SCM var = scm_eval_closure_lookup (scm_standard_eval_closure (mod),
187 sym, SCM_BOOL_F);
188 if (SCM_FALSEP (var))
189 /* Create a new variable if not defined yet */
190 var = scm_eval_closure_lookup (scm_standard_eval_closure (mod),
191 sym, SCM_BOOL_T);
192 PUSH (SCM_VARVCELL (var));
193 NEXT;
194 }
fdcedea6
KN
195}
196
17e90c5e
KN
197/*
198 Local Variables:
199 c-file-style: "gnu"
200 End:
201*/