expand.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. /* classes: h_files */
  2. #ifndef SCM_EXPAND_H
  3. #define SCM_EXPAND_H
  4. /* Copyright (C) 2010, 2011, 2013, 2014
  5. * Free Software Foundation, Inc.
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public License
  9. * as published by the Free Software Foundation; either version 3 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. */
  22. #include "libguile/__scm.h"
  23. #ifdef BUILDING_LIBGUILE
  24. /* All private for now. Ask if you want to use this. Surely this should be
  25. auto-generated by something; for now I wrangle it with keyboard macros. */
  26. typedef enum
  27. {
  28. SCM_EXPANDED_VOID,
  29. SCM_EXPANDED_CONST,
  30. SCM_EXPANDED_PRIMITIVE_REF,
  31. SCM_EXPANDED_LEXICAL_REF,
  32. SCM_EXPANDED_LEXICAL_SET,
  33. SCM_EXPANDED_MODULE_REF,
  34. SCM_EXPANDED_MODULE_SET,
  35. SCM_EXPANDED_TOPLEVEL_REF,
  36. SCM_EXPANDED_TOPLEVEL_SET,
  37. SCM_EXPANDED_TOPLEVEL_DEFINE,
  38. SCM_EXPANDED_CONDITIONAL,
  39. SCM_EXPANDED_CALL,
  40. SCM_EXPANDED_PRIMCALL,
  41. SCM_EXPANDED_SEQ,
  42. SCM_EXPANDED_LAMBDA,
  43. SCM_EXPANDED_LAMBDA_CASE,
  44. SCM_EXPANDED_LET,
  45. SCM_EXPANDED_LETREC,
  46. SCM_NUM_EXPANDED_TYPES,
  47. } scm_t_expanded_type;
  48. /* {Expanded Source}
  49. */
  50. SCM_INTERNAL SCM scm_exp_vtable_vtable;
  51. enum
  52. {
  53. SCM_EXPANDED_TYPE_NAME = scm_vtable_offset_user,
  54. SCM_EXPANDED_TYPE_CODE,
  55. SCM_EXPANDED_TYPE_FIELDS,
  56. };
  57. #define SCM_EXPANDED_P(x) \
  58. (SCM_STRUCTP (x) \
  59. && (scm_is_eq (SCM_STRUCT_VTABLE (SCM_STRUCT_VTABLE (x)), scm_exp_vtable_vtable)))
  60. #define SCM_EXPANDED_REF(x,type,field) \
  61. (scm_struct_ref (x, SCM_I_MAKINUM (SCM_EXPANDED_##type##_##field)))
  62. #define SCM_EXPANDED_TYPE(x) \
  63. SCM_STRUCT_DATA_REF (SCM_STRUCT_VTABLE (x), SCM_EXPANDED_TYPE_CODE)
  64. #define SCM_EXPANDED_VOID_TYPE_NAME "void"
  65. #define SCM_EXPANDED_VOID_FIELD_NAMES \
  66. { "src" }
  67. enum
  68. {
  69. SCM_EXPANDED_VOID_SRC,
  70. SCM_NUM_EXPANDED_VOID_FIELDS,
  71. };
  72. #define SCM_MAKE_EXPANDED_VOID(src) \
  73. scm_c_make_struct (exp_vtables[SCM_EXPANDED_VOID], 0, SCM_NUM_EXPANDED_VOID_FIELDS, SCM_UNPACK (src))
  74. #define SCM_EXPANDED_CONST_TYPE_NAME "const"
  75. #define SCM_EXPANDED_CONST_FIELD_NAMES \
  76. { "src", "exp", }
  77. enum
  78. {
  79. SCM_EXPANDED_CONST_SRC,
  80. SCM_EXPANDED_CONST_EXP,
  81. SCM_NUM_EXPANDED_CONST_FIELDS,
  82. };
  83. #define SCM_MAKE_EXPANDED_CONST(src, exp) \
  84. scm_c_make_struct (exp_vtables[SCM_EXPANDED_CONST], 0, SCM_NUM_EXPANDED_CONST_FIELDS, SCM_UNPACK (src), SCM_UNPACK (exp))
  85. #define SCM_EXPANDED_PRIMITIVE_REF_TYPE_NAME "primitive-ref"
  86. #define SCM_EXPANDED_PRIMITIVE_REF_FIELD_NAMES \
  87. { "src", "name", }
  88. enum
  89. {
  90. SCM_EXPANDED_PRIMITIVE_REF_SRC,
  91. SCM_EXPANDED_PRIMITIVE_REF_NAME,
  92. SCM_NUM_EXPANDED_PRIMITIVE_REF_FIELDS,
  93. };
  94. #define SCM_MAKE_EXPANDED_PRIMITIVE_REF(src, name) \
  95. scm_c_make_struct (exp_vtables[SCM_EXPANDED_PRIMITIVE_REF], 0, SCM_NUM_EXPANDED_PRIMITIVE_REF_FIELDS, SCM_UNPACK (src), SCM_UNPACK (name))
  96. #define SCM_EXPANDED_LEXICAL_REF_TYPE_NAME "lexical-ref"
  97. #define SCM_EXPANDED_LEXICAL_REF_FIELD_NAMES \
  98. { "src", "name", "gensym", }
  99. enum
  100. {
  101. SCM_EXPANDED_LEXICAL_REF_SRC,
  102. SCM_EXPANDED_LEXICAL_REF_NAME,
  103. SCM_EXPANDED_LEXICAL_REF_GENSYM,
  104. SCM_NUM_EXPANDED_LEXICAL_REF_FIELDS,
  105. };
  106. #define SCM_MAKE_EXPANDED_LEXICAL_REF(src, name, gensym) \
  107. scm_c_make_struct (exp_vtables[SCM_EXPANDED_LEXICAL_REF], 0, SCM_NUM_EXPANDED_LEXICAL_REF_FIELDS, SCM_UNPACK (src), SCM_UNPACK (name), SCM_UNPACK (gensym))
  108. #define SCM_EXPANDED_LEXICAL_SET_TYPE_NAME "lexical-set"
  109. #define SCM_EXPANDED_LEXICAL_SET_FIELD_NAMES \
  110. { "src", "name", "gensym", "exp", }
  111. enum
  112. {
  113. SCM_EXPANDED_LEXICAL_SET_SRC,
  114. SCM_EXPANDED_LEXICAL_SET_NAME,
  115. SCM_EXPANDED_LEXICAL_SET_GENSYM,
  116. SCM_EXPANDED_LEXICAL_SET_EXP,
  117. SCM_NUM_EXPANDED_LEXICAL_SET_FIELDS,
  118. };
  119. #define SCM_MAKE_EXPANDED_LEXICAL_SET(src, name, gensym, exp) \
  120. scm_c_make_struct (exp_vtables[SCM_EXPANDED_LEXICAL_SET], 0, SCM_NUM_EXPANDED_LEXICAL_SET_FIELDS, SCM_UNPACK (src), SCM_UNPACK (name), SCM_UNPACK (gensym), SCM_UNPACK (exp))
  121. #define SCM_EXPANDED_MODULE_REF_TYPE_NAME "module-ref"
  122. #define SCM_EXPANDED_MODULE_REF_FIELD_NAMES \
  123. { "src", "mod", "name", "public?", }
  124. enum
  125. {
  126. SCM_EXPANDED_MODULE_REF_SRC,
  127. SCM_EXPANDED_MODULE_REF_MOD,
  128. SCM_EXPANDED_MODULE_REF_NAME,
  129. SCM_EXPANDED_MODULE_REF_PUBLIC,
  130. SCM_NUM_EXPANDED_MODULE_REF_FIELDS,
  131. };
  132. #define SCM_MAKE_EXPANDED_MODULE_REF(src, mod, name, public) \
  133. scm_c_make_struct (exp_vtables[SCM_EXPANDED_MODULE_REF], 0, SCM_NUM_EXPANDED_MODULE_REF_FIELDS, SCM_UNPACK (src), SCM_UNPACK (mod), SCM_UNPACK (name), SCM_UNPACK (public))
  134. #define SCM_EXPANDED_MODULE_SET_TYPE_NAME "module-set"
  135. #define SCM_EXPANDED_MODULE_SET_FIELD_NAMES \
  136. { "src", "mod", "name", "public?", "exp", }
  137. enum
  138. {
  139. SCM_EXPANDED_MODULE_SET_SRC,
  140. SCM_EXPANDED_MODULE_SET_MOD,
  141. SCM_EXPANDED_MODULE_SET_NAME,
  142. SCM_EXPANDED_MODULE_SET_PUBLIC,
  143. SCM_EXPANDED_MODULE_SET_EXP,
  144. SCM_NUM_EXPANDED_MODULE_SET_FIELDS,
  145. };
  146. #define SCM_MAKE_EXPANDED_MODULE_SET(src, mod, name, public, exp) \
  147. scm_c_make_struct (exp_vtables[SCM_EXPANDED_MODULE_SET], 0, SCM_NUM_EXPANDED_MODULE_SET_FIELDS, SCM_UNPACK (src), SCM_UNPACK (mod), SCM_UNPACK (name), SCM_UNPACK (public), SCM_UNPACK (exp))
  148. #define SCM_EXPANDED_TOPLEVEL_REF_TYPE_NAME "toplevel-ref"
  149. #define SCM_EXPANDED_TOPLEVEL_REF_FIELD_NAMES \
  150. { "src", "name", }
  151. enum
  152. {
  153. SCM_EXPANDED_TOPLEVEL_REF_SRC,
  154. SCM_EXPANDED_TOPLEVEL_REF_NAME,
  155. SCM_NUM_EXPANDED_TOPLEVEL_REF_FIELDS,
  156. };
  157. #define SCM_MAKE_EXPANDED_TOPLEVEL_REF(src, name) \
  158. scm_c_make_struct (exp_vtables[SCM_EXPANDED_TOPLEVEL_REF], 0, SCM_NUM_EXPANDED_TOPLEVEL_REF_FIELDS, SCM_UNPACK (src), SCM_UNPACK (name))
  159. #define SCM_EXPANDED_TOPLEVEL_SET_TYPE_NAME "toplevel-set"
  160. #define SCM_EXPANDED_TOPLEVEL_SET_FIELD_NAMES \
  161. { "src", "name", "exp", }
  162. enum
  163. {
  164. SCM_EXPANDED_TOPLEVEL_SET_SRC,
  165. SCM_EXPANDED_TOPLEVEL_SET_NAME,
  166. SCM_EXPANDED_TOPLEVEL_SET_EXP,
  167. SCM_NUM_EXPANDED_TOPLEVEL_SET_FIELDS,
  168. };
  169. #define SCM_MAKE_EXPANDED_TOPLEVEL_SET(src, name, exp) \
  170. scm_c_make_struct (exp_vtables[SCM_EXPANDED_TOPLEVEL_SET], 0, SCM_NUM_EXPANDED_TOPLEVEL_SET_FIELDS, SCM_UNPACK (src), SCM_UNPACK (name), SCM_UNPACK (exp))
  171. #define SCM_EXPANDED_TOPLEVEL_DEFINE_TYPE_NAME "toplevel-define"
  172. #define SCM_EXPANDED_TOPLEVEL_DEFINE_FIELD_NAMES \
  173. { "src", "name", "exp", }
  174. enum
  175. {
  176. SCM_EXPANDED_TOPLEVEL_DEFINE_SRC,
  177. SCM_EXPANDED_TOPLEVEL_DEFINE_NAME,
  178. SCM_EXPANDED_TOPLEVEL_DEFINE_EXP,
  179. SCM_NUM_EXPANDED_TOPLEVEL_DEFINE_FIELDS,
  180. };
  181. #define SCM_MAKE_EXPANDED_TOPLEVEL_DEFINE(src, name, exp) \
  182. scm_c_make_struct (exp_vtables[SCM_EXPANDED_TOPLEVEL_DEFINE], 0, SCM_NUM_EXPANDED_TOPLEVEL_DEFINE_FIELDS, SCM_UNPACK (src), SCM_UNPACK (name), SCM_UNPACK (exp))
  183. #define SCM_EXPANDED_CONDITIONAL_TYPE_NAME "conditional"
  184. #define SCM_EXPANDED_CONDITIONAL_FIELD_NAMES \
  185. { "src", "test", "consequent", "alternate", }
  186. enum
  187. {
  188. SCM_EXPANDED_CONDITIONAL_SRC,
  189. SCM_EXPANDED_CONDITIONAL_TEST,
  190. SCM_EXPANDED_CONDITIONAL_CONSEQUENT,
  191. SCM_EXPANDED_CONDITIONAL_ALTERNATE,
  192. SCM_NUM_EXPANDED_CONDITIONAL_FIELDS,
  193. };
  194. #define SCM_MAKE_EXPANDED_CONDITIONAL(src, test, consequent, alternate) \
  195. scm_c_make_struct (exp_vtables[SCM_EXPANDED_CONDITIONAL], 0, SCM_NUM_EXPANDED_CONDITIONAL_FIELDS, SCM_UNPACK (src), SCM_UNPACK (test), SCM_UNPACK (consequent), SCM_UNPACK (alternate))
  196. #define SCM_EXPANDED_CALL_TYPE_NAME "call"
  197. #define SCM_EXPANDED_CALL_FIELD_NAMES \
  198. { "src", "proc", "args", }
  199. enum
  200. {
  201. SCM_EXPANDED_CALL_SRC,
  202. SCM_EXPANDED_CALL_PROC,
  203. SCM_EXPANDED_CALL_ARGS,
  204. SCM_NUM_EXPANDED_CALL_FIELDS,
  205. };
  206. #define SCM_MAKE_EXPANDED_CALL(src, proc, args) \
  207. scm_c_make_struct (exp_vtables[SCM_EXPANDED_CALL], 0, SCM_NUM_EXPANDED_CALL_FIELDS, SCM_UNPACK (src), SCM_UNPACK (proc), SCM_UNPACK (args))
  208. #define SCM_EXPANDED_PRIMCALL_TYPE_NAME "primcall"
  209. #define SCM_EXPANDED_PRIMCALL_FIELD_NAMES \
  210. { "src", "name", "args", }
  211. enum
  212. {
  213. SCM_EXPANDED_PRIMCALL_SRC,
  214. SCM_EXPANDED_PRIMCALL_NAME,
  215. SCM_EXPANDED_PRIMCALL_ARGS,
  216. SCM_NUM_EXPANDED_PRIMCALL_FIELDS,
  217. };
  218. #define SCM_MAKE_EXPANDED_PRIMCALL(src, name, args) \
  219. scm_c_make_struct (exp_vtables[SCM_EXPANDED_PRIMCALL], 0, SCM_NUM_EXPANDED_PRIMCALL_FIELDS, SCM_UNPACK (src), SCM_UNPACK (name), SCM_UNPACK (args))
  220. #define SCM_EXPANDED_SEQ_TYPE_NAME "seq"
  221. #define SCM_EXPANDED_SEQ_FIELD_NAMES \
  222. { "src", "head", "tail", }
  223. enum
  224. {
  225. SCM_EXPANDED_SEQ_SRC,
  226. SCM_EXPANDED_SEQ_HEAD,
  227. SCM_EXPANDED_SEQ_TAIL,
  228. SCM_NUM_EXPANDED_SEQ_FIELDS,
  229. };
  230. #define SCM_MAKE_EXPANDED_SEQ(src, head, tail) \
  231. scm_c_make_struct (exp_vtables[SCM_EXPANDED_SEQ], 0, SCM_NUM_EXPANDED_SEQ_FIELDS, SCM_UNPACK (src), SCM_UNPACK (head), SCM_UNPACK (tail))
  232. #define SCM_EXPANDED_LAMBDA_TYPE_NAME "lambda"
  233. #define SCM_EXPANDED_LAMBDA_FIELD_NAMES \
  234. { "src", "meta", "body", }
  235. enum
  236. {
  237. SCM_EXPANDED_LAMBDA_SRC,
  238. SCM_EXPANDED_LAMBDA_META,
  239. SCM_EXPANDED_LAMBDA_BODY,
  240. SCM_NUM_EXPANDED_LAMBDA_FIELDS,
  241. };
  242. #define SCM_MAKE_EXPANDED_LAMBDA(src, meta, body) \
  243. scm_c_make_struct (exp_vtables[SCM_EXPANDED_LAMBDA], 0, SCM_NUM_EXPANDED_LAMBDA_FIELDS, SCM_UNPACK (src), SCM_UNPACK (meta), SCM_UNPACK (body))
  244. #define SCM_EXPANDED_LAMBDA_CASE_TYPE_NAME "lambda-case"
  245. #define SCM_EXPANDED_LAMBDA_CASE_FIELD_NAMES \
  246. { "src", "req", "opt", "rest", "kw", "inits", "gensyms", "body", "alternate", }
  247. enum
  248. {
  249. SCM_EXPANDED_LAMBDA_CASE_SRC,
  250. SCM_EXPANDED_LAMBDA_CASE_REQ,
  251. SCM_EXPANDED_LAMBDA_CASE_OPT,
  252. SCM_EXPANDED_LAMBDA_CASE_REST,
  253. SCM_EXPANDED_LAMBDA_CASE_KW,
  254. SCM_EXPANDED_LAMBDA_CASE_INITS,
  255. SCM_EXPANDED_LAMBDA_CASE_GENSYMS,
  256. SCM_EXPANDED_LAMBDA_CASE_BODY,
  257. SCM_EXPANDED_LAMBDA_CASE_ALTERNATE,
  258. SCM_NUM_EXPANDED_LAMBDA_CASE_FIELDS,
  259. };
  260. #define SCM_MAKE_EXPANDED_LAMBDA_CASE(src, req, opt, rest, kw, inits, gensyms, body, alternate) \
  261. scm_c_make_struct (exp_vtables[SCM_EXPANDED_LAMBDA_CASE], 0, SCM_NUM_EXPANDED_LAMBDA_CASE_FIELDS, SCM_UNPACK (src), SCM_UNPACK (req), SCM_UNPACK (opt), SCM_UNPACK (rest), SCM_UNPACK (kw), SCM_UNPACK (inits), SCM_UNPACK (gensyms), SCM_UNPACK (body), SCM_UNPACK (alternate))
  262. #define SCM_EXPANDED_LET_TYPE_NAME "let"
  263. #define SCM_EXPANDED_LET_FIELD_NAMES \
  264. { "src", "names", "gensyms", "vals", "body", }
  265. enum
  266. {
  267. SCM_EXPANDED_LET_SRC,
  268. SCM_EXPANDED_LET_NAMES,
  269. SCM_EXPANDED_LET_GENSYMS,
  270. SCM_EXPANDED_LET_VALS,
  271. SCM_EXPANDED_LET_BODY,
  272. SCM_NUM_EXPANDED_LET_FIELDS,
  273. };
  274. #define SCM_MAKE_EXPANDED_LET(src, names, gensyms, vals, body) \
  275. scm_c_make_struct (exp_vtables[SCM_EXPANDED_LET], 0, SCM_NUM_EXPANDED_LET_FIELDS, SCM_UNPACK (src), SCM_UNPACK (names), SCM_UNPACK (gensyms), SCM_UNPACK (vals), SCM_UNPACK (body))
  276. #define SCM_EXPANDED_LETREC_TYPE_NAME "letrec"
  277. #define SCM_EXPANDED_LETREC_FIELD_NAMES \
  278. { "src", "in-order?", "names", "gensyms", "vals", "body", }
  279. enum
  280. {
  281. SCM_EXPANDED_LETREC_SRC,
  282. SCM_EXPANDED_LETREC_IN_ORDER_P,
  283. SCM_EXPANDED_LETREC_NAMES,
  284. SCM_EXPANDED_LETREC_GENSYMS,
  285. SCM_EXPANDED_LETREC_VALS,
  286. SCM_EXPANDED_LETREC_BODY,
  287. SCM_NUM_EXPANDED_LETREC_FIELDS,
  288. };
  289. #define SCM_MAKE_EXPANDED_LETREC(src, in_order_p, names, gensyms, vals, body) \
  290. scm_c_make_struct (exp_vtables[SCM_EXPANDED_LETREC], 0, SCM_NUM_EXPANDED_LETREC_FIELDS, SCM_UNPACK (src), SCM_UNPACK (in_order_p), SCM_UNPACK (names), SCM_UNPACK (gensyms), SCM_UNPACK (vals), SCM_UNPACK (body))
  291. #endif /* BUILDING_LIBGUILE */
  292. SCM_INTERNAL SCM scm_macroexpand (SCM exp);
  293. SCM_INTERNAL SCM scm_macroexpanded_p (SCM exp);
  294. SCM_INTERNAL SCM scm_convert_assignment (SCM exp);
  295. SCM_INTERNAL void scm_init_expand (void);
  296. #endif /* SCM_EXPAND_H */
  297. /*
  298. Local Variables:
  299. c-file-style: "gnu"
  300. End:
  301. */