1 /* Copyright (C) 2001 Free Software Foundation, Inc.
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)
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.
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
18 * As a special exception, the Free Software Foundation gives permission
19 * for additional uses of the text contained in its release of GUILE.
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.
27 * This exception does not however invalidate any other reasons why
28 * the executable file might be covered by the GNU General Public License.
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.
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. */
42 /* This file is included in vm_engine.c */
49 #define ARGS1(a1) SCM a1 = sp[0];
50 #define ARGS2(a1,a2) SCM a1 = sp[-1], a2 = sp[0]; sp--; NULLSTACK (1);
51 #define ARGS3(a1,a2,a3) SCM a1 = sp[-2], a2 = sp[-1], a3 = sp[0]; sp -= 2; NULLSTACK (2);
53 #define RETURN(x) do { *sp = x; NEXT; } while (0)
55 VM_DEFINE_FUNCTION (80, not, "not", 1)
58 RETURN (SCM_BOOL (SCM_FALSEP (x
)));
61 VM_DEFINE_FUNCTION (81, not_not
, "not-not", 1)
64 RETURN (SCM_BOOL (!SCM_FALSEP (x
)));
67 VM_DEFINE_FUNCTION (82, eq
, "eq?", 2)
70 RETURN (SCM_BOOL (SCM_EQ_P (x
, y
)));
73 VM_DEFINE_FUNCTION (83, not_eq, "not-eq?", 2)
76 RETURN (SCM_BOOL (!SCM_EQ_P (x
, y
)));
79 VM_DEFINE_FUNCTION (84, nullp
, "null?", 1)
82 RETURN (SCM_BOOL (SCM_NULLP (x
)));
85 VM_DEFINE_FUNCTION (85, not_nullp
, "not-null?", 1)
88 RETURN (SCM_BOOL (!SCM_NULLP (x
)));
91 VM_DEFINE_FUNCTION (86, eqv
, "eqv?", 2)
96 if (SCM_IMP (x
) || SCM_IMP (y
))
99 RETURN (scm_eqv_p (x
, y
));
102 VM_DEFINE_FUNCTION (87, equal
, "equal?", 2)
107 if (SCM_IMP (x
) || SCM_IMP (y
))
110 RETURN (scm_equal_p (x
, y
));
113 VM_DEFINE_FUNCTION (88, pairp
, "pair?", 1)
116 RETURN (SCM_BOOL (SCM_CONSP (x
)));
119 VM_DEFINE_FUNCTION (89, listp
, "list?", 1)
122 RETURN (SCM_BOOL (scm_ilength (x
) >= 0));
130 VM_DEFINE_FUNCTION (90, cons
, "cons", 2)
137 #define VM_VALIDATE_CONS(x) \
138 if (SCM_UNLIKELY (!scm_is_pair (x))) \
140 goto vm_error_not_a_pair; \
143 VM_DEFINE_FUNCTION (91, car
, "car", 1)
146 VM_VALIDATE_CONS (x
);
147 RETURN (SCM_CAR (x
));
150 VM_DEFINE_FUNCTION (92, cdr
, "cdr", 1)
153 VM_VALIDATE_CONS (x
);
154 RETURN (SCM_CDR (x
));
157 VM_DEFINE_FUNCTION (93, set_car
, "set-car!", 2)
160 VM_VALIDATE_CONS (x
);
162 RETURN (SCM_UNSPECIFIED
);
165 VM_DEFINE_FUNCTION (94, set_cdr
, "set-cdr!", 2)
168 VM_VALIDATE_CONS (x
);
170 RETURN (SCM_UNSPECIFIED
);
175 * Numeric relational tests
179 #define REL(crel,srel) \
182 if (SCM_I_INUMP (x) && SCM_I_INUMP (y)) \
183 RETURN (SCM_BOOL (SCM_I_INUM (x) crel SCM_I_INUM (y))); \
185 RETURN (srel (x, y)); \
188 VM_DEFINE_FUNCTION (95, ee
, "ee?", 2)
190 REL (==, scm_num_eq_p
);
193 VM_DEFINE_FUNCTION (96, lt
, "lt?", 2)
198 VM_DEFINE_FUNCTION (97, le
, "le?", 2)
203 VM_DEFINE_FUNCTION (98, gt
, "gt?", 2)
208 VM_DEFINE_FUNCTION (99, ge
, "ge?", 2)
219 #define FUNC2(CFUNC,SFUNC) \
222 if (SCM_I_INUMP (x) && SCM_I_INUMP (y)) \
224 scm_t_bits n = SCM_I_INUM (x) CFUNC SCM_I_INUM (y);\
225 if (SCM_FIXABLE (n)) \
226 RETURN (SCM_I_MAKINUM (n)); \
229 RETURN (SFUNC (x, y)); \
232 VM_DEFINE_FUNCTION (100, add
, "add", 2)
237 VM_DEFINE_FUNCTION (101, sub
, "sub", 2)
239 FUNC2 (-, scm_difference
);
242 VM_DEFINE_FUNCTION (102, mul
, "mul", 2)
246 RETURN (scm_product (x
, y
));
249 VM_DEFINE_FUNCTION (103, div
, "div", 2)
253 RETURN (scm_divide (x
, y
));
256 VM_DEFINE_FUNCTION (104, quo
, "quo", 2)
260 RETURN (scm_quotient (x
, y
));
263 VM_DEFINE_FUNCTION (105, rem
, "rem", 2)
267 RETURN (scm_remainder (x
, y
));
270 VM_DEFINE_FUNCTION (106, mod
, "mod", 2)
274 RETURN (scm_modulo (x
, y
));
281 VM_DEFINE_FUNCTION (107, slot_ref
, "slot-ref", 2)
284 ARGS2 (instance
, idx
);
285 slot
= SCM_I_INUM (idx
);
286 RETURN (SCM_PACK (SCM_STRUCT_DATA (instance
) [slot
]));
289 VM_DEFINE_FUNCTION (108, slot_set
, "slot-set", 3)
292 ARGS3 (instance
, idx
, val
);
293 slot
= SCM_I_INUM (idx
);
294 SCM_STRUCT_DATA (instance
) [slot
] = SCM_UNPACK (val
);
295 RETURN (SCM_UNSPECIFIED
);
299 (defun renumber-ops ()
300 "start from top of buffer and renumber 'VM_DEFINE_FOO (\n' sequences"
303 (let ((counter 79)) (goto-char (point-min))
304 (while (re-search-forward "^VM_DEFINE_[^ ]+ (\\([^,]+\\)," (point-max) t)
306 (number-to-string (setq counter (1+ counter)))