1996-07-25 22:56:11 +00:00
|
|
|
|
/* classes: h_files */
|
|
|
|
|
|
|
2001-03-30 15:03:23 +00:00
|
|
|
|
#ifndef SCM_PROCS_H
|
|
|
|
|
|
#define SCM_PROCS_H
|
2001-08-31 12:13:50 +00:00
|
|
|
|
|
2009-01-18 12:44:15 +01:00
|
|
|
|
/* Copyright (C) 1995,1996,1998,1999,2000,2001, 2006, 2008, 2009 Free Software Foundation, Inc.
|
2001-08-31 12:13:50 +00:00
|
|
|
|
*
|
2003-04-05 19:15:35 +00:00
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2001-08-31 12:13:50 +00:00
|
|
|
|
*
|
2003-04-05 19:15:35 +00:00
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
1996-07-25 22:56:11 +00:00
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2003-04-05 19:15:35 +00:00
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
|
* Lesser General Public License for more details.
|
2001-08-31 12:13:50 +00:00
|
|
|
|
*
|
2003-04-05 19:15:35 +00:00
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2005-05-23 19:57:22 +00:00
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2003-04-05 19:15:35 +00:00
|
|
|
|
*/
|
1999-12-16 03:46:42 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
* alist.h, append.h, arbiters.h, async.h, boolean.h, chars.h,
continuations.h, debug.h, dynwind.h, error.h, eval.h, fdsocket.h,
feature.h, filesys.h, fports.h, gc.h, gdbint.h, genio.h, gsubr.h,
hash.h, init.h, ioext.h, kw.h, list.h, markers.h, marksweep.h,
mbstrings.h, numbers.h, objprop.h, options.h, pairs.h, ports.h,
posix.h, print.h, procprop.h, procs.h, ramap.h, read.h, root.h,
sequences.h, smob.h, socket.h, srcprop.h, stackchk.h, stime.h,
strings.h, strop.h, strorder.h, strports.h, struct.h, symbols.h,
tag.h, throw.h, unif.h, variable.h, vectors.h, version.h,
vports.h, weaks.h: #include "libguile/__scm.h", not
<libguile/__scm.h>. This allows 'gcc -MM' to determine which
dependencies are within libguile properly.
1996-09-05 21:19:08 +00:00
|
|
|
|
#include "libguile/__scm.h"
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Subrs
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
Use double-cells to store subrs.
* libguile/procs.c (scm_subr_table, scm_subr_table_size,
scm_subr_table_room, subr_table_gc_hint, scm_init_subr_table,
scm_mark_subr_table): Remove.
(scm_c_make_subr): Simply return a double-cell, with the procedure
name and properties stored in a two-element array.
(scm_free_subr_entry): Free the meta-info slot.
* libguile/init.c (scm_i_init_guile): Remove call to
`scm_init_subr_table ()'.
* libguile/procs.h (SCM_SUBR_META_INFO): New macro.
(SCM_SNAME, SCM_SUBR_PROPS): Use it.
(SCM_SUBR_GENERIC, SCM_SET_SUBR_GENERIC, SCM_SET_SUBR_GENERIC_LOC):
Update.
(scm_t_subr_entry, SCM_SUBR_ENTRY, SCM_SUBRNUM, scm_subr_table,
scm_mark_subr_table, scm_init_subr_table): Remove.
2009-02-12 00:02:11 +01:00
|
|
|
|
#define SCM_SUBR_META_INFO(x) ((SCM *) SCM_CELL_WORD_3 (x))
|
|
|
|
|
|
#define SCM_SNAME(x) (SCM_SUBR_META_INFO (x) [0])
|
2000-04-25 09:45:16 +00:00
|
|
|
|
#define SCM_SUBRF(x) ((SCM (*)()) SCM_CELL_WORD_1 (x))
|
2000-06-05 12:54:40 +00:00
|
|
|
|
#define SCM_SET_SUBRF(x, v) (SCM_SET_CELL_WORD_1 ((x), (v)))
|
2000-04-25 09:45:16 +00:00
|
|
|
|
#define SCM_DSUBRF(x) ((double (*)()) SCM_CELL_WORD_1 (x))
|
Use double-cells to store subrs.
* libguile/procs.c (scm_subr_table, scm_subr_table_size,
scm_subr_table_room, subr_table_gc_hint, scm_init_subr_table,
scm_mark_subr_table): Remove.
(scm_c_make_subr): Simply return a double-cell, with the procedure
name and properties stored in a two-element array.
(scm_free_subr_entry): Free the meta-info slot.
* libguile/init.c (scm_i_init_guile): Remove call to
`scm_init_subr_table ()'.
* libguile/procs.h (SCM_SUBR_META_INFO): New macro.
(SCM_SNAME, SCM_SUBR_PROPS): Use it.
(SCM_SUBR_GENERIC, SCM_SET_SUBR_GENERIC, SCM_SET_SUBR_GENERIC_LOC):
Update.
(scm_t_subr_entry, SCM_SUBR_ENTRY, SCM_SUBRNUM, scm_subr_table,
scm_mark_subr_table, scm_init_subr_table): Remove.
2009-02-12 00:02:11 +01:00
|
|
|
|
#define SCM_SUBR_PROPS(x) (SCM_SUBR_META_INFO (x) [1])
|
|
|
|
|
|
#define SCM_SUBR_GENERIC(x) ((SCM *) SCM_CELL_WORD_2 (x))
|
|
|
|
|
|
#define SCM_SET_SUBR_GENERIC(x, g) (*((SCM *) SCM_CELL_WORD_2 (x)) = (g))
|
|
|
|
|
|
#define SCM_SET_SUBR_GENERIC_LOC(x, g) (SCM_SET_CELL_WORD_2 (x, (scm_t_bits) g))
|
2000-09-26 20:11:22 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
/* Closures
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2001-08-31 12:13:50 +00:00
|
|
|
|
#define SCM_CLOSUREP(x) (!SCM_IMP(x) && (SCM_TYP3 (x) == scm_tc3_closure))
|
2000-05-24 11:22:38 +00:00
|
|
|
|
#define SCM_CLOSCAR(x) SCM_PACK (SCM_CELL_WORD_0 (x) - scm_tc3_closure)
|
2000-03-11 15:10:16 +00:00
|
|
|
|
#define SCM_CODE(x) SCM_CAR (SCM_CLOSCAR (x))
|
2001-04-19 14:46:01 +00:00
|
|
|
|
#define SCM_CLOSURE_FORMALS(x) SCM_CAR (SCM_CODE (x))
|
2002-01-10 20:52:45 +00:00
|
|
|
|
#define SCM_CLOSURE_BODY(x) SCM_CDR (SCM_CODE (x))
|
2000-03-11 15:10:16 +00:00
|
|
|
|
#define SCM_PROCPROPS(x) SCM_CDR (SCM_CLOSCAR (x))
|
|
|
|
|
|
#define SCM_SETPROCPROPS(x, p) SCM_SETCDR (SCM_CLOSCAR (x), p)
|
2000-04-19 09:37:48 +00:00
|
|
|
|
#define SCM_SETCODE(x, e) (SCM_SET_CELL_WORD_0 (x, SCM_UNPACK (scm_cons ((e), SCM_EOL)) \
|
2000-03-11 15:10:16 +00:00
|
|
|
|
+ scm_tc3_closure))
|
2001-03-30 15:03:23 +00:00
|
|
|
|
#define SCM_ENV(x) SCM_CELL_OBJECT_1 (x)
|
|
|
|
|
|
#define SCM_SETENV(x, e) SCM_SET_CELL_OBJECT_1 ((x), (e))
|
2004-09-22 17:41:37 +00:00
|
|
|
|
#define SCM_TOP_LEVEL(ENV) (scm_is_null (ENV) || (scm_is_true (scm_procedure_p (SCM_CAR (ENV)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1999-05-02 17:22:47 +00:00
|
|
|
|
/* Procedure-with-setter
|
|
|
|
|
|
|
|
|
|
|
|
Four representations for procedure-with-setters were
|
|
|
|
|
|
considered before selecting this one:
|
|
|
|
|
|
|
|
|
|
|
|
1. A closure where the CODE and ENV slots are used to represent
|
|
|
|
|
|
the getter and a new SETTER slot is used for the setter. The
|
|
|
|
|
|
original getter is stored as a `getter' procedure property. For
|
|
|
|
|
|
closure getters, the CODE and ENV slots contains a copy of the
|
|
|
|
|
|
getter's CODE and ENV slots. For subr getters, the CODE contains
|
|
|
|
|
|
a call to the subr.
|
|
|
|
|
|
|
|
|
|
|
|
2. A compiled closure with a call to the getter in the cclo
|
|
|
|
|
|
procedure. The getter and setter are stored in slots 1 and 2.
|
|
|
|
|
|
|
|
|
|
|
|
3. An entity (i.e. a struct with an associated procedure) with a
|
|
|
|
|
|
call to the getter in the entity procedure and the setter stored
|
|
|
|
|
|
in slot 0. The original getter is stored in slot 1.
|
|
|
|
|
|
|
|
|
|
|
|
4. A new primitive procedure type supported in the evaluator. The
|
|
|
|
|
|
getter and setter are stored in a GETTER and SETTER slot. A call
|
|
|
|
|
|
to this procedure type results in a retrieval of the getter and a
|
|
|
|
|
|
jump back to the correct eval dispatcher.
|
|
|
|
|
|
|
|
|
|
|
|
Representation 4 was selected because of efficiency and
|
|
|
|
|
|
simplicity.
|
|
|
|
|
|
|
|
|
|
|
|
Rep 1 has the advantage that there is zero penalty for closure
|
|
|
|
|
|
getters, but primitive getters will get considerable overhead
|
|
|
|
|
|
because the procedure-with-getter will be a closure which calls
|
|
|
|
|
|
the getter.
|
|
|
|
|
|
|
|
|
|
|
|
Rep 3 has the advantage that a GOOPS accessor can be a subclass of
|
|
|
|
|
|
<procedure-with-setter>, but together with rep 2 it suffers from a
|
|
|
|
|
|
three level dispatch for non-GOOPS getters:
|
|
|
|
|
|
|
|
|
|
|
|
cclo/struct --> dispatch proc --> getter
|
|
|
|
|
|
|
|
|
|
|
|
This is because the dispatch procedure must take an extra initial
|
|
|
|
|
|
argument (cclo for rep 2, struct for rep 3).
|
|
|
|
|
|
|
|
|
|
|
|
Rep 4 has the single disadvantage that it uses up one tc7 type
|
|
|
|
|
|
code, but the plan for uniform vectors will very likely free tc7
|
|
|
|
|
|
codes, so this is probably no big problem. Also note that the
|
|
|
|
|
|
GETTER and SETTER slots can live directly on the heap, using the
|
|
|
|
|
|
new four-word cells. */
|
|
|
|
|
|
|
2001-08-31 12:13:50 +00:00
|
|
|
|
#define SCM_PROCEDURE_WITH_SETTER_P(obj) (!SCM_IMP(obj) && (SCM_TYP7 (obj) == scm_tc7_pws))
|
2000-03-24 08:55:14 +00:00
|
|
|
|
#define SCM_PROCEDURE(obj) SCM_CELL_OBJECT_1 (obj)
|
|
|
|
|
|
#define SCM_SETTER(obj) SCM_CELL_OBJECT_2 (obj)
|
1999-03-11 11:47:40 +00:00
|
|
|
|
|
* procs.c, procs.h (scm_subr_entry): New type: Stores data
associated with subrs.
(SCM_SUBRNUM, SCM_SUBR_ENTRY, SCM_SUBR_GENERIC, SCM_SUBR_PROPS,
SCM_SUBR_DOC): New macros.
(scm_subr_table): New variable.
(scm_mark_subr_table): New function.
* init.c (scm_boot_guile_1): Call scm_init_subr_table.
* gc.c (scm_gc_mark): Don't mark subr names here.
(scm_igc): Call scm_mark_subr_table.
* snarf.h (SCM_GPROC, SCM_GPROC1): New macros.
* procs.c, procs.h (scm_subr_p): New function (used internally).
* gsubr.c, gsubr.h (scm_make_gsubr_with_generic): New function.
* objects.c, objects.h (scm_primitive_generic): New class.
* objects.h (SCM_CMETHOD_CODE, SCM_CMETHOD_ENV): New macros.
* print.c (scm_iprin1): Print primitive-generics.
* __scm.h (SCM_WTA_DISPATCH_1, SCM_GASSERT1,
SCM_WTA_DISPATCH_2, SCM_GASSERT2): New macros.
* eval.c (SCM_CEVAL, SCM_APPLY): Replace scm_wta -->
SCM_WTA_DISPATCH_1 for scm_cxr's (unary floating point
primitives). NOTE: This means that it is now *required* to use
SCM_GPROC1 when creating float scm_cxr's (float scm_cxr's is an
obscured representation that will be removed in the future anyway,
so backward compatibility is no problem here).
* numbers.c: Converted most numeric primitives (all but bit
comparison operations and bit operations) to dispatch on generic
if args don't match.
* eval.c, eval.h (scm_eval_body): New function.
* objects.c (scm_call_generic_0, scm_call_generic_1,
scm_call_generic_2, scm_call_generic_3, scm_apply_generic): New
functions.
* eval.c (SCM_CEVAL): Apply the cmethod directly after having
called scm_memoize_method instead of doing a second lookup.
* objects.h (scm_memoize_method): Now returns the memoized cmethod.
* procs.c (scm_make_subr_opt): Use scm_sysintern0 instead of
scm_sysintern so that the binding connected with the subr name
isn't cleared when we give set = 0.
1999-08-26 04:24:42 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
2001-11-02 00:19:12 +00:00
|
|
|
|
SCM_API void scm_free_subr_entry (SCM subr);
|
|
|
|
|
|
SCM_API SCM scm_c_make_subr (const char *name, long type, SCM (*fcn)());
|
|
|
|
|
|
SCM_API SCM scm_c_make_subr_with_generic (const char *name, long type,
|
|
|
|
|
|
SCM (*fcn)(), SCM *gf);
|
|
|
|
|
|
SCM_API SCM scm_c_define_subr (const char *name, long type, SCM (*fcn)());
|
|
|
|
|
|
SCM_API SCM scm_c_define_subr_with_generic (const char *name, long type,
|
|
|
|
|
|
SCM (*fcn)(), SCM *gf);
|
|
|
|
|
|
SCM_API SCM scm_procedure_p (SCM obj);
|
|
|
|
|
|
SCM_API SCM scm_closure_p (SCM obj);
|
|
|
|
|
|
SCM_API SCM scm_thunk_p (SCM obj);
|
|
|
|
|
|
SCM_API int scm_subr_p (SCM obj);
|
|
|
|
|
|
SCM_API SCM scm_procedure_documentation (SCM proc);
|
|
|
|
|
|
SCM_API SCM scm_procedure_with_setter_p (SCM obj);
|
|
|
|
|
|
SCM_API SCM scm_make_procedure_with_setter (SCM procedure, SCM setter);
|
|
|
|
|
|
SCM_API SCM scm_procedure (SCM proc);
|
|
|
|
|
|
SCM_API SCM scm_setter (SCM proc);
|
2008-05-14 05:20:47 +02:00
|
|
|
|
SCM_INTERNAL void scm_init_procs (void);
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2001-03-30 15:03:23 +00:00
|
|
|
|
#endif /* SCM_PROCS_H */
|
2000-03-19 19:01:16 +00:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
Local Variables:
|
|
|
|
|
|
c-file-style: "gnu"
|
|
|
|
|
|
End:
|
|
|
|
|
|
*/
|