procs.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /* classes: h_files */
  2. #ifndef PROCSH
  3. #define PROCSH
  4. /* Copyright (C) 1995, 1996, 1998, 1999, 2000, 2002 Free Software Foundation, Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2, or (at your option)
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this software; see the file COPYING. If not, write to
  18. * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  19. * Boston, MA 02111-1307 USA
  20. *
  21. * As a special exception, the Free Software Foundation gives permission
  22. * for additional uses of the text contained in its release of GUILE.
  23. *
  24. * The exception is that, if you link the GUILE library with other files
  25. * to produce an executable, this does not by itself cause the
  26. * resulting executable to be covered by the GNU General Public License.
  27. * Your use of that executable is in no way restricted on account of
  28. * linking the GUILE library code into it.
  29. *
  30. * This exception does not however invalidate any other reasons why
  31. * the executable file might be covered by the GNU General Public License.
  32. *
  33. * This exception applies only to the code released by the
  34. * Free Software Foundation under the name GUILE. If you copy
  35. * code from other Free Software Foundation releases into a copy of
  36. * GUILE, as the General Public License permits, the exception does
  37. * not apply to the code that you add in this way. To avoid misleading
  38. * anyone as to the status of such modified files, you must delete
  39. * this exception notice from them.
  40. *
  41. * If you write modifications of your own for GUILE, it is your choice
  42. * whether to permit this exception to apply to your modifications.
  43. * If you do not wish that, delete this exception notice. */
  44. #include "libguile/__scm.h"
  45. /* Subrs
  46. */
  47. typedef struct
  48. {
  49. SCM handle; /* link back to procedure object */
  50. SCM name;
  51. SCM *generic; /* 0 if no generic support
  52. * *generic == 0 until first method
  53. */
  54. SCM properties; /* procedure properties */
  55. SCM documentation;
  56. } scm_subr_entry;
  57. #define SCM_SUBRNUM(subr) (SCM_CELL_WORD_0 (subr) >> 8)
  58. #define SCM_SET_SUBRNUM(subr, num) \
  59. SCM_SET_CELL_WORD_0 (subr, (num << 8) + SCM_TYP7 (subr))
  60. #define SCM_SUBR_ENTRY(x) (scm_subr_table[SCM_SUBRNUM (x)])
  61. #define SCM_SNAME(x) (SCM_SUBR_ENTRY (x).name)
  62. #define SCM_SUBRF(x) ((SCM (*)()) SCM_CELL_WORD_1 (x))
  63. #define SCM_SET_SUBRF(x, v) (SCM_SET_CELL_WORD_1 ((x), (v)))
  64. #define SCM_DSUBRF(x) ((double (*)()) SCM_CELL_WORD_1 (x))
  65. #define SCM_CCLO_SUBR(x) (SCM_VELTS(x)[0])
  66. #define SCM_SUBR_GENERIC(x) (SCM_SUBR_ENTRY (x).generic)
  67. #define SCM_SUBR_PROPS(x) (SCM_SUBR_ENTRY (x).properties)
  68. #define SCM_SUBR_DOC(x) (SCM_SUBR_ENTRY (x).documentation)
  69. /* Closures
  70. */
  71. #define SCM_CLOSUREP(x) (SCM_NIMP(x) && (SCM_TYP3 (x) == scm_tc3_closure))
  72. #define SCM_CLOSCAR(x) SCM_PACK (SCM_CELL_WORD_0 (x) - scm_tc3_closure)
  73. #define SCM_CODE(x) SCM_CAR (SCM_CLOSCAR (x))
  74. #define SCM_PROCPROPS(x) SCM_CDR (SCM_CLOSCAR (x))
  75. #define SCM_SETPROCPROPS(x, p) SCM_SETCDR (SCM_CLOSCAR (x), p)
  76. #define SCM_SETCODE(x, e) (SCM_SET_CELL_WORD_0 (x, SCM_UNPACK (scm_cons ((e), SCM_EOL)) \
  77. + scm_tc3_closure))
  78. #define SCM_ENV(x) SCM_CDR(x)
  79. #define SCM_SETENV(x, e) SCM_SETCDR (x, e)
  80. #define SCM_TOP_LEVEL(ENV) (SCM_NULLP (ENV) || (SCM_EQ_P (scm_procedure_p (SCM_CAR (ENV)), SCM_BOOL_T)))
  81. /* Procedure-with-setter
  82. Four representations for procedure-with-setters were
  83. considered before selecting this one:
  84. 1. A closure where the CODE and ENV slots are used to represent
  85. the getter and a new SETTER slot is used for the setter. The
  86. original getter is stored as a `getter' procedure property. For
  87. closure getters, the CODE and ENV slots contains a copy of the
  88. getter's CODE and ENV slots. For subr getters, the CODE contains
  89. a call to the subr.
  90. 2. A compiled closure with a call to the getter in the cclo
  91. procedure. The getter and setter are stored in slots 1 and 2.
  92. 3. An entity (i.e. a struct with an associated procedure) with a
  93. call to the getter in the entity procedure and the setter stored
  94. in slot 0. The original getter is stored in slot 1.
  95. 4. A new primitive procedure type supported in the evaluator. The
  96. getter and setter are stored in a GETTER and SETTER slot. A call
  97. to this procedure type results in a retrieval of the getter and a
  98. jump back to the correct eval dispatcher.
  99. Representation 4 was selected because of efficiency and
  100. simplicity.
  101. Rep 1 has the advantage that there is zero penalty for closure
  102. getters, but primitive getters will get considerable overhead
  103. because the procedure-with-getter will be a closure which calls
  104. the getter.
  105. Rep 3 has the advantage that a GOOPS accessor can be a subclass of
  106. <procedure-with-setter>, but together with rep 2 it suffers from a
  107. three level dispatch for non-GOOPS getters:
  108. cclo/struct --> dispatch proc --> getter
  109. This is because the dispatch procedure must take an extra initial
  110. argument (cclo for rep 2, struct for rep 3).
  111. Rep 4 has the single disadvantage that it uses up one tc7 type
  112. code, but the plan for uniform vectors will very likely free tc7
  113. codes, so this is probably no big problem. Also note that the
  114. GETTER and SETTER slots can live directly on the heap, using the
  115. new four-word cells. */
  116. #define SCM_PROCEDURE_WITH_SETTER_P(obj) (SCM_NIMP(obj) && (SCM_TYP7 (obj) == scm_tc7_pws))
  117. #define SCM_PROCEDURE(obj) SCM_CELL_OBJECT_1 (obj)
  118. #define SCM_SETTER(obj) SCM_CELL_OBJECT_2 (obj)
  119. extern scm_subr_entry *scm_subr_table;
  120. extern int scm_subr_table_size;
  121. extern int scm_subr_table_room;
  122. extern void scm_mark_subr_table (void);
  123. extern void scm_free_subr_entry (SCM subr);
  124. extern SCM scm_make_subr (const char *name, int type, SCM (*fcn) ());
  125. extern SCM scm_make_subr_with_generic (const char *name,
  126. int type,
  127. SCM (*fcn) (),
  128. SCM *gf);
  129. extern SCM scm_make_subr_opt (const char *name,
  130. int type,
  131. SCM (*fcn) (),
  132. int set);
  133. extern SCM scm_makcclo (SCM proc, long len);
  134. extern SCM scm_procedure_p (SCM obj);
  135. extern SCM scm_closure_p (SCM obj);
  136. extern SCM scm_thunk_p (SCM obj);
  137. extern int scm_subr_p (SCM obj);
  138. extern SCM scm_procedure_documentation (SCM proc);
  139. extern SCM scm_procedure_with_setter_p (SCM obj);
  140. extern SCM scm_make_procedure_with_setter (SCM procedure, SCM setter);
  141. extern SCM scm_procedure (SCM proc);
  142. extern SCM scm_setter (SCM proc);
  143. extern void scm_init_subr_table (void);
  144. extern void scm_init_procs (void);
  145. #ifdef GUILE_DEBUG
  146. extern SCM scm_make_cclo (SCM proc, SCM len);
  147. #endif /*GUILE_DEBUG*/
  148. #endif /* PROCSH */
  149. /*
  150. Local Variables:
  151. c-file-style: "gnu"
  152. End:
  153. */