PageRenderTime 51ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 2ms

/src/eval.d

https://github.com/ynd/clisp-branch--ynd-devel
D | 8279 lines | 6840 code | 101 blank | 1338 comment | 1014 complexity | 28dc8e89963bce245b99b7f7458d96a8 MD5 | raw file
Possible License(s): LGPL-2.0, GPL-2.0, BSD-3-Clause
  1. /*
  2. * EVAL, APPLY and bytecode interpreter for CLISP
  3. * Bruno Haible 1990-2005
  4. * Sam Steingold 1998-2008
  5. * German comments translated into English: Stefan Kain 2001-08-13
  6. */
  7. #include "lispbibl.c"
  8. /* function-table:
  9. In this table only SUBRS are listed, which may be inlined by the compiler.
  10. In FUNTAB1 and FUNTAB2 SUBRs without Rest-Parameter (i.e. with
  11. fixed number of arguments known at compile-time) are listed.
  12. In FUNTABR SUBRs with Rest-Parameter are listed. */
  13. #define _(name) &subr_tab.D_##name /* address of SUBR name, like L(name) */
  14. /* FUNTAB1 and FUNTAB2, first: */
  15. local const Subr FUNTAB[] = {
  16. /* SPVW : 0 SUBRs */
  17. /* EVAL : 3 SUBRs */
  18. _(funtabref), _(subr_info), _(special_variable_p),
  19. /* ARRAY : 30-2 SUBRs */
  20. _(copy_simple_vector), /* _(svref), _(psvstore), */ _(row_major_aref),
  21. _(row_major_store), _(array_element_type), _(array_rank),
  22. _(array_dimension), _(array_dimensions), _(array_total_size),
  23. _(adjustable_array_p), _(bit_and), _(bit_ior), _(bit_xor), _(bit_eqv),
  24. _(bit_nand), _(bit_nor), _(bit_andc1), _(bit_andc2), _(bit_orc1),
  25. _(bit_orc2), _(bit_not), _(array_has_fill_pointer_p), _(fill_pointer),
  26. _(set_fill_pointer), _(vector_push), _(vector_pop), _(vector_push_extend),
  27. _(make_array), _(adjust_array),
  28. /* CHARSTRG : 54 SUBRs */
  29. _(standard_char_p), _(graphic_char_p), _(string_char_p), _(alpha_char_p),
  30. _(upper_case_p), _(lower_case_p), _(both_case_p), _(digit_char_p),
  31. _(alphanumericp), _(char_code), _(code_char), _(character), _(char_upcase),
  32. _(char_downcase), _(digit_char), _(char_int), _(int_char), _(char_name),
  33. _(char), _(schar), _(store_char), _(store_schar),
  34. _(string_eq), _(cs_string_eq), _(string_noteq), _(cs_string_noteq),
  35. _(string_less), _(cs_string_less), _(string_greater), _(cs_string_greater),
  36. _(string_ltequal), _(cs_string_ltequal),
  37. _(string_gtequal), _(cs_string_gtequal), _(string_equal),
  38. _(string_not_equal), _(string_lessp), _(string_greaterp),
  39. _(string_not_greaterp), _(string_not_lessp), _(search_string_eq),
  40. _(search_string_equal), _(make_string), _(string_both_trim),
  41. _(nstring_upcase), _(string_upcase), _(nstring_downcase),
  42. _(string_downcase), _(nstring_capitalize), _(string_capitalize),
  43. _(string), _(cs_string), _(name_char), _(substring),
  44. /* CONTROL : 25-2 SUBRs */
  45. _(symbol_value), /* _(symbol_function), */ _(fdefinition), _(boundp),
  46. _(fboundp), _(special_operator_p), _(set), _(makunbound), _(fmakunbound),
  47. /* _(values_list), */ _(driver), _(unwind_to_driver), _(macro_function),
  48. _(macroexpand), _(macroexpand_1), _(proclaim), _(eval),
  49. _(evalhook), _(applyhook), _(constantp), _(function_side_effect),
  50. _(function_name_p),_(parse_body), _(keyword_test), _(check_function_name),
  51. /* DEBUG : 0 SUBRs */
  52. /* ERROR : 1 SUBR */
  53. _(invoke_debugger),
  54. /* HASHTABL : 11 SUBRs */
  55. _(make_hash_table), _(gethash), _(puthash), _(remhash), _(maphash),
  56. _(clrhash), _(hash_table_count), _(hash_table_iterator),
  57. _(hash_table_iterate), _(class_gethash), _(sxhash),
  58. /* IO : 38 SUBRs */
  59. _(copy_readtable), _(set_syntax_from_char), _(set_macro_character),
  60. _(get_macro_character), _(make_dispatch_macro_character),
  61. _(set_dispatch_macro_character), _(get_dispatch_macro_character),
  62. _(read), _(read_preserving_whitespace), _(read_delimited_list),
  63. _(read_line), _(read_char), _(unread_char), _(peek_char), _(listen),
  64. _(read_char_no_hang), _(clear_input), _(read_from_string), _(parse_integer),
  65. _(whitespacep), _(write), _(prin1), _(print), _(pprint), _(princ),
  66. _(write_to_string), _(prin1_to_string), _(princ_to_string), _(write_char),
  67. _(write_string), _(write_line), _(terpri), _(fresh_line), _(elastic_newline),
  68. _(finish_output), _(force_output), _(clear_output), _(line_position),
  69. /* LIST : 84-36=48 SUBRs */
  70. /* _(car), _(cdr), _(caar), _(cadr), _(cdar), _(cddr), _(caaar), _(caadr),
  71. _(cadar), _(caddr), _(cdaar), _(cdadr), _(cddar), _(cdddr), _(caaaar),
  72. _(caaadr), _(caadar), _(caaddr), _(cadaar), _(cadadr), _(caddar),
  73. _(cadddr), _(cdaaar), _(cdaadr), _(cdadar), _(cdaddr), _(cddaar),
  74. _(cddadr), _(cdddar), _(cddddr), _(cons), */ _(tree_equal), _(endp),
  75. _(list_length), _(nth), /* _(first), _(second), _(third), _(fourth), */
  76. _(fifth), _(sixth), _(seventh), _(eighth), _(ninth), _(tenth), /* _(rest), */
  77. _(nthcdr), _(last), _(make_list), _(copy_list), _(copy_alist), _(memq),
  78. _(copy_tree), _(revappend), _(nreconc), _(list_nreverse), _(butlast),
  79. _(nbutlast), _(ldiff), _(rplaca), _(prplaca), _(rplacd), _(prplacd),
  80. _(subst), _(subst_if), _(subst_if_not), _(nsubst), _(nsubst_if),
  81. _(nsubst_if_not), _(sublis), _(nsublis), _(member), _(member_if),
  82. _(member_if_not), _(tailp), _(adjoin), _(acons), _(pairlis), _(assoc),
  83. _(assoc_if), _(assoc_if_not), _(rassoc), _(rassoc_if), _(rassoc_if_not),
  84. /* MISC : 10 SUBRs */
  85. _(lisp_implementation_type), _(lisp_implementation_version),
  86. _(software_type), _(software_version), _(identity), _(get_universal_time),
  87. _(get_internal_run_time), _(get_internal_real_time), _(sleep), _(time),
  88. /* PACKAGE : 32 SUBRs */
  89. _(make_symbol), _(find_package), _(package_name), _(package_nicknames),
  90. _(rename_package), _(package_use_list), _(package_used_by_list),
  91. _(package_shadowing_symbols), _(list_all_packages), _(intern), _(cs_intern),
  92. _(find_symbol), _(cs_find_symbol), _(unintern), _(export), _(unexport),
  93. _(import), _(shadowing_import), _(shadow), _(cs_shadow),
  94. _(use_package), _(unuse_package),
  95. _(make_package), _(cs_make_package), _(pin_package),
  96. _(find_all_symbols), _(cs_find_all_symbols),
  97. _(map_symbols), _(map_external_symbols), _(map_all_symbols),
  98. _(pfind_package), _(re_export),
  99. /* PATHNAME : 27 SUBRs */
  100. _(parse_namestring), _(pathname), _(pathnamehost), _(pathnamedevice),
  101. _(pathnamedirectory), _(pathnamename), _(pathnametype),
  102. _(pathnameversion), _(file_namestring), _(directory_namestring),
  103. _(host_namestring), _(merge_pathnames), _(enough_namestring),
  104. _(make_pathname), _(namestring), _(truename), _(probe_file),
  105. _(delete_file), _(rename_file), _(open), _(directory), _(cd),
  106. _(make_directory), _(delete_directory), _(file_write_date), _(file_author),
  107. _(savemem),
  108. /* PREDTYPE : 48-3 SUBRs */
  109. /* _(eq), */ _(eql), _(equal), _(equalp), _(consp), _(atom), _(symbolp),
  110. _(stringp), _(numberp), _(compiled_function_p), /* _(null), _(not), */
  111. _(closurep), _(listp), _(integerp), _(fixnump), _(rationalp), _(floatp),
  112. _(short_float_p), _(single_float_p), _(double_float_p), _(long_float_p),
  113. _(realp), _(complexp), _(streamp), _(random_state_p), _(readtablep),
  114. _(hash_table_p), _(pathnamep), _(logical_pathname_p), _(characterp),
  115. _(functionp), _(packagep), _(arrayp), _(simple_array_p), _(bit_vector_p),
  116. _(vectorp), _(simple_vector_p), _(simple_string_p), _(simple_bit_vector_p),
  117. _(type_of), _(class_of), _(find_class), _(coerce), _(typep_class),
  118. _(defined_class_p), _(proper_list_p), _(pcompiled_function_p),
  119. /* RECORD : 29 SUBRs */
  120. _(record_ref), _(record_store), _(record_length), _(structure_ref),
  121. _(structure_store), _(make_structure), _(copy_structure),
  122. _(structure_type_p), _(closure_name), _(closure_codevec),
  123. _(closure_consts), _(make_closure), _(make_macro),
  124. _(copy_generic_function), _(make_load_time_eval),
  125. _(function_macro_function), _(structure_object_p), _(std_instance_p),
  126. _(slot_value), _(set_slot_value), _(slot_boundp), _(slot_makunbound),
  127. _(slot_exists_p), _(macrop), _(macro_expander), _(symbol_macro_p),
  128. _(symbol_macro_expand),
  129. _(standard_instance_access), _(set_standard_instance_access),
  130. /* SEQUENCE : 40-1 SUBRs */
  131. _(sequencep), _(elt), _(setelt), _(subseq), _(copy_seq), _(length),
  132. _(reverse), _(nreverse), _(make_sequence), _(reduce), _(fill),
  133. _(replace), _(remove), _(remove_if), _(remove_if_not), _(delete),
  134. _(delete_if), _(delete_if_not), _(remove_duplicates),
  135. _(delete_duplicates), _(substitute), _(substitute_if),
  136. _(substitute_if_not), _(nsubstitute), _(nsubstitute_if),
  137. _(nsubstitute_if_not), _(find), _(find_if), _(find_if_not), _(position),
  138. _(position_if), _(position_if_not), _(count), _(count_if),
  139. _(count_if_not), _(mismatch), _(search), _(sort), /* _(stable_sort), */
  140. _(merge),
  141. /* STREAM : 24 SUBRs */
  142. _(file_stream_p), _(make_synonym_stream), _(synonym_stream_p),
  143. _(broadcast_stream_p), _(concatenated_stream_p), _(make_two_way_stream),
  144. _(two_way_stream_p), _(make_echo_stream), _(echo_stream_p),
  145. _(make_string_input_stream), _(string_input_stream_index),
  146. _(make_string_output_stream), _(get_output_stream_string),
  147. _(make_string_push_stream), _(string_stream_p), _(input_stream_p),
  148. _(output_stream_p), _(built_in_stream_element_type),
  149. _(stream_external_format), _(built_in_stream_close), _(read_byte),
  150. _(write_byte), _(file_position), _(file_length),
  151. /* SYMBOL : 15 SUBRs */
  152. _(putd), _(proclaim_constant), _(get), _(getf), _(get_properties),
  153. _(putplist), _(put), _(remprop), _(symbol_package), _(symbol_plist),
  154. _(symbol_name), _(cs_symbol_name), _(keywordp), _(gensym), _(gensym),
  155. /* LISPARIT : 84 SUBRs */
  156. _(decimal_string), _(zerop), _(plusp), _(minusp), _(oddp), _(evenp),
  157. _(plus_one), _(minus_one), _(conjugate), _(exp), _(expt), _(log),
  158. _(sqrt), _(isqrt), _(abs), _(phase), _(signum), _(sin), _(cos), _(tan),
  159. _(cis), _(asin), _(acos), _(atan), _(sinh), _(cosh), _(tanh), _(asinh),
  160. _(acosh), _(atanh), _(float), _(rational), _(rationalize), _(numerator),
  161. _(denominator), _(floor), _(ceiling), _(truncate), _(round), _(mod),
  162. _(rem), _(ffloor), _(fceiling), _(ftruncate), _(fround), _(decode_float),
  163. _(scale_float), _(float_radix), _(float_sign), _(float_digits),
  164. _(float_precision), _(integer_decode_float), _(complex), _(realpart),
  165. _(imagpart), _(lognand), _(lognor), _(logandc1), _(logandc2), _(logorc1),
  166. _(logorc2), _(boole), _(lognot), _(logtest), _(logbitp), _(ash),
  167. _(logcount), _(integer_length), _(byte), _(bytesize), _(byteposition),
  168. _(ldb), _(ldb_test), _(mask_field), _(dpb), _(deposit_field), _(random),
  169. _(make_random_state), _(factorial), _(exquo), _(long_float_digits),
  170. _(set_long_float_digits), _(log2), _(log10),
  171. /* ENCODING: 1 SUBRs */
  172. _(encodingp),
  173. }; /* that were 512 = 556 - 44 SUBRs.
  174. (- (+ 0 3 30 54 25 0 1 11 38 84 10 32 27 48 29 40 24 15 84 1)
  175. (+ 0 0 2 0 2 0 0 0 0 36 0 0 0 3 0 1 0 0 0 0)) */
  176. /* Now FUNTABR : */
  177. local const Subr FUNTABR[] = {
  178. /* SPVW : 0 SUBRs */
  179. /* EVAL : 0 SUBRs */
  180. /* ARRAY : 7 SUBRs */
  181. _(vector), _(aref), _(store), _(array_in_bounds_p),
  182. _(array_row_major_index), _(bit), _(sbit),
  183. /* CHARSTRG : 13 SUBRs */
  184. _(char_eq), _(char_noteq), _(char_less), _(char_greater),
  185. _(char_ltequal), _(char_gtequal), _(char_equal), _(char_not_equal),
  186. _(char_lessp), _(char_greaterp), _(char_not_greaterp), _(char_not_lessp),
  187. _(string_concat),
  188. /* CONTROL : 10 SUBRs */
  189. _(apply), _(funcall), _(mapcar), _(maplist), _(mapc),
  190. _(mapl), _(mapcan), _(mapcap), _(mapcon), _(values),
  191. /* DEBUG : 0 SUBRs */
  192. /* ERROR : 2 SUBRs */
  193. _(error), _(error_of_type),
  194. /* HASHTABL : 1 SUBR */
  195. _(class_tuple_gethash),
  196. /* IO : 0 SUBRs */
  197. /* LIST : 4 SUBRs */
  198. _(list), _(liststar), _(append), _(nconc),
  199. /* MISC : 0 SUBRs */
  200. /* PACKAGE : 0 SUBRs */
  201. /* PATHNAME : 0 SUBRs */
  202. /* PREDTYPE : 0 SUBRs */
  203. /* RECORD : 1 SUBR */
  204. _(pallocate_instance),
  205. /* SEQUENCE : 7 SUBRs */
  206. _(concatenate), _(map), _(map_into), _(some), _(every), _(notany),
  207. _(notevery),
  208. /* STREAM : 2 SUBRs */
  209. _(make_broadcast_stream), _(make_concatenated_stream),
  210. /* SYMBOL : 0 SUBRs */
  211. /* LISPARIT : 19 SUBRs */
  212. _(numequal), _(numunequal), _(smaller), _(greater), _(ltequal),
  213. _(gtequal), _(max), _(min), _(plus), _(minus), _(star), _(slash), _(gcd),
  214. _(xgcd), _(lcm), _(logior), _(logxor), _(logand), _(logeqv)
  215. }; /* That were (+ 0 0 7 13 10 0 2 1 0 4 0 0 0 0 1 7 2 0 19) = 66 SUBRs. */
  216. #undef _
  217. #define FUNTAB1 (&FUNTAB[0])
  218. #define FUNTAB2 (&FUNTAB[256])
  219. #define FUNTAB_length (sizeof(FUNTAB)/sizeof(Subr))
  220. #define FUNTABR_length (sizeof(FUNTABR)/sizeof(Subr))
  221. #if defined(DEBUG_SPVW)
  222. local void check_funtab (void) {
  223. uintL i;
  224. for (i=0; i < FUNTAB_length; i++)
  225. if (FUNTAB[i]->rest_flag != subr_norest) {
  226. nobject_out(stdout,FUNTAB[i]->name);
  227. printf("=FUNTAB[%d] accepts &rest\n",i);
  228. }
  229. for (i=0; i < FUNTABR_length; i++)
  230. if (FUNTABR[i]->rest_flag != subr_rest) {
  231. nobject_out(stdout,FUNTABR[i]->name);
  232. printf("=FUNTABR[%d] does NOT accept &rest\n",i);
  233. }
  234. printf("FUNTAB_length=%d\n",FUNTAB_length);
  235. if (FUNTAB_length > 512) printf(" *** - > 512!\n");
  236. printf("FUNTABR_length=%d\n",FUNTABR_length);
  237. if (FUNTABR_length > 256) printf(" *** - > 256!\n");
  238. }
  239. #endif
  240. /* argument-type-tokens for compiled closures: */
  241. typedef enum {
  242. cclos_argtype_default,
  243. cclos_argtype_0_0,
  244. cclos_argtype_1_0,
  245. cclos_argtype_2_0,
  246. cclos_argtype_3_0,
  247. cclos_argtype_4_0,
  248. cclos_argtype_5_0,
  249. cclos_argtype_0_1,
  250. cclos_argtype_1_1,
  251. cclos_argtype_2_1,
  252. cclos_argtype_3_1,
  253. cclos_argtype_4_1,
  254. cclos_argtype_0_2,
  255. cclos_argtype_1_2,
  256. cclos_argtype_2_2,
  257. cclos_argtype_3_2,
  258. cclos_argtype_0_3,
  259. cclos_argtype_1_3,
  260. cclos_argtype_2_3,
  261. cclos_argtype_0_4,
  262. cclos_argtype_1_4,
  263. cclos_argtype_0_5,
  264. cclos_argtype_0_0_rest,
  265. cclos_argtype_1_0_rest,
  266. cclos_argtype_2_0_rest,
  267. cclos_argtype_3_0_rest,
  268. cclos_argtype_4_0_rest,
  269. cclos_argtype_0_0_key,
  270. cclos_argtype_1_0_key,
  271. cclos_argtype_2_0_key,
  272. cclos_argtype_3_0_key,
  273. cclos_argtype_4_0_key,
  274. cclos_argtype_0_1_key,
  275. cclos_argtype_1_1_key,
  276. cclos_argtype_2_1_key,
  277. cclos_argtype_3_1_key,
  278. cclos_argtype_0_2_key,
  279. cclos_argtype_1_2_key,
  280. cclos_argtype_2_2_key,
  281. cclos_argtype_0_3_key,
  282. cclos_argtype_1_3_key,
  283. cclos_argtype_0_4_key,
  284. cclos_argtype_for_broken_compilers_that_dont_like_trailing_commas
  285. } cclos_argtype_t;
  286. /* Call of the bytecode-interpreter:
  287. interpretes the bytecode of a compiled closure.
  288. interpret_bytecode(closure,codevec,index);
  289. > closure: compiled closure
  290. > codevec: its codevector, a Simple-Bit-Vector
  291. > index: Start-Index
  292. < mv_count/mv_space: values
  293. changes STACK, can trigger GC
  294. local Values interpret_bytecode (object closure, object codevec, uintL index);
  295. */
  296. local /*maygc*/ Values interpret_bytecode_ (object closure, Sbvector codeptr,
  297. const uintB* byteptr);
  298. /* GCC2 can jump directly to labels.
  299. This results in faster code than switch(). */
  300. #if defined(GNU) && !(__APPLE_CC__ > 1)
  301. #if (__GNUC__ >= 2) && !defined(UNIX_HPUX) && !defined(NO_FAST_DISPATCH) /* work around HP-UX Linker Bug */
  302. #define FAST_DISPATCH
  303. #if (__GNUC__ >= 3) || (__GNUC_MINOR__ >= 7) /* work around gcc-2.6.3 Bug (-fno-defer-pop ginge auch) */
  304. #define FAST_DISPATCH_THREADED
  305. #endif
  306. #endif
  307. #endif
  308. #if defined(USE_JITC)
  309. /* replacement for interpret_bytecode_ */
  310. local /*maygc*/ Values jitc_run (object closure_in, Sbvector codeptr,
  311. const uintB* byteptr_in);
  312. local inline /*maygc*/ Values cclosure_run (object closure_in, Sbvector codevec,
  313. const uintB* byteptr_in) {
  314. if (cclosure_jitc_p(closure_in)) jitc_run(closure_in,codevec,byteptr_in);
  315. else interpret_bytecode_(closure_in,codevec,byteptr_in);
  316. }
  317. #define interpret_bytecode(closure,codevec,index) \
  318. with_saved_back_trace_cclosure(closure, \
  319. cclosure_run(closure,TheSbvector(codevec),&TheSbvector(codevec)->data[index]); )
  320. #else
  321. #define interpret_bytecode(closure,codevec,index) \
  322. with_saved_back_trace_cclosure(closure, \
  323. interpret_bytecode_(closure,TheSbvector(codevec),&TheSbvector(codevec)->data[index]); )
  324. #endif
  325. /* Values of the bytecodes (256 totally): */
  326. typedef enum {
  327. #define BYTECODE(code) code,
  328. #include "bytecode.c"
  329. #undef BYTECODE
  330. cod_for_broken_compilers_that_dont_like_trailing_commas
  331. } bytecode_enum_t;
  332. /* ---------------------- LISP-FUNCTIONS ----------------------- */
  333. /* (SYS::%FUNTABREF i) returns the name of function Nr. i from the function-
  334. table (a symbol), resp. NIL if i is not in the right range. */
  335. LISPFUNNF(funtabref,1)
  336. {
  337. var object arg = popSTACK(); /* argument */
  338. var uintV i;
  339. if (posfixnump(arg) /* should be Fixnum >=0 */
  340. && (i = posfixnum_to_V(arg),
  341. i < FUNTAB_length+FUNTABR_length)) { /* and < table-length */
  342. /* Name of the indexed element of the table: */
  343. value1 = (i < FUNTAB_length
  344. ? FUNTAB[i] /* from FUNTAB1/2 */
  345. : FUNTABR[i-FUNTAB_length] /* resp. from FUNTABR */
  346. )->name;
  347. } else {
  348. value1 = NIL; /* or NIL */
  349. }
  350. mv_count=1; /* as value */
  351. }
  352. /* (SYS::SUBR-INFO obj) returns information for this SUBR, if obj is a SUBR
  353. (or a Symbol with a SUBR as global function definition),
  354. 6 values:
  355. name Name,
  356. req-count number of required parameters,
  357. opt-count number of optional parameters,
  358. rest-p flag, if &rest is specified,
  359. keywords list of admissible keywords (empty: no &key specified),
  360. allow-other-keys flag, if additional keywords are allowed,
  361. otherwise NIL. */
  362. LISPFUNNR(subr_info,1)
  363. {
  364. var object obj = popSTACK();
  365. if (!subrp(obj)) {
  366. if (!(symbolp(obj) && subrp(Symbol_function(obj)))) {
  367. VALUES0; return; /* no SUBR -> no value */
  368. }
  369. obj = Symbol_function(obj);
  370. }
  371. /* obj is a SUBR */
  372. pushSTACK(TheSubr(obj)->name); /* Name */
  373. pushSTACK(fixnum(TheSubr(obj)->req_count)); /* req-count (req-nr) */
  374. pushSTACK(fixnum(TheSubr(obj)->opt_count)); /* opt-count (opt-nr) */
  375. pushSTACK(TheSubr(obj)->rest_flag == subr_norest ? NIL : T); /* rest-p */
  376. /* during bootstrap, before defseq.lisp is loaded, this may fail: */
  377. coerce_sequence(TheSubr(obj)->keywords,S(list),false);
  378. /* keyword-vector as list (during bootstrap: vector) */
  379. pushSTACK(eq(value1,nullobj) ? (object)TheSubr(obj)->keywords : value1);
  380. pushSTACK(TheSubr(obj)->key_flag == subr_key_allow ? T : NIL); /* allow-other-keys */
  381. funcall(L(values),6); /* 6 values */
  382. }
  383. /* ----------------------- SUBROUTINES ----------------------- */
  384. /* UP: unwinds a frame, which is pointed at by STACK.
  385. unwind();
  386. The values mv_count/mv_space remain unmodified.
  387. If it is no Unwind-Protect-Frame: return normally.
  388. If it is a Unwind-Protect-Frame:
  389. save the values, climbs(?) up STACK and SP
  390. and then calls unwind_protect_to_save.fun .
  391. changes STACK
  392. can trigger GC */
  393. global /*maygc*/ void unwind (void)
  394. {
  395. var fcint frame_info = framecode(STACK_0);
  396. GCTRIGGER_IF(frame_info == APPLY_frame_info || frame_info == TRAPPED_APPLY_frame_info
  397. || frame_info == EVAL_frame_info || frame_info == TRAPPED_EVAL_frame_info,
  398. GCTRIGGER1(mv_space));
  399. #ifdef unwind_bit_t
  400. if (frame_info & bit(unwind_bit_t)) /* anything to do? */
  401. #else
  402. if (frame_info >= unwind_limit_t) /* anything to do? */
  403. #endif
  404. { /* (not at APPLY, EVAL untrapped, CATCH, HANDLER,
  405. IBLOCK or ITAGBODY unnested) */
  406. if ((frame_info & bit(skip2_bit_t)) == 0) { /* ENV- or DYNBIND-Frame? */
  407. #ifdef entrypoint_bit_t
  408. if (frame_info & bit(entrypoint_bit_t)) /* BLOCK, TAGBODY, CATCH etc. ? */
  409. #else
  410. if (frame_info < entrypoint_limit_t) /* BLOCK, TAGBODY, CATCH etc. ? */
  411. #endif
  412. /* Frame with Exitpoint */
  413. if (frame_info & bit(blockgo_bit_t)) { /* BLOCK or TAGBODY? */
  414. /* BLOCK_FRAME or TAGBODY_FRAME */
  415. if (frame_info & bit(cframe_bit_t)) { /* compiled? */
  416. /* CBLOCK_FRAME or CTAGBODY_FRAME
  417. In Cons (NAME/Tags . <Framepointer>) */
  418. Cdr(STACK_(frame_ctag)) = disabled; /* disable Exit/Tags */
  419. } else {
  420. /* IBLOCK_FRAME or ITAGBODY_FRAME, nested
  421. In Cons (NAME/Tags . <Framepointer>)
  422. (first pair of alist next_env) */
  423. Cdr(Car(STACK_(frame_next_env))) = disabled; /* disable Exit/Tags */
  424. }
  425. } else {
  426. /* UNWIND_PROTECT_FRAME DRIVER_FRAME or trapped APPLY/EVAL_FRAME */
  427. if (frame_info & bit(dynjump_bit_t)) {
  428. /* UNWIND_PROTECT_FRAME or DRIVER_FRAME */
  429. if (frame_info & bit(driver_bit_t)) {
  430. /* DRIVER_FRAME */
  431. } else {
  432. /* UNWIND_PROTECT_FRAME */
  433. enter_frame_at_STACK();
  434. }
  435. } else {
  436. /* trapped APPLY/EVAL_FRAME
  437. like in the tracer: */
  438. var object values;
  439. mv_to_list(); values = popSTACK(); /* pack values into list */
  440. dynamic_bind(S(trace_values),values); /* bind *TRACE-VALUES* */
  441. break_driver(true); /* call break-driver */
  442. list_to_mv(Symbol_value(S(trace_values)), /* build values again */
  443. error_mv_toomany(framecode(STACK_(0+3))==
  444. TRAPPED_EVAL_frame_info
  445. ? S(eval)
  446. : S(apply)););
  447. dynamic_unbind(S(trace_values)); /* unbind */
  448. }
  449. }
  450. else {
  451. #ifdef HAVE_SAVED_REGISTERS
  452. if ((frame_info & bit(callback_bit_t)) == 0) {
  453. /* CALLBACK_FRAME */
  454. var gcv_object_t* new_STACK = topofframe(STACK_0); /* Pointer to Frame */
  455. /* set callback_saved_registers: */
  456. callback_saved_registers = (struct registers *)(aint)as_oint(STACK_1);
  457. /* set STACK, thus unwind frame: */
  458. setSTACK(STACK = new_STACK);
  459. goto done;
  460. } else
  461. #endif
  462. {
  463. /* VAR_FRAME or FUN_FRAME */
  464. var gcv_object_t* new_STACK = topofframe(STACK_0); /* Pointer to Frame */
  465. if (frame_info & bit(fun_bit_t)) {
  466. /* for functions: do nothing */
  467. } else {
  468. /* VAR_FRAME, bindingptr iterates over the bindungs */
  469. var gcv_object_t* frame_end = STACKpointable(new_STACK);
  470. var gcv_object_t* bindingptr = &STACK_(frame_bindings); /* start of the variable-/functionbindings */
  471. while (bindingptr != frame_end) {
  472. if (as_oint(*(bindingptr STACKop 0)) & wbit(dynam_bit_o))
  473. if (as_oint(*(bindingptr STACKop 0)) & wbit(active_bit_o)) {
  474. /* binding static or inactive -> nothing to do
  475. binding dynamic and active -> write back value: */
  476. TheSymbolflagged(*(bindingptr STACKop varframe_binding_sym))->symvalue =
  477. *(bindingptr STACKop varframe_binding_value);
  478. }
  479. bindingptr skipSTACKop varframe_binding_size; /* next binding */
  480. }
  481. }
  482. /* set STACK, thus unwind frame: */
  483. setSTACK(STACK = new_STACK);
  484. goto done;
  485. }
  486. }
  487. } else {
  488. /* DYNBIND_FRAME or CALLBACK_FRAME or ENV_FRAME */
  489. if (frame_info & bit(envbind_bit_t)) {
  490. /* ENV_FRAME */
  491. var gcv_object_t* ptr = &STACK_1;
  492. switch (frame_info & envbind_case_mask_t) {
  493. case (ENV1V_frame_info & envbind_case_mask_t): /* 1 VAR_ENV */
  494. aktenv.var_env = *ptr; ptr skipSTACKop 1; break;
  495. case (ENV1F_frame_info & envbind_case_mask_t): /* 1 FUN_ENV */
  496. aktenv.fun_env = *ptr; ptr skipSTACKop 1; break;
  497. case (ENV1B_frame_info & envbind_case_mask_t): /* 1 BLOCK_ENV */
  498. aktenv.block_env = *ptr; ptr skipSTACKop 1; break;
  499. case (ENV1G_frame_info & envbind_case_mask_t): /* 1 GO_ENV */
  500. aktenv.go_env = *ptr; ptr skipSTACKop 1; break;
  501. case (ENV1D_frame_info & envbind_case_mask_t): /* 1 DECL_ENV */
  502. aktenv.decl_env = *ptr; ptr skipSTACKop 1; break;
  503. case (ENV2VD_frame_info & envbind_case_mask_t): /* 1 VAR_ENV and 1 DECL_ENV */
  504. aktenv.var_env = *ptr; ptr skipSTACKop 1;
  505. aktenv.decl_env = *ptr; ptr skipSTACKop 1;
  506. break;
  507. case (ENV5_frame_info & envbind_case_mask_t): /* all 5 Environments */
  508. aktenv.var_env = *ptr; ptr skipSTACKop 1;
  509. aktenv.fun_env = *ptr; ptr skipSTACKop 1;
  510. aktenv.block_env = *ptr; ptr skipSTACKop 1;
  511. aktenv.go_env = *ptr; ptr skipSTACKop 1;
  512. aktenv.decl_env = *ptr; ptr skipSTACKop 1;
  513. break;
  514. default: NOTREACHED;
  515. }
  516. } else {
  517. /* DYNBIND_FRAME */
  518. var gcv_object_t* new_STACK = topofframe(STACK_0); /* Pointer to Frame */
  519. var gcv_object_t* frame_end = STACKpointable(new_STACK);
  520. var gcv_object_t* bindingptr = &STACK_1; /* start of the bindings */
  521. /* bindingptr iterates through the bindings */
  522. while (bindingptr != frame_end) {
  523. Symbol_value(*(bindingptr STACKop 0)) = *(bindingptr STACKop 1);
  524. bindingptr skipSTACKop 2; /* next binding */
  525. }
  526. /* set STACK, thus unwind frame: */
  527. setSTACK(STACK = new_STACK);
  528. goto done;
  529. }
  530. }
  531. }
  532. /* set STACK, thus unwind frame: */
  533. setSTACK(STACK = topofframe(STACK_0));
  534. done: ;
  535. }
  536. /* UP: "unwinds" the STACK up to the next DRIVER_FRAME and
  537. jumps into the corresponding top-level-loop.
  538. if count=0, unwind to TOP; otherwise reset that many times */
  539. nonreturning_function(global, reset, (uintL count)) {
  540. /* when unwinding UNWIND-PROTECT-frames, don't save values: */
  541. bool top_p = (count==0);
  542. gcv_object_t *last_driver_frame = NULL;
  543. VALUES0;
  544. unwind_protect_to_save.fun = (restartf_t)&reset;
  545. unwind_protect_to_save.upto_frame = NULL;
  546. while (1) {
  547. /* does STACK end here? */
  548. if (eq(STACK_0,nullobj) && eq(STACK_1,nullobj)) { /* check STACK_start? */
  549. if (last_driver_frame) { /* restart at last driver frame */
  550. setSTACK(STACK = last_driver_frame);
  551. break;
  552. }
  553. /* we used to start a new driver() here, but this is wrong because it
  554. does not clean up SP & back_trace, just STACK, see
  555. https://sourceforge.net/tracker/?func=detail&atid=101355&aid=1448744&group_id=1355
  556. we probably cannot even do NOTREACHED - the STACK is bad. */
  557. fprintf(stderr,"\n[%s:%d] reset() found no driver frame (sp=0x%x-0x%x)\n",
  558. __FILE__,__LINE__,(aint)SP_anchor,(aint)SP());
  559. abort();
  560. }
  561. if (framecode(STACK_0) & bit(frame_bit_t)) {
  562. /* at STACK_0: beginning of a frame */
  563. if (framecode(STACK_0) == DRIVER_frame_info) { /* DRIVER_FRAME ? */
  564. last_driver_frame = STACK; /* save the frame */
  565. if (!top_p && --count==0) /* done count resets */
  566. break; /* yes -> found */
  567. }
  568. unwind(); /* unwind frame */
  569. } else { /* STACK_0 contains a normal LISP-object */
  570. skipSTACK(1);
  571. }
  572. }
  573. /* At STACK_0 a new Driver-Frame starts. */
  574. enter_frame_at_STACK();
  575. }
  576. /* UP: dynamically binds the symbols of list symlist
  577. to the the values of list vallist.
  578. progv(symlist,vallist);
  579. > symlist, vallist: two lists
  580. Exactly one variable binding frame is constructed.
  581. changes STACK
  582. can trigger GC */
  583. global maygc void progv (object symlist, object vallist) {
  584. /* check symlist */
  585. var uintL llen = 0;
  586. var bool need_new_symlist = true;
  587. pushSTACK(symlist); pushSTACK(vallist);
  588. for (pushSTACK(symlist); consp(STACK_0); STACK_0 = Cdr(STACK_0), llen++) {
  589. var object sym = check_symbol_non_constant(Car(STACK_0),S(progv));
  590. if (!eq(sym,Car(STACK_0))) { /* changed symbol ==> must copy symlist */
  591. if (need_new_symlist) { /* have not copied symlist yet */
  592. pushSTACK(sym); /* save sym */
  593. STACK_1 = STACK_3 = copy_list(STACK_3); /* copy symlist */
  594. var uintL pos = llen; /* skip copy ... */
  595. while (pos--) STACK_1 = Cdr(STACK_1); /* ... to the right position */
  596. need_new_symlist = false; /* do not copy symlist twice */
  597. sym = popSTACK(); /* restore sym */
  598. }
  599. Car(STACK_0) = sym;
  600. }
  601. }
  602. skipSTACK(1); vallist = popSTACK(); symlist = popSTACK();
  603. /* demand room on STACK: */
  604. get_space_on_STACK(llen * 2 * sizeof(gcv_object_t));
  605. /* build frame: */
  606. var gcv_object_t* top_of_frame = STACK; /* Pointer to Frame */
  607. var object symlistr = symlist;
  608. while (consp(symlistr)) { /* loop over symbol list */
  609. var object sym = Car(symlistr);
  610. pushSTACK(Symbol_value(sym)); /* old value of the variables */
  611. pushSTACK(sym); /* variable */
  612. symlistr = Cdr(symlistr);
  613. }
  614. finish_frame(DYNBIND);
  615. /* building of frame completed, now change the values of the variables: */
  616. while (consp(symlist)) {
  617. if (atomp(vallist)) {
  618. /* value list shorter than symbol list
  619. -> all further "values" are #<UNBOUND> */
  620. do {
  621. Symbol_value(Car(symlist)) = unbound;
  622. symlist = Cdr(symlist);
  623. } while (consp(symlist));
  624. break;
  625. }
  626. /* symbol obtains new value: */
  627. Symbol_value(Car(symlist)) = Car(vallist);
  628. symlist = Cdr(symlist); vallist = Cdr(vallist);
  629. }
  630. }
  631. /* UP: unwinds the dynamic nesting in STACK up to the frame
  632. (exclusively), which is pointed to by upto, and then jumps to it.
  633. unwind_upto(upto);
  634. > upto: pointer to a frame (into the stack, without typinfo).
  635. saves the values mv_count/mv_space.
  636. changes STACK,SP
  637. can trigger GC
  638. then jumps to the frame, which was found. */
  639. nonreturning_function(global /*maygc*/, unwind_upto, (gcv_object_t* upto_frame)) {
  640. GCTRIGGER1(mv_space);
  641. unwind_protect_to_save.fun = &unwind_upto;
  642. unwind_protect_to_save.upto_frame = upto_frame;
  643. while (STACK != upto_frame) { /* arrived at target-frame? */
  644. if (framecode(STACK_0) & bit(frame_bit_t)) { /* is it a frame? */
  645. unwind(); /* yes -> unwind */
  646. /* (if this is a Unwind-Protect-Frame, then
  647. unwind_upto(upto_frame) is called again, and we are again here.) */
  648. } else {
  649. skipSTACK(1); /* no -> simply go ahead */
  650. }
  651. }
  652. /* now STACK points to the FRAME found. */
  653. enter_frame_at_STACK();
  654. }
  655. /* UP: throws to the Tag tag and passes the values mv_count/mv_space.
  656. returns only, if there is no CATCH-Frame for this tag.
  657. throw_to(tag); */
  658. global void throw_to (object tag) {
  659. /* search for Catch-Frame with Tag = tag: */
  660. var gcv_object_t* FRAME = STACK;
  661. while (1) { /* search in the Stack starting at FRAME
  662. for a CATCH-Frame with the same Tag: */
  663. if (eq(FRAME_(0),nullobj)) /* end of Stack? */
  664. return; /* yes -> no suitable Catch there -> jump back */
  665. if (framecode(FRAME_(0)) & bit(frame_bit_t)) {
  666. /* found frame */
  667. if ((framecode(FRAME_(0)) == CATCH_frame_info) /* Catch-Frame? */
  668. && eq(FRAME_(frame_tag),tag)) /* with the same tag? */
  669. break; /* yes -> search-loop finished */
  670. /* skip Frame: */
  671. FRAME = topofframe(FRAME_(0));
  672. } else {
  673. FRAME skipSTACKop 1;
  674. }
  675. }
  676. /* FRAME points to the lowest CATCH-Frame with the same Tag */
  677. unwind_upto(FRAME); /* unwind upto there, then jump */
  678. }
  679. /* UP: Invokes all handlers for condition cond. Returns only, if none
  680. of these handlers feels responsible (i.e. if each handler returns).
  681. invoke_handlers(cond);
  682. can trigger GC
  683. This deactivates the handler, that is called right now,
  684. and all newer handlers. */
  685. global maygc void invoke_handlers (object cond) {
  686. /* Also deactivates the handler being called, and all newer handlers.
  687. the handler-ranges, which are screened off: */
  688. var stack_range_t* other_ranges = inactive_handlers;
  689. var stack_range_t new_range;
  690. /* Search for Handler-Frame, that handles a Type with (TYPEP cond type): */
  691. var gcv_object_t* FRAME = STACK;
  692. while (1) {
  693. /* search in Stack starting at FRAME for a suitable HANDLER-Frame: */
  694. if (!(other_ranges == NULL) && (FRAME == other_ranges->low_limit)) {
  695. FRAME = other_ranges->high_limit;
  696. other_ranges = other_ranges->next;
  697. } else if (eq(FRAME_(0),nullobj)) { /* End of Stack? */
  698. break; /* yes -> finised, jump back */
  699. } else if (framecode(FRAME_(0)) & bit(frame_bit_t)) {
  700. /* found frame */
  701. if (framecode(FRAME_(0)) == HANDLER_frame_info) { /* Handler-Frame? */
  702. /* loop over types of the vectors #(type1 label1 ... typem labelm): */
  703. var uintL m2 = Svector_length(Car(FRAME_(frame_handlers))); /* 2*m */
  704. var uintL i = 0;
  705. do {
  706. pushSTACK(cond); /* save cond */
  707. pushSTACK(cond);
  708. pushSTACK(TheSvector(Car(FRAME_(frame_handlers)))->data[i]); /* typei */
  709. funcall(S(safe_typep),2); /* execute (SYS::SAFE-TYPEP cond typei) */
  710. if (!nullp(value1)) { /* found a suitable handler */
  711. /* CLtL2 S. 873, 884:
  712. "A handler is executed in the dynamic context
  713. of the signaler, except that the set of available condition
  714. handlers will have been rebound to the value that was active
  715. at the time the condition handler was made active."
  716. we make the whole thing bullet-proof by an
  717. Unwind-Protect-Frame: */
  718. var stack_range_t* saved_inactive_handlers = inactive_handlers;
  719. new_range.low_limit = STACK;
  720. new_range.high_limit = topofframe(FRAME_(0));
  721. new_range.next = other_ranges;
  722. var gcv_object_t* top_of_frame = STACK;
  723. var sp_jmp_buf returner; /* return point */
  724. finish_entry_frame(UNWIND_PROTECT,returner,, {
  725. var restartf_t fun = unwind_protect_to_save.fun;
  726. var gcv_object_t* arg = unwind_protect_to_save.upto_frame;
  727. skipSTACK(2); /* unwind Unwind-Protect-Frame */
  728. /* Cleanup: reactivate Handler: */
  729. inactive_handlers = saved_inactive_handlers;
  730. /* and jump ahead: */
  731. fun(arg);
  732. NOTREACHED;
  733. });
  734. /* deactivate Handler: */
  735. inactive_handlers = &new_range;
  736. if (!nullp(Cdr(FRAME_(frame_handlers)))) {
  737. /* make information available for Handler: */
  738. handler_args.condition = STACK_(0+2);
  739. handler_args.stack = FRAME STACKop 4;
  740. handler_args.sp = (SPint*)(aint)as_oint(FRAME_(frame_SP));
  741. handler_args.spdepth = Cdr(FRAME_(frame_handlers));
  742. /* call Handler: */
  743. var object closure = FRAME_(frame_closure);
  744. var object codevec = TheCclosure(closure)->clos_codevec;
  745. var uintL index = (TheCodevec(codevec)->ccv_flags & bit(7) ? CCV_START_KEY : CCV_START_NONKEY)
  746. + (uintL)posfixnum_to_V(TheSvector(Car(FRAME_(frame_handlers)))->data[i+1]);
  747. interpret_bytecode(closure,codevec,index);
  748. } else {
  749. /* call C-Handler: */
  750. void* handler_fn = TheMachineCode(FRAME_(frame_closure));
  751. ((void (*) (void*, gcv_object_t*, object, object)) handler_fn)
  752. ((void*)(aint)as_oint(FRAME_(frame_SP)),FRAME,
  753. TheSvector(Car(FRAME_(frame_handlers)))->data[i+1],
  754. STACK_(0+2));
  755. }
  756. skipSTACK(2); /* unwind Unwind-Protect-Frame */
  757. /* reactivate Handler: */
  758. inactive_handlers = saved_inactive_handlers;
  759. }
  760. cond = popSTACK(); /* cond back */
  761. i += 2;
  762. } while (i < m2);
  763. }
  764. /* skip Frame: */
  765. FRAME = topofframe(FRAME_(0));
  766. } else {
  767. FRAME skipSTACKop 1;
  768. }
  769. }
  770. var object handler = Symbol_function(S(global_handler));
  771. if (boundp(handler)) { /* unbound during bootstrap */
  772. pushSTACK(cond); funcall(handler,1); /* (GLOBAL-HANDLER cond) */
  773. }
  774. }
  775. /* UP: finds out, if an object is a function name, i.e. a Symbol or
  776. a list of the form (SETF symbol).
  777. funnamep(obj)
  778. > obj: Object
  779. < result: true if function name */
  780. global bool funnamep (object obj) {
  781. if (symbolp(obj))
  782. return true;
  783. if (consp(obj) && eq(Car(obj),S(setf))) {
  784. obj = Cdr(obj);
  785. if (consp(obj) && nullp(Cdr(obj)) && symbolp(Car(obj)))
  786. return true;
  787. }
  788. return false;
  789. }
  790. /* UP: find whether the symbol is bound in the environment */
  791. local inline gcv_object_t* symbol_env_search (object sym, object venv)
  792. {
  793. /* Does the binding at bindptr bind the symbol sym? */
  794. #ifdef NO_symbolflags
  795. #define binds_sym_p(bindingptr) \
  796. (eq(*(bindingptr STACKop 1),sym) /* the right symbol? */ \
  797. && eq(*(bindingptr STACKop 0),fixnum(bit(active_bit)))) /* active & static? */
  798. #else
  799. var object cmp = SET_BIT(sym,active_bit_o); /* for comparison: binding must be active */
  800. #define binds_sym_p(bindingptr) \
  801. (eq(*(bindingptr STACKop 0),cmp)) /* right symbol & active & static? */
  802. #endif
  803. next_env:
  804. if (framepointerp(venv)) {
  805. /* Environment is a Pointer to a variable-binding-frame */
  806. var gcv_object_t* FRAME = TheFramepointer(venv);
  807. var uintL count = as_oint(FRAME_(frame_count)); /* number of bindings */
  808. if (count > 0) {
  809. var gcv_object_t* bindingsptr = &FRAME_(frame_bindings); /* 1st binding */
  810. do {
  811. if (binds_sym_p(bindingsptr)) /* right symbol & active & static? */
  812. return bindingsptr STACKop varframe_binding_value;
  813. bindingsptr skipSTACKop varframe_binding_size; /* no: next binding */
  814. } while (--count);
  815. }
  816. venv = FRAME_(frame_next_env);
  817. goto next_env;
  818. }
  819. var bool from_inside_macrolet = false;
  820. for (;;) {
  821. if (simple_vector_p(venv)) {
  822. /* environment is a simple-vector */
  823. var uintL count = floor(Svector_length(venv),2); /* number of bindings */
  824. var gcv_object_t* ptr = &TheSvector(venv)->data[0];
  825. dotimesL(count,count, {
  826. if (eq(*ptr,sym)) { /* right symbol? */
  827. if (from_inside_macrolet && !eq(*(ptr+1),specdecl)
  828. && !symbolmacrop(*(ptr+1)))
  829. goto macrolet_error;
  830. return ptr+1;
  831. }
  832. ptr += 2; /* next binding */
  833. });
  834. venv = *ptr; /* next environment */
  835. continue;
  836. } else if (consp(venv)) {
  837. /* environment is a MACROLET capsule */
  838. ASSERT(eq(Car(venv),S(macrolet)));
  839. from_inside_macrolet = true;
  840. venv = Cdr(venv);
  841. continue;
  842. } else
  843. break;
  844. }
  845. /* Environment is NIL */
  846. return NULL;
  847. #undef binds_sym_p
  848. macrolet_error:
  849. pushSTACK(sym); /* SOURCE-PROGRAM-ERROR slot DETAIL */
  850. pushSTACK(S(macrolet)); pushSTACK(sym);
  851. error(program_error,
  852. GETTEXT("Invalid access to the value of the lexical variable ~S from within a ~S definition"));
  853. }
  854. /* (SYS::SPECIAL-VARIABLE-P symbol &optional environment)
  855. tests whether the symbol is a special variable or a constant.
  856. A missing or NIL environment means the global environment. */
  857. LISPFUN(special_variable_p,seclass_read,1,1,norest,nokey,0,NIL)
  858. {
  859. var object symbol = check_symbol(STACK_1);
  860. var object env = STACK_0; skipSTACK(2);
  861. if (special_var_p(TheSymbol(symbol))) {
  862. value1 = T;
  863. } else if (missingp(env)) {
  864. value1 = NIL;
  865. } else {
  866. if (simple_vector_p(env)) {
  867. var uintL len = Svector_length(env);
  868. if (len == 2 || len == 5)
  869. env = TheSvector(env)->data[0]; /* venv */
  870. else
  871. error_environment(env);
  872. }
  873. var gcv_object_t *binding = symbol_env_search(symbol,env);
  874. if ((binding != NULL) && eq(*binding,specdecl))
  875. value1 = T;
  876. else
  877. value1 = NIL;
  878. }
  879. mv_count = 1;
  880. }
  881. /* UP: returns the value of a symbol in an environment.
  882. sym_value(symbol,venv,&symbolmacro)
  883. > symbol: Symbol
  884. > venv: a Variable- and Symbolmacro-Environment
  885. < symbolmacro: symbol-macro definition, or nullobj if not a symbol-macro
  886. < result: value of the symbol in this environment, or
  887. nullobj if a symbol-macro */
  888. local gcv_object_t sym_value (object sym, object env, object* symbolmacro_)
  889. {
  890. if (special_var_p(TheSymbol(sym))) {
  891. /* Constants and symbols declared special have only global values. */
  892. goto global_value;
  893. } else {
  894. var gcv_object_t* binding = symbol_env_search(sym,env);
  895. if (binding != NULL) {
  896. var object val = *binding;
  897. if (eq(val,specdecl))
  898. goto global_value;
  899. if (symbolmacrop(val)) {
  900. *symbolmacro_ = val;
  901. return nullobj;
  902. }
  903. *symbolmacro_ = nullobj;
  904. return val;
  905. }
  906. if (symmacro_var_p(TheSymbol(sym))) {
  907. /* Fetch the symbol-macro definition from the property list: */
  908. var object symbolmacro = get(sym,S(symbolmacro));
  909. if (!eq(symbolmacro,unbound)) {
  910. ASSERT(globalsymbolmacrop(symbolmacro));
  911. *symbolmacro_ = TheGlobalSymbolmacro(symbolmacro)->globalsymbolmacro_definition;
  912. return nullobj;
  913. }
  914. /* Huh? The symbol-macro definition got lost. */
  915. clear_symmacro_flag(TheSymbol(sym));
  916. }
  917. }
  918. global_value: /* the global (dynamic) value of the Symbol */
  919. *symbolmacro_ = nullobj;
  920. return Symbol_value(sym);
  921. }
  922. /* UP: determines, if a Symbol is a Macro in the current environment.
  923. sym_macrop(symbol)
  924. > symbol: Symbol
  925. < result: true if sym is a Symbol-Macro */
  926. global bool sym_macrop (object sym) {
  927. var object symbolmacro;
  928. sym_value(sym,aktenv.var_env,&symbolmacro);
  929. return !eq(symbolmacro,nullobj);
  930. }
  931. /* UP: Sets the value of a Symbol in the current Environment.
  932. setq(symbol,value);
  933. > symbol: Symbol, no constant, not a symbol-macro in the current Environment
  934. > value: desired value of the Symbols in the current Environment
  935. < result: value
  936. can trigger GC */
  937. global maygc object setq (object sym, object value)
  938. {
  939. if (special_var_p(TheSymbol(sym))) {
  940. /* Constants and symbols declared special have only global values. */
  941. goto global_value;
  942. } else {
  943. var gcv_object_t* binding = symbol_env_search(sym,aktenv.var_env);
  944. if (binding != NULL) {
  945. var object val = *binding;
  946. if (eq(val,specdecl))
  947. goto global_value;
  948. ASSERT(!symbolmacrop(val));
  949. return *binding = value;
  950. }
  951. ASSERT(!symmacro_var_p(TheSymbol(sym)));
  952. }
  953. global_value: /* the global (dynamic) value of the Symbol */
  954. pushSTACK(value); pushSTACK(sym);
  955. symbol_value_check_lock(S(setq),sym);
  956. Symbol_value(STACK_0) = STACK_1;
  957. skipSTACK(1);
  958. return popSTACK();
  959. }
  960. /* UP: returns for a Symbol its function definition in an Environment
  961. sym_function(sym,fenv)
  962. > sym: function name (e.g. Symbol)
  963. > fenv: a function- and macro-bindung-environment
  964. < result: function definition, either unbound (if undefined function)
  965. or Closure/SUBR/FSUBR/Macro/FunctionMacro. */
  966. global object sym_function (object sym, object env)
  967. {
  968. var object value;
  969. { next_env:
  970. if (framepointerp(env)) {
  971. /* Environment is a Pointer to a function-binding-frame */
  972. var gcv_object_t* FRAME = TheFramepointer(env);
  973. var uintL count = as_oint(FRAME_(frame_count)); /* number of bindings */
  974. if (count > 0) {
  975. var gcv_object_t* bindingsptr = &FRAME_(frame_bindings); /* pointer to the first binding */
  976. dotimespL(count,count, {
  977. if (equal(*(bindingsptr STACKop 0),sym)) { /* right Symbol? */
  978. value = *(bindingsptr STACKop 1); goto done;
  979. }
  980. bindingsptr skipSTACKop 2; /* no: next binding */
  981. });
  982. }
  983. env = FRAME_(frame_next_env);
  984. goto next_env;
  985. }
  986. var bool from_inside_macrolet = false;
  987. for (;;) {
  988. if (simple_vector_p(env)) {
  989. /* Environment is a Simple-Vector */
  990. var uintL count = floor(Svector_length(env),2); /* number of bindings */
  991. var gcv_object_t* ptr = &TheSvector(env)->data[0];
  992. dotimesL(count,count, {
  993. if (equal(*ptr,sym)) { /* right Symbol? */
  994. value = *(ptr+1);
  995. if (from_inside_macrolet && !macrop(value))
  996. goto macrolet_error;
  997. goto done;
  998. }
  999. ptr += 2; /* next binding */
  1000. });
  1001. env = *ptr; /* next Environment */
  1002. continue;
  1003. } else if (consp(env)) {
  1004. /* environment is a MACROLET capsule */
  1005. ASSERT(eq(Car(env),S(macrolet)));
  1006. from_inside_macrolet = true;
  1007. env = Cdr(env);
  1008. continue;
  1009. } else /* Environment is NIL */
  1010. goto global_value;
  1011. }
  1012. }
  1013. global_value: /* global function-definition */
  1014. if (!symbolp(sym)) {
  1015. sym = get(Car(Cdr(sym)),S(setf_function)); /* (get s 'SYS::SETF-FUNCTION) */
  1016. if (!symbolp(sym)) /* should be (uninterned) Symbol */
  1017. return unbound; /* else undefined */
  1018. }
  1019. return Symbol_function(sym);
  1020. done:
  1021. /* Symbol found active in Environment, "Value" value (a Closure or Macro
  1022. or FunctionMacro or NIL) if Definition = NIL (during LABELS),
  1023. the function is passed for as undefined: */
  1024. if (nullp(value))
  1025. value = unbound;
  1026. return value;
  1027. macrolet_error:
  1028. pushSTACK(sym); /* SOURCE-PROGRAM-ERROR slot DETAIL */
  1029. pushSTACK(S(macrolet)); pushSTACK(sym);
  1030. error(source_program_error,
  1031. GETTEXT("Invalid access to the local function definition of ~S from within a ~S definition"));
  1032. }
  1033. /* UP: evaluates a Form in a given Environment.
  1034. eval_5env(form,var,fun,block,go,decl);
  1035. > var_env: value for VAR_ENV
  1036. > fun_env: value for FUN_ENV
  1037. > block_env: value for BLOCK_ENV
  1038. > go_env: value for GO_ENV
  1039. > decl_env: value for DECL_ENV
  1040. > form: Form
  1041. < mv_count/mv_space: values
  1042. can trigger GC */
  1043. global maygc Values eval_5env (object form, object var_env, object fun_env,
  1044. object block_env, object go_env, object decl_env)
  1045. {
  1046. /* bind Environments: */
  1047. make_ENV5_frame();
  1048. /* set current Environments: */
  1049. aktenv.var_env = var_env;
  1050. aktenv.fun_env = fun_env;
  1051. aktenv.block_env = block_env;
  1052. aktenv.go_env = go_env;
  1053. aktenv.decl_env = decl_env;
  1054. /* evaluate Form: */
  1055. eval(form);
  1056. /* unwind Environment-Frame: */
  1057. unwind();
  1058. return; /* finished */
  1059. }
  1060. /* UP: evaluates a form in an empty environment.
  1061. eval_noenv(form);
  1062. > form: Form
  1063. < mv_count/mv_space: values
  1064. can trigger GC */
  1065. global maygc Values eval_noenv (object form) {
  1066. return_Values eval_5env(form,NIL,NIL,NIL,NIL,O(top_decl_env));
  1067. }
  1068. /* UP: "nests" a FUN-Environment, i.e. writes all active bindings
  1069. from the Stack into freshly allocated vectors.
  1070. nest_fun(env)
  1071. > env: FUN-Env
  1072. < result: same environment, no Pointer into the Stack
  1073. can trigger GC */
  1074. global maygc object nest_fun (object env)
  1075. {
  1076. var uintL depth = 0; /* recursion counter := 0 */
  1077. /* Pseudorecursion with Input env, Output env. */
  1078. nest_start: /* start of recursion */
  1079. if (framepointerp(env)) {
  1080. /* env is a pointer to a STACK-Frame. */
  1081. check_STACK();
  1082. pushSTACK(env); /* save env */
  1083. /* execute nest_fun(NEXT_ENV(env)) "disrecursified" :-) : */
  1084. {
  1085. var gcv_object_t* FRAME = TheFramepointer(env);
  1086. env = FRAME_(frame_next_env); depth++; goto nest_start;
  1087. }
  1088. nest_reentry: depth--;
  1089. { /* NEXT_ENV is now nested. */
  1090. var gcv_object_t* FRAME = TheFramepointer(STACK_0); /* next STACK-Frame to be nested */
  1091. STACK_0 = env; /* bisher genestetes Environment */
  1092. var uintL bcount = as_oint(FRAME_(frame_count)); /* number of not yet netsted bindings */
  1093. if (bcount == 0) {
  1094. /* no bindings -> unnecessary, to create a vector. */
  1095. env = popSTACK();
  1096. } else {
  1097. /* create vector for bcount bindings: */
  1098. env = allocate_vector(2*bcount+1);
  1099. /* and fill: */
  1100. {
  1101. var gcv_object_t* ptr = &TheSvector(env)->data[0];
  1102. var gcv_object_t* bindingsptr = &FRAME_(frame_bindings); /* Pointer to the first binding */
  1103. /* put bcount bindings starting at bindingsptr into the vector at ptr: */
  1104. dotimespL(bcount,bcount, {
  1105. *ptr++ = *(bindingsptr STACKop 0); /* copy binding into the vector */
  1106. *ptr++ = *(bindingsptr STACKop 1);
  1107. bindingsptr skipSTACKop 2;
  1108. });
  1109. *ptr++ = popSTACK(); /* put nested NEXT_ENV into vector */
  1110. }
  1111. FRAME_(frame_next_env) = env; /* Vector as NEXT_ENV into the Frame */
  1112. FRAME_(frame_count) = as_object(0); /* new number of not yet nested bindings */
  1113. }
  1114. }
  1115. }
  1116. /* finished with this Nest-substep. */
  1117. if (depth>0) /* end of recursion */
  1118. goto nest_reentry;
  1119. return env;
  1120. }
  1121. /* UP: "nests" a VAR-Environment, i.e. writes all active bindings
  1122. from the Stack in freshly allocated vectors.
  1123. nest_var(env)
  1124. > env: VAR-Env
  1125. < result: same Environment, no Pointer in the Stack
  1126. can trigger GC */
  1127. local maygc object nest_var (object env)
  1128. {
  1129. var uintL depth = 0; /* Recursion counter := 0 */
  1130. /* Pseudorecursion with Input env, Output env. */
  1131. nest_start: /* start of Recursion */
  1132. if (framepointerp(env)) {
  1133. /* env is a Pointer to a STACK-Frame. */
  1134. check_STACK();
  1135. pushSTACK(env); /* save env */
  1136. /* execute nest_var(NEXT_ENV(env)) "disrecursified" :-) : */
  1137. {
  1138. var gcv_object_t* FRAME = TheFramepointer(env);
  1139. env = FRAME_(frame_next_env); depth++; goto nest_start;
  1140. }
  1141. nest_reentry: depth--;
  1142. /* NEXT_ENV is now nested. */
  1143. {
  1144. var gcv_object_t* FRAME = TheFramepointer(STACK_0); /* next STACK-Frame to be nested */
  1145. STACK_0 = env; /* formerly nested Environment */
  1146. /* Search (from bottom) the first active among the not yet
  1147. nested bindings: */
  1148. var uintL bcount = as_oint(FRAME_(frame_count)); /* number of not yet nested bindings */
  1149. var uintL count = 0;
  1150. var gcv_object_t* bindingsptr = &FRAME_(frame_bindings); /* Pointer to the first binding */
  1151. while (!((count>=bcount) /* all unnested bindings through? */
  1152. || (as_oint(*(bindingsptr STACKop 0)) & wbit(active_bit_o)))) { /* discovered active binding? */
  1153. /* no -> continue search: */
  1154. bindingsptr skipSTACKop varframe_binding_size;
  1155. count++;
  1156. }
  1157. /* Below bindingsptr are count inactive bindings.
  1158. From bindingsptr on there are bcount-count active, to be nested bindings. */
  1159. bcount = bcount-count; /* number of bindings to be nested */
  1160. if (bcount == 0) {
  1161. /* no bindings -> creating a vector is unnecessary. */
  1162. env = popSTACK();
  1163. } else {
  1164. /* create vector for bcount bindings: */
  1165. env = allocate_vector(2*bcount+1);
  1166. /* and fill: */
  1167. {
  1168. var gcv_object_t* ptr = &TheSvector(env)->data[0];
  1169. /* put bindungs starting at bindingsptr in the vector at ptr: */
  1170. dotimespL(bcount,bcount, {
  1171. if (as_oint(*(bindingsptr STACKop varframe_binding_mark)) & wbit(dynam_bit_o)) { /* binding dynamic? */
  1172. /* dynamic binding, lexical scope */
  1173. *ptr++ = symbol_without_flags(*(bindingsptr STACKop varframe_binding_sym)); /* put Symbol without Flag-Bits in the Vector */
  1174. *ptr++ = specdecl; /* mark as special reference */
  1175. /* binding stays active in the Frame */
  1176. } else {
  1177. /* static binding, lexical scope */
  1178. *(bindingsptr STACKop varframe_binding_mark) =
  1179. CLR_BIT(*(bindingsptr STACKop varframe_binding_mark),active_bit_o); /* deactivate binding */
  1180. *ptr++ = *(bindingsptr STACKop varframe_binding_sym); /* copy binding in the vector */
  1181. *ptr++ = *(bindingsptr STACKop varframe_binding_value);
  1182. }
  1183. bindingsptr skipSTACKop varframe_binding_size;
  1184. });
  1185. *ptr++ = popSTACK(); /* put nested NEXT_ENV in the vector */
  1186. }
  1187. FRAME_(frame_next_env) = env; /* vector as NEXT_ENV in the Frame */
  1188. FRAME_(frame_count) = fake_gcv_object(count); /* new number of not yet nested bindings */
  1189. }
  1190. }
  1191. }
  1192. /* finished with this Nest-substep. */
  1193. if (depth>0) /* end of recursion */
  1194. goto nest_reentry;
  1195. return env;
  1196. }
  1197. /* UP: Nests the Environments in *env (i.e. writes all information in
  1198. Stack-independent structures) and pushes them onto the STACK.
  1199. (The values VAR_ENV, FUN_ENV, BLOCK_ENV, GO_ENV, DECL_ENV will not
  1200. be changed, because inactive bindings might poss. still sit in the frames.
  1201. It has to be feasible, to activate these bindings without change of VAR_ENV.)
  1202. nest_env(env)
  1203. > gcv_environment_t* env: Pointer to five Environments
  1204. < gcv_environment_t* result: Pointer to the Environments in the STACK
  1205. changes STACK, can trigger GC */
  1206. global maygc gcv_environment_t* nest_env (gcv_environment_t* env5)
  1207. {
  1208. /* First copy all Environments in the STACK: */
  1209. make_STACK_env(env5->var_env,env5->fun_env,env5->block_env,env5->go_env,
  1210. env5->decl_env,env5 = );
  1211. /* DECL_ENV: Not to be changed. */
  1212. { /* GO_ENV: */
  1213. var object env = env5->go_env;
  1214. var uintL depth = 0; /* recursion depth := 0 */
  1215. /* pseudo-recursion: nests a GO_ENV. */
  1216. /* Input: env, a GO_ENV. Output: env, with Alist. */
  1217. nest_go_start: { /* start of recursion */
  1218. var gcv_object_t* FRAME;
  1219. if (framepointerp(env)) {
  1220. /* env is a pointer into the STACK to a ITAGBODY-frame. */
  1221. check_STACK();
  1222. FRAME = TheFramepointer(env);
  1223. if (framecode(FRAME_(0)) & bit(nested_bit_t)) { /* frame already nested? */
  1224. env = FRAME_(frame_next_env); /* yes -> fetch former Alist */
  1225. } else {
  1226. pushSTACK(env); /* save env */
  1227. /* execute nest_go(NEXT_ENV(env)) "disrecursivied": */
  1228. env = FRAME_(frame_next_env); depth++; goto nest_go_start;
  1229. nest_go_reentry: depth--;
  1230. { /* NEXT_ENV is now nested. */
  1231. var object frame = STACK_0; /* next to be nested STACK-Frame */
  1232. FRAME = uTheFramepointer(frame);
  1233. STACK_0 = env; /* so far nested Environment */
  1234. var gcv_object_t* tagsptr = &FRAME_(frame_bindings); /* Pointer to the bottom Tag */
  1235. var gcv_object_t* frame_end = STACKpointable(topofframe(FRAME_(0))); /* Pointer to Frame */
  1236. var uintL count = /* number of tags */
  1237. /* subtract the pointers tagsptr and frame_end (both without Typinfo!): */
  1238. STACK_item_count(tagsptr,frame_end) / 2;
  1239. { /* create vector for count tags: */
  1240. var object tagvec = allocate_vector(count);
  1241. /* and fill: */
  1242. if (count > 0) {
  1243. var gcv_object_t* ptr = &TheSvector(tagvec)->data[0];
  1244. /* put tags starting at tagsptr in the vector at ptr: */
  1245. dotimespL(count,count, {
  1246. *ptr++ = *(tagsptr STACKop 0);
  1247. tagsptr skipSTACKop 2;
  1248. });
  1249. }
  1250. pushSTACK(tagvec); /* and save */
  1251. }
  1252. { /* create next Alist Cons (cons tag-vector frame-pointer) : */
  1253. var object new_cons = allocate_cons();
  1254. Car(new_cons) = STACK_0; /* tagvec */
  1255. Cdr(new_cons) = frame;
  1256. STACK_0 = new_cons;
  1257. }
  1258. /* and prepend to Alist: */
  1259. env = allocate_cons();
  1260. Car(env) = popSTACK(); /* new_cons */
  1261. Cdr(env) = popSTACK(); /* previous Alist */
  1262. FRAME_(frame_next_env) = env; /* store new NEXT_ENV */
  1263. *(oint*)(&FRAME_(0)) |= wbit(nested_bit_o); /* this frame is now nested. */
  1264. }
  1265. }
  1266. }
  1267. /* finished with this Nest-Substep. */
  1268. if (depth>0) /* end of Recursion */
  1269. goto nest_go_reentry;
  1270. env5->go_env = env; /* file nested GO_ENV */
  1271. }
  1272. }
  1273. { /* BLOCK_ENV: */
  1274. var object env = env5->block_env;
  1275. var uintL depth = 0; /* recursion depth := 0 */
  1276. /* Pseudo-Recursion: nests a BLOCK_ENV. */
  1277. /* Input: env, a BLOCK_ENV. Output: env, with Aliste. */
  1278. nest_block_start: { /* start of recursion */
  1279. var gcv_object_t* FRAME;
  1280. if (framepointerp(env)) {
  1281. /* env is a pointer into the STACK to a IBLOCK-Frame. */
  1282. check_STACK();
  1283. FRAME = TheFramepointer(env);
  1284. if (framecode(FRAME_(0)) & bit(nested_bit_t)) { /* Frame already nested? */
  1285. env = FRAME_(frame_next_env); /* yes -> fetch previous Alist */
  1286. } else {
  1287. pushSTACK(env); /* save env */
  1288. /* execute nest_block(NEXT_ENV(env)) "disrecursified": */
  1289. env = FRAME_(frame_next_env); depth++; goto nest_block_start;
  1290. nest_block_reentry: depth--;
  1291. { /* NEXT_ENV is now nested. */
  1292. var object frame = STACK_0; /* next to be nested STACK-Frame */
  1293. FRAME = TheFramepointer(frame);
  1294. STACK_0 = env; /* so far nested Environment */
  1295. { /* create next Alist Cons (cons Block-Name Frame-Pointer) : */
  1296. var object new_cons = allocate_cons();
  1297. Car(new_cons) = FRAME_(frame_name);
  1298. Cdr(new_cons) = frame;
  1299. pushSTACK(new_cons);
  1300. }
  1301. /* and prepend to the Aliste: */
  1302. env = allocate_cons();
  1303. Car(env) = popSTACK(); /* new_cons */
  1304. Cdr(env) = popSTACK(); /* previous Alist */
  1305. FRAME_(frame_next_env) = env; /* store new NEXT_ENV */
  1306. *(oint*)(&FRAME_(0)) |= wbit(nested_bit_o); /* this frame is now nested. */
  1307. }
  1308. }
  1309. }
  1310. }
  1311. /* finished with this Nest-Substep. */
  1312. if (depth>0) /* end of recursion */
  1313. goto nest_block_reentry;
  1314. env5->block_env = env; /* file nested BLOCK_ENV */
  1315. }
  1316. /* FUN_ENV: */
  1317. env5->fun_env = nest_fun(env5->fun_env);
  1318. /* VAR_ENV: */
  1319. env5->var_env = nest_var(env5->var_env);
  1320. /* done */
  1321. return env5;
  1322. }
  1323. /* UP: Nests the current environments (i.e. writes all Information in
  1324. Stack-independent Structures) and pushes them onto the STACK.
  1325. (The values VAR_ENV, FUN_ENV, BLOCK_ENV, GO_ENV, DECL_ENV are not
  1326. modified, because inactive bindings might poss. still sit in the Frames.
  1327. It has to be feasible, to activate these bindings without change of VAR_ENV.)
  1328. nest_aktenv()
  1329. < gcv_environment* result: Pointer to the Environments in the STACK
  1330. changes STACK, can trigger GC */
  1331. #define nest_aktenv() nest_env(&aktenv)
  1332. /* UP: augments a Declaration-Environment with a decl-spec.
  1333. augment_decl_env(declspec,env)
  1334. > declspec: Declaration-Specifier, a Cons
  1335. > env: Declaration-Environment
  1336. < result: new (poss. augmented) Declaration-Environment
  1337. can trigger GC */
  1338. global maygc object augment_decl_env (object new_declspec, object env)
  1339. {
  1340. var object decltype = Car(new_declspec); /* Declaration-Type */
  1341. /* Is this a declaration type to be payed attention to?
  1342. Is there a Decl-Spec of the form (DECLARATION ... decltype ...) in env?
  1343. Aside: The List O(declaration_types) is the last Decl-Spec in env. */
  1344. if (symbolp(decltype)) {
  1345. /* loop over all local to be respected Declaration-Types: */
  1346. var object declspecs = env;
  1347. while (consp(declspecs)) { /* loop over all declspecs from env */
  1348. var object declspec = Car(declspecs);
  1349. if (eq(Car(declspec),S(declaration)) /* (DECLARATION ...) ? */
  1350. && !nullp(memq(decltype,Cdr(declspec))))
  1351. goto beachten;
  1352. declspecs = Cdr(declspecs);
  1353. }
  1354. }
  1355. /* not to be respected Declaration. */
  1356. return env; /* leave env unchanged */
  1357. beachten:
  1358. /* a to be respected Declaration -> env := (cons new_declspec env) */
  1359. pushSTACK(env); pushSTACK(new_declspec);
  1360. env = allocate_cons();
  1361. Car(env) = popSTACK(); Cdr(env) = popSTACK();
  1362. return env;
  1363. }
  1364. /* UP: expands a form, if possible, (however it doesn't, if FSUBR-Call
  1365. or Symbol or FunctionMacro-Call) in an Environment
  1366. macroexp(form,venv,fenv);
  1367. > form: Form
  1368. > venv: a Variable- and Symbolmacro-Environment
  1369. > fenv: a Function- and Macrobinding-Environment
  1370. < value1: the expansion
  1371. < value2: NIL, if not expanded,
  1372. T, if expansion has taken place
  1373. can trigger GC */
  1374. global maygc void macroexp (object form, object venv, object fenv)
  1375. {
  1376. if (consp(form)) { /* only lists can be a macro-call */
  1377. var object funname = Car(form); /* function name */
  1378. if (symbolp(funname)) {
  1379. var object fdef = sym_function(funname,fenv); /* fetch function definition */
  1380. /* is it a #<MACRO expander> ? */
  1381. if (macrop(fdef)) {
  1382. /* yes -> expand:
  1383. execute (FUNCALL *MACROEXPAND-HOOK* expander form env) : */
  1384. pushSTACK(TheMacro(fdef)->macro_expander); /* expander as first argument */
  1385. pushSTACK(form); /* form as second argument */
  1386. pushSTACK(fenv);
  1387. pushSTACK(nest_var(venv)); /* nested Variable- and Symbolmacro-Environment */
  1388. STACK_1 = nest_fun(STACK_1); /* nested Functions- and Macrobinding-Environment */
  1389. var object env = allocate_vector(2); /* Environment for both */
  1390. TheSvector(env)->data[0] = popSTACK(); /* venv as 1st component */
  1391. TheSvector(env)->data[1] = STACK_0; /* fenv as 2nd component */
  1392. STACK_0 = env; /* Environment as third Argument */
  1393. funcall(Symbol_value(S(macroexpand_hook)),3);
  1394. value2 = T; /* expanded Form as 1st value, T as 2nd value */
  1395. return;
  1396. }
  1397. }
  1398. }
  1399. /* else, don't expand: */
  1400. value1 = form; value2 = NIL;
  1401. }
  1402. /* UP: expands a form, if possible, (also, when FSUBR-Call or
  1403. Symbol, however not, when FunctionMacro-Call) in an Environment
  1404. macroexp0(form,env);
  1405. > form: Form
  1406. > env: a Macroexpansion-Environment
  1407. < value1: the Expansion
  1408. < value2: NIL, if not expanded,
  1409. T, if expansion has taken place
  1410. can trigger GC */
  1411. global maygc void macroexp0 (object form, object env)
  1412. {
  1413. if (consp(form)) { /* only lists can be a macro-call */
  1414. var object funname = Car(form); /* function name */
  1415. if (symbolp(funname)) {
  1416. var object fdef = sym_function(funname,TheSvector(env)->data[1]); /* fetch function definition */
  1417. if (fsubrp(fdef)) {
  1418. /* fdef is a FSUBR, so the global function definition was valid.
  1419. loop up, if the property list contains a macro definition: */
  1420. var object expander = get(funname,S(macro)); /* search for Property SYS::MACRO */
  1421. if (boundp(expander)) {
  1422. /* found. Expand with th Expander from the property list:
  1423. execute (FUNCALL *MACROEXPAND-HOOK* expander form env) : */
  1424. pushSTACK(expander); /* expander as first argument */
  1425. pushSTACK(form); /* form as second Argument */
  1426. pushSTACK(env); /* environment as third argument */
  1427. funcall(Symbol_value(S(macroexpand_hook)),3);
  1428. value2 = T; /* expanded form as 1st value, t as 2nd value */
  1429. return;
  1430. }
  1431. } else {
  1432. /* 4 possibilities:
  1433. #UNBOUND/SUBR/Closure (global or lexical function def.)
  1434. -> don't expand
  1435. #<MACRO expander> (lexical macro definition)
  1436. -> expand (call expander)
  1437. #<FUNCTION-MACRO function expander> (lexical FunctionMacro-
  1438. Definition) -> don't expand, because
  1439. (MACRO-FUNCTION funname) => NIL
  1440. Symbol (lexical function definition during SYS::%EXPAND)
  1441. expand: (list* 'FUNCALL Symbol (cdr form)) */
  1442. if (macrop(fdef)) {
  1443. /* #<MACRO expander> -> expand:
  1444. execute (FUNCALL *MACROEXPAND-HOOK* expander form env) : */
  1445. pushSTACK(TheMacro(fdef)->macro_expander); /* Expander as first Argument */
  1446. pushSTACK(form); /* Form as second Argument */
  1447. pushSTACK(env); /* Environment as third Argument */
  1448. funcall(Symbol_value(S(macroexpand_hook)),3);
  1449. value2 = T; /* expanded Form as 1st value, T as 2nd value */
  1450. return;
  1451. } else if (symbolp(fdef)) {
  1452. /* fdef a Symbol
  1453. Must be expanded to (FUNCALL fdef ...) : */
  1454. pushSTACK(Cdr(form)); /* (cdr form) */
  1455. pushSTACK(fdef); /* Symbol */
  1456. {
  1457. var object new_cons = allocate_cons();
  1458. Car(new_cons) = popSTACK(); Cdr(new_cons) = STACK_0;
  1459. STACK_0 = new_cons; /* (cons Symbol (cdr form)) */
  1460. }
  1461. {
  1462. var object new_cons = allocate_cons();
  1463. Car(new_cons) = S(funcall); Cdr(new_cons) = popSTACK();
  1464. value1 = new_cons; /* (cons 'FUNCALL (cons Symbol (cdr form))) */
  1465. }
  1466. value2 = T; return; /* expansion has taken place. */
  1467. }
  1468. }
  1469. }
  1470. } else if (symbolp(form)) {
  1471. var object symbolmacro;
  1472. var object val = sym_value(form,TheSvector(env)->data[0],&symbolmacro);
  1473. if (!eq(symbolmacro,nullobj)) { /* found Symbol-Macro? */
  1474. /* yes -> expand */
  1475. value1 = TheSymbolmacro(symbolmacro)->symbolmacro_expansion; value2 = T;
  1476. return;
  1477. }
  1478. }
  1479. /* else, don't expand: */
  1480. value1 = form; value2 = NIL;
  1481. }
  1482. /* UP: Parse-Declarations-Docstring. Detaches those from a list of forms,
  1483. that have to be viewed as declarations resp. documentation string.
  1484. parse_dd(formlist)
  1485. > formlist: ( {decl|doc-string} . body )
  1486. < value1: body
  1487. < value2: List of decl-specs
  1488. < value3: Doc-String or NIL
  1489. < result: true if one (COMPILE)-declaration occurred, else false
  1490. can trigger GC */
  1491. global maygc bool parse_dd (object formlist)
  1492. {
  1493. pushSTACK(formlist); /* store formlist for error message */
  1494. pushSTACK(NIL); /* preliminary Doc-String */
  1495. pushSTACK(NIL); /* start of decl-spec-Liste */
  1496. /* stack layout: formlist, docstring, declspecs. */
  1497. var bool compile_decl = false; /* flag: (COMPILE)-declaration occurred */
  1498. var object body = formlist; /* rest of the form-list */
  1499. while (consp(body)) {
  1500. var object form = Car(body); /* next form */
  1501. var object body_rest = Cdr(body); /* shorten body */
  1502. if (stringp(form)) { /* found Doc-String? */
  1503. if (atomp(body_rest)) /* at the last position of the form list? */
  1504. break; /* yes -> last form can't be a Doc-String! */
  1505. if (!nullp(STACK_1)) { /* preceding Doc-String? */
  1506. /* yes -> more than one Doc-String is too much: */
  1507. pushSTACK(STACK_2); /* SOURCE-PROGRAM-ERROR slot DETAIL */
  1508. pushSTACK(STACK_0);
  1509. error(source_program_error,
  1510. GETTEXT("Too many documentation strings in ~S"));
  1511. }
  1512. STACK_1 = form; /* new Doc-String */
  1513. body = body_rest;
  1514. } else if (consp(form) && eq(Car(form),S(declare))) {/* (DECLARE ...) */
  1515. /* cons decl-specs one by one onto STACK_0: */
  1516. pushSTACK(body_rest); /* save body_rest */
  1517. pushSTACK(Cdr(form)); /* list of the new decl-specs */
  1518. while (mconsp(STACK_0)) {
  1519. var object declspec = Car(STACK_0); /* next decl-spec */
  1520. /* check for (COMPILE)
  1521. Test: (EQUAL d '(COMPILE)) =
  1522. (and (consp d) (eq (car d) 'COMPILE) (null (cdr d))) */
  1523. if (consp(declspec)
  1524. && eq(Car(declspec),S(compile))
  1525. && nullp(Cdr(declspec)))
  1526. compile_decl = true;
  1527. { /* push this declaration onto STACK_(0+2) : */
  1528. pushSTACK(declspec);
  1529. var object new_cons = allocate_cons();
  1530. Car(new_cons) = popSTACK(); /* declspec */
  1531. Cdr(new_cons) = STACK_(0+2);
  1532. STACK_(0+2) = new_cons;
  1533. }
  1534. /* go to next decl-spec: */
  1535. STACK_0 = Cdr(STACK_0);
  1536. }
  1537. skipSTACK(1);
  1538. body = popSTACK(); /* body := old body_rest */
  1539. } else { /* finished with loop over the form list */
  1540. break;
  1541. }
  1542. }
  1543. value1 = body;
  1544. value2 = nreverse(popSTACK()); /* decl-spec-Liste */
  1545. value3 = popSTACK(); /* Doc-String */
  1546. skipSTACK(1);
  1547. return compile_decl;
  1548. }
  1549. /* UP: binds *EVALHOOK* and *APPLYHOOK* dynamically to the specified values.
  1550. bindhooks(evalhook_value,applyhook_value);
  1551. > evalhook_value: value for *EVALHOOK*
  1552. > applyhook_value: value for *APPLYHOOK*
  1553. changes STACK */
  1554. global void bindhooks (object evalhook_value, object applyhook_value) {
  1555. /* build frame: */
  1556. {
  1557. var gcv_object_t* top_of_frame = STACK; /* Pointer to Frame */
  1558. pushSTACK(Symbol_value(S(evalhookstern))); /* old value of *EVALHOOK* */
  1559. pushSTACK(S(evalhookstern)); /* *EVALHOOK* */
  1560. pushSTACK(Symbol_value(S(applyhookstern))); /* old value of *APPLYHOOK* */
  1561. pushSTACK(S(applyhookstern)); /* *APPLYHOOK* */
  1562. finish_frame(DYNBIND);
  1563. }
  1564. /* Frame got ready, now change the values of the variables: */
  1565. Symbol_value(S(evalhookstern)) = evalhook_value; /* (SETQ *EVALHOOK* evalhook_value) */
  1566. Symbol_value(S(applyhookstern)) = applyhook_value; /* (SETQ *APPLYHOOK* applyhook_value) */
  1567. }
  1568. /* UP: binds *EVALHOOK* and *APPLYHOOK* dynamically to NIL.
  1569. bindhooks_NIL();
  1570. changes STACK */
  1571. #define bindhooks_NIL() bindhooks(NIL,NIL)
  1572. /* UP: Determines the source-lambdabody of a lambda body.
  1573. lambdabody_source(lambdabody)
  1574. > lambdabody: Lambdabody (a Cons)
  1575. < result: Source-Lambdabody (unbound if no source specified) */
  1576. local object lambdabody_source (object lambdabody) {
  1577. var object body = Cdr(lambdabody);
  1578. /* body = ((DECLARE (SOURCE ...) ...) ...) ? */
  1579. if (consp(body)) {
  1580. var object form = Car(body); /* first Form */
  1581. /* form = (DECLARE (SOURCE ...) ...) ? */
  1582. if (consp(form) && eq(Car(form),S(declare))) {
  1583. var object declspecs = Cdr(form);
  1584. /* declspecs = ((SOURCE ...) ...) ? */
  1585. if (consp(declspecs)) {
  1586. var object declspec = Car(declspecs);
  1587. /* declspec = (SOURCE ...) ? */
  1588. if (consp(declspec) && eq(Car(declspec),S(source))) {
  1589. var object declspecr = Cdr(declspec);
  1590. if (consp(declspecr))
  1591. /* found Source */
  1592. return Car(declspecr);
  1593. }
  1594. }
  1595. }
  1596. }
  1597. return unbound;
  1598. }
  1599. /* UP: Inserts an implicit BLOCK in a lambda body.
  1600. add_implicit_block();
  1601. > STACK_1: function name
  1602. > STACK_0: lambda body
  1603. > value1: body
  1604. > value2: list of decl-specs
  1605. > value3: Doc-String or NIL
  1606. < STACK_0: new lambda body
  1607. can trigger GC */
  1608. local /*maygc*/ void add_implicit_block (void)
  1609. {
  1610. GCTRIGGER3(value1,value2,value3);
  1611. /* Replace lambdabody with
  1612. (cons (car lambdabody) ; lambda list
  1613. (multiple-value-bind (body-rest declarations docstring)
  1614. (sys::parse-body (cdr lambdabody) t) ; body
  1615. (append (if declarations (list (cons 'DECLARE declarations)))
  1616. (if docstring (list docstring))
  1617. (list (list* 'BLOCK (function-block-name name)
  1618. body-rest))))) */
  1619. var object new_body;
  1620. pushSTACK(value2); /* declarations */
  1621. pushSTACK(value3); /* docstring */
  1622. pushSTACK(funname_blockname(STACK_(1+2))); /* blockname */
  1623. pushSTACK(value1); /* body-rest */
  1624. { /* stack layout: name, lambdabody, declarations, docstring,
  1625. blockname, body-rest. */
  1626. var object tmp = allocate_cons();
  1627. Cdr(tmp) = popSTACK(); Car(tmp) = STACK_0;
  1628. STACK_0 = tmp;
  1629. }
  1630. {
  1631. var object tmp = allocate_cons();
  1632. Car(tmp) = S(block); Cdr(tmp) = STACK_0;
  1633. STACK_0 = tmp;
  1634. }
  1635. { /* stack layout: name, lambdabody, declarations, docstring, block-form. */
  1636. var object tmp = allocate_cons();
  1637. Car(tmp) = popSTACK();
  1638. new_body = tmp;
  1639. }
  1640. /* stack layout: name, lambdabody, declarations, docstring. */
  1641. if (nullp(STACK_0)) {
  1642. skipSTACK(1);
  1643. } else {
  1644. pushSTACK(new_body);
  1645. var object tmp = allocate_cons();
  1646. Cdr(tmp) = popSTACK(); Car(tmp) = popSTACK();
  1647. new_body = tmp;
  1648. }
  1649. /* stack layout: name, lambdabody, declarations. */
  1650. if (nullp(STACK_0)) {
  1651. STACK_0 = new_body;
  1652. } else {
  1653. pushSTACK(new_body);
  1654. {
  1655. var object tmp = allocate_cons();
  1656. Car(tmp) = S(declare); Cdr(tmp) = STACK_1;
  1657. STACK_1 = tmp;
  1658. }
  1659. {
  1660. var object tmp = allocate_cons();
  1661. Cdr(tmp) = popSTACK(); Car(tmp) = STACK_0;
  1662. STACK_0 = tmp;
  1663. }
  1664. }
  1665. { /* stack layout: name, lambdabody, new-body. */
  1666. var object tmp = allocate_cons();
  1667. Cdr(tmp) = popSTACK(); Car(tmp) = Car(STACK_0);
  1668. STACK_0 = tmp;
  1669. }
  1670. }
  1671. LISPFUNNR(add_implicit_block,2)
  1672. { /* (ADD-IMPLICIT-BLOCK name (lambda-list . lambda-body))
  1673. inserts an implicit BLOCK in the BODY */
  1674. parse_dd(Cdr(STACK_0)); /* just the lambda-body */
  1675. add_implicit_block();
  1676. VALUES1(STACK_0);
  1677. skipSTACK(2);
  1678. }
  1679. LISPFUNNR(function_block_name,1)
  1680. { /* returns the name of the implicit block for a function-name */
  1681. var object funname =
  1682. check_funname(type_error,S(function_block_name),popSTACK());
  1683. VALUES1(funname_blockname(funname));
  1684. }
  1685. /* UP: Creates the corresponding Closure for a Lambdabody by decomposition
  1686. of the lambda list and poss. macro-expansion of all forms.
  1687. get_closure(lambdabody,name,blockp,env)
  1688. > lambdabody: (lambda-list {decl|doc} {form})
  1689. > name: Name, a Symbol or (SETF symbol)
  1690. > blockp: if an implicit BLOCK has to be inserted
  1691. > env: Pointer to the five distinct environments:
  1692. env->var_env = VENV, env->fun_env = FENV,
  1693. env->block_env = BENV, env->go_env = GENV,
  1694. env->decl_env = DENV.
  1695. < result: Closure
  1696. can trigger GC */
  1697. global maygc object get_closure (object lambdabody, object name, bool blockp,
  1698. gcv_environment_t* env)
  1699. {
  1700. /* Lambdabody must be a Cons: */
  1701. if (atomp(lambdabody)) {
  1702. pushSTACK(lambdabody); /* SOURCE-PROGRAM-ERROR slot DETAIL */
  1703. pushSTACK(name);
  1704. error(source_program_error,GETTEXT("~S: lambda-list for ~S is missing"));
  1705. }
  1706. { /* and the CAR must be a List: */
  1707. var object lambdalist = Car(lambdabody);
  1708. if (!listp(lambdalist)) {
  1709. pushSTACK(lambdalist); /* SOURCE-PROGRAM-ERROR slot DETAIL */
  1710. pushSTACK(lambdalist); pushSTACK(name); pushSTACK(S(function));
  1711. error(source_program_error,
  1712. GETTEXT("~S: lambda-list for ~S should be a list, not ~S"));
  1713. }
  1714. }
  1715. pushSTACK(name);
  1716. pushSTACK(lambdabody);
  1717. /* stack layout: name, lambdabody.
  1718. decompose ({decl|doc} {form}) */
  1719. if (parse_dd(Cdr(lambdabody))) {
  1720. /* A (COMPILE)-Declaration occurred.
  1721. replace Lambdabody by its source (because some Macros
  1722. can be compiled more efficiently than their Macro-Expansion): */
  1723. { var object source = lambdabody_source(STACK_0);
  1724. if (!boundp(source)) {
  1725. if (blockp)
  1726. add_implicit_block();
  1727. } else {
  1728. STACK_0 = source;
  1729. }
  1730. }
  1731. { /* nest environments: */
  1732. var gcv_environment_t* stack_env = nest_env(env); /* push on STACK */
  1733. #if !defined(STACK_UP)
  1734. /* and transfer over here */
  1735. var object my_var_env = stack_env->var_env;
  1736. var object my_fun_env = stack_env->fun_env;
  1737. var object my_block_env = stack_env->block_env;
  1738. var object my_go_env = stack_env->go_env;
  1739. var object my_decl_env = stack_env->decl_env;
  1740. skipSTACK(5); /* and pop from STACK again */
  1741. pushSTACK(my_var_env);
  1742. pushSTACK(my_fun_env);
  1743. pushSTACK(my_block_env);
  1744. pushSTACK(my_go_env);
  1745. pushSTACK(my_decl_env);
  1746. #endif
  1747. /* stack layout: name, lambdabody, venv, fenv, benv, genv, denv. */
  1748. }
  1749. /* (SYS::COMPILE-LAMBDA name lambdabody venv fenv benv genv denv t) : */
  1750. pushSTACK(T); funcall(S(compile_lambda),8);
  1751. return value1; /* compiled Closure as value */
  1752. }
  1753. { /* build Interpreted Closure: */
  1754. var object source = lambdabody_source(STACK_0);
  1755. if (!boundp(source)) { /* no source specified -> expand Lambdabody: */
  1756. if (blockp)
  1757. add_implicit_block();
  1758. /* call (SYS::%EXPAND-LAMBDABODY-MAIN lambdabody venv fenv) : */
  1759. pushSTACK(STACK_0); /* Lambdabody */
  1760. pushSTACK(nest_var(env->var_env)); /* nested Variable Environment */
  1761. pushSTACK(nest_fun(env->fun_env)); /* nested Function Environment */
  1762. funcall(S(expand_lambdabody_main),3);
  1763. lambdabody = value1; /* expanded Lambdabody */
  1764. } else { /* Source specified -> it replaces the old Lambdabody: */
  1765. lambdabody = STACK_0; /* Lambdabody */
  1766. STACK_0 = source; /* Source-Lambdabody */
  1767. }
  1768. }
  1769. /* Now STACK_0 is the Source-Lambdabody,
  1770. lambdabody is the Lambdabody to be used. */
  1771. pushSTACK(Car(lambdabody)); /* Lambdalist */
  1772. /* decompose ({decl|doc} {form}) : */
  1773. parse_dd(Cdr(lambdabody));
  1774. pushSTACK(value1); /* Body */
  1775. pushSTACK(value2); /* Declarations */
  1776. pushSTACK(value3); /* Doc-String or NIL */
  1777. var gcv_object_t* closure_; /* Pointer to the Closure in the STACK */
  1778. { /* create Closure (filled with NIL): */
  1779. var object closure = allocate_closure(iclos_length,seclass_default<<4);
  1780. /* and fill partially: */
  1781. TheIclosure(closure)->clos_docstring = popSTACK(); /* Doc-String */
  1782. var object declarations = popSTACK(); /* Declarations */
  1783. TheIclosure(closure)->clos_body = popSTACK(); /* Body */
  1784. var object lambdalist = popSTACK(); /* Lambda-List */
  1785. TheIclosure(closure)->clos_form = popSTACK(); /* Source-Lambdabody */
  1786. TheIclosure(closure)->clos_name = STACK_0; /* Name */
  1787. /* and save: */
  1788. STACK_0 = closure;
  1789. /* stack layout: closure. */
  1790. closure_ = &STACK_0; /* Pointer to the Closure in the STACK */
  1791. if (!nullpSv(defun_accept_specialized_lambda_list)
  1792. && functionp(Symbol_function(S(specialized_lambda_list_to_ordinary)))) {
  1793. /* convert lambda list to ordinary */
  1794. pushSTACK(declarations); /* save */
  1795. pushSTACK(lambdalist); pushSTACK(S(function));
  1796. funcall(S(specialized_lambda_list_to_ordinary),2);
  1797. lambdalist = value1; /* new ordinary lambda list */
  1798. declarations = popSTACK(); /* restore */
  1799. if (!nullp(value2)) /* merge in declarations */
  1800. declarations = nreconc(value2,declarations);
  1801. }
  1802. pushSTACK(lambdalist); pushSTACK(lambdalist); pushSTACK(lambdalist);
  1803. pushSTACK(declarations);
  1804. }
  1805. { /* nest Environments and put them nested in the closure: */
  1806. var gcv_environment_t* stack_env = nest_env(env);
  1807. var object closure = *closure_;
  1808. TheIclosure(closure)->clos_var_env = stack_env->var_env ;
  1809. TheIclosure(closure)->clos_fun_env = stack_env->fun_env ;
  1810. TheIclosure(closure)->clos_block_env = stack_env->block_env;
  1811. TheIclosure(closure)->clos_go_env = stack_env->go_env ;
  1812. TheIclosure(closure)->clos_decl_env = stack_env->decl_env ;
  1813. skipSTACK(5);
  1814. /* keywords:=0, as long as &KEY is missing: */
  1815. TheIclosure(closure)->clos_keywords = Fixnum_0;
  1816. }
  1817. /* stack layout:
  1818. closure, lambdalist, lalist-save, lalist-rest, declarations */
  1819. var uintL spec_count = 0; /* number of dynamic references */
  1820. var uintL req_count = 0; /* number of required-parameters */
  1821. var uintL opt_count = 0; /* number of optional-parameters */
  1822. var uintL key_count = 0; /* number of keyword-parameters */
  1823. var uintL aux_count = 0; /* number of &AUX-variables */
  1824. var uintL var_count = 0; /* total number of the variables on the STACK */
  1825. { /* process declarations:
  1826. read dynamically referenced variables from the decl-spec-list
  1827. declarations and push them on STACK. Other to be respected
  1828. declarations change the declarations-environment of the Closure. */
  1829. var object declarations = popSTACK();
  1830. while (consp(declarations)) { /* all decl-specs processed? */
  1831. var object declspec = Car(declarations);
  1832. /* declspec must be a List: */
  1833. if (atomp(declspec)) {
  1834. pushSTACK(declspec); /* SOURCE-PROGRAM-ERROR slot DETAIL */
  1835. pushSTACK(declspec); pushSTACK(S(function));
  1836. error(source_program_error,
  1837. GETTEXT("~S: illegal declaration ~S"));
  1838. }
  1839. /* process SPECIAL-declaration: */
  1840. if (eq(Car(declspec),S(special))) { /* SPECIAL-declaration ? */
  1841. var object declspecrest = Cdr(declspec);
  1842. while (consp(declspecrest)) {
  1843. var object sym = Car(declspecrest);
  1844. if (!symbolp(sym)) {
  1845. pushSTACK(declarations); pushSTACK(declspec); /* save */
  1846. pushSTACK(declspecrest);
  1847. sym = check_symbol_special(sym,S(function));
  1848. declspecrest = popSTACK(); Car(declspecrest) = sym;
  1849. declspec = popSTACK(); declarations = popSTACK(); /* restore */
  1850. }
  1851. /* push Symbol on STACK: */
  1852. check_STACK(); pushSTACK(sym); spec_count++; var_count++;
  1853. declspecrest = Cdr(declspecrest);
  1854. }
  1855. }
  1856. /* process other declaration: */
  1857. pushSTACK(Cdr(declarations)); /* shorten and save declarations */
  1858. {
  1859. var object denv = TheIclosure(*closure_)->clos_decl_env;
  1860. denv = augment_decl_env(declspec,denv);
  1861. TheIclosure(*closure_)->clos_decl_env = denv;
  1862. }
  1863. declarations = popSTACK();
  1864. }
  1865. }
  1866. /* stack layout:
  1867. closure, lambdalist, lalist-save, lalist-rest [special symbols]* */
  1868. var gcv_object_t *lalist_ = closure_ STACKop -2; /* remaining lambda list */
  1869. var gcv_object_t *lalist_save_ = closure_ STACKop -3; /* save fixed items */
  1870. var object item; /* element of the lambda list */
  1871. /* Macro:
  1872. NEXT_ITEM(&OPTIONAL_label,&REST_label,&KEY_label,
  1873. &ALLOW-OTHER-KEYS_label,&AUX_label,Ende_label)
  1874. shortens the rest of the lambda list, moves the next Element to "item"
  1875. and in case of one of the 6 specified lambda-list-markers, it jumps to
  1876. the respective locations. */
  1877. #define NEXT_ITEM(opt_label,rest_label,key_label,allow_label,aux_label,end_label) \
  1878. { if (atomp(*lalist_)) goto end_label; /* Lambda-List finished? */ \
  1879. item = Car(*lalist_); *lalist_save_ = *lalist_; /* next element */ \
  1880. *lalist_ = Cdr(*lalist_); /* shorten List */ \
  1881. if (eq(item,S(LLoptional))) goto opt_label; /* &OPTIONAL ? */ \
  1882. if (eq(item,S(LLrest))) goto rest_label; /* &REST ? */ \
  1883. if (eq(item,S(LLkey))) goto key_label; /* &KEY ? */ \
  1884. if (eq(item,S(LLallow_other_keys))) goto allow_label; /* &ALLOW-OTHER-KEYS ? */ \
  1885. if (eq(item,S(LLaux))) goto aux_label; /* &AUX ? */ \
  1886. if (eq(item,S(LLbody))) goto badLLkey; /* &BODY ? */ \
  1887. }
  1888. req: /* process required-parameter push on STACK: */
  1889. while (1) {
  1890. NEXT_ITEM(opt,rest,key,badLLkey,aux,ende);
  1891. item = check_symbol_non_constant(item,S(function));
  1892. Car(*lalist_save_) = item;
  1893. /* push Variable on STACK: */
  1894. check_STACK();
  1895. pushSTACK(item); pushSTACK(Fixnum_0); req_count++; var_count++;
  1896. }
  1897. opt: /* process &OPTIONAL-parameter, push on STACK and
  1898. put Init-Forms into the Closure: */
  1899. while(1) {
  1900. NEXT_ITEM(badLLkey,rest,key,badLLkey,aux,ende);
  1901. var object init_form;
  1902. /* Parse variable spezification in item:
  1903. var or (var [init [svar]])
  1904. push var and poss. svar on STACK, set in var poss.
  1905. the svar_bit. Returns also init (or NIL) in init_form. */
  1906. check_STACK();
  1907. if (atomp(item)) {
  1908. item = check_symbol_non_constant(item,S(function));
  1909. Car(*lalist_save_) = item;
  1910. /* push variable on STACK: */
  1911. pushSTACK(item); pushSTACK(Fixnum_0); opt_count++; var_count++;
  1912. init_form = NIL; /* Default-Init */
  1913. } else {
  1914. var object item_rest = item;
  1915. /* first list-element: var */
  1916. pushSTACK(item_rest);
  1917. item = check_symbol_non_constant(Car(item),S(function));
  1918. item_rest = popSTACK(); Car(item_rest) = item;
  1919. item_rest = Cdr(item_rest);
  1920. /* push variable on STACK: */
  1921. pushSTACK(item); pushSTACK(Fixnum_0); opt_count++; var_count++;
  1922. if (consp(item_rest)) {
  1923. init_form = Car(item_rest); /* second list-element: init */
  1924. item_rest = Cdr(item_rest);
  1925. if (consp(item_rest)) {
  1926. if (mconsp(Cdr(item_rest))) { /* varspec is too lang */
  1927. pushSTACK(item_rest); /* SOURCE-PROGRAM-ERROR slot DETAIL */
  1928. pushSTACK(*(closure_ STACKop -1)); /* entire Lambda-List */
  1929. pushSTACK(S(LLoptional)); pushSTACK(S(function));
  1930. error(source_program_error,
  1931. GETTEXT("~S: variable specification after ~S too long: ~S"));
  1932. }
  1933. /* third list-element: svar */
  1934. pushSTACK(init_form); pushSTACK(item_rest);
  1935. item = check_symbol_non_constant(Car(item_rest),S(function));
  1936. item_rest = popSTACK(); Car(item_rest) = item;
  1937. init_form = popSTACK();
  1938. /* set svar-bit for var: */
  1939. STACK_0 = fixnum_inc(STACK_0,bit(svar_bit));
  1940. /* push variable on STACK: */
  1941. pushSTACK(item); pushSTACK(Fixnum_0); var_count++;
  1942. }
  1943. } else
  1944. init_form = NIL; /* Default-Init */
  1945. }
  1946. /* push init_form in front of (clos_opt_inits closure) : */
  1947. pushSTACK(init_form);
  1948. {
  1949. var object new_cons = allocate_cons();
  1950. Car(new_cons) = popSTACK();
  1951. var object closure = *closure_;
  1952. Cdr(new_cons) = TheIclosure(closure)->clos_opt_inits;
  1953. TheIclosure(closure)->clos_opt_inits = new_cons;
  1954. }
  1955. }
  1956. rest: { /* process &REST-parameter and push on Stack: */
  1957. NEXT_ITEM(badrest,badrest,badrest,badrest,badrest,badrest);
  1958. item = check_symbol_non_constant(item,S(function));
  1959. Car(*lalist_save_) = item;
  1960. /* push variable on STACK: */
  1961. pushSTACK(item); pushSTACK(Fixnum_0); var_count++;
  1962. /* set Rest-Flag to T: */
  1963. TheIclosure(*closure_)->clos_rest_flag = T;
  1964. NEXT_ITEM(badLLkey,badLLkey,key,badLLkey,aux,ende);
  1965. pushSTACK(item); /* SOURCE-PROGRAM-ERROR slot DETAIL */
  1966. pushSTACK(*(closure_ STACKop -1)); /* entire Lambda-List */
  1967. pushSTACK(S(LLaux)); pushSTACK(S(LLkey));
  1968. pushSTACK(S(LLrest)); pushSTACK(S(function));
  1969. error(source_program_error,GETTEXT("~S: ~S var must be followed by ~S or ~S or end of list: ~S"));
  1970. }
  1971. badrest: {
  1972. pushSTACK(*(closure_ STACKop -1)); /* entire Lambda-List */
  1973. pushSTACK(STACK_0); /* SOURCE-PROGRAM-ERROR slot DETAIL */
  1974. pushSTACK(S(LLrest)); pushSTACK(S(function));
  1975. error(source_program_error,
  1976. GETTEXT("~S: ~S must be followed by a variable: ~S"));
  1977. }
  1978. key: /* process &KEY-Parameter, push on STACK
  1979. and put Init-Forms in the Closure: */
  1980. { TheIclosure(*closure_)->clos_keywords = NIL; } /* keywords:=NIL */
  1981. while(1) {
  1982. NEXT_ITEM(badLLkey,badLLkey,badLLkey,allow,aux,ende);
  1983. var object keyword;
  1984. var object init_form;
  1985. /* Parse variable-spezification in item:
  1986. var or (var [init [svar]]) or ((key var) [init [svar]])
  1987. push var and poss. svar on STACK, set in var poss.
  1988. the svar_bit. Returns also the Keyword in keyword and
  1989. init (or NIL) in init_form. */
  1990. check_STACK();
  1991. if (atomp(item)) {
  1992. item = check_symbol_non_constant(item,S(function));
  1993. Car(*lalist_save_) = item;
  1994. /* push variable on STACK: */
  1995. pushSTACK(item); pushSTACK(Fixnum_0); key_count++; var_count++;
  1996. /* fetch Keyword: */
  1997. keyword = intern_keyword(Symbol_name(item));
  1998. /* Default-Init: */
  1999. init_form = NIL;
  2000. } else {
  2001. var object item_rest = item; /* (item [init [svar]]) */
  2002. item = Car(item); /* first list-element: var or (key var) */
  2003. pushSTACK(item_rest); /* save */
  2004. if (atomp(item)) {
  2005. item = check_symbol_non_constant(item,S(function)); /* item = var */
  2006. /* push variable on STACK: */
  2007. item_rest = popSTACK(); /* restore */
  2008. Car(item_rest) = item; item_rest = Cdr(item_rest); /*([init [svar]])*/
  2009. pushSTACK(item); pushSTACK(Fixnum_0); key_count++; var_count++;
  2010. /* fetch Keyword: */
  2011. pushSTACK(item_rest); /* save */
  2012. keyword = intern_keyword(Symbol_name(item));
  2013. item_rest = popSTACK(); /* restore */
  2014. } else {
  2015. pushSTACK(item);
  2016. /* item = (key var) */
  2017. keyword = check_symbol(Car(item)); /* key */
  2018. item = popSTACK(); Car(item) = keyword;
  2019. item = Cdr(item); /* (var) */
  2020. if (!(consp(item) && matomp(Cdr(item))))
  2021. goto error_keyspec;
  2022. pushSTACK(keyword); pushSTACK(item); /* save */
  2023. item = check_symbol_non_constant(Car(item),S(function)); /* var */
  2024. Car(popSTACK()) = item; keyword = popSTACK(); /* restore */
  2025. item_rest = popSTACK(); item_rest = Cdr(item_rest); /*([init [svar]])*/
  2026. /* push variable on STACK: */
  2027. pushSTACK(item); pushSTACK(Fixnum_0); key_count++; var_count++;
  2028. }
  2029. if (consp(item_rest)) {
  2030. init_form = Car(item_rest); /* second list-element: init */
  2031. item_rest = Cdr(item_rest); /* ([svar]) */
  2032. if (consp(item_rest)) {
  2033. if (mconsp(Cdr(item_rest)))
  2034. goto error_keyspec;
  2035. /* third list-element: svar */
  2036. pushSTACK(init_form); pushSTACK(keyword); pushSTACK(item_rest);
  2037. item = check_symbol_non_constant(Car(item_rest),S(function));
  2038. item_rest = popSTACK(); Car(item_rest) = item;
  2039. keyword = popSTACK(); init_form = popSTACK(); /* restore */
  2040. /* set svar-Bit in var: */
  2041. STACK_0 = fixnum_inc(STACK_0,bit(svar_bit));
  2042. /* push variable on STACK: */
  2043. pushSTACK(item); pushSTACK(Fixnum_0); var_count++;
  2044. }
  2045. } else
  2046. init_form = NIL; /* Default-Init */
  2047. }
  2048. /* push keyword in front of (clos_keywords closure) and
  2049. push init_form in front of (clos_key_inits closure) : */
  2050. pushSTACK(init_form); pushSTACK(keyword);
  2051. {
  2052. var object new_cons = allocate_cons();
  2053. Car(new_cons) = popSTACK();
  2054. var object closure = *closure_;
  2055. Cdr(new_cons) = TheIclosure(closure)->clos_keywords;
  2056. TheIclosure(closure)->clos_keywords = new_cons;
  2057. }
  2058. {
  2059. var object new_cons = allocate_cons();
  2060. Car(new_cons) = popSTACK();
  2061. var object closure = *closure_;
  2062. Cdr(new_cons) = TheIclosure(closure)->clos_key_inits;
  2063. TheIclosure(closure)->clos_key_inits = new_cons;
  2064. }
  2065. }
  2066. error_keyspec: {
  2067. pushSTACK(*(closure_ STACKop -1)); /* entire Lambda-List */
  2068. pushSTACK(STACK_0); /* SOURCE-PROGRAM-ERROR slot DETAIL */
  2069. pushSTACK(S(LLkey)); pushSTACK(S(function));
  2070. error(source_program_error,
  2071. GETTEXT("~S: incorrect variable specification after ~S: ~S"));
  2072. }
  2073. allow: { /* process &ALLOW-OTHER-KEYS: */
  2074. TheIclosure(*closure_)->clos_allow_flag = T; /* set Flag to T */
  2075. NEXT_ITEM(badLLkey,badLLkey,badLLkey,badLLkey,aux,ende);
  2076. pushSTACK(*(closure_ STACKop -1)); /* entire Lambda-List */
  2077. pushSTACK(STACK_0); /* SOURCE-PROGRAM-ERROR slot DETAIL */
  2078. pushSTACK(S(LLaux)); pushSTACK(S(LLallow_other_keys));
  2079. pushSTACK(S(function));
  2080. error(source_program_error,
  2081. GETTEXT("~S: ~S must be followed by ~S or end of list: ~S"));
  2082. }
  2083. aux: /* process &AUX-Parameter, push on STACK and
  2084. put Init-Forms in the Closure: */
  2085. while(1) {
  2086. NEXT_ITEM(badLLkey,badLLkey,badLLkey,badLLkey,badLLkey,ende);
  2087. var object init_form;
  2088. /* Parse variable-spezification in item:
  2089. var or (var [init])
  2090. push var on STACK.
  2091. Returns also init (or NIL) in init_form. */
  2092. check_STACK();
  2093. if (atomp(item)) {
  2094. item = check_symbol_non_constant(item,S(function));
  2095. Car(*lalist_save_) = item;
  2096. /* push variable on STACK: */
  2097. pushSTACK(item); pushSTACK(Fixnum_0); aux_count++; var_count++;
  2098. init_form = NIL; /* Default-Init */
  2099. } else {
  2100. var object item_rest = item; pushSTACK(item_rest);
  2101. /* first list-element: var */
  2102. item = check_symbol_non_constant(Car(item),S(function));
  2103. item_rest = popSTACK(); Car(item_rest) = item; item_rest = Cdr(item_rest);
  2104. /* push variable on STACK: */
  2105. pushSTACK(item); pushSTACK(Fixnum_0); aux_count++; var_count++;
  2106. if (consp(item_rest)) {
  2107. init_form = Car(item_rest); /* second list-element: init */
  2108. if (mconsp(Cdr(item_rest))) { /* varspec too long */
  2109. pushSTACK(item_rest); /* SOURCE-PROGRAM-ERROR slot DETAIL */
  2110. pushSTACK(*(closure_ STACKop -1)); /* entire Lambda-List */
  2111. pushSTACK(S(LLaux)); pushSTACK(S(function));
  2112. error(source_program_error,
  2113. GETTEXT("~S: variable specification after ~S too long: ~S"));
  2114. }
  2115. } else
  2116. init_form = NIL; /* Default-Init */
  2117. }
  2118. /* push init_form in front of (clos_aux_inits closure) : */
  2119. pushSTACK(init_form);
  2120. {
  2121. var object new_cons = allocate_cons();
  2122. Car(new_cons) = popSTACK();
  2123. var object closure = *closure_;
  2124. Cdr(new_cons) = TheIclosure(closure)->clos_aux_inits;
  2125. TheIclosure(closure)->clos_aux_inits = new_cons;
  2126. }
  2127. }
  2128. /* Collected error messages: */
  2129. badLLkey: {
  2130. pushSTACK(item); /* SOURCE-PROGRAM-ERROR slot DETAIL */
  2131. pushSTACK(*(closure_ STACKop -1)); /* entire Lambda-List */
  2132. pushSTACK(item); pushSTACK(S(function));
  2133. error(source_program_error,
  2134. GETTEXT("~S: badly placed lambda-list keyword ~S: ~S"));
  2135. }
  2136. ende: /* reached list-end */
  2137. #undef NEXT_ITEM
  2138. if (((uintL)~(uintL)0 > lp_limit_1) && (var_count > lp_limit_1)) {
  2139. /* too many parameters? */
  2140. pushSTACK(*(closure_ STACKop -1)); /* entire Lambda-List */
  2141. pushSTACK(STACK_0); /* SOURCE-PROGRAM-ERROR slot DETAIL */
  2142. pushSTACK(S(function));
  2143. error(source_program_error,
  2144. GETTEXT("~S: too many parameters in the lambda-list ~S"));
  2145. }
  2146. /* var_count <= lp_limit_1, therefore all counts fit in an uintC. */
  2147. if (!nullp(*lalist_)) { /* is Lambda-List a Dotted List? */
  2148. pushSTACK(*lalist_); /* SOURCE-PROGRAM-ERROR slot DETAIL */
  2149. pushSTACK(*(closure_ STACKop -1)); /* entire Lambda-List */
  2150. pushSTACK(S(function));
  2151. error(source_program_error,
  2152. GETTEXT("~S: a dot in a lambda-list is allowed only for macros, not here: ~S"));
  2153. }
  2154. /* Collect variables into a vector and put it into the Closure,
  2155. Collect variable-flags into a Byte-Vector and put it into the Closure: */
  2156. pushSTACK(allocate_bit_vector(Atype_8Bit,var_count-spec_count)); /* create Byte-Vector */
  2157. var object vars = allocate_vector(var_count); /* create Vector */
  2158. var object varflags = popSTACK();
  2159. { /* write variables in the Vector (last one to the back,
  2160. leading ones in front): */
  2161. var gcv_object_t* ptr = &TheSvector(vars)->data[var_count];
  2162. var uintB* ptrflags = &TheSbvector(varflags)->data[var_count-spec_count];
  2163. var uintC count = var_count-spec_count;
  2164. while (count--) {
  2165. *--ptrflags = (uintB)posfixnum_to_V(popSTACK());
  2166. *--ptr = popSTACK();
  2167. }
  2168. for (count = spec_count; count--;)
  2169. *--ptr = popSTACK();
  2170. }
  2171. var object closure = *closure_;
  2172. TheIclosure(closure)->clos_vars = vars;
  2173. TheIclosure(closure)->clos_varflags = varflags;
  2174. /* write counts in the Closure: */
  2175. TheIclosure(closure)->clos_spec_count = fixnum(spec_count);
  2176. TheIclosure(closure)->clos_req_count = fixnum(req_count);
  2177. TheIclosure(closure)->clos_opt_count = fixnum(opt_count);
  2178. TheIclosure(closure)->clos_key_count = fixnum(key_count);
  2179. TheIclosure(closure)->clos_aux_count = fixnum(aux_count);
  2180. /* In the Variable-Vector the first spec_count variables are the
  2181. SPECIAL-declared ones. In each remaining variable the DYNAM_BIT is
  2182. set, if it occurs among the SPECIAL-declared one. */
  2183. if (spec_count) { /* loop over the remaining variables: */
  2184. if (var_count-spec_count > 0) {
  2185. var gcv_object_t* othervarptr = &TheSvector(vars)->data[spec_count];
  2186. var uintB* othervarflagsptr = &TheSbvector(varflags)->data[0];
  2187. var uintC count1 = var_count-spec_count;
  2188. do {
  2189. var object othervar = *othervarptr++; /* next variable */
  2190. { /* Search for it among the SPECIAL-declared variables: */
  2191. var gcv_object_t* specvarptr = &TheSvector(vars)->data[0];
  2192. var uintC count2 = spec_count;
  2193. do {
  2194. if (eq(*specvarptr++,othervar)) { /* found? */
  2195. /* yes -> so the variable othervar is to be bound dynamically. */
  2196. *othervarflagsptr |= bit(dynam_bit); break;
  2197. }
  2198. } while (--count2);
  2199. }
  2200. othervarflagsptr++;
  2201. } while (--count1);
  2202. }
  2203. }
  2204. /* Finally reverse the accumulated lists in the Closure: */
  2205. nreverse(TheIclosure(closure)->clos_opt_inits);
  2206. nreverse(TheIclosure(closure)->clos_keywords);
  2207. nreverse(TheIclosure(closure)->clos_key_inits);
  2208. nreverse(TheIclosure(closure)->clos_aux_inits);
  2209. /* stack layout: closure, lambdalist, lalist-save, lalist-rest */
  2210. skipSTACK(4);
  2211. return closure;
  2212. }
  2213. /* error, if symbol to be called is a special form.
  2214. error_specialform(caller,funname);
  2215. > caller: caller (a symbol)
  2216. > funname: a symbol */
  2217. nonreturning_function(local, error_specialform, (object caller, object funname)) {
  2218. pushSTACK(funname); /* CELL-ERROR slot NAME */
  2219. pushSTACK(funname);
  2220. pushSTACK(caller);
  2221. error(undefined_function,
  2222. GETTEXT("~S: ~S is a special operator, not a function"));
  2223. }
  2224. /* error, if symbol to be called is a macro.
  2225. error_macro(caller,funname);
  2226. > caller: caller (a symbol)
  2227. > funname: a symbol */
  2228. nonreturning_function(local, error_macro, (object caller, object funname)) {
  2229. pushSTACK(funname); /* CELL-ERROR slot NAME */
  2230. pushSTACK(funname);
  2231. pushSTACK(caller);
  2232. error(undefined_function,GETTEXT("~S: ~S is a macro, not a function"));
  2233. }
  2234. /* UP: Alters argument to a function.
  2235. coerce_function(obj)
  2236. > obj: object
  2237. < result: object as function (SUBR or Closure)
  2238. can trigger GC */
  2239. global maygc object coerce_function (object obj)
  2240. {
  2241. /* obj should be a symbol, a SUBR or a Closure. */
  2242. if (functionp(obj)) {
  2243. return obj; /* function is OK */
  2244. } else if (symbolp(obj)) {
  2245. var object fdef = Symbol_function(obj);
  2246. if (functionp(fdef))
  2247. return fdef;
  2248. else if (orecordp(fdef)) {
  2249. switch (Record_type(fdef)) {
  2250. case Rectype_Fsubr:
  2251. error_specialform(TheSubr(subr_self)->name,obj);
  2252. case Rectype_Macro:
  2253. error_macro(TheSubr(subr_self)->name,obj);
  2254. default: NOTREACHED;
  2255. }
  2256. } else
  2257. return check_fdefinition(obj,TheSubr(subr_self)->name);
  2258. } else if (funnamep(obj)) {
  2259. /* this could have be done easier but we inline the checks -
  2260. symbolp and functionp for performance reasons */
  2261. var object symbol = get(Car(Cdr(obj)),S(setf_function)); /* (get ... 'SYS::SETF-FUNCTION) */
  2262. if (!symbolp(symbol)) { /* should be symbol */
  2263. pushSTACK(obj); symbol = check_symbol(symbol); obj = popSTACK();
  2264. }
  2265. var object fdef = Symbol_function(symbol);
  2266. if (functionp(fdef))
  2267. return fdef;
  2268. else
  2269. return check_fdefinition(obj,TheSubr(subr_self)->name);
  2270. } else if (consp(obj) && eq(Car(obj),S(lambda))) { /* (LAMBDA . ...) ? */
  2271. error_lambda_expression(TheSubr(subr_self)->name,obj);
  2272. } else
  2273. return check_function(obj);
  2274. }
  2275. #ifdef DEBUG_EVAL
  2276. /* Emit some trace output for a function call, to *funcall-trace-output*.
  2277. trace_call(fun,type_of_call,caller_type);
  2278. > object fun: function being called, a SUBR/FSUBR/Closure
  2279. > uintB type_of_call: 'A' for apply, 'F' for funcall, 'B' for bytecode
  2280. > uintB caller_type: 'F' for fsubr, 'S' for subr,
  2281. 'C' for cclosure, 'I' for iclosure
  2282. can trigger GC */
  2283. local maygc void trace_call (object fun, uintB type_of_call, uintB caller_type)
  2284. {
  2285. var object stream = Symbol_value(S(funcall_trace_output)); /* SYS::*FUNCALL-TRACE-OUTPUT* */
  2286. /* No output until *funcall-trace-output* has been initialized: */
  2287. if (!streamp(stream))
  2288. return;
  2289. pushSTACK(stream);
  2290. if (cclosurep(fun)) {
  2291. pushSTACK(Closure_name(fun));
  2292. write_ascii_char(&STACK_1,'c');
  2293. } else if (closurep(fun)) {
  2294. pushSTACK(TheIclosure(fun)->clos_name);
  2295. write_ascii_char(&STACK_1,'C');
  2296. } else if (subrp(fun)) {
  2297. pushSTACK(TheSubr(fun)->name);
  2298. write_ascii_char(&STACK_1,'S');
  2299. } else if (fsubrp(fun)) {
  2300. pushSTACK(TheFsubr(fun)->name);
  2301. write_ascii_char(&STACK_1,'F');
  2302. } else {
  2303. pushSTACK(NIL);
  2304. write_ascii_char(&STACK_1,'?');
  2305. }
  2306. write_ascii_char(&STACK_1,type_of_call); /* output type of call */
  2307. write_ascii_char(&STACK_1,caller_type); /* output caller */
  2308. write_ascii_char(&STACK_1,'[');
  2309. prin1(&STACK_1,STACK_0); /* output function name */
  2310. write_ascii_char(&STACK_1,']');
  2311. terpri(&STACK_1);
  2312. skipSTACK(2);
  2313. }
  2314. #define TRACE_CALL(fu,tc,ct) \
  2315. if (streamp(Symbol_value(S(funcall_trace_output)))) { \
  2316. pushSTACK(fu); trace_call(fu,tc,ct); fu = popSTACK(); \
  2317. }
  2318. #else
  2319. #define TRACE_CALL(fu,tc,ct)
  2320. #endif
  2321. /* Test for illegal keywords
  2322. check_for_illegal_keywords(allow_flag,error_statement);
  2323. > uintC argcount: Number of Keyword/Value-pairs
  2324. > gcv_object_t* rest_args_pointer: Pointer to the 2*argcount remaining arguments
  2325. > bool allow_flag: Flag, if &ALLOW-OTHER-KEYS was specified
  2326. > for_every_keyword: Macro, which loops over all Keywords and assigns
  2327. them to 'keyword'.
  2328. > error_statement: Statement, that reports, that bad_keyword is illegal. */
  2329. #define check_for_illegal_keywords(allow_flag_expr,caller,error_statement) \
  2330. { var gcv_object_t* argptr = rest_args_pointer; /* Pointer to the arguments */ \
  2331. var object bad_keyword = nullobj; /* first illegal keyword or nullobj */ \
  2332. var object bad_value = nullobj; /* its value */ \
  2333. var bool allow_flag = /* Flag for allow-other-keys (if */ \
  2334. /* &ALLOW-OTHER-KEYS was specified or ':ALLOW-OTHER-KEY T' occurred) */ \
  2335. (allow_flag_expr); \
  2336. /* But ':ALLOW-OTHER-KEYS NIL' hides a subsequent ':ALLOW-OTHER-KEYS T' \
  2337. (see CLHS 3.4.1.4.1.1). */ \
  2338. var bool allow_hidden = false; /* true if seen ':ALLOW-OTHER-KEYS NIL' */ \
  2339. var uintC check_count=argcount; \
  2340. while (check_count--) { \
  2341. var object kw = NEXT(argptr); /* next Argument */ \
  2342. var object val = NEXT(argptr); /* and value for it */ \
  2343. /* must be a symbol, should be a keyword: */ \
  2344. if (!symbolp(kw)) error_key_notkw(kw,caller); \
  2345. if (!allow_flag) { /* other keywords allowed? yes -> ok */ \
  2346. if (eq(kw,S(Kallow_other_keys))) { \
  2347. if (!allow_hidden) { \
  2348. if (!nullp(val)) \
  2349. allow_flag = true; \
  2350. else \
  2351. allow_hidden = true; \
  2352. } \
  2353. } else { \
  2354. /* up to now :ALLOW-OTHER-KEYS was not there, and NOALLOW */ \
  2355. if (eq(bad_keyword,nullobj)) { /* all Keywords ok so far? */ \
  2356. /* must test, if the keyword kw is allowed. */ \
  2357. for_every_keyword({ if (eq(keyword,kw)) goto kw_ok; }); \
  2358. /* keyword kw was not allowed. */ \
  2359. bad_keyword = kw; \
  2360. bad_value = val; \
  2361. kw_ok: ; \
  2362. } \
  2363. } \
  2364. } \
  2365. }; \
  2366. if (!allow_flag) \
  2367. if (!eq(bad_keyword,nullobj)) { \
  2368. /* wrong keyword occurred */ \
  2369. error_statement \
  2370. } \
  2371. }
  2372. /* For a Keyword 'keyword' search the pair Key.Value:
  2373. find_keyword_value( notfound_statement, found_statement );
  2374. > keyword: Keyword
  2375. > uintC argcount: Number of Keyword/Value-Pairs
  2376. > gcv_object_t* rest_args_pointer: Pointer to the 2*argcount remaining Arguments
  2377. > notfound_statement: what is to be done, if not found
  2378. > found_statement: what is to be done, if value found */
  2379. #define find_keyword_value(notfound_statement,found_statement) \
  2380. { var gcv_object_t* argptr = rest_args_pointer; \
  2381. var uintC find_count; \
  2382. dotimesC(find_count,argcount, { \
  2383. if (eq(NEXT(argptr),keyword)) goto kw_found; /* right keyword? */ \
  2384. argptr skipSTACKop -1; /* NEXT */ \
  2385. }); \
  2386. if (true) { notfound_statement } /* not found */ \
  2387. else { kw_found: /* found */ \
  2388. {var object value = NEXT(argptr); \
  2389. found_statement }} \
  2390. }
  2391. /* UP: Applies an interpreted closure to arguments.
  2392. funcall_iclosure(closure,args_pointer,argcount);
  2393. > closure: Closure
  2394. > args_pointer: Pointer to the arguments (in Stack)
  2395. > argcount: Number of Arguments
  2396. < mv_count/mv_space: values
  2397. < STACK: cleaned up, = args_pointer
  2398. can trigger GC */
  2399. local maygc Values funcall_iclosure (object closure, gcv_object_t* args_pointer,
  2400. uintC argcount)
  2401. {
  2402. /* 1st step: finish building of APPLY-frame: */
  2403. var sp_jmp_buf my_jmp_buf;
  2404. TRACE_CALL(closure,'F','I');
  2405. {
  2406. var gcv_object_t* top_of_frame = args_pointer; /* Pointer to frame */
  2407. pushSTACK(closure);
  2408. finish_entry_frame(APPLY,my_jmp_buf,,{
  2409. if (mv_count==0) { /* after reentry: pass form? */
  2410. closure = STACK_(frame_closure); /* try the same APPLY again */
  2411. args_pointer = topofframe(STACK_0);
  2412. argcount = STACK_item_count(STACK STACKop frame_args,args_pointer);
  2413. } else {
  2414. setSTACK(STACK = topofframe(STACK_0)); /* clean STACK ?or unwind()?*/
  2415. eval_noenv(value1); return; /* evaluate passed form */
  2416. }
  2417. });
  2418. }
  2419. var gcv_object_t* closure_ = &STACK_(frame_closure); /* &closure */
  2420. var gcv_object_t* frame_pointer; /* pointer to the frame */
  2421. var uintC spec_count = posfixnum_to_V(TheIclosure(closure)->clos_spec_count);
  2422. var gcv_object_t *spec_ptr;
  2423. { /* 2nd step: build variable-binding-frame: */
  2424. var gcv_object_t* top_of_frame = STACK; /* Pointer to Frame */
  2425. var object vars = TheIclosure(closure)->clos_vars; /* Vector of variable-names */
  2426. var uintL var_count = Svector_length(vars); /* number of variables */
  2427. get_space_on_STACK(var_count*varframe_binding_size*sizeof(gcv_object_t));
  2428. {
  2429. var gcv_object_t* varptr = &TheSvector(vars)->data[0]; /* Pointer to variables in vector */
  2430. var uintC count;
  2431. /* the special-references first: */
  2432. spec_ptr = args_end_pointer;
  2433. dotimesC(count,spec_count, {
  2434. pushSTACK(specdecl); /* SPECDECL as "value" */
  2435. pushSTACK_symbolwithflags(*varptr++,0); /* INactive */
  2436. });
  2437. frame_pointer = args_end_pointer;
  2438. if (var_count-spec_count > 0) {
  2439. var uintB* varflagsptr = &TheSbvector(TheIclosure(closure)->clos_varflags)->data[0];
  2440. dotimespC(count,var_count-spec_count, {
  2441. pushSTACK(NIL); /* NIL as preliminary value */
  2442. var object next_var = *varptr++; /* next variable */
  2443. var oint next_varflags = (oint)(*varflagsptr++)<<oint_symbolflags_shift; /* with poss. dynam_bit, svar_bit */
  2444. if (special_var_p(TheSymbol(next_var))) /* proclaimed SPECIAL? */
  2445. next_varflags |= wbit(dynam_bit_o); /* -> bind dynamically */
  2446. pushSTACK_symbolwithflags(next_var,next_varflags);
  2447. });
  2448. }
  2449. }
  2450. /* VAR_ENV of closure becomes NEXT_ENV in frame: */
  2451. pushSTACK(TheIclosure(closure)->clos_var_env);
  2452. pushSTACK(fake_gcv_object(var_count)); /* var_count bindungs, all still un-nested */
  2453. finish_frame(VAR);
  2454. }
  2455. /* STACK now points below the variable-binding-frame.
  2456. frame_pointer = Pointer in the variable-binding-frame, above the first
  2457. still inactive binding, below the already active SPECIAL-references. */
  2458. { /* 3rd step: bind current environments: */
  2459. var object new_var_env = make_framepointer(STACK);
  2460. /* this frame will become the new VAR_ENV later. */
  2461. make_ENV5_frame();
  2462. /* activate the closure-environment: */
  2463. aktenv.var_env = new_var_env; /* variable-binding-frame */
  2464. aktenv.fun_env = TheIclosure(closure)->clos_fun_env;
  2465. aktenv.block_env = TheIclosure(closure)->clos_block_env;
  2466. aktenv.go_env = TheIclosure(closure)->clos_go_env;
  2467. aktenv.decl_env = TheIclosure(closure)->clos_decl_env;
  2468. }
  2469. /* stack layout: APPLY-frame, variable-binding-frame, ENV-frame */
  2470. { /* 4th step: process parameters: */
  2471. check_SP();
  2472. /* Macro for binding of variables in variable-frame:
  2473. binds the next variable to value, decreases frame_pointer by 2 resp. 3.
  2474. (takes advantage of varframe_binding_mark = 0 !) */
  2475. #define bind_next_var(value,markptr_assignment) \
  2476. { frame_pointer skipSTACKop -varframe_binding_size; \
  2477. {var gcv_object_t* markptr = markptr_assignment &Before(frame_pointer); \
  2478. if (as_oint(*markptr) & wbit(dynam_bit_o)) { \
  2479. /* activate dynamic Binding: */ \
  2480. var object sym = *(markptr STACKop varframe_binding_sym); /* var */ \
  2481. *(markptr STACKop varframe_binding_value) = /* old value in frame */ \
  2482. TheSymbolflagged(sym)->symvalue; \
  2483. /* new value in value-cell: */ \
  2484. TheSymbolflagged(sym)->symvalue = (value); \
  2485. activate_specdecl(sym,spec_ptr,spec_count); \
  2486. } else { /* activate static binding: */ \
  2487. /* new value in frame: */ \
  2488. *(markptr STACKop varframe_binding_value) = (value); \
  2489. } \
  2490. *markptr = SET_BIT(*markptr,active_bit_o);/* activate binding */ \
  2491. }}
  2492. { /* process required parameters: fetch next argument and bind in stack */
  2493. var uintC count = posfixnum_to_V(TheIclosure(closure)->clos_req_count);
  2494. if (count>0) {
  2495. if (argcount < count) {
  2496. pushSTACK(TheIclosure(closure)->clos_name);
  2497. /* ANSI CL 3.5.1.2. wants a PROGRAM-ERROR here. */
  2498. error(program_error,
  2499. GETTEXT("EVAL/APPLY: too few arguments given to ~S"));
  2500. }
  2501. argcount -= count;
  2502. dotimespC(count,count, {
  2503. var object next_arg = NEXT(args_pointer); /* next argument */
  2504. bind_next_var(next_arg,); /* bind next variable */
  2505. });
  2506. }
  2507. }
  2508. { /* process optional parameters:
  2509. fetch next argument; if there is none,
  2510. execute an Init-form; then bind in stack. */
  2511. var uintC count = posfixnum_to_V(TheIclosure(closure)->clos_opt_count);
  2512. if (count==0)
  2513. goto optional_ende;
  2514. {
  2515. var object inits = TheIclosure(closure)->clos_opt_inits; /*init forms*/
  2516. do {
  2517. if (argcount==0)
  2518. goto optional_aus;
  2519. argcount--;
  2520. var object next_arg = NEXT(args_pointer); /* next argument */
  2521. var gcv_object_t* optmarkptr;
  2522. bind_next_var(next_arg,optmarkptr=); /* bind next variable */
  2523. if (as_oint(*optmarkptr) & wbit(svar_bit_o)) {
  2524. /* supplied-p-Parameter follows? */
  2525. *optmarkptr = CLR_BIT(*optmarkptr,svar_bit_o);
  2526. bind_next_var(T,); /* yes -> bind to T */
  2527. }
  2528. inits = Cdr(inits); /* shorten Init-Forms-List */
  2529. count--;
  2530. } while (count);
  2531. goto optional_ende;
  2532. optional_aus: /* no more optional arguments here. */
  2533. pushSTACK(inits);
  2534. }
  2535. /* execute all Init-forms of the optional parameters here: */
  2536. dotimespC(count,count, {
  2537. var object inits = STACK_0; /* remaining Initforms */
  2538. STACK_0 = Cdr(inits);
  2539. inits = (eval(Car(inits)),value1); /* next Initform, evaluated */
  2540. var gcv_object_t* optmarkptr;
  2541. bind_next_var(inits,optmarkptr=); /* bind next variable */
  2542. if (as_oint(*optmarkptr) & wbit(svar_bit_o)) {
  2543. /* supplied-p-Parameter follows? */
  2544. *optmarkptr = CLR_BIT(*optmarkptr,svar_bit_o);
  2545. bind_next_var(NIL,); /* yes -> bind to NIL */
  2546. }
  2547. });
  2548. closure = *closure_;
  2549. /* initialize &REST-parameters without arguments: */
  2550. if (!nullp(TheIclosure(closure)->clos_rest_flag)) /* Rest-Flag? */
  2551. bind_next_var(NIL,); /* yes -> bind to NIL */
  2552. /* initialize &KEY-parameters without arguments : */
  2553. count = posfixnum_to_V(TheIclosure(closure)->clos_key_count); /* number of Keyword-parameters */
  2554. if (count>0) {
  2555. STACK_0 = TheIclosure(closure)->clos_key_inits; /* their Init-forms */
  2556. dotimespC(count,count, {
  2557. var object inits = STACK_0; /* remaining Initforms */
  2558. STACK_0 = Cdr(inits);
  2559. inits = (eval(Car(inits)),value1); /* next Initform, evaluated */
  2560. var gcv_object_t* keymarkptr;
  2561. bind_next_var(inits,keymarkptr=); /* bind next Variable */
  2562. if (as_oint(*keymarkptr) & wbit(svar_bit_o)) {
  2563. /* supplied-p-Parameter follows? */
  2564. *keymarkptr = CLR_BIT(*keymarkptr,svar_bit_o);
  2565. bind_next_var(NIL,); /* yes -> bind to NIL */
  2566. }
  2567. });
  2568. closure = *closure_;
  2569. }
  2570. skipSTACK(1); /* remaining Init-forms forgotten */
  2571. goto aux; /* go to the AUX-variables */
  2572. }
  2573. optional_ende:
  2574. /* prepare &KEY-parameters and &REST-parameters: */
  2575. if (numberp(TheIclosure(closure)->clos_keywords) /* is keyword a number? */
  2576. && nullp(TheIclosure(closure)->clos_rest_flag)) { /* and no Rest-parameter? */
  2577. /* yes -> neither &KEY nor &REST specified */
  2578. if (argcount>0) { /* still arguments there? -> Error */
  2579. pushSTACK(TheIclosure(closure)->clos_name);
  2580. /* ANSI CL 3.5.1.3. wants a PROGRAM-ERROR here. */
  2581. error(program_error,
  2582. GETTEXT("EVAL/APPLY: too many arguments given to ~S"));
  2583. }
  2584. } else { /* &KEY or &REST present. */
  2585. /* process &REST-parameters: */
  2586. if (!nullp(TheIclosure(closure)->clos_rest_flag)) { /* &rest? */
  2587. /* yes -> collect residual arguments in a list: */
  2588. pushSTACK(NIL); /* start of list */
  2589. if (argcount>0) {
  2590. var gcv_object_t* ptr = args_pointer STACKop -(uintP)argcount;
  2591. var uintC count;
  2592. dotimespC(count,argcount, {
  2593. var object new_cons = allocate_cons();
  2594. Car(new_cons) = BEFORE(ptr);
  2595. Cdr(new_cons) = STACK_0;
  2596. STACK_0 = new_cons;
  2597. });
  2598. closure = *closure_;
  2599. }
  2600. var object list = popSTACK(); /* entire list */
  2601. bind_next_var(list,); /* bind &REST-parameter to this list */
  2602. }
  2603. /* process &KEY-parameters: */
  2604. if (!numberp(TheIclosure(closure)->clos_keywords)) {
  2605. /* Keyword-parameters present */
  2606. var gcv_object_t* rest_args_pointer = args_pointer;
  2607. /* argcount = number of remaining arguments */
  2608. /* halve argcount --> number of pairs Key.Value: */
  2609. if (argcount%2) { /* number was odd -> not paired: */
  2610. var uintC count = 0;
  2611. while (count<argcount) pushSTACK(rest_args_pointer[count++]);
  2612. error_key_odd(argcount,TheIclosure(closure)->clos_name);
  2613. }
  2614. argcount = argcount/2;
  2615. { /* test for illegal keywords: */
  2616. var object keywords = TheIclosure(closure)->clos_keywords;
  2617. #define for_every_keyword(statement) \
  2618. { var object keywordsr = keywords; \
  2619. while (consp(keywordsr)) { \
  2620. var object keyword = Car(keywordsr); \
  2621. statement; \
  2622. keywordsr = Cdr(keywordsr); \
  2623. }}
  2624. check_for_illegal_keywords
  2625. (!nullp(TheIclosure(closure)->clos_allow_flag),
  2626. TheIclosure(closure)->clos_name,
  2627. { error_key_badkw(TheIclosure(closure)->clos_name,
  2628. bad_keyword,bad_value,
  2629. TheIclosure(closure)->clos_keywords);});
  2630. #undef for_every_keyword
  2631. /* Now assign the Key-values and evaluate the Key-Inits: */
  2632. var uintC count = posfixnum_to_V(TheIclosure(closure)->clos_key_count);
  2633. if (count > 0) {
  2634. var object key_inits = TheIclosure(closure)->clos_key_inits;
  2635. dotimespC(count,count, {
  2636. var object keyword = Car(keywords); /* Keyword */
  2637. var object var_value;
  2638. var object svar_value;
  2639. /* Find the pair Key.Value for Keyword: */
  2640. find_keyword_value({ /* not found, must evaluate the Init: */
  2641. pushSTACK(keywords); pushSTACK(key_inits);
  2642. var_value = (eval(Car(key_inits)),value1);
  2643. key_inits = popSTACK(); keywords = popSTACK();
  2644. svar_value = NIL; /* NIL for poss. supplied-p-Parameter */
  2645. },{ /* found -> take value: */
  2646. var_value = value;
  2647. svar_value = T; /* T for poss. supplied-p-Parameter */
  2648. });
  2649. {
  2650. var gcv_object_t* keymarkptr;
  2651. bind_next_var(var_value,keymarkptr=); /* bind keyword-var */
  2652. if (as_oint(*keymarkptr) & wbit(svar_bit_o)) { /* supplied-p-Parameter follows? */
  2653. *keymarkptr = CLR_BIT(*keymarkptr,svar_bit_o);
  2654. bind_next_var(svar_value,); /* yes -> bind to NIL resp. T */
  2655. }
  2656. }
  2657. keywords = Cdr(keywords);
  2658. key_inits = Cdr(key_inits);
  2659. });
  2660. }
  2661. }
  2662. closure = *closure_;
  2663. }
  2664. }
  2665. aux: { /* process &AUX-parameter: */
  2666. var uintC count = posfixnum_to_V(TheIclosure(closure)->clos_aux_count);
  2667. if (count>0) {
  2668. pushSTACK(TheIclosure(closure)->clos_aux_inits); /* Init-forms for &AUX-variables */
  2669. dotimespC(count,count, {
  2670. var object inits = STACK_0;
  2671. STACK_0 = Cdr(inits);
  2672. inits = (eval(Car(inits)),value1); /* evaluate nnext Init */
  2673. bind_next_var(inits,); /* and bind next variable to it */
  2674. });
  2675. skipSTACK(1); /* forget remaining Init-forms */
  2676. closure = *closure_;
  2677. }
  2678. }
  2679. #undef bind_next_var
  2680. }
  2681. if (spec_count > 0) activate_specdecls(spec_ptr,spec_count);
  2682. /* 5th step: evaluate Body: */
  2683. implicit_progn(TheIclosure(closure)->clos_body,NIL);
  2684. unwind(); /* unwind ENV-frame */
  2685. unwind(); /* unwind variable-binding-frame */
  2686. unwind(); /* unwind APPLY-frame */
  2687. }
  2688. /* UP: provides the assignment of the Key-arguments for SUBRs.
  2689. call only, if key_flag /= subr_nokey.
  2690. > fun: function, a SUBR
  2691. > argcount: number of arguments after optional ones
  2692. > STACK_(argcount-1),...,STACK_0: the argcount arguments after the optional ones
  2693. > key_args_pointer: Pointer to the Key-parameters in the STACK
  2694. > rest_args_pointer: Pointer to the remaining arguments in the STACK
  2695. < STACK: set correctly
  2696. changes STACK */
  2697. local void match_subr_key (object fun, uintL argcount,
  2698. gcv_object_t* key_args_pointer,
  2699. gcv_object_t* rest_args_pointer) {
  2700. /* halve argcount --> the number of pairs Key.Value: */
  2701. if (argcount%2) /* number was odd -> not paired: */
  2702. error_key_odd(argcount,TheSubr(fun)->name);
  2703. if (((uintL)~(uintL)0 > ca_limit_1) && (argcount > ca_limit_1))
  2704. error_too_many_args(unbound,fun,argcount,ca_limit_1);
  2705. /* Due to argcount <= ca_limit_1, all count's fit in a uintC. */
  2706. argcount = argcount/2;
  2707. { /* test for illegal Keywords: */
  2708. var gcv_object_t* keywords_pointer =
  2709. &TheSvector(TheSubr(fun)->keywords)->data[0];
  2710. var uintC key_count = TheSubr(fun)->key_count;
  2711. #define for_every_keyword(statement) \
  2712. if (key_count > 0) { \
  2713. var gcv_object_t* keywordptr = keywords_pointer; \
  2714. var uintC count = key_count; \
  2715. do { \
  2716. var object keyword = *keywordptr++; \
  2717. statement; \
  2718. } while (--count); \
  2719. }
  2720. check_for_illegal_keywords
  2721. (TheSubr(fun)->key_flag == subr_key_allow,TheSubr(fun)->name,
  2722. { pushSTACK(bad_keyword); /* save bad keyword */
  2723. pushSTACK(bad_value); /* save bad value */
  2724. pushSTACK(fun); /* save the function */
  2725. /* convert Keyword-Vector to a List:
  2726. (SYS::COERCE-SEQUENCE kwvec 'LIST) */
  2727. coerce_sequence(TheSubr(fun)->keywords,S(list),true);
  2728. fun = popSTACK(); bad_value = popSTACK();
  2729. bad_keyword = popSTACK();
  2730. error_key_badkw(TheSubr(fun)->name,bad_keyword,
  2731. bad_value,value1);
  2732. });
  2733. #undef for_every_keyword
  2734. /* now assign Arguments and Parameters: */
  2735. if (key_count > 0) {
  2736. var gcv_object_t* keywordptr = keywords_pointer;
  2737. var gcv_object_t* key_args_ptr = key_args_pointer;
  2738. var uintC count;
  2739. dotimespC(count,key_count, {
  2740. var object keyword = *keywordptr++; /* Keyword */
  2741. /* find the pair Key.Value for this Keyword: */
  2742. find_keyword_value(
  2743. /* not found -> value remains #<UNBOUND> : */
  2744. { (void)NEXT(key_args_ptr); },
  2745. /* found -> save value: */
  2746. { NEXT(key_args_ptr) = value; }
  2747. );
  2748. });
  2749. }
  2750. }
  2751. /* poss. process Rest-Parameters: */
  2752. if (TheSubr(fun)->rest_flag == subr_norest) {
  2753. /* SUBR without &REST-Flag: forget remaining Arguments: */
  2754. set_args_end_pointer(rest_args_pointer);
  2755. }
  2756. /* SUBR with &REST-Flag: leave remaining Arguments in Stack */
  2757. }
  2758. /* UP: provides the assignment between Argument-list and Keyword-parameters
  2759. and poss. Rest-parameters of a compiled Closure.
  2760. > closure: compiled Closure with &KEY-parameters
  2761. > argcount: number of arguments after optional ones
  2762. > STACK_(argcount-1),...,STACK_0: the argcount arguments after the optional ones
  2763. > key_args_pointer: Pointer to the Key-parameters in the STACK
  2764. (poss. also Pointer beneath the Rest-parameters in the STACK,
  2765. which is #<UNBOUND>, if it is still to be supplied with)
  2766. > rest_args_pointer: Pointer to the remaining Arguments in the STACK
  2767. < STACK: set correctly
  2768. < result: closure
  2769. changes STACK
  2770. can trigger GC */
  2771. local maygc object match_cclosure_key (object closure, uintL argcount,
  2772. gcv_object_t* key_args_pointer,
  2773. gcv_object_t* rest_args_pointer) {
  2774. /* half argcount --> the number of pairs Key.Value: */
  2775. if (argcount%2) /* number was odd -> not paired: */
  2776. error_key_odd(argcount,Closure_name(closure));
  2777. if (((uintL)~(uintL)0 > ca_limit_1) && (argcount > ca_limit_1))
  2778. error_too_many_args(unbound,closure,argcount,ca_limit_1);
  2779. /* Due to argcount <= ca_limit_1, all count's fit in a uintC. */
  2780. argcount = argcount/2;
  2781. var object codevec = TheCclosure(closure)->clos_codevec; /* Code-Vector */
  2782. {
  2783. var uintC key_count = TheCodevec(codevec)->ccv_numkey; /* number of Keywords */
  2784. var uintL keywords_offset = TheCodevec(codevec)->ccv_keyconsts; /* Offset of Keywords in FUNC */
  2785. var gcv_object_t* keywords_pointer = /* points to the first Keyword */
  2786. (TheCodevec(codevec)->ccv_flags & bit(4) /* generic function? */
  2787. ? &TheSvector(TheCclosure(closure)->clos_consts[0])->data[keywords_offset]
  2788. : &TheCclosure(closure)->clos_consts[keywords_offset]
  2789. );
  2790. /* test for illegal Keywords: */
  2791. #define for_every_keyword(statement) \
  2792. if (key_count > 0) { \
  2793. var gcv_object_t* keywordptr = keywords_pointer; \
  2794. var uintC count = key_count; \
  2795. do { \
  2796. var object keyword = *keywordptr++; \
  2797. statement; \
  2798. } while (--count); \
  2799. }
  2800. check_for_illegal_keywords
  2801. (!((TheCodevec(codevec)->ccv_flags & bit(6)) == 0),
  2802. Closure_name(closure),
  2803. { pushSTACK(bad_keyword); /* save */
  2804. pushSTACK(bad_value); /* save */
  2805. pushSTACK(closure); /* save the closure */
  2806. /* build list of legal Keywords: */
  2807. for_every_keyword( { pushSTACK(keyword); } );
  2808. {var object kwlist = listof(key_count);
  2809. closure = popSTACK(); bad_value = popSTACK();
  2810. bad_keyword = popSTACK(); /* report errors: */
  2811. error_key_badkw(Closure_name(closure),
  2812. bad_keyword,bad_value,kwlist);}});
  2813. #undef for_every_keyword
  2814. /* now assign Arguments and Parameters: */
  2815. if (key_count > 0) {
  2816. var gcv_object_t* keywordptr = keywords_pointer;
  2817. var gcv_object_t* key_args_ptr = key_args_pointer;
  2818. var uintC count;
  2819. dotimespC(count,key_count, {
  2820. var object keyword = *keywordptr++; /* Keyword */
  2821. /* find the pair Key.value for this keyword: */
  2822. find_keyword_value(
  2823. /* not found -> Wert remains #<UNBOUND> : */
  2824. { (void)NEXT(key_args_ptr); },
  2825. /* found -> save value: */
  2826. { NEXT(key_args_ptr) = value; }
  2827. );
  2828. });
  2829. }
  2830. }
  2831. /* poss. process Rest-parameters: */
  2832. if (TheCodevec(codevec)->ccv_flags & bit(0)) { /* Rest-Flag? */
  2833. /* Closure with Keywords and &REST-Flag: */
  2834. var gcv_object_t* rest_arg_ = &BEFORE(key_args_pointer); /* Pointer to the REST-Parameter */
  2835. if (!boundp(*rest_arg_)) {
  2836. /* must still be filed: handicraft list */
  2837. *rest_arg_ = closure; /* save Closure */
  2838. var object rest_arg = NIL;
  2839. while (args_end_pointer != rest_args_pointer) {
  2840. pushSTACK(rest_arg);
  2841. rest_arg = allocate_cons();
  2842. Cdr(rest_arg) = popSTACK();
  2843. Car(rest_arg) = popSTACK();
  2844. }
  2845. closure = *rest_arg_; /* return Closure */
  2846. *rest_arg_ = rest_arg;
  2847. } else {
  2848. /* forget remaining arguments: */
  2849. set_args_end_pointer(rest_args_pointer);
  2850. }
  2851. } else {
  2852. /* Closure without &REST-Flag: forget remaining arguments: */
  2853. set_args_end_pointer(rest_args_pointer);
  2854. }
  2855. return closure;
  2856. }
  2857. /* ----------------------- E V A L ----------------------- */
  2858. /* later: */
  2859. local Values eval1 (object form);
  2860. local Values eval_fsubr (object fun, object args);
  2861. local Values eval_applyhook (object fun);
  2862. local Values eval_subr (object fun);
  2863. local Values eval_closure (object fun);
  2864. #ifdef DYNAMIC_FFI
  2865. local Values eval_ffunction (object fun);
  2866. #endif
  2867. /* UP: evaluates a form in the current environment.
  2868. eval(form);
  2869. > form: form
  2870. < mv_count/mv_space: values
  2871. can trigger GC */
  2872. global maygc Values eval (object form)
  2873. {
  2874. start:
  2875. /* Test for Keyboard-Interrupt: */
  2876. interruptp({
  2877. pushSTACK(form); /* save form */
  2878. pushSTACK(S(eval)); tast_break(); /* call break-loop */
  2879. form = popSTACK();
  2880. goto start;
  2881. });
  2882. var sp_jmp_buf my_jmp_buf;
  2883. /* build EVAL-frame: */
  2884. {
  2885. var gcv_object_t* top_of_frame = STACK; /* Pointer to Frame */
  2886. pushSTACK(form); /* Form */
  2887. finish_entry_frame(EVAL,my_jmp_buf,,
  2888. {
  2889. if (mv_count==0) { /* after reentry: Form passed over? */
  2890. form = STACK_(frame_form); /* evaluate the same form again */
  2891. } else {
  2892. form = STACK_(frame_form) = value1; /* evaluate form passed over */
  2893. }
  2894. });
  2895. }
  2896. /* Test for *EVALHOOK*: */
  2897. {
  2898. var object evalhook_value = Symbol_value(S(evalhookstern)); /* *EVALHOOK* */
  2899. if (nullp(evalhook_value)) { /* *EVALHOOK* = NIL ? */
  2900. /* yes -> continue evaluation normally */
  2901. pushSTACK(Symbol_value(S(applyhookstern))); eval1(form);
  2902. } else {
  2903. /* bind *EVALHOOK*, *APPLYHOOK* to NIL: */
  2904. bindhooks_NIL();
  2905. /* execute (FUNCALL *EVALHOOK* form env) : */
  2906. pushSTACK(form); /* Form as 1st Argument */
  2907. pushSTACK(evalhook_value); /* save Function */
  2908. var gcv_environment_t* stack_env = nest_aktenv(); /* Environments in the Stack, */
  2909. var object env = allocate_vector(5); /* in newly allocated Vector */
  2910. *(gcv_environment_t*)(&TheSvector(env)->data[0]) = *stack_env; /* push in */
  2911. skipSTACK(5);
  2912. evalhook_value = popSTACK(); /* return Function */
  2913. pushSTACK(env); /* entire Environment as 2nd Argument */
  2914. funcall(evalhook_value,2);
  2915. /* restore old values of *EVALHOOK*, *APPLYHOOK* : */
  2916. unwind();
  2917. /* unwind EVAL-Frame: */
  2918. unwind();
  2919. }
  2920. }
  2921. }
  2922. /* UP: evaluates a form in the current Environment. Does not take
  2923. *EVALHOOK* and *APPLYHOOK* into consideration.
  2924. eval_no_hooks(form);
  2925. > form: Form
  2926. < mv_count/mv_space: values
  2927. can trigger GC */
  2928. global maygc Values eval_no_hooks (object form) {
  2929. var sp_jmp_buf my_jmp_buf;
  2930. /* build EVAL-Frame: */
  2931. {
  2932. var gcv_object_t* top_of_frame = STACK; /* Pointer to Frame */
  2933. pushSTACK(form); /* Form */
  2934. finish_entry_frame(EVAL,my_jmp_buf,,
  2935. {
  2936. if (mv_count==0) { /* after reentry: Form passed over? */
  2937. form = STACK_(frame_form); /* evaluate the same form again */
  2938. } else {
  2939. form = STACK_(frame_form) = value1; /* evaluate form passed over */
  2940. }
  2941. });
  2942. }
  2943. /* continue evaluation, consider *APPLYHOOK* as being NIL: */
  2944. pushSTACK(NIL); eval1(form);
  2945. }
  2946. /* UP: evaluates a form in the current environment.
  2947. Does not take the value of *EVALHOOK* into consideration
  2948. and expects the value of *APPLYHOOK*.
  2949. the EVAL-frame must already have been built; it will then be unwound.
  2950. eval1(form);
  2951. > form: form
  2952. > STACK_3..STACK_1: EVAL-Frame, with form in STACK_3
  2953. > STACK_0: value of *APPLYHOOK*
  2954. < mv_count/mv_space: values
  2955. changes STACK
  2956. can trigger GC */
  2957. local maygc Values eval1 (object form)
  2958. {
  2959. if (atomp(form)) {
  2960. if (symbolp(form)) { /* Form is a Symbol */
  2961. /* value1 = value in the current Environment - not unbound! */
  2962. var object symbolmacro;
  2963. value1 = sym_value(form,aktenv.var_env,&symbolmacro);
  2964. if (!eq(symbolmacro,nullobj)) { /* Symbol-Macro? */
  2965. /* yes -> expand and evaluate again: */
  2966. skipSTACK(1); /* forget value of *APPLYHOOK* */
  2967. check_SP(); check_STACK();
  2968. eval(TheSymbolmacro(symbolmacro)->symbolmacro_expansion); /* evaluate Expansion */
  2969. unwind(); /* unwind EVAL-Frame */
  2970. } else {
  2971. if (!boundp(value1)) {
  2972. do {
  2973. pushSTACK(form); /* PLACE */
  2974. pushSTACK(form); /* CELL-ERROR slot NAME */
  2975. pushSTACK(form);
  2976. check_value(unbound_variable,GETTEXT("EVAL: variable ~S has no value"));
  2977. form = STACK_(frame_form+1);
  2978. } while (!boundp(value1));
  2979. if (!nullp(value2)) /* STORE-VALUE */
  2980. value1 = setq(form,value1);
  2981. }
  2982. mv_count=1; /* value1 as value */
  2983. skipSTACK(1);
  2984. unwind(); /* unwind EVAL-Frame */
  2985. }
  2986. } else {
  2987. /* self-evaluating form */
  2988. VALUES1(form);
  2989. skipSTACK(1);
  2990. unwind(); /* unwind EVAL-Frame */
  2991. }
  2992. } else { /* Form is a Cons */
  2993. eval_cons:
  2994. /* determine, if Macro-call, poss. expand: */
  2995. macroexp(form,aktenv.var_env,aktenv.fun_env); form = value1;
  2996. if (!nullp(value2)) { /* expanded ? */
  2997. /* now really evaluate: */
  2998. skipSTACK(1); /* forget value of *APPLYHOOK* */
  2999. check_SP(); check_STACK();
  3000. eval(form); /* evaluate expanded form */
  3001. unwind(); /* unwind EVAL-Frame */
  3002. } else {
  3003. var object fun = Car(form); /* function designation */
  3004. if (funnamep(fun)) {
  3005. /* fetch function-definition in the environment: */
  3006. fun = sym_function(fun,aktenv.fun_env);
  3007. fun_dispatch:
  3008. /* branch according to type of function:
  3009. unbound / SUBR/FSUBR/Closure / FunctionMacro / Macro */
  3010. #ifdef TYPECODES
  3011. switch (typecode(fun))
  3012. #else
  3013. if (immsubrp(fun))
  3014. goto case_subr;
  3015. else if (orecordp(fun))
  3016. goto case_orecord;
  3017. else
  3018. switch (0)
  3019. #endif
  3020. {
  3021. case_subr: /* SUBR */
  3022. pushSTACK(Cdr(form)); /* argument list */
  3023. if (!nullp(STACK_1))
  3024. goto applyhook;
  3025. eval_subr(fun);
  3026. break;
  3027. case_closure: /* closure */
  3028. pushSTACK(Cdr(form)); /* argument list */
  3029. closure: /* fun is a closure */
  3030. if (!nullp(STACK_1))
  3031. goto applyhook;
  3032. eval_closure(fun);
  3033. break;
  3034. applyhook: /* value of *APPLYHOOK* is /= NIL. */
  3035. eval_applyhook(fun);
  3036. break;
  3037. case_orecord:
  3038. switch (Record_type(fun)) {
  3039. case_Rectype_Closure_above;
  3040. case_Rectype_Subr_above;
  3041. case Rectype_Fsubr: /* Fsubr */
  3042. eval_fsubr(fun,Cdr(form));
  3043. break;
  3044. #ifdef DYNAMIC_FFI
  3045. case Rectype_Ffunction: /* Foreign-Function */
  3046. pushSTACK(Cdr(form)); /* argument list */
  3047. if (!nullp(STACK_1))
  3048. goto applyhook;
  3049. eval_ffunction(fun);
  3050. break;
  3051. #endif
  3052. case Rectype_FunctionMacro:
  3053. /* FunctionMacro -> treat like a function */
  3054. fun = TheFunctionMacro(fun)->functionmacro_function;
  3055. goto fun_dispatch;
  3056. default:
  3057. goto undef;
  3058. }
  3059. break;
  3060. default: undef: {
  3061. pushSTACK(form);
  3062. fun = check_fdefinition(Car(form),S(eval));
  3063. form = popSTACK();
  3064. goto fun_dispatch;
  3065. }
  3066. }
  3067. } else if (consp(fun) && eq(Car(fun),S(lambda))) {
  3068. /* lambda-expression? */
  3069. pushSTACK(Cdr(form)); /* Argument list */
  3070. fun = get_closure(Cdr(fun),S(Klambda),false,&aktenv); /* create closure in current environment */
  3071. goto closure; /* und apply it to the arguments, as above */
  3072. } else {
  3073. pushSTACK(Cdr(form));
  3074. fun = check_funname_replacement(source_program_error,S(eval),fun);
  3075. pushSTACK(fun);
  3076. form = allocate_cons();
  3077. Car(form) = popSTACK(); /* fun */
  3078. Cdr(form) = popSTACK(); /* Cdr(form) */
  3079. goto eval_cons;
  3080. }
  3081. }
  3082. }
  3083. }
  3084. #define CHECK_STACK(stack_before,fun) do { \
  3085. if (STACK != stack_before) { /* STACK as before? */ \
  3086. fprintf(stderr,"\n[%s:%d] STACK is not restored: %d in ", \
  3087. __FILE__,__LINE__,STACK_item_count(STACK,stack_before)); \
  3088. nobject_out(stderr,fun); fprintf(stderr,"\n"); \
  3089. abort(); /* no -> go to Debugger */ \
  3090. }} while(0)
  3091. #if STACKCHECKS
  3092. #define CHECK_STACK_S(stack_before,fun) CHECK_STACK(stack_before,fun)
  3093. #else
  3094. #define CHECK_STACK_S(stack_before,fun)
  3095. #endif
  3096. #if STACKCHECKC
  3097. #define CHECK_STACK_C(stack_before,fun) CHECK_STACK(stack_before,fun)
  3098. #else
  3099. #define CHECK_STACK_C(stack_before,fun)
  3100. #endif
  3101. /* In EVAL: Applies a FSUBR to an argument-list, cleans up STACK
  3102. and returns the values.
  3103. eval_fsubr(fun,args);
  3104. > fun: a FSUBR
  3105. > args: argument-list
  3106. > STACK-layout: EVAL-Frame, *APPLYHOOK*.
  3107. < STACK: cleaned up
  3108. < mv_count/mv_space: values
  3109. changes STACK
  3110. can trigger GC */
  3111. local maygc Values eval_fsubr (object fun, object args)
  3112. {
  3113. skipSTACK(1); /* forget value of *APPLYHOOK* */
  3114. check_SP(); check_STACK();
  3115. #if STACKCHECKS
  3116. var gcv_object_t* STACKbefore = STACK;
  3117. #endif
  3118. /* put arguments in the STACK: */
  3119. switch ((uintW)posfixnum_to_V(TheFsubr(fun)->argtype)) {
  3120. /* Macro for 1 required-Parameter: */
  3121. #define REQ_PAR() \
  3122. { if (atomp(args)) goto error_toofew; \
  3123. pushSTACK(Car(args)); /* next parameter in the STACK */ \
  3124. args = Cdr(args); \
  3125. }
  3126. case (uintW)fsubr_argtype_2_0_nobody:
  3127. /* FSUBR with 2 required-Parameters */
  3128. REQ_PAR();
  3129. case (uintW)fsubr_argtype_1_0_nobody:
  3130. /* FSUBR with 1 required-Parameter */
  3131. REQ_PAR();
  3132. if (!nullp(args)) goto error_toomany;
  3133. break;
  3134. case (uintW)fsubr_argtype_2_1_nobody:
  3135. /* FSUBR with 2 required-Parameters and 1 optional-Parameter */
  3136. REQ_PAR();
  3137. case (uintW)fsubr_argtype_1_1_nobody:
  3138. /* FSUBR with 1 required-Parameter and 1 optional-Parameter */
  3139. REQ_PAR();
  3140. if (consp(args)) {
  3141. pushSTACK(Car(args)); /* optional parameter into STACK */
  3142. args = Cdr(args);
  3143. if (!nullp(args)) goto error_toomany;
  3144. } else {
  3145. pushSTACK(unbound); /* unbound into STACK instead */
  3146. if (!nullp(args)) goto error_dotted;
  3147. }
  3148. break;
  3149. case (uintW)fsubr_argtype_2_body:
  3150. /* FSUBR with 2 required-Parameters and Body-Parameter */
  3151. REQ_PAR();
  3152. case (uintW)fsubr_argtype_1_body:
  3153. /* FSUBR with 1 required-Parameter and Body-Parameter */
  3154. REQ_PAR();
  3155. case (uintW)fsubr_argtype_0_body:
  3156. /* FSUBR with 0 required-Parameters and Body-Parameter */
  3157. pushSTACK(args); /* remaining body into STACK */
  3158. break;
  3159. default: NOTREACHED;
  3160. error_toofew: /* argument-list args is an atom, prematurely */
  3161. if (!nullp(args)) goto error_dotted;
  3162. /* clean up STACK up to the calling EVAL-Frame: */
  3163. while (!(framecode(STACK_0) & bit(frame_bit_t))) {
  3164. skipSTACK(1);
  3165. }
  3166. {
  3167. var object form = STACK_(frame_form); /* Form from EVAL-Frame */
  3168. pushSTACK(form); /* SOURCE-PROGRAM-ERROR slot DETAIL */
  3169. pushSTACK(form); pushSTACK(Car(form));
  3170. error(source_program_error,
  3171. GETTEXT("EVAL: too few parameters for special operator ~S: ~S"));
  3172. }
  3173. error_toomany: /* argument-list args is not NIL at the tail */
  3174. if (atomp(args)) goto error_dotted;
  3175. /* clean up STACK up to the calling EVAL-Frame: */
  3176. while (!(framecode(STACK_0) & bit(frame_bit_t))) {
  3177. skipSTACK(1);
  3178. }
  3179. {
  3180. var object form = STACK_(frame_form); /* Form from EVAL-Frame */
  3181. pushSTACK(form); /* SOURCE-PROGRAM-ERROR slot DETAIL */
  3182. pushSTACK(form); pushSTACK(Car(form));
  3183. error(source_program_error,
  3184. GETTEXT("EVAL: too many parameters for special operator ~S: ~S"));
  3185. }
  3186. error_dotted: /* argument-list args ends with Atom /= NIL */
  3187. /* clean up STACK up to the calling EVAL-Frame: */
  3188. while (!(framecode(STACK_0) & bit(frame_bit_t))) {
  3189. skipSTACK(1);
  3190. }
  3191. {
  3192. var object form = STACK_(frame_form); /* Form from EVAL-Frame */
  3193. pushSTACK(form); /* SOURCE-PROGRAM-ERROR slot DETAIL */
  3194. pushSTACK(form); pushSTACK(Car(form));
  3195. error(source_program_error,
  3196. GETTEXT("EVAL: dotted parameter list for special operator ~S: ~S"));
  3197. }
  3198. #undef REQ_PAR
  3199. }
  3200. /* Now STACK = STACKbefore STACKop - (req + opt + (body-flag ? 1 : 0)).
  3201. Call FSUBR: */
  3202. with_saved_back_trace_fsubr(fun,
  3203. (*(fsubr_function_t*)(TheFsubr(fun)->function))(); );
  3204. CHECK_STACK_S(STACKbefore,fun);
  3205. unwind(); /* unwind EVAL-Frame */
  3206. }
  3207. /* In EVAL: Applies *APPLYHOOK* to a function (SUBR or Closure) and
  3208. an argument-list, cleans up the STACK and returns the values.
  3209. eval_applyhook(fun);
  3210. > fun: function, a SUBR or a closure
  3211. > STACK-layout: EVAL-Frame, *APPLYHOOK* (/= NIL), argument-list.
  3212. < STACK: cleaned up
  3213. < mv_count/mv_space: values
  3214. changes STACK
  3215. can trigger GC */
  3216. local maygc Values eval_applyhook(object fun) {
  3217. var object args = popSTACK(); /* argument-list */
  3218. var object applyhook_value = popSTACK(); /* value of *APPLYHOOK* */
  3219. check_SP();
  3220. /* bind *EVALHOOK*, *APPLYHOOK* to NIL: */
  3221. bindhooks_NIL();
  3222. #ifndef X3J13_005
  3223. /* execute (FUNCALL *APPLYHOOK* fun args env) : */
  3224. pushSTACK(fun); /* Funktion as 1st Argument */
  3225. pushSTACK(args); /* argument-list as 2nd Argument */
  3226. pushSTACK(applyhook_value); /* save function */
  3227. {
  3228. var gcv_environment_t* stack_env = nest_aktenv(); /* Environments into Stack, */
  3229. var object env = allocate_vector(5); /* in newly allocated Vector */
  3230. *(gcv_environment_t*)(&TheSvector(env)->data[0]) = *stack_env; /* push in */
  3231. skipSTACK(5);
  3232. }
  3233. applyhook_value = popSTACK(); /* function back */
  3234. pushSTACK(env); /* entire Environment as 3rd Argument */
  3235. funcall(applyhook_value,3);
  3236. #else
  3237. /* execute (FUNCALL *APPLYHOOK* fun args) : */
  3238. pushSTACK(fun); /* function as 1st Argument */
  3239. pushSTACK(args); /* argument-list as 2nd Argument */
  3240. funcall(applyhook_value,2);
  3241. #endif
  3242. /* old values of *EVALHOOK*, *APPLYHOOK* back: */
  3243. unwind();
  3244. /* unwind EVAL-Frame: */
  3245. unwind();
  3246. }
  3247. /* In EVAL: error, if too few arguments */
  3248. nonreturning_function(local, error_eval_toofew, (object fun)) {
  3249. var object form = STACK_(frame_form); /* Form */
  3250. pushSTACK(form); /* SOURCE-PROGRAM-ERROR slot DETAIL */
  3251. pushSTACK(form); pushSTACK(fun);
  3252. /* ANSI CL 3.5.1.2. wants a PROGRAM-ERROR here. */
  3253. error(source_program_error,
  3254. GETTEXT("EVAL: too few arguments given to ~S: ~S"));
  3255. }
  3256. /* In EVAL: error, if too many arguments */
  3257. nonreturning_function(local, error_eval_toomany, (object fun)) {
  3258. var object form = STACK_(frame_form); /* Form */
  3259. pushSTACK(form); /* SOURCE-PROGRAM-ERROR slot DETAIL */
  3260. pushSTACK(form); pushSTACK(fun);
  3261. /* ANSI CL 3.5.1.3. wants a PROGRAM-ERROR here. */
  3262. error(source_program_error,
  3263. GETTEXT("EVAL: too many arguments given to ~S: ~S"));
  3264. }
  3265. /* In EVAL: error, if dotted argument-list */
  3266. nonreturning_function(global, error_dotted_form, (object form, object fun)) {
  3267. pushSTACK(form); /* SOURCE-PROGRAM-ERROR slot DETAIL */
  3268. pushSTACK(form); pushSTACK(fun);
  3269. error(source_program_error,
  3270. GETTEXT("EVAL: argument list given to ~S is dotted: ~S"));
  3271. }
  3272. #define error_eval_dotted(fun) error_dotted_form(STACK_(frame_form),fun)
  3273. /* In EVAL: Applies an SUBR to an argument-list, cleans up STACK
  3274. and returns the values.
  3275. eval_subr(fun);
  3276. > fun: function, a SUBR
  3277. > STACK-layout: EVAL-Frame, *APPLYHOOK*, argument-list.
  3278. < STACK: cleaned up
  3279. < mv_count/mv_space: values
  3280. changes STACK
  3281. can trigger GC */
  3282. local maygc Values eval_subr (object fun)
  3283. {
  3284. var object args = popSTACK(); /* argument-list */
  3285. skipSTACK(1); /* forget value of *APPLYHOOK* */
  3286. check_SP(); check_STACK();
  3287. var gcv_object_t* args_pointer = args_end_pointer; /* Pointer to the arguments */
  3288. var gcv_object_t* rest_args_pointer; /* Pointer to the remaining arguments */
  3289. var uintL argcount; /* number of remaining arguments */
  3290. /* push arguments evaluated in the STACK:
  3291. first a Dispatch for most important cases: */
  3292. switch (TheSubr(fun)->argtype) {
  3293. /* Macro for a required-argument: */
  3294. #define REQ_ARG() \
  3295. { if (atomp(args)) goto error_toofew; \
  3296. pushSTACK(Cdr(args)); /* remaining arguments */ \
  3297. eval(Car(args)); /* evaluate next argument */ \
  3298. args = STACK_0; STACK_0 = value1; /* and into STACK */ \
  3299. }
  3300. /* Macro for the n-th last optional-argument: */
  3301. #define OPT_ARG(n) \
  3302. { if (atomp(args)) goto unbound_optional_##n ; \
  3303. pushSTACK(Cdr(args)); /* remaining arguments */ \
  3304. eval(Car(args)); /* evaluate next argument */ \
  3305. args = STACK_0; STACK_0 = value1; /* and into STACK */ \
  3306. }
  3307. case (uintW)subr_argtype_6_0: /* SUBR with 6 required arguments */
  3308. REQ_ARG();
  3309. case (uintW)subr_argtype_5_0: /* SUBR with 5 required arguments */
  3310. REQ_ARG();
  3311. case (uintW)subr_argtype_4_0: /* SUBR with 4 required arguments */
  3312. REQ_ARG();
  3313. case (uintW)subr_argtype_3_0: /* SUBR with 3 required arguments */
  3314. REQ_ARG();
  3315. case (uintW)subr_argtype_2_0: /* SUBR with 2 required arguments */
  3316. REQ_ARG();
  3317. case (uintW)subr_argtype_1_0: /* SUBR with 1 required argument */
  3318. REQ_ARG();
  3319. case (uintW)subr_argtype_0_0: /* SUBR without Arguments */
  3320. if (!nullp(args)) goto error_toomany;
  3321. goto apply_subr_norest;
  3322. case (uintW)subr_argtype_4_1: /* SUBR with 4 required and 1 optional */
  3323. REQ_ARG();
  3324. case (uintW)subr_argtype_3_1: /* SUBR with 3 required and 1 optional */
  3325. REQ_ARG();
  3326. case (uintW)subr_argtype_2_1: /* SUBR with 2 required and 1 optional */
  3327. REQ_ARG();
  3328. case (uintW)subr_argtype_1_1: /* SUBR with 1 required and 1 optional */
  3329. REQ_ARG();
  3330. case (uintW)subr_argtype_0_1: /* SUBR with 1 optional argument */
  3331. OPT_ARG(1);
  3332. if (!nullp(args)) goto error_toomany;
  3333. goto apply_subr_norest;
  3334. case (uintW)subr_argtype_3_2: /* SUBR with 3 required and 2 optional */
  3335. REQ_ARG();
  3336. case (uintW)subr_argtype_2_2: /* SUBR with 2 required and 2 optional */
  3337. REQ_ARG();
  3338. case (uintW)subr_argtype_1_2: /* SUBR with 1 required and 2 optional */
  3339. REQ_ARG();
  3340. case (uintW)subr_argtype_0_2: /* SUBR with 2 optional arguments */
  3341. OPT_ARG(2);
  3342. OPT_ARG(1);
  3343. if (!nullp(args)) goto error_toomany;
  3344. goto apply_subr_norest;
  3345. case (uintW)subr_argtype_2_3: /* SUBR with 2 required and 3 optional */
  3346. REQ_ARG();
  3347. case (uintW)subr_argtype_1_3: /* SUBR with 1 required and 3 optional */
  3348. REQ_ARG();
  3349. case (uintW)subr_argtype_0_3: /* SUBR with 3 optional arguments */
  3350. OPT_ARG(3);
  3351. OPT_ARG(2);
  3352. OPT_ARG(1);
  3353. if (!nullp(args)) goto error_toomany;
  3354. goto apply_subr_norest;
  3355. case (uintW)subr_argtype_0_5: /* SUBR with 5 optional arguments */
  3356. OPT_ARG(5);
  3357. case (uintW)subr_argtype_0_4: /* SUBR with 4 optional arguments */
  3358. OPT_ARG(4);
  3359. OPT_ARG(3);
  3360. OPT_ARG(2);
  3361. OPT_ARG(1);
  3362. if (!nullp(args)) goto error_toomany;
  3363. goto apply_subr_norest;
  3364. unbound_optional_5: /* Still 5 optional Arguments, but atomp(args) */
  3365. { pushSTACK(unbound); }
  3366. unbound_optional_4: /* Still 4 optional Arguments, but atomp(args) */
  3367. { pushSTACK(unbound); }
  3368. unbound_optional_3: /* Still 3 optional Arguments, but atomp(args) */
  3369. { pushSTACK(unbound); }
  3370. unbound_optional_2: /* Still 2 optional Arguments, but atomp(args) */
  3371. { pushSTACK(unbound); }
  3372. unbound_optional_1: /* Still 1 optional Argument, but atomp(args) */
  3373. { pushSTACK(unbound); }
  3374. if (!nullp(args)) goto error_dotted;
  3375. goto apply_subr_norest;
  3376. case (uintW)subr_argtype_3_0_rest: /* SUBR with 3 required and rest */
  3377. REQ_ARG();
  3378. case (uintW)subr_argtype_2_0_rest: /* SUBR with 2 required and rest */
  3379. REQ_ARG();
  3380. case (uintW)subr_argtype_1_0_rest: /* SUBR with 1 required and rest */
  3381. REQ_ARG();
  3382. case (uintW)subr_argtype_0_0_rest: /* SUBR with &rest Arguments */
  3383. rest_args_pointer = args_end_pointer; /* Pointer to the remaining arguments */
  3384. /* evaluate all further arguments and into Stack: */
  3385. argcount = 0; /* counter for the remaining arguments */
  3386. while (consp(args)) {
  3387. check_STACK();
  3388. pushSTACK(Cdr(args)); /* remaining arguments */
  3389. eval(Car(args)); /* evaluate next argument */
  3390. args = STACK_0; STACK_0 = value1; /* and into STACK */
  3391. argcount++;
  3392. }
  3393. goto apply_subr_rest;
  3394. case (uintW)subr_argtype_4_0_key: /* SUBR with 4 required and &key */
  3395. REQ_ARG();
  3396. case (uintW)subr_argtype_3_0_key: /* SUBR with 3 required and &key */
  3397. REQ_ARG();
  3398. case (uintW)subr_argtype_2_0_key: /* SUBR with 2 required and &key */
  3399. REQ_ARG();
  3400. case (uintW)subr_argtype_1_0_key: /* SUBR with 1 required and &key */
  3401. REQ_ARG();
  3402. case (uintW)subr_argtype_0_0_key: /* SUBR with &key */
  3403. if (atomp(args)) goto unbound_optional_key_0;
  3404. goto apply_subr_key;
  3405. case (uintW)subr_argtype_1_1_key:
  3406. /* SUBR with 1 required argument, 1 optional argument and &key */
  3407. REQ_ARG();
  3408. case (uintW)subr_argtype_0_1_key: /* SUBR with 1 optional and &key */
  3409. OPT_ARG(key_1);
  3410. if (atomp(args)) goto unbound_optional_key_0;
  3411. goto apply_subr_key;
  3412. case (uintW)subr_argtype_1_2_key:
  3413. /* SUBR with 1 required argument, 2 optional arguments and &key */
  3414. REQ_ARG();
  3415. OPT_ARG(key_2);
  3416. OPT_ARG(key_1);
  3417. if (atomp(args)) goto unbound_optional_key_0;
  3418. goto apply_subr_key;
  3419. unbound_optional_key_2: /* Silll 2 optional Arguments, but atomp(args) */
  3420. { pushSTACK(unbound); }
  3421. unbound_optional_key_1: /* Still 1 optional Argument, but atomp(args) */
  3422. { pushSTACK(unbound); }
  3423. unbound_optional_key_0: /* Before the keywords is atomp(args) */
  3424. {
  3425. var uintC count;
  3426. dotimesC(count,TheSubr(fun)->key_count, { pushSTACK(unbound); } );
  3427. }
  3428. if (!nullp(args)) goto error_dotted;
  3429. goto apply_subr_norest;
  3430. default: NOTREACHED;
  3431. #undef OPT_ARG
  3432. #undef REQ_ARG
  3433. }
  3434. /* Now the general Version:
  3435. reserve space on the STACK: */
  3436. get_space_on_STACK(sizeof(gcv_object_t) *
  3437. (uintL)(TheSubr(fun)->req_count +
  3438. TheSubr(fun)->opt_count +
  3439. TheSubr(fun)->key_count));
  3440. /* evaluate required parameters and push into Stack: */
  3441. {
  3442. var uintC count;
  3443. dotimesC(count,TheSubr(fun)->req_count, {
  3444. if (atomp(args)) goto error_toofew; /* at the end of argument-list? */
  3445. pushSTACK(Cdr(args)); /* remaining argument-list */
  3446. eval(Car(args)); /* evaluate next argument */
  3447. args = STACK_0; STACK_0 = value1; /* and into Stack */
  3448. });
  3449. }
  3450. { /* evaluate optional parameters and push into Stack: */
  3451. var uintC count = TheSubr(fun)->opt_count;
  3452. while (!atomp(args)) { /* argument-list not finished? */
  3453. if (count==0) /* all optional parameters supplied with? */
  3454. goto optionals_ok;
  3455. count--;
  3456. pushSTACK(Cdr(args)); /* remaining argument-list */
  3457. eval(Car(args)); /* evaluate next argument */
  3458. args = STACK_0; STACK_0 = value1; /* and into Stack */
  3459. }
  3460. /* argument-list finished.
  3461. All further count optional parameters get the "value"
  3462. #<UNBOUND>, the same for the Keyword-parameters: */
  3463. dotimesC(count,count + TheSubr(fun)->key_count, { pushSTACK(unbound); } );
  3464. if (TheSubr(fun)->rest_flag == subr_rest) { /* &REST-Flag? */
  3465. /* yes -> 0 additional arguments: */
  3466. argcount = 0; rest_args_pointer = args_end_pointer;
  3467. }
  3468. /* no -> nothing to do */
  3469. goto los;
  3470. }
  3471. optionals_ok:
  3472. /* process Rest- and Keyword-parameters.
  3473. args = remaining argument-list (not yet finished) */
  3474. if (TheSubr(fun)->key_flag == subr_nokey) {
  3475. /* SUBR without KEY */
  3476. if (TheSubr(fun)->rest_flag == subr_norest) {
  3477. /* SUBR without REST or KEY -> argument-list should be finished */
  3478. goto error_toomany;
  3479. } else {
  3480. /* SUBR with only REST, without KEY: treatment of remaining arguments */
  3481. rest_args_pointer = args_end_pointer;
  3482. argcount = 0; /* counter for the remaining arguments */
  3483. do {
  3484. check_STACK();
  3485. pushSTACK(Cdr(args)); /* remaining argument-list */
  3486. eval(Car(args)); /* evaluate next argument */
  3487. args = STACK_0; STACK_0 = value1; /* and into Stack */
  3488. argcount++;
  3489. } while (consp(args));
  3490. if (((uintL)~(uintL)0 > ca_limit_1) && (argcount > ca_limit_1))
  3491. goto error_toomany;
  3492. }
  3493. } else
  3494. apply_subr_key: { /* SUBR with Keywords. */
  3495. /* args = remaining argument-list (not yet finished)
  3496. First initialize the Keyword-parameters with #<UNBOUND> , then
  3497. evaluate the remaining arguments and push into Stack, then
  3498. assign the Keywords: */
  3499. var gcv_object_t* key_args_pointer = args_end_pointer; /* Pointer to Keyword-parameters */
  3500. /* initialize all Keyword-parameters with #<UNBOUND> : */
  3501. {
  3502. var uintC count;
  3503. dotimesC(count,TheSubr(fun)->key_count, { pushSTACK(unbound); } );
  3504. }
  3505. rest_args_pointer = args_end_pointer; /* Pointer to the remaining arguments */
  3506. /* evaluate all further arguments and into Stack: */
  3507. argcount = 0; /* counter for the remaining arguments */
  3508. do {
  3509. check_STACK();
  3510. pushSTACK(Cdr(args)); /* remaining argument-list */
  3511. eval(Car(args)); /* evaluate next argument */
  3512. args = STACK_0; STACK_0 = value1; /* and into Stack */
  3513. argcount++;
  3514. } while (consp(args));
  3515. if (((uintL)~(uintL)0 > ca_limit_1) && (argcount > ca_limit_1))
  3516. goto error_toomany;
  3517. /* assign Keywords and poss. discard remaining arguments: */
  3518. match_subr_key(fun,argcount,key_args_pointer,rest_args_pointer);
  3519. }
  3520. los: /* call function */
  3521. /* remaining argument-list must be NIL : */
  3522. if (!nullp(args)) goto error_dotted;
  3523. if (TheSubr(fun)->rest_flag == subr_norest) {
  3524. /* SUBR without &REST-Flag: */
  3525. apply_subr_norest:
  3526. with_saved_back_trace_subr(fun,STACK,-1,
  3527. (*(subr_norest_function_t*)(TheSubr(fun)->function))(); );
  3528. } else {
  3529. /* SUBR with &REST-Flag: */
  3530. apply_subr_rest:
  3531. with_saved_back_trace_subr(fun,STACK,
  3532. TheSubr(fun)->req_count + TheSubr(fun)->opt_count + argcount,
  3533. (*(subr_rest_function_t*)(TheSubr(fun)->function))(argcount,rest_args_pointer); );
  3534. }
  3535. CHECK_STACK_S(args_end_pointer,fun);
  3536. unwind(); /* unwind EVAL-Frame */
  3537. return; /* finished */
  3538. /* Gathered error-messages: */
  3539. error_toofew: /* Argument-List args is prematurely an Atom */
  3540. if (!nullp(args)) goto error_dotted;
  3541. set_args_end_pointer(args_pointer); /* clean up STACK */
  3542. error_eval_toofew(TheSubr(fun)->name);
  3543. error_toomany: /* Argument-List args is not NIL at the end */
  3544. if (atomp(args)) goto error_dotted;
  3545. set_args_end_pointer(args_pointer); /* clean up STACK */
  3546. error_eval_toomany(TheSubr(fun)->name);
  3547. error_dotted: /* Argument-List args ends with Atom /= NIL */
  3548. set_args_end_pointer(args_pointer); /* clean up STACK */
  3549. error_eval_dotted(TheSubr(fun)->name);
  3550. }
  3551. /* In EVAL: Applies a Closure to an argument-list, cleans up the STACK
  3552. and returns the values.
  3553. eval_closure(fun);
  3554. > fun: function, a Closure
  3555. > STACK-layout: EVAL-Frame, *APPLYHOOK*, argument-list.
  3556. < STACK: cleaned up
  3557. < mv_count/mv_space: values
  3558. changes STACK
  3559. can trigger GC */
  3560. local maygc Values eval_closure (object closure)
  3561. {
  3562. var object args = popSTACK(); /* argument-list */
  3563. skipSTACK(1); /* forget value of *APPLYHOOK* */
  3564. /* STACK-layout: EVAL-Frame. */
  3565. check_SP(); check_STACK();
  3566. pushSTACK(closure); /* save Closure */
  3567. var gcv_object_t* closure_ = &STACK_0; /* and memorize, where it is */
  3568. var gcv_object_t* STACKbefore = STACK;
  3569. if (simple_bit_vector_p(Atype_8Bit,TheClosure(closure)->clos_codevec)) {
  3570. /* closure is a compiled Closure */
  3571. var object codevec = TheCclosure(closure)->clos_codevec; /* Code-Vector */
  3572. /* push arguments evaluated into STACK:
  3573. first a dispatch for the most important cases: */
  3574. switch (TheCodevec(codevec)->ccv_signature) {
  3575. /* Macro for a required-argument: */
  3576. #define REQ_ARG() \
  3577. { if (atomp(args)) goto error_toofew; \
  3578. pushSTACK(Cdr(args)); /* remaining arguments */ \
  3579. eval(Car(args)); /* evaluate next argument */ \
  3580. args = STACK_0; STACK_0 = value1; /* and into STACK */ \
  3581. }
  3582. /* Macro for the n-last optional-argument: */
  3583. #define OPT_ARG(n) \
  3584. { if (atomp(args)) goto unbound_optional_##n ; \
  3585. pushSTACK(Cdr(args)); /* remaining arguments */ \
  3586. eval(Car(args)); /* evaluate next argument */ \
  3587. args = STACK_0; STACK_0 = value1; /* and into STACK */ \
  3588. }
  3589. case (uintB)cclos_argtype_5_0: /* 5 required arguments */
  3590. REQ_ARG();
  3591. case (uintB)cclos_argtype_4_0: /* 4 required arguments */
  3592. REQ_ARG();
  3593. case (uintB)cclos_argtype_3_0: /* 3 required arguments */
  3594. REQ_ARG();
  3595. case (uintB)cclos_argtype_2_0: /* 2 required arguments */
  3596. REQ_ARG();
  3597. case (uintB)cclos_argtype_1_0: /* 1 required argument */
  3598. REQ_ARG();
  3599. case (uintB)cclos_argtype_0_0: /* no Arguments */
  3600. noch_0_opt_args:
  3601. if (!nullp(args)) goto error_toomany;
  3602. goto apply_cclosure_nokey;
  3603. case (uintB)cclos_argtype_4_1: /* 4 required and 1 optional */
  3604. REQ_ARG();
  3605. case (uintB)cclos_argtype_3_1: /* 3 required and 1 optional */
  3606. REQ_ARG();
  3607. case (uintB)cclos_argtype_2_1: /* 2 required and 1 optional */
  3608. REQ_ARG();
  3609. case (uintB)cclos_argtype_1_1: /* 1 required and 1 optional */
  3610. REQ_ARG();
  3611. case (uintB)cclos_argtype_0_1: /* 1 optional argument */
  3612. noch_1_opt_args:
  3613. OPT_ARG(1);
  3614. goto noch_0_opt_args;
  3615. case (uintB)cclos_argtype_3_2: /* 3 required and 2 optional */
  3616. REQ_ARG();
  3617. case (uintB)cclos_argtype_2_2: /* 2 required and 2 optional */
  3618. REQ_ARG();
  3619. case (uintB)cclos_argtype_1_2: /* 1 required and 2 optional */
  3620. REQ_ARG();
  3621. case (uintB)cclos_argtype_0_2: /* 2 optional arguments */
  3622. noch_2_opt_args:
  3623. OPT_ARG(2);
  3624. goto noch_1_opt_args;
  3625. case (uintB)cclos_argtype_2_3: /* 2 required and 3 optional */
  3626. REQ_ARG();
  3627. case (uintB)cclos_argtype_1_3: /* 1 required and 3 optional */
  3628. REQ_ARG();
  3629. case (uintB)cclos_argtype_0_3: /* 3 optional arguments */
  3630. noch_3_opt_args:
  3631. OPT_ARG(3);
  3632. goto noch_2_opt_args;
  3633. case (uintB)cclos_argtype_1_4: /* 1 required and 4 optional */
  3634. REQ_ARG();
  3635. case (uintB)cclos_argtype_0_4: /* 4 optional arguments */
  3636. noch_4_opt_args:
  3637. OPT_ARG(4);
  3638. goto noch_3_opt_args;
  3639. case (uintB)cclos_argtype_0_5: /* 5 optional arguments */
  3640. OPT_ARG(5);
  3641. goto noch_4_opt_args;
  3642. unbound_optional_5: /* Still 5 optional Arguments, but atomp(args) */
  3643. { pushSTACK(unbound); }
  3644. unbound_optional_4: /* Still 4 optional Arguments, but atomp(args) */
  3645. { pushSTACK(unbound); }
  3646. unbound_optional_3: /* Still 3 optional Arguments, but atomp(args) */
  3647. { pushSTACK(unbound); }
  3648. unbound_optional_2: /* Still 2 optional Arguments, but atomp(args) */
  3649. { pushSTACK(unbound); }
  3650. unbound_optional_1: /* Still 1 optional Argument, but atomp(args) */
  3651. { pushSTACK(unbound); }
  3652. if (!nullp(args)) goto error_dotted;
  3653. goto apply_cclosure_nokey;
  3654. case (uintB)cclos_argtype_4_0_rest: /* 4 required + &rest */
  3655. REQ_ARG();
  3656. case (uintB)cclos_argtype_3_0_rest: /* 3 required + &rest */
  3657. REQ_ARG();
  3658. case (uintB)cclos_argtype_2_0_rest: /* 2 required + &rest */
  3659. REQ_ARG();
  3660. case (uintB)cclos_argtype_1_0_rest: /* 1 required + &rest */
  3661. REQ_ARG();
  3662. case (uintB)cclos_argtype_0_0_rest: /* no Arguments, Rest-Parameter */
  3663. if (consp(args)) goto apply_cclosure_rest_nokey;
  3664. if (!nullp(args)) goto error_dotted;
  3665. { pushSTACK(NIL); } /* Rest-Parameter := NIL */
  3666. goto apply_cclosure_nokey;
  3667. case (uintB)cclos_argtype_4_0_key: /* 4 required arguments, &key */
  3668. REQ_ARG();
  3669. case (uintB)cclos_argtype_3_0_key: /* 3 required arguments, &key */
  3670. REQ_ARG();
  3671. case (uintB)cclos_argtype_2_0_key: /* 2 required arguments, &key */
  3672. REQ_ARG();
  3673. case (uintB)cclos_argtype_1_0_key: /* 1 required argument, &key */
  3674. REQ_ARG();
  3675. noch_0_opt_args_key:
  3676. closure = *closure_; codevec = TheCclosure(closure)->clos_codevec;
  3677. case (uintB)cclos_argtype_0_0_key:
  3678. /* only &key */
  3679. if (atomp(args)) goto unbound_optional_key_0;
  3680. goto apply_cclosure_key;
  3681. case (uintB)cclos_argtype_3_1_key:
  3682. /* 3 required arguments and 1 optional argument, &key */
  3683. REQ_ARG();
  3684. case (uintB)cclos_argtype_2_1_key:
  3685. /* 2 required arguments and 1 optional argument, &key */
  3686. REQ_ARG();
  3687. case (uintB)cclos_argtype_1_1_key:
  3688. /* 1 required argument and 1 optional argument, &key */
  3689. REQ_ARG();
  3690. case (uintB)cclos_argtype_0_1_key:
  3691. /* 1 optional argument, &key */
  3692. noch_1_opt_args_key:
  3693. OPT_ARG(key_1);
  3694. goto noch_0_opt_args_key;
  3695. case (uintB)cclos_argtype_2_2_key: /* 2 required and 2 optional, &key */
  3696. REQ_ARG();
  3697. case (uintB)cclos_argtype_1_2_key: /* 1 required and 2 optional, &key */
  3698. REQ_ARG();
  3699. case (uintB)cclos_argtype_0_2_key: /* 2 optional arguments, &key */
  3700. noch_2_opt_args_key:
  3701. OPT_ARG(key_2);
  3702. goto noch_1_opt_args_key;
  3703. case (uintB)cclos_argtype_1_3_key: /* 1 required and 3 optional, &key */
  3704. REQ_ARG();
  3705. case (uintB)cclos_argtype_0_3_key: /* 3 optional arguments, &key */
  3706. noch_3_opt_args_key:
  3707. OPT_ARG(key_3);
  3708. goto noch_2_opt_args_key;
  3709. case (uintB)cclos_argtype_0_4_key: /* 4 optional arguments, &key */
  3710. OPT_ARG(key_4);
  3711. goto noch_3_opt_args_key;
  3712. unbound_optional_key_4: /* Still 4 optional Arguments, but atomp(args) */
  3713. { pushSTACK(unbound); }
  3714. unbound_optional_key_3: /* Still 3 optional Arguments, but atomp(args) */
  3715. { pushSTACK(unbound); }
  3716. unbound_optional_key_2: /* Still 2 optional Arguments, but atomp(args) */
  3717. { pushSTACK(unbound); }
  3718. unbound_optional_key_1: /* Still 1 optional Argument, but atomp(args) */
  3719. { pushSTACK(unbound); }
  3720. unbound_optional_key_0: /* Before the Keywords is atomp(args) */
  3721. if (!nullp(args)) goto error_dotted;
  3722. goto apply_cclosure_key_noargs;
  3723. case (uintB)cclos_argtype_default:
  3724. /* General Version */
  3725. break;
  3726. default: NOTREACHED;
  3727. #undef OPT_ARG
  3728. #undef REQ_ARG
  3729. }
  3730. /* Now the general Version: */
  3731. {
  3732. var uintL req_count = TheCodevec(codevec)->ccv_numreq; /* number of required parameters */
  3733. var uintL opt_count = TheCodevec(codevec)->ccv_numopt; /* number of optional parameters */
  3734. var uintB flags = TheCodevec(codevec)->ccv_flags; /* Flags */
  3735. /* reserve space on STACK: */
  3736. get_space_on_STACK(sizeof(gcv_object_t) * (req_count+opt_count));
  3737. /* evaluate required parameters and push into Stack: */
  3738. {
  3739. var uintC count;
  3740. dotimesC(count,req_count, {
  3741. if (atomp(args)) goto error_toofew; /* argument-list finished? */
  3742. pushSTACK(Cdr(args)); /* remaining argument-list */
  3743. eval(Car(args)); /* evaluate nnext argument */
  3744. args = STACK_0; STACK_0 = value1; /* and into Stack */
  3745. });
  3746. }
  3747. { /* evaluate optional parameters and push into Stack: */
  3748. var uintC count = opt_count;
  3749. while (!atomp(args)) { /* argument-list not finished? */
  3750. if (count==0) /* all optional parameters supplied with? */
  3751. goto optionals_ok;
  3752. count--;
  3753. pushSTACK(Cdr(args)); /* remaining argument-list */
  3754. eval(Car(args)); /* evaluate next argument */
  3755. args = STACK_0; STACK_0 = value1; /* and into Stack */
  3756. }
  3757. /* argument-list finished. */
  3758. if (!nullp(args)) goto error_dotted;
  3759. /* All further count optional parameters get the "value"
  3760. #<UNBOUND>, the &REST-parameter gets the value NIL,
  3761. the Keyword-parameter gets the value #<UNBOUND> : */
  3762. dotimesC(count,count, { pushSTACK(unbound); } );
  3763. }
  3764. closure = *closure_; codevec = TheCclosure(closure)->clos_codevec;
  3765. if (flags & bit(0)) /* &REST-Flag? */
  3766. pushSTACK(NIL); /* yes -> initialize with NIL */
  3767. if (flags & bit(7)) /* &KEY-Flag? */
  3768. goto apply_cclosure_key_noargs;
  3769. else
  3770. goto apply_cclosure_nokey_;
  3771. optionals_ok:
  3772. /* process Rest- and Keyword-parameters.
  3773. args = remaining argument-list (not yet finished) */
  3774. closure = *closure_; codevec = TheCclosure(closure)->clos_codevec;
  3775. if (flags == 0)
  3776. /* Closure without REST or KEY -> argument-list should be finished */
  3777. goto error_toomany;
  3778. else if (flags & bit(7)) { /* Key-Flag? */
  3779. /* Closure with Keywords.
  3780. args = remaining argument-list (not yet finished)
  3781. First initialize the Keyword-parameters with #<UNBOUND> , then
  3782. evaluate the remaining arguments and push into Stack, then
  3783. assign the Keywords:
  3784. poss. initialize the Rest-Parameter: */
  3785. if (flags & bit(0))
  3786. pushSTACK(unbound);
  3787. goto apply_cclosure_key;
  3788. } else
  3789. goto apply_cclosure_rest_nokey;
  3790. }
  3791. apply_cclosure_key_noargs:
  3792. {
  3793. var uintC count = TheCodevec(codevec)->ccv_numkey; /* number of Keyword-parameters */
  3794. dotimesC(count,count, { pushSTACK(unbound); } ); /* initialize with #<UNBOUND> */
  3795. interpret_bytecode(closure,codevec,CCV_START_KEY); /* interprete bytecode starting at Byte 12 */
  3796. }
  3797. goto done;
  3798. apply_cclosure_key: /* jump to Closure only with &KEY: */
  3799. {
  3800. var gcv_object_t* key_args_pointer = args_end_pointer; /* Pointer to Keyword-Parameter */
  3801. /* initialize all Keyword-parameters with #<UNBOUND> : */
  3802. {
  3803. var uintC count = TheCodevec(codevec)->ccv_numkey;
  3804. dotimesC(count,count, { pushSTACK(unbound); } );
  3805. }
  3806. var gcv_object_t* rest_args_pointer = args_end_pointer; /* Pointer to the remaining arguments */
  3807. /* evaluate all further arguments and push into Stack: */
  3808. var uintL argcount = 0; /* counter for the remaining arguments */
  3809. do {
  3810. check_STACK();
  3811. pushSTACK(Cdr(args)); /* remaining argument-list */
  3812. eval(Car(args)); /* evaluate next argument */
  3813. args = STACK_0; STACK_0 = value1; /* and into Stack */
  3814. argcount++;
  3815. } while (consp(args));
  3816. /* argument-list finished. */
  3817. if (!nullp(args)) goto error_dotted;
  3818. /* assign Keywords, build Rest-Parameter
  3819. and poss. discard remaining arguments: */
  3820. closure = match_cclosure_key(*closure_,argcount,key_args_pointer,rest_args_pointer);
  3821. codevec = TheCclosure(closure)->clos_codevec;
  3822. interpret_bytecode(closure,codevec,CCV_START_KEY); /* interprete bytecode starting at Byte 12 */
  3823. }
  3824. goto done;
  3825. apply_cclosure_rest_nokey: {
  3826. /* Closure with only REST, without KEY:
  3827. evaluate remaining arguments one by on, put into list
  3828. args = remaining argument-list (not yet finished) */
  3829. pushSTACK(NIL); /* so far evaluated remaining arguments */
  3830. pushSTACK(args); /* remaining arguments, unevaluated */
  3831. do {
  3832. args = STACK_0; STACK_0 = Cdr(args);
  3833. eval(Car(args)); /* evaluate next argument */
  3834. pushSTACK(value1);
  3835. /* and cons onto the list: */
  3836. var object new_cons = allocate_cons();
  3837. Car(new_cons) = popSTACK();
  3838. Cdr(new_cons) = STACK_1;
  3839. STACK_1 = new_cons;
  3840. } while (mconsp(STACK_0));
  3841. args = popSTACK();
  3842. /* reverse list STACK_0 and use as REST-parameter: */
  3843. nreverse(STACK_0);
  3844. /* argument-list finished. */
  3845. if (!nullp(args)) goto error_dotted;
  3846. }
  3847. apply_cclosure_nokey: /* jump to Closure without &KEY : */
  3848. closure = *closure_; codevec = TheCclosure(closure)->clos_codevec;
  3849. apply_cclosure_nokey_:
  3850. interpret_bytecode(closure,codevec,CCV_START_NONKEY); /* interprete bytecode starting at Byte 8 */
  3851. done:
  3852. CHECK_STACK_C(STACKbefore,closure);
  3853. skipSTACK(1); /* discard Closure */
  3854. unwind(); /* unwind EVAL-Frame */
  3855. return; /* finished */
  3856. } else {
  3857. /* closure is an interpreted Closure */
  3858. var gcv_object_t* args_pointer = args_end_pointer; /* Pointer to the arguments */
  3859. var uintC args_on_stack = 0; /* number of arguments */
  3860. while (consp(args)) {
  3861. pushSTACK(Cdr(args)); /* save rest of list */
  3862. eval(Car(args)); /* evaluate next element */
  3863. args = STACK_0; STACK_0 = value1; /* result into STACK */
  3864. args_on_stack += 1;
  3865. if (((uintL)~(uintL)0 > ca_limit_1) && (args_on_stack > ca_limit_1))
  3866. goto error_toomany;
  3867. }
  3868. with_saved_back_trace_iclosure(*closure_,args_pointer,args_on_stack,
  3869. funcall_iclosure(*closure_,args_pointer,args_on_stack); );
  3870. skipSTACK(1); /* discard Closure */
  3871. unwind(); /* unwind EVAL-Frame */
  3872. return; /* finished */
  3873. }
  3874. /* Gathered errormessages: */
  3875. error_toofew: /* Argument-list args is prematurely an Atom */
  3876. if (!nullp(args)) goto error_dotted;
  3877. setSTACK(STACK = STACKbefore); /* clean up STACK */
  3878. closure = popSTACK();
  3879. error_eval_toofew(Closure_name(closure));
  3880. error_toomany: /* Argument-list args is not NIL at the end */
  3881. if (atomp(args)) goto error_dotted;
  3882. setSTACK(STACK = STACKbefore); /* clean up STACK */
  3883. closure = popSTACK();
  3884. error_eval_toomany(Closure_name(closure));
  3885. error_dotted: /* Argument-list args ends with Atom /= NIL */
  3886. setSTACK(STACK = STACKbefore); /* clean up STACK */
  3887. closure = popSTACK();
  3888. error_eval_dotted(Closure_name(closure));
  3889. }
  3890. #ifdef DYNAMIC_FFI
  3891. /* In EVAL: Applies a Foreign-Function to an argument-list,
  3892. cleans up STACK and returns the values.
  3893. eval_ffunction(fun);
  3894. > fun: function, a Foreign-Function
  3895. > STACK-layout: EVAL-Frame, *APPLYHOOK*, argument-list.
  3896. < STACK: cleaned up
  3897. < mv_count/mv_space: values
  3898. changes STACK
  3899. can trigger GC */
  3900. local maygc Values eval_ffunction(object ffun) {
  3901. var object args = popSTACK(); /* Argument-list */
  3902. skipSTACK(1); /* skip value of *APPLYHOOK* */
  3903. /* STACK-layout: EVAL-Frame.
  3904. (ffun arg ...) --> (FFI::FOREIGN-CALL-OUT ffun arg ...) */
  3905. check_SP(); check_STACK();
  3906. pushSTACK(ffun); /* Foreign-Function as 1st Argument */
  3907. {
  3908. var gcv_object_t* args_pointer = args_end_pointer; /* Pointer to the arguments */
  3909. var uintC args_on_stack = 1; /* number of arguments */
  3910. while (consp(args)) {
  3911. pushSTACK(Cdr(args)); /* save list-rest */
  3912. eval(Car(args)); /* evaluate next element */
  3913. args = STACK_0; STACK_0 = value1; /* result into STACK */
  3914. args_on_stack += 1;
  3915. if (((uintL)~(uintL)0 > ca_limit_1) && (args_on_stack > ca_limit_1)) {
  3916. set_args_end_pointer(args_pointer);
  3917. error_eval_toomany(popSTACK());
  3918. }
  3919. }
  3920. funcall(L(foreign_call_out),args_on_stack);
  3921. }
  3922. unwind(); /* unwind EVAL-Frame */
  3923. return; /* finished */
  3924. }
  3925. #endif
  3926. /* ----------------------- A P P L Y ----------------------- */
  3927. /* later: */
  3928. local Values apply_subr (object fun, uintC args_on_stack, object other_args);
  3929. local Values apply_closure(object fun, uintC args_on_stack, object other_args);
  3930. /* UP: Applies a function to its arguments.
  3931. apply(function,args_on_stack,other_args);
  3932. > function: function
  3933. > arguments: args_on_stack arguments on the STACK,
  3934. remaining argument-list in other_args
  3935. < STACK: cleaned up (i.e. STACK is increased by args_on_stack)
  3936. < mv_count/mv_space: values
  3937. changes STACK, can trigger GC */
  3938. global maygc Values apply (object fun, uintC args_on_stack, object other_args)
  3939. {
  3940. apply_restart:
  3941. /* fun must be a SUBR or a Closure or a Cons (LAMBDA ...) : */
  3942. if (subrp(fun)) { /* SUBR ? */
  3943. return_Values apply_subr(fun,args_on_stack,other_args);
  3944. } else if (closurep(fun)) { /* Closure ? */
  3945. return_Values apply_closure(fun,args_on_stack,other_args);
  3946. } else if (symbolp(fun)) { /* Symbol ? */
  3947. /* apply Symbol: global Definition Symbol_function(fun) applies. */
  3948. var object fdef = Symbol_function(fun);
  3949. if (subrp(fdef)) { /* SUBR -> apply */
  3950. return_Values apply_subr(fdef,args_on_stack,other_args);
  3951. } else if (closurep(fdef)) { /* Closure -> apply */
  3952. return_Values apply_closure(fdef,args_on_stack,other_args);
  3953. } else if (orecordp(fdef)) {
  3954. #ifdef DYNAMIC_FFI
  3955. if (ffunctionp(fdef)) { /* Foreign-Function ? */
  3956. fun = fdef; goto call_ffunction;
  3957. }
  3958. #endif
  3959. switch (Record_type(fdef)) {
  3960. case Rectype_Fsubr: { error_specialform(S(apply),fun); }
  3961. case Rectype_Macro: { error_macro(S(apply),fun); }
  3962. default: NOTREACHED;
  3963. }
  3964. } else
  3965. /* if no SUBR, no Closure, no FSUBR, no Macro:
  3966. Symbol_function(fun) must be #<UNBOUND> . */
  3967. goto undef;
  3968. } else if (funnamep(fun)) { /* List (SETF symbol) ? */
  3969. /* global Definition (symbol-function (get-setf-symbol symbol)) applies. */
  3970. var object symbol = get(Car(Cdr(fun)),S(setf_function)); /* (get ... 'SYS::SETF-FUNCTION) */
  3971. if (!symbolp(symbol)) /* should be (uninterned) Symbol */
  3972. goto undef; /* else undefined */
  3973. var object fdef = Symbol_function(symbol);
  3974. if (closurep(fdef)) { /* Closure -> apply */
  3975. return_Values apply_closure(fdef,args_on_stack,other_args);
  3976. } else if (subrp(fdef)) { /* SUBR -> apply */
  3977. return_Values apply_subr(fdef,args_on_stack,other_args);
  3978. }
  3979. #ifdef DYNAMIC_FFI
  3980. else if (ffunctionp(fdef)) { /* Foreign-Function ? */
  3981. fun = fdef; goto call_ffunction;
  3982. }
  3983. #endif
  3984. else
  3985. /* Such function-names cannot denote FSUBRs or Macros.
  3986. fdef is presumably #<UNBOUND> . */
  3987. goto undef;
  3988. }
  3989. #ifdef DYNAMIC_FFI
  3990. else if (ffunctionp(fun)) /* Foreign-Function ? */
  3991. call_ffunction: { /* call (SYS::FOREIGN-CALL-OUT foreign-function . args) */
  3992. /* Therefore first shift down the arguments in Stack by 1. */
  3993. var uintC count;
  3994. var gcv_object_t* ptr = &STACK_0;
  3995. dotimesC(count,args_on_stack, {
  3996. *(ptr STACKop -1) = *ptr; ptr skipSTACKop 1;
  3997. });
  3998. *(ptr STACKop -1) = fun;
  3999. skipSTACK(-1);
  4000. return_Values apply_subr(L(foreign_call_out),args_on_stack+1,other_args);
  4001. }
  4002. #endif
  4003. else if (consp(fun) && eq(Car(fun),S(lambda))) /* Cons (LAMBDA ...) ? */
  4004. error_lambda_expression(S(apply),fun);
  4005. else {
  4006. pushSTACK(other_args);
  4007. fun = check_funname_replacement(type_error,S(apply),fun);
  4008. other_args = popSTACK();
  4009. goto apply_restart;
  4010. }
  4011. return;
  4012. undef:
  4013. pushSTACK(other_args);
  4014. fun = check_fdefinition(fun,S(apply));
  4015. other_args = popSTACK();
  4016. goto apply_restart;
  4017. }
  4018. /* Error because of dotted argument-list
  4019. > name: name of function */
  4020. nonreturning_function(local, error_apply_dotted, (object name, object end)) {
  4021. pushSTACK(end);
  4022. pushSTACK(name);
  4023. pushSTACK(S(apply));
  4024. error(program_error,GETTEXT("~S: argument list given to ~S is dotted (terminated by ~S)"));
  4025. }
  4026. /* Error because of too many arguments
  4027. > name: name of function */
  4028. nonreturning_function(local, error_apply_toomany, (object name)) {
  4029. pushSTACK(name);
  4030. /* ANSI CL 3.5.1.3. wants a PROGRAM-ERROR here. */
  4031. error(program_error,GETTEXT("APPLY: too many arguments given to ~S"));
  4032. }
  4033. /* Error because of too few arguments
  4034. > name: name of function
  4035. > tail: atom at the end of the argument list */
  4036. nonreturning_function(local, error_apply_toofew, (object name, object tail)) {
  4037. if (!nullp(tail)) {
  4038. pushSTACK(tail); /* ARGUMENT-LIST-DOTTED slot DATUM */
  4039. pushSTACK(tail); pushSTACK(name);
  4040. error(argument_list_dotted,
  4041. GETTEXT("APPLY: dotted argument list given to ~S : ~S"));
  4042. } else {
  4043. pushSTACK(name);
  4044. /* ANSI CL 3.5.1.2. wants a PROGRAM-ERROR here. */
  4045. error(program_error,GETTEXT("APPLY: too few arguments given to ~S"));
  4046. }
  4047. }
  4048. /* Error because of too many arguments for a SUBR
  4049. > fun: function, a SUBR */
  4050. nonreturning_function(local, error_subr_toomany, (object fun));
  4051. #define error_subr_toomany(fun) error_apply_toomany(TheSubr(fun)->name)
  4052. /* Error because of too few arguments for a SUBR
  4053. > fun: function, a SUBR
  4054. > tail: atom at the end of the argument list */
  4055. nonreturning_function(local, error_subr_toofew, (object fun, object tail));
  4056. #define error_subr_toofew(fun,tail) \
  4057. error_apply_toofew(TheSubr(fun)->name,tail)
  4058. /* In APPLY: Applies a SUBR to an argument-list, cleans up STACK
  4059. and returns the values.
  4060. apply_subr(fun,args_on_stack,other_args);
  4061. > fun: function, a SUBR
  4062. > Arguments: args_on_stack Arguments on STACK,
  4063. remaining argument-list in other_args
  4064. < STACK: cleaned up (i.e. STACK is increased by args_on_stack)
  4065. < mv_count/mv_space: values
  4066. changes STACK, can trigger GC */
  4067. local maygc Values apply_subr (object fun, uintC args_on_stack, object args)
  4068. {
  4069. #if STACKCHECKS
  4070. var gcv_object_t* args_pointer = args_end_pointer STACKop args_on_stack; /* Pointer to the arguments */
  4071. #endif
  4072. var gcv_object_t* key_args_pointer; /* Pointer to the &key */
  4073. var gcv_object_t* rest_args_pointer; /* Pointer to the remaining Arguments */
  4074. var uintL argcount; /* number of remaining Arguments */
  4075. TRACE_CALL(fun,'A','S');
  4076. /* push Arguments on STACK:
  4077. first a Dispatch for the most important cases: */
  4078. switch (TheSubr(fun)->argtype) {
  4079. /* Macro for a required argument: */
  4080. #define REQ_ARG() \
  4081. { if (args_on_stack>0) { args_on_stack--; } \
  4082. else if (consp(args)) { pushSTACK(Car(args)); args = Cdr(args); } \
  4083. else goto error_toofew; \
  4084. }
  4085. /* Macro for the n-last optional argument: */
  4086. #define OPT_ARG(n) \
  4087. { if (args_on_stack>0) { args_on_stack--; } \
  4088. else if (consp(args)) { pushSTACK(Car(args)); args = Cdr(args); } \
  4089. else goto unbound_optional_##n; \
  4090. }
  4091. case (uintW)subr_argtype_6_0: /* SUBR with 6 required arguments */
  4092. REQ_ARG();
  4093. case (uintW)subr_argtype_5_0: /* SUBR with 5 required arguments */
  4094. REQ_ARG();
  4095. case (uintW)subr_argtype_4_0: /* SUBR with 4 required arguments */
  4096. REQ_ARG();
  4097. case (uintW)subr_argtype_3_0: /* SUBR with 3 required arguments */
  4098. REQ_ARG();
  4099. case (uintW)subr_argtype_2_0: /* SUBR with 2 required arguments */
  4100. REQ_ARG();
  4101. case (uintW)subr_argtype_1_0: /* SUBR with 1 required argument */
  4102. REQ_ARG();
  4103. case (uintW)subr_argtype_0_0: /* SUBR without Arguments */
  4104. if ((args_on_stack>0) || consp(args)) goto error_toomany;
  4105. goto apply_subr_norest;
  4106. case (uintW)subr_argtype_4_1: /* SUBR with 4 required and 1 optional */
  4107. REQ_ARG();
  4108. case (uintW)subr_argtype_3_1: /* SUBR with 3 required and 1 optional */
  4109. REQ_ARG();
  4110. case (uintW)subr_argtype_2_1: /* SUBR with 2 required and 1 optional */
  4111. REQ_ARG();
  4112. case (uintW)subr_argtype_1_1: /* SUBR with 1 required and 1 optional */
  4113. REQ_ARG();
  4114. case (uintW)subr_argtype_0_1: /* SUBR with 1 optional argument */
  4115. OPT_ARG(1);
  4116. if ((args_on_stack>0) || consp(args)) goto error_toomany;
  4117. goto apply_subr_norest;
  4118. case (uintW)subr_argtype_3_2: /* SUBR with 3 required and 2 optional */
  4119. REQ_ARG();
  4120. case (uintW)subr_argtype_2_2: /* SUBR with 2 required and 2 optional */
  4121. REQ_ARG();
  4122. case (uintW)subr_argtype_1_2: /* SUBR with 1 required and 2 optional */
  4123. REQ_ARG();
  4124. case (uintW)subr_argtype_0_2: /* SUBR with 2 optional arguments */
  4125. OPT_ARG(2);
  4126. OPT_ARG(1);
  4127. if ((args_on_stack>0) || consp(args)) goto error_toomany;
  4128. goto apply_subr_norest;
  4129. case (uintW)subr_argtype_2_3: /* SUBR with 2 required and 3 optional */
  4130. REQ_ARG();
  4131. case (uintW)subr_argtype_1_3: /* SUBR with 1 required and 3 optional */
  4132. REQ_ARG();
  4133. case (uintW)subr_argtype_0_3: /* SUBR with 3 optional arguments */
  4134. OPT_ARG(3);
  4135. OPT_ARG(2);
  4136. OPT_ARG(1);
  4137. if ((args_on_stack>0) || consp(args)) goto error_toomany;
  4138. goto apply_subr_norest;
  4139. case (uintW)subr_argtype_0_5: /* SUBR with 5 optional arguments */
  4140. OPT_ARG(5);
  4141. case (uintW)subr_argtype_0_4: /* SUBR with 4 optional arguments */
  4142. OPT_ARG(4);
  4143. OPT_ARG(3);
  4144. OPT_ARG(2);
  4145. OPT_ARG(1);
  4146. if ((args_on_stack>0) || consp(args)) goto error_toomany;
  4147. goto apply_subr_norest;
  4148. unbound_optional_5: /* Still 5 optionals Arguments, but args_on_stack=0 and atomp(args) */
  4149. { pushSTACK(unbound); }
  4150. unbound_optional_4: /* Still 4 optional Arguments, but args_on_stack=0 and atomp(args) */
  4151. { pushSTACK(unbound); }
  4152. unbound_optional_3: /* Still 3 optional Arguments, but args_on_stack=0 and atomp(args) */
  4153. { pushSTACK(unbound); }
  4154. unbound_optional_2: /* Still 2 optional Arguments, but args_on_stack=0 and atomp(args) */
  4155. { pushSTACK(unbound); }
  4156. unbound_optional_1: /* Still 1 optionals Argument, but args_on_stack=0 and atomp(args) */
  4157. { pushSTACK(unbound); }
  4158. goto apply_subr_norest;
  4159. case (uintW)subr_argtype_3_0_rest: /* SUBR with 3 required and &rest */
  4160. REQ_ARG();
  4161. case (uintW)subr_argtype_2_0_rest: /* SUBR with 2 required and &rest */
  4162. REQ_ARG();
  4163. case (uintW)subr_argtype_1_0_rest: /* SUBR with 1 required and &rest */
  4164. REQ_ARG();
  4165. case (uintW)subr_argtype_0_0_rest: /* SUBR with rest arguments */
  4166. if (args_on_stack==0)
  4167. goto apply_subr_rest_onlylist;
  4168. else
  4169. goto apply_subr_rest_withlist;
  4170. case (uintW)subr_argtype_4_0_key: /* SUBR with 4 required and &key */
  4171. REQ_ARG();
  4172. case (uintW)subr_argtype_3_0_key: /* SUBR with 3 required and &key */
  4173. REQ_ARG();
  4174. case (uintW)subr_argtype_2_0_key: /* SUBR with 2 required and &key */
  4175. REQ_ARG();
  4176. case (uintW)subr_argtype_1_0_key: /* SUBR with 1 required and &key */
  4177. REQ_ARG();
  4178. case (uintW)subr_argtype_0_0_key: /* SUBR with &key */
  4179. if ((args_on_stack==0) && atomp(args)) goto unbound_optional_key_0;
  4180. goto apply_subr_key;
  4181. case (uintW)subr_argtype_1_1_key:
  4182. /* SUBR with 1 required argument, 1 optional argument and &key */
  4183. REQ_ARG();
  4184. case (uintW)subr_argtype_0_1_key:
  4185. /* SUBR with 1 optional argument and &key */
  4186. OPT_ARG(key_1);
  4187. if ((args_on_stack==0) && atomp(args)) goto unbound_optional_key_0;
  4188. goto apply_subr_key;
  4189. case (uintW)subr_argtype_1_2_key:
  4190. /* SUBR with 1 required argument, 2 optional arguments and &key */
  4191. REQ_ARG();
  4192. OPT_ARG(key_2);
  4193. OPT_ARG(key_1);
  4194. if ((args_on_stack==0) && atomp(args)) goto unbound_optional_key_0;
  4195. goto apply_subr_key;
  4196. unbound_optional_key_2: /* Still 2 optional Arguments, but args_on_stack=0 and atomp(args) */
  4197. { pushSTACK(unbound); }
  4198. unbound_optional_key_1: /* Still 1 optional Argument, but args_on_stack=0 and atomp(args) */
  4199. { pushSTACK(unbound); }
  4200. unbound_optional_key_0: /* Before the Keywords is args_on_stack=0 and atomp(args) */
  4201. {
  4202. var uintC count;
  4203. dotimesC(count,TheSubr(fun)->key_count, { pushSTACK(unbound); } );
  4204. }
  4205. goto apply_subr_norest;
  4206. default: NOTREACHED;
  4207. #undef OPT_ARG
  4208. #undef REQ_ARG
  4209. }
  4210. /* Now the general Version: */
  4211. {
  4212. var uintC key_count;
  4213. {
  4214. var uintC req_count = TheSubr(fun)->req_count;
  4215. var uintC opt_count = TheSubr(fun)->opt_count;
  4216. key_count = TheSubr(fun)->key_count;
  4217. if (args_on_stack < req_count) {
  4218. /* fewer Arguments there than required */
  4219. req_count = req_count - args_on_stack; /* as many as these must go on STACK */
  4220. /* reserve space on STACK: */
  4221. get_space_on_STACK(sizeof(gcv_object_t) * (uintL)(req_count + opt_count + key_count));
  4222. /* store required Parameter in Stack: */
  4223. {
  4224. var uintC count;
  4225. dotimespC(count,req_count, {
  4226. if (atomp(args))
  4227. goto error_toofew;
  4228. pushSTACK(Car(args)); /* store next Argument */
  4229. args = Cdr(args);
  4230. });
  4231. }
  4232. goto optionals_from_list;
  4233. }
  4234. args_on_stack -= req_count; /* remaining number */
  4235. if (args_on_stack < opt_count) {
  4236. /* Arguments in Stack don't last for the optional ones */
  4237. opt_count = opt_count - args_on_stack; /* as many as these must go on STACK */
  4238. /* reserve space on STACK: */
  4239. get_space_on_STACK(sizeof(gcv_object_t) * (uintL)(opt_count + key_count));
  4240. optionals_from_list:
  4241. { /* store optional Parameters on Stack: */
  4242. var uintC count = opt_count;
  4243. while (!atomp(args)) { /* argument-list not finished? */
  4244. if (count==0) /* all optional Parameters supplied with? */
  4245. goto optionals_ok;
  4246. count--;
  4247. pushSTACK(Car(args)); /* store next Argument */
  4248. args = Cdr(args);
  4249. }
  4250. /* Argument-list finished.
  4251. All further count optional Parameters receive the "value"
  4252. #<UNBOUND>, including the Keyword-Parameters: */
  4253. dotimesC(count,count + key_count, { pushSTACK(unbound); } );
  4254. if (TheSubr(fun)->rest_flag == subr_rest) { /* &REST-Flag? */
  4255. /* yes -> 0 additional Arguments: */
  4256. argcount = 0; rest_args_pointer = args_end_pointer;
  4257. goto apply_subr_rest;
  4258. } else {
  4259. /* no -> nothing to do */
  4260. goto apply_subr_norest;
  4261. }
  4262. }
  4263. optionals_ok: /* optional Argument OK, continue processing (non-empty) list */
  4264. if (TheSubr(fun)->key_flag == subr_nokey) {
  4265. /* SUBR without KEY */
  4266. if (TheSubr(fun)->rest_flag == subr_norest)
  4267. /* SUBR without REST or KEY */
  4268. error_subr_toomany(fun); /* too many Arguments */
  4269. else
  4270. /* SUBR with only REST, without KEY */
  4271. goto apply_subr_rest_onlylist;
  4272. } else {
  4273. /* SUBR with KEY */
  4274. key_args_pointer = args_end_pointer;
  4275. {
  4276. var uintC count;
  4277. dotimesC(count,key_count, { pushSTACK(unbound); } );
  4278. }
  4279. rest_args_pointer = args_end_pointer;
  4280. argcount = 0;
  4281. goto key_from_list;
  4282. }
  4283. }
  4284. args_on_stack -= opt_count; /* remaining number */
  4285. if (TheSubr(fun)->key_flag == subr_nokey) {
  4286. /* SUBR without KEY */
  4287. if (TheSubr(fun)->rest_flag == subr_norest) {
  4288. /* SUBR without REST or KEY */
  4289. if ((args_on_stack>0) || consp(args)) /* still Arguments? */
  4290. error_subr_toomany(fun);
  4291. goto apply_subr_norest;
  4292. } else
  4293. /* SUBR with only REST, without KEY */
  4294. goto apply_subr_rest_withlist;
  4295. } else
  4296. /* SUBR with Keywords. */
  4297. goto apply_subr_key_;
  4298. }
  4299. apply_subr_key:
  4300. key_count = TheSubr(fun)->key_count;
  4301. apply_subr_key_:
  4302. /* shift down remaining Arguments on STACK and thus
  4303. create room for the Keyword-Parameters: */
  4304. argcount = args_on_stack;
  4305. get_space_on_STACK(sizeof(gcv_object_t) * (uintL)key_count);
  4306. {
  4307. var gcv_object_t* new_args_end_pointer = args_end_pointer STACKop -(uintP)key_count;
  4308. var gcv_object_t* ptr1 = args_end_pointer;
  4309. var gcv_object_t* ptr2 = new_args_end_pointer;
  4310. var uintC count;
  4311. dotimesC(count,args_on_stack, { BEFORE(ptr2) = BEFORE(ptr1); } );
  4312. key_args_pointer = ptr1;
  4313. rest_args_pointer = ptr2;
  4314. dotimesC(count,key_count, { NEXT(ptr1) = unbound; } );
  4315. set_args_end_pointer(new_args_end_pointer);
  4316. }
  4317. key_from_list: /* take remaining Arguments for Keywords from list */
  4318. while (consp(args)) {
  4319. check_STACK(); pushSTACK(Car(args)); /* push next argument onto Stack */
  4320. args = Cdr(args);
  4321. argcount++;
  4322. }
  4323. /* assign Keywords and poss. discard remaining arguments: */
  4324. match_subr_key(fun,argcount,key_args_pointer,rest_args_pointer);
  4325. if (TheSubr(fun)->rest_flag != subr_norest)
  4326. /* SUBR with &REST-Flag: */
  4327. goto apply_subr_rest;
  4328. else
  4329. /* SUBR without &REST-Flag: */
  4330. goto apply_subr_norest;
  4331. }
  4332. apply_subr_rest_onlylist:
  4333. argcount = 0; rest_args_pointer = args_end_pointer;
  4334. goto rest_from_list;
  4335. apply_subr_rest_withlist:
  4336. argcount = args_on_stack;
  4337. rest_args_pointer = args_end_pointer STACKop argcount;
  4338. rest_from_list: /* take remaining Arguments from list */
  4339. while (consp(args)) {
  4340. check_STACK(); pushSTACK(Car(args)); /* next argument onto Stack */
  4341. args = Cdr(args);
  4342. argcount++;
  4343. }
  4344. if (((uintL)~(uintL)0 > ca_limit_1) && (argcount > ca_limit_1)) /* too many arguments? */
  4345. goto error_toomany;
  4346. apply_subr_rest:
  4347. if (!nullp(args))
  4348. goto error_dotted;
  4349. with_saved_back_trace_subr(fun,STACK,
  4350. TheSubr(fun)->req_count + TheSubr(fun)->opt_count + argcount,
  4351. (*(subr_rest_function_t*)(TheSubr(fun)->function))(argcount,rest_args_pointer); );
  4352. goto done;
  4353. apply_subr_norest:
  4354. if (!nullp(args))
  4355. goto error_dotted;
  4356. with_saved_back_trace_subr(fun,STACK,-1,
  4357. (*(subr_norest_function_t*)(TheSubr(fun)->function))(); );
  4358. done:
  4359. CHECK_STACK_S(args_end_pointer,fun);
  4360. return; /* finished */
  4361. /* gathered error messages: */
  4362. error_toofew: error_subr_toofew(fun,args);
  4363. error_toomany: error_subr_toomany(fun);
  4364. error_dotted: error_apply_dotted(TheSubr(fun)->name,args);
  4365. }
  4366. /* Error because of too many arguments for a Closure
  4367. > closure: function, a Closure */
  4368. nonreturning_function(local, error_closure_toomany, (object closure));
  4369. #define error_closure_toomany(closure) error_apply_toomany(closure)
  4370. /* Error because of too few arguments for a Closure
  4371. > closure: function, a Closure
  4372. > tail: atom at the end of the argument list */
  4373. nonreturning_function(local, error_closure_toofew, (object closure, object tail));
  4374. #define error_closure_toofew(closure,tail) error_apply_toofew(closure,tail)
  4375. /* In APPLY: Applies a Closure to an argument-list, cleans up STACK
  4376. and returns the values.
  4377. apply_closure(fun,args_on_stack,other_args);
  4378. > fun: function, a Closure
  4379. > Argumente: args_on_stack arguments on STACK,
  4380. remaining argument-list in other_args
  4381. < STACK: cleaned up (i.e. STACK is increased by args_on_stack)
  4382. < mv_count/mv_space: values
  4383. changes STACK, can trigger GC */
  4384. local maygc Values apply_closure (object closure, uintC args_on_stack, object args)
  4385. {
  4386. TRACE_CALL(closure,'A','C');
  4387. if (simple_bit_vector_p(Atype_8Bit,TheClosure(closure)->clos_codevec)) {
  4388. /* closure is a compiled Closure */
  4389. #if STACKCHECKC
  4390. var gcv_object_t* args_pointer = args_end_pointer STACKop args_on_stack; /* Pointer to the arguments */
  4391. #endif
  4392. var object codevec = TheCclosure(closure)->clos_codevec; /* Code-Vector */
  4393. var gcv_object_t* key_args_pointer; /* Pointer to the Keyword-arguments */
  4394. var gcv_object_t* rest_args_pointer; /* Pointer to the remaining arguments */
  4395. var uintL argcount; /* number of remaining arguments */
  4396. check_SP(); check_STACK();
  4397. /* put argumente in STACK:
  4398. first a Dispatch for the most important cases: */
  4399. switch (TheCodevec(codevec)->ccv_signature) {
  4400. /* Macro for a required-argument: */
  4401. #define REQ_ARG() \
  4402. { if (args_on_stack>0) { args_on_stack--; } \
  4403. else if (consp(args)) { pushSTACK(Car(args)); args = Cdr(args); } \
  4404. else goto error_toofew; \
  4405. }
  4406. /* Macro for the n-last optional-argument: */
  4407. #define OPT_ARG(n) \
  4408. { if (args_on_stack>0) { args_on_stack--; } \
  4409. else if (consp(args)) { pushSTACK(Car(args)); args = Cdr(args); } \
  4410. else goto unbound_optional_##n; \
  4411. }
  4412. case (uintB)cclos_argtype_5_0: /* 5 required arguments */
  4413. REQ_ARG();
  4414. case (uintB)cclos_argtype_4_0: /* 4 required arguments */
  4415. REQ_ARG();
  4416. case (uintB)cclos_argtype_3_0: /* 3 required arguments */
  4417. REQ_ARG();
  4418. case (uintB)cclos_argtype_2_0: /* 2 required arguments */
  4419. REQ_ARG();
  4420. case (uintB)cclos_argtype_1_0: /* 1 required argument */
  4421. REQ_ARG();
  4422. case (uintB)cclos_argtype_0_0: /* no Arguments */
  4423. noch_0_opt_args:
  4424. if (args_on_stack>0) goto error_toomany;
  4425. if (!nullp(args)) {
  4426. if (consp(args))
  4427. goto error_toomany;
  4428. else
  4429. goto error_dotted;
  4430. }
  4431. goto apply_cclosure_nokey;
  4432. case (uintB)cclos_argtype_4_1: /* 4 required and 1 optional */
  4433. REQ_ARG();
  4434. case (uintB)cclos_argtype_3_1: /* 3 required and 1 optional */
  4435. REQ_ARG();
  4436. case (uintB)cclos_argtype_2_1: /* 2 required and 1 optional */
  4437. REQ_ARG();
  4438. case (uintB)cclos_argtype_1_1: /* 1 required and 1 optional */
  4439. REQ_ARG();
  4440. case (uintB)cclos_argtype_0_1: /* 1 optional argument */
  4441. noch_1_opt_args:
  4442. OPT_ARG(1);
  4443. goto noch_0_opt_args;
  4444. case (uintB)cclos_argtype_3_2: /* 3 required and 2 optional */
  4445. REQ_ARG();
  4446. case (uintB)cclos_argtype_2_2: /* 2 required and 2 optional */
  4447. REQ_ARG();
  4448. case (uintB)cclos_argtype_1_2: /* 1 required and 2 optional */
  4449. REQ_ARG();
  4450. case (uintB)cclos_argtype_0_2: /* 2 optional arguments */
  4451. noch_2_opt_args:
  4452. OPT_ARG(2);
  4453. goto noch_1_opt_args;
  4454. case (uintB)cclos_argtype_2_3: /* 2 required and 3 optional */
  4455. REQ_ARG();
  4456. case (uintB)cclos_argtype_1_3: /* 1 required and 3 optional */
  4457. REQ_ARG();
  4458. case (uintB)cclos_argtype_0_3: /* 3 optional arguments */
  4459. noch_3_opt_args:
  4460. OPT_ARG(3);
  4461. goto noch_2_opt_args;
  4462. case (uintB)cclos_argtype_1_4: /* 1 required and 4 optional */
  4463. REQ_ARG();
  4464. case (uintB)cclos_argtype_0_4: /* 4 optional arguments */
  4465. noch_4_opt_args:
  4466. OPT_ARG(4);
  4467. goto noch_3_opt_args;
  4468. case (uintB)cclos_argtype_0_5: /* 5 optional arguments */
  4469. OPT_ARG(5);
  4470. goto noch_4_opt_args;
  4471. unbound_optional_5: /* Still 5 optional Arguments, but args_on_stack=0 and atomp(args) */
  4472. { pushSTACK(unbound); }
  4473. unbound_optional_4: /* Still 4 optional Arguments, but args_on_stack=0 and atomp(args) */
  4474. { pushSTACK(unbound); }
  4475. unbound_optional_3: /* Still 3 optional Arguments, but args_on_stack=0 and atomp(args) */
  4476. { pushSTACK(unbound); }
  4477. unbound_optional_2: /* Still 2 optional Arguments, but args_on_stack=0 and atomp(args) */
  4478. { pushSTACK(unbound); }
  4479. unbound_optional_1: /* Still 1 optional Argument, but args_on_stack=0 and atomp(args) */
  4480. { pushSTACK(unbound); }
  4481. if (!nullp(args)) goto error_dotted;
  4482. goto apply_cclosure_nokey;
  4483. case (uintB)cclos_argtype_4_0_rest: /* 4 required + &rest */
  4484. REQ_ARG();
  4485. case (uintB)cclos_argtype_3_0_rest: /* 3 required + &rest */
  4486. REQ_ARG();
  4487. case (uintB)cclos_argtype_2_0_rest: /* 2 required + &rest */
  4488. REQ_ARG();
  4489. case (uintB)cclos_argtype_1_0_rest: /* 1 required + &rest */
  4490. REQ_ARG();
  4491. case (uintB)cclos_argtype_0_0_rest: /* no Arguments, Rest-Parameter */
  4492. goto apply_cclosure_rest_nokey;
  4493. case (uintB)cclos_argtype_4_0_key: /* 4 required arguments, &key */
  4494. REQ_ARG();
  4495. case (uintB)cclos_argtype_3_0_key: /* 3 required arguments, &key */
  4496. REQ_ARG();
  4497. case (uintB)cclos_argtype_2_0_key: /* 2 required arguments, &key */
  4498. REQ_ARG();
  4499. case (uintB)cclos_argtype_1_0_key: /* 1 required argument, &key */
  4500. REQ_ARG();
  4501. noch_0_opt_args_key:
  4502. case (uintB)cclos_argtype_0_0_key: /* only &key */
  4503. if ((args_on_stack==0) && atomp(args)) goto unbound_optional_key_0;
  4504. goto apply_cclosure_key_withlist;
  4505. case (uintB)cclos_argtype_3_1_key:
  4506. /* 3 required arguments and 1 optional argument, &key */
  4507. REQ_ARG();
  4508. case (uintB)cclos_argtype_2_1_key:
  4509. /* 2 required arguments and 1 optional argument, &key */
  4510. REQ_ARG();
  4511. case (uintB)cclos_argtype_1_1_key:
  4512. /* 1 required argument and 1 optional argument, &key */
  4513. REQ_ARG();
  4514. case (uintB)cclos_argtype_0_1_key: /* 1 optional argument, &key */
  4515. noch_1_opt_args_key:
  4516. OPT_ARG(key_1);
  4517. goto noch_0_opt_args_key;
  4518. case (uintB)cclos_argtype_2_2_key:
  4519. /* 2 required arguments and 2 optional arguments, &key */
  4520. REQ_ARG();
  4521. case (uintB)cclos_argtype_1_2_key:
  4522. /* 1 required argument and 2 optional arguments, &key */
  4523. REQ_ARG();
  4524. case (uintB)cclos_argtype_0_2_key:
  4525. /* 2 optional arguments, &key */
  4526. noch_2_opt_args_key:
  4527. OPT_ARG(key_2);
  4528. goto noch_1_opt_args_key;
  4529. case (uintB)cclos_argtype_1_3_key:
  4530. /* 1 required argument and 3 optional arguments, &key */
  4531. REQ_ARG();
  4532. case (uintB)cclos_argtype_0_3_key:
  4533. /* 3 optional arguments, &key */
  4534. noch_3_opt_args_key:
  4535. OPT_ARG(key_3);
  4536. goto noch_2_opt_args_key;
  4537. case (uintB)cclos_argtype_0_4_key:
  4538. /* 4 optional arguments, &key */
  4539. OPT_ARG(key_4);
  4540. goto noch_3_opt_args_key;
  4541. unbound_optional_key_4: /* Still 4 optional Arguments, but args_on_stack=0 and atomp(args) */
  4542. { pushSTACK(unbound); }
  4543. unbound_optional_key_3: /* Still 3 optional Arguments, but args_on_stack=0 and atomp(args) */
  4544. { pushSTACK(unbound); }
  4545. unbound_optional_key_2: /* Still 2 optional Arguments, but args_on_stack=0 and atomp(args) */
  4546. { pushSTACK(unbound); }
  4547. unbound_optional_key_1: /* Still 1 optional Argument, but args_on_stack=0 and atomp(args) */
  4548. { pushSTACK(unbound); }
  4549. unbound_optional_key_0: /* Before the Keywords is args_on_stack=0 and atomp(args) */
  4550. if (!nullp(args)) goto error_dotted;
  4551. goto apply_cclosure_key_noargs;
  4552. case (uintB)cclos_argtype_default:
  4553. /* General Version */
  4554. break;
  4555. default: NOTREACHED;
  4556. #undef OPT_ARG
  4557. #undef REQ_ARG
  4558. }
  4559. /* Now the general Version: */
  4560. {
  4561. var uintB flags;
  4562. {
  4563. var uintC req_count = TheCodevec(codevec)->ccv_numreq; /* number of required Parameters */
  4564. var uintC opt_count = TheCodevec(codevec)->ccv_numopt; /* number of optional Parameters */
  4565. flags = TheCodevec(codevec)->ccv_flags; /* Flags */
  4566. if (args_on_stack < req_count) {
  4567. /* fewer Arguments than demanded */
  4568. req_count = req_count - args_on_stack; /* as many as these must on STACK */
  4569. /* reserve space on STACK: */
  4570. get_space_on_STACK(sizeof(gcv_object_t) * (uintL)(req_count + opt_count));
  4571. /* store required Parameters on Stack: */
  4572. {
  4573. var uintC count;
  4574. dotimespC(count,req_count, {
  4575. if (atomp(args))
  4576. goto error_toofew;
  4577. pushSTACK(Car(args)); /* store next argument */
  4578. args = Cdr(args);
  4579. });
  4580. }
  4581. goto optionals_from_list;
  4582. }
  4583. args_on_stack -= req_count; /* remaining number */
  4584. if (args_on_stack < opt_count) {
  4585. /* Arguments in Stack don't last for the optional ones */
  4586. opt_count = opt_count - args_on_stack; /* as many as these must go on STACK */
  4587. /* reserve space on STACK: */
  4588. get_space_on_STACK(sizeof(gcv_object_t) * (uintL)opt_count);
  4589. optionals_from_list:
  4590. { /* store optional parameters on Stack: */
  4591. var uintC count = opt_count;
  4592. while (!atomp(args)) { /* argument-list not finished? */
  4593. if (count==0) /* all optional parameters supplied with? */
  4594. goto optionals_ok;
  4595. count--;
  4596. pushSTACK(Car(args)); /* store next argument */
  4597. args = Cdr(args);
  4598. }
  4599. /* argument-list finished. */
  4600. if (!nullp(args)) goto error_dotted;
  4601. /* All further count optional parameters receive the "value"
  4602. #<UNBOUND>, the &REST-parameter receives NIL,
  4603. the Keyword-parameters receive the value #<UNBOUND> : */
  4604. dotimesC(count,count, { pushSTACK(unbound); } );
  4605. }
  4606. if (flags & bit(0)) /* &REST-Flag? */
  4607. pushSTACK(NIL); /* yes -> initialize with NIL */
  4608. if (flags & bit(7)) /* &KEY-Flag? */
  4609. goto apply_cclosure_key_noargs;
  4610. else
  4611. goto apply_cclosure_nokey;
  4612. optionals_ok:
  4613. /* process Rest- and Keyword-parameters.
  4614. args = remaining argument-list (not yet finished) */
  4615. if (flags == 0)
  4616. /* Closure without REST or KEY -> argument-list should be finished */
  4617. goto error_toomany;
  4618. /* poss. fill the Rest-parameter: */
  4619. if (flags & bit(0))
  4620. pushSTACK(args);
  4621. if (flags & bit(7)) { /* Key-Flag? */
  4622. /* Closure with Keywords.
  4623. args = remaining argument-list (not yet finished)
  4624. First initialize the Keyword-parameters with #<UNBOUND> ,
  4625. the store the remaining arguments in Stack,
  4626. then assign the Keywords: */
  4627. key_args_pointer = args_end_pointer; /* Pointer to the Keyword-parameters */
  4628. /* initialize all Keyword-parameters with #<UNBOUND> : */
  4629. {
  4630. var uintC count = TheCodevec(codevec)->ccv_numkey;
  4631. dotimesC(count,count, { pushSTACK(unbound); } );
  4632. }
  4633. rest_args_pointer = args_end_pointer; /* Pointer to the remaining arguments */
  4634. argcount = 0; /* counter for the remaining arguments */
  4635. goto key_from_list;
  4636. } else
  4637. /* Closure with only REST, without KEY: */
  4638. goto apply_cclosure_nokey;
  4639. }
  4640. args_on_stack -= opt_count; /* remaining number */
  4641. if (flags & bit(7)) /* Key-Flag? */
  4642. goto apply_cclosure_key_withlist_;
  4643. else if (flags & bit(0))
  4644. goto apply_cclosure_rest_nokey;
  4645. else {
  4646. /* Closure without REST or KEY */
  4647. if ((args_on_stack>0) || consp(args)) /* still arguments? */
  4648. goto error_toomany;
  4649. goto apply_cclosure_nokey;
  4650. }
  4651. }
  4652. apply_cclosure_key_noargs:
  4653. {
  4654. var uintC key_count = TheCodevec(codevec)->ccv_numkey; /* number of Keyword-parameters */
  4655. if (key_count > 0) {
  4656. get_space_on_STACK(sizeof(gcv_object_t) * (uintL)key_count);
  4657. var uintC count;
  4658. dotimespC(count,key_count, { pushSTACK(unbound); } ); /* initialize with #<UNBOUND> */
  4659. }
  4660. goto apply_cclosure_key;
  4661. }
  4662. apply_cclosure_key_withlist:
  4663. flags = TheCodevec(codevec)->ccv_flags; /* initialize flags! */
  4664. apply_cclosure_key_withlist_:
  4665. /* Closure with Keywords */
  4666. {
  4667. var uintC key_count = TheCodevec(codevec)->ccv_numkey; /* number of Keyword-parameters */
  4668. /* shift down remaining arguments in STACK and thus
  4669. create room for the Keyword-parameters
  4670. (and poss. Rest-parameters): */
  4671. var uintL shift = key_count;
  4672. if (flags & bit(0))
  4673. shift++; /* poss. 1 more for Rest-Parameter */
  4674. argcount = args_on_stack;
  4675. get_space_on_STACK(sizeof(gcv_object_t) * shift);
  4676. var gcv_object_t* new_args_end_pointer = args_end_pointer STACKop -(uintP)shift;
  4677. var gcv_object_t* ptr1 = args_end_pointer;
  4678. var gcv_object_t* ptr2 = new_args_end_pointer;
  4679. var uintC count;
  4680. dotimesC(count,args_on_stack, { BEFORE(ptr2) = BEFORE(ptr1); } );
  4681. if (flags & bit(0))
  4682. NEXT(ptr1) = args; /* Rest-Parameter (preliminary) */
  4683. key_args_pointer = ptr1;
  4684. rest_args_pointer = ptr2;
  4685. dotimesC(count,key_count, { NEXT(ptr1) = unbound; } );
  4686. set_args_end_pointer(new_args_end_pointer);
  4687. if (flags & bit(0))
  4688. /* fill Rest-Parameter, less effort than with match_cclosure_key: */
  4689. if (args_on_stack > 0) {
  4690. var gcv_object_t* ptr3 = new_args_end_pointer;
  4691. pushSTACK(closure); /* save Closure */
  4692. pushSTACK(args); /* save args */
  4693. dotimespC(count,args_on_stack, {
  4694. var object new_cons = allocate_cons();
  4695. Car(new_cons) = BEFORE(ptr3);
  4696. Cdr(new_cons) = Before(key_args_pointer);
  4697. Before(key_args_pointer) = new_cons;
  4698. });
  4699. args = popSTACK();
  4700. closure = popSTACK();
  4701. }
  4702. }
  4703. key_from_list: /* remove remaining arguments for Keywords from list */
  4704. while (consp(args)) {
  4705. check_STACK(); pushSTACK(Car(args)); /* store next argument in Stack */
  4706. args = Cdr(args);
  4707. argcount++;
  4708. }
  4709. /* argument-list finished. */
  4710. if (!nullp(args)) goto error_dotted;
  4711. /* assign Keywords, build Rest-parameter
  4712. and poss. discard remaining arguments: */
  4713. closure = match_cclosure_key(closure,argcount,key_args_pointer,rest_args_pointer);
  4714. codevec = TheCclosure(closure)->clos_codevec;
  4715. apply_cclosure_key:
  4716. interpret_bytecode(closure,codevec,CCV_START_KEY); /* process Bytecode starting at Byte 12 */
  4717. goto done;
  4718. }
  4719. apply_cclosure_rest_nokey:
  4720. /* Closure with only REST, without KEY:
  4721. still has to cons args_on_stack Arguments from Stack to args: */
  4722. pushSTACK(args);
  4723. if (args_on_stack > 0) {
  4724. pushSTACK(closure); /* Closure must be saved */
  4725. dotimespC(args_on_stack,args_on_stack, {
  4726. var object new_cons = allocate_cons();
  4727. Cdr(new_cons) = STACK_1;
  4728. Car(new_cons) = STACK_2; /* cons next argument to it */
  4729. STACK_2 = new_cons;
  4730. STACK_1 = STACK_0; skipSTACK(1);
  4731. });
  4732. closure = popSTACK(); codevec = TheCclosure(closure)->clos_codevec;
  4733. }
  4734. goto apply_cclosure_nokey;
  4735. apply_cclosure_nokey: /* jump to Closure without &KEY: */
  4736. interpret_bytecode(closure,codevec,CCV_START_NONKEY); /* process Bytecode starting at Byte 8 */
  4737. done:
  4738. CHECK_STACK_C(args_end_pointer,closure);
  4739. return; /* finished */
  4740. } else {
  4741. /* closure is an interpreted Closure
  4742. reserve space on STACK: */
  4743. get_space_on_STACK(sizeof(gcv_object_t) * llength(args));
  4744. while (consp(args)) { /* Still Arguments in list? */
  4745. pushSTACK(Car(args)); /* push next Element in STACK */
  4746. args = Cdr(args);
  4747. args_on_stack += 1;
  4748. if (((uintL)~(uintL)0 > ca_limit_1) && (args_on_stack > ca_limit_1))
  4749. goto error_toomany;
  4750. }
  4751. var gcv_object_t* args_pointer = args_end_pointer STACKop args_on_stack;
  4752. with_saved_back_trace_iclosure(closure,args_pointer,args_on_stack,
  4753. funcall_iclosure(closure,args_pointer,args_on_stack); );
  4754. return; /* finished */
  4755. }
  4756. /* Gathered error-messages: */
  4757. error_toofew: error_closure_toofew(closure,args);
  4758. error_toomany: error_closure_toomany(closure);
  4759. error_dotted: error_apply_dotted(closure,args);
  4760. }
  4761. /* ----------------------- F U N C A L L ----------------------- */
  4762. /* later: */
  4763. local Values funcall_subr (object fun, uintC args_on_stack);
  4764. local Values funcall_closure (object fun, uintC args_on_stack);
  4765. /* UP: Applies a function to its arguments.
  4766. funcall(function,argcount);
  4767. > function: function
  4768. > Argumente: argcount arguments on STACK
  4769. < STACK: cleaned up (i.e. STACK is increased by argcount)
  4770. < mv_count/mv_space: values
  4771. changes STACK, can trigger GC */
  4772. global maygc Values funcall (object fun, uintC args_on_stack)
  4773. {
  4774. funcall_restart:
  4775. /* fun must be a SUBR or a Closure or a Cons (LAMBDA ...) : */
  4776. if (subrp(fun)) { /* SUBR ? */
  4777. return_Values funcall_subr(fun,args_on_stack);
  4778. } else if (closurep(fun)) { /* Closure ? */
  4779. return_Values funcall_closure(fun,args_on_stack);
  4780. } else if (symbolp(fun)) { /* Symbol ? */
  4781. /* apply Symbol: global Definition Symbol_function(fun) applies. */
  4782. var object fdef = Symbol_function(fun);
  4783. if (subrp(fdef)) { /* SUBR -> apply */
  4784. return_Values funcall_subr(fdef,args_on_stack);
  4785. } else if (closurep(fdef)) { /* Closure -> apply */
  4786. return_Values funcall_closure(fdef,args_on_stack);
  4787. } else if (orecordp(fdef)) {
  4788. #ifdef DYNAMIC_FFI
  4789. if (ffunctionp(fdef)) { /* Foreign-Function ? */
  4790. fun = fdef; goto call_ffunction;
  4791. }
  4792. #endif
  4793. switch (Record_type(fdef)) {
  4794. case Rectype_Fsubr: { error_specialform(S(funcall),fun); }
  4795. case Rectype_Macro: { error_macro(S(funcall),fun); }
  4796. default: NOTREACHED;
  4797. }
  4798. } else
  4799. /* if no SUBR, no Closure, no FSUBR, no Macro:
  4800. Symbol_function(fun) must be #<UNBOUND> . */
  4801. goto undef;
  4802. } else if (funnamep(fun)) { /* list (SETF symbol) ? */
  4803. /* global definition (symbol-function (get-setf-symbol symbol)) applies. */
  4804. var object symbol = get(Car(Cdr(fun)),S(setf_function)); /* (get ... 'SYS::SETF-FUNCTION) */
  4805. if (!symbolp(symbol)) /* should be (uninterned) symbol */
  4806. goto undef; /* else undefined */
  4807. var object fdef = Symbol_function(symbol);
  4808. if (closurep(fdef)) { /* Closure -> apply */
  4809. return_Values funcall_closure(fdef,args_on_stack);
  4810. } else if (subrp(fdef)) { /* SUBR -> apply */
  4811. return_Values funcall_subr(fdef,args_on_stack);
  4812. }
  4813. #ifdef DYNAMIC_FFI
  4814. else if (ffunctionp(fdef)) { /* Foreign-Function ? */
  4815. fun = fdef; goto call_ffunction;
  4816. }
  4817. #endif
  4818. else
  4819. /* Such function-names cannot denote FSUBRs or Macros.
  4820. fdef is presumable #<UNBOUND> . */
  4821. goto undef;
  4822. }
  4823. #ifdef DYNAMIC_FFI
  4824. else if (ffunctionp(fun)) /* Foreign-Function ? */
  4825. call_ffunction: { /* call (SYS::FOREIGN-CALL-OUT foreign-function . args) */
  4826. /* First shift down the arguments in Stack by 1. */
  4827. var uintC count;
  4828. var gcv_object_t* ptr = &STACK_0;
  4829. dotimesC(count,args_on_stack, {
  4830. *(ptr STACKop -1) = *ptr; ptr skipSTACKop 1;
  4831. });
  4832. *(ptr STACKop -1) = fun;
  4833. skipSTACK(-1);
  4834. return_Values funcall_subr(L(foreign_call_out),args_on_stack+1);
  4835. }
  4836. #endif
  4837. else if (consp(fun) && eq(Car(fun),S(lambda))) /* Cons (LAMBDA ...) ? */
  4838. error_lambda_expression(S(funcall),fun);
  4839. else {
  4840. fun = check_funname_replacement(type_error,S(funcall),fun);
  4841. goto funcall_restart;
  4842. }
  4843. return;
  4844. undef:
  4845. fun = check_fdefinition(fun,S(funcall));
  4846. goto funcall_restart;
  4847. }
  4848. /* In FUNCALL: Applies a SUBR to arguments, cleans up STACK
  4849. and returns the values.
  4850. funcall_subr(fun,args_on_stack);
  4851. > fun: function, a SUBR
  4852. > Arguments: args_on_stack arguments on STACK
  4853. < STACK: cleaned up (i.e. STACK is increased by args_on_stack)
  4854. < mv_count/mv_space: values
  4855. changes STACK, can trigger GC */
  4856. local maygc Values funcall_subr (object fun, uintC args_on_stack)
  4857. {
  4858. #if STACKCHECKS
  4859. var gcv_object_t* args_pointer = args_end_pointer STACKop args_on_stack; /* Pointer to the arguments */
  4860. #endif
  4861. var gcv_object_t* key_args_pointer; /* Pointer to the Keyword-arguments */
  4862. var gcv_object_t* rest_args_pointer; /* Pointer to the remaining arguments */
  4863. var uintL argcount; /* number of remaining arguments */
  4864. TRACE_CALL(fun,'F','S');
  4865. /* store arguments in STACK:
  4866. First a Dispatch for the most important cases: */
  4867. switch (TheSubr(fun)->argtype) {
  4868. case (uintW)subr_argtype_0_0: /* SUBR without Arguments */
  4869. if (!(args_on_stack==0)) goto error_toomany;
  4870. goto apply_subr_norest;
  4871. case (uintW)subr_argtype_1_0: /* SUBR with 1 required argument */
  4872. if (!(args_on_stack==1)) goto error_count;
  4873. goto apply_subr_norest;
  4874. case (uintW)subr_argtype_2_0: /* SUBR with 2 required arguments */
  4875. if (!(args_on_stack==2)) goto error_count;
  4876. goto apply_subr_norest;
  4877. case (uintW)subr_argtype_3_0: /* SUBR with 3 required arguments */
  4878. if (!(args_on_stack==3)) goto error_count;
  4879. goto apply_subr_norest;
  4880. case (uintW)subr_argtype_4_0: /* SUBR with 4 required arguments */
  4881. if (!(args_on_stack==4)) goto error_count;
  4882. goto apply_subr_norest;
  4883. case (uintW)subr_argtype_5_0: /* SUBR with 5 required arguments */
  4884. if (!(args_on_stack==5)) goto error_count;
  4885. goto apply_subr_norest;
  4886. case (uintW)subr_argtype_6_0: /* SUBR with 6 required arguments */
  4887. if (!(args_on_stack==6)) goto error_count;
  4888. goto apply_subr_norest;
  4889. case (uintW)subr_argtype_0_1: /* SUBR with 1 optional argument */
  4890. if (args_on_stack==1) goto apply_subr_norest;
  4891. else if (args_on_stack>1) goto error_toomany;
  4892. else { pushSTACK(unbound); goto apply_subr_norest; }
  4893. case (uintW)subr_argtype_1_1: /* SUBR with 1 required and 1 optional */
  4894. if (args_on_stack==2) goto apply_subr_norest;
  4895. else if (args_on_stack>2) goto error_toomany;
  4896. else if (args_on_stack==0) goto error_toofew;
  4897. else { pushSTACK(unbound); goto apply_subr_norest; }
  4898. case (uintW)subr_argtype_2_1: /* SUBR with 2 required and 1 optional */
  4899. if (args_on_stack==3) goto apply_subr_norest;
  4900. else if (args_on_stack>3) goto error_toomany;
  4901. else if (args_on_stack<2) goto error_toofew;
  4902. else { pushSTACK(unbound); goto apply_subr_norest; }
  4903. case (uintW)subr_argtype_3_1: /* SUBR with 3 required and 1 optional */
  4904. if (args_on_stack==4) goto apply_subr_norest;
  4905. else if (args_on_stack>4) goto error_toomany;
  4906. else if (args_on_stack<3) goto error_toofew;
  4907. else { pushSTACK(unbound); goto apply_subr_norest; }
  4908. case (uintW)subr_argtype_4_1: /* SUBR with 4 required and 1 optional */
  4909. if (args_on_stack==5) goto apply_subr_norest;
  4910. else if (args_on_stack>5) goto error_toomany;
  4911. else if (args_on_stack<4) goto error_toofew;
  4912. else { pushSTACK(unbound); goto apply_subr_norest; }
  4913. case (uintW)subr_argtype_0_2: /* SUBR with 2 optional arguments */
  4914. switch (args_on_stack) {
  4915. case 0: { pushSTACK(unbound); }
  4916. case 1: { pushSTACK(unbound); }
  4917. case 2: goto apply_subr_norest;
  4918. default: goto error_toomany;
  4919. }
  4920. case (uintW)subr_argtype_1_2: /* SUBR with 1 required and 2 optional */
  4921. switch (args_on_stack) {
  4922. case 0: goto error_toofew;
  4923. case 1: { pushSTACK(unbound); }
  4924. case 2: { pushSTACK(unbound); }
  4925. case 3: goto apply_subr_norest;
  4926. default: goto error_toomany;
  4927. }
  4928. case (uintW)subr_argtype_2_2: /* SUBR with 2 required and 2 optional */
  4929. switch (args_on_stack) {
  4930. case 0: goto error_toofew;
  4931. case 1: goto error_toofew;
  4932. case 2: { pushSTACK(unbound); }
  4933. case 3: { pushSTACK(unbound); }
  4934. case 4: goto apply_subr_norest;
  4935. default: goto error_toomany;
  4936. }
  4937. case (uintW)subr_argtype_3_2: /* SUBR with 3 required and 2 optional */
  4938. switch (args_on_stack) {
  4939. case 0: goto error_toofew;
  4940. case 1: goto error_toofew;
  4941. case 2: goto error_toofew;
  4942. case 3: { pushSTACK(unbound); }
  4943. case 4: { pushSTACK(unbound); }
  4944. case 5: goto apply_subr_norest;
  4945. default: goto error_toomany;
  4946. }
  4947. case (uintW)subr_argtype_0_3: /* SUBR with 3 optional arguments */
  4948. switch (args_on_stack) {
  4949. case 0: { pushSTACK(unbound); }
  4950. case 1: { pushSTACK(unbound); }
  4951. case 2: { pushSTACK(unbound); }
  4952. case 3: goto apply_subr_norest;
  4953. default: goto error_toomany;
  4954. }
  4955. case (uintW)subr_argtype_1_3: /* SUBR with 1 required and 3 optional */
  4956. switch (args_on_stack) {
  4957. case 0: goto error_toofew;
  4958. case 1: { pushSTACK(unbound); }
  4959. case 2: { pushSTACK(unbound); }
  4960. case 3: { pushSTACK(unbound); }
  4961. case 4: goto apply_subr_norest;
  4962. default: goto error_toomany;
  4963. }
  4964. case (uintW)subr_argtype_2_3: /* SUBR with 2 required and 3 optional */
  4965. switch (args_on_stack) {
  4966. case 0: goto error_toofew;
  4967. case 1: goto error_toofew;
  4968. case 2: { pushSTACK(unbound); }
  4969. case 3: { pushSTACK(unbound); }
  4970. case 4: { pushSTACK(unbound); }
  4971. case 5: goto apply_subr_norest;
  4972. default: goto error_toomany;
  4973. }
  4974. case (uintW)subr_argtype_0_4: /* SUBR with 4 optional arguments */
  4975. switch (args_on_stack) {
  4976. case 0: { pushSTACK(unbound); }
  4977. case 1: { pushSTACK(unbound); }
  4978. case 2: { pushSTACK(unbound); }
  4979. case 3: { pushSTACK(unbound); }
  4980. case 4: goto apply_subr_norest;
  4981. default: goto error_toomany;
  4982. }
  4983. case (uintW)subr_argtype_0_5: /* SUBR with 5 optional arguments */
  4984. switch (args_on_stack) {
  4985. case 0: { pushSTACK(unbound); }
  4986. case 1: { pushSTACK(unbound); }
  4987. case 2: { pushSTACK(unbound); }
  4988. case 3: { pushSTACK(unbound); }
  4989. case 4: { pushSTACK(unbound); }
  4990. case 5: goto apply_subr_norest;
  4991. default: goto error_toomany;
  4992. }
  4993. case (uintW)subr_argtype_0_0_rest: /* SUBR with &rest arguments */
  4994. goto apply_subr_rest_ok;
  4995. case (uintW)subr_argtype_1_0_rest: /* SUBR with 1 required and &rest */
  4996. if (args_on_stack==0) goto error_toofew;
  4997. args_on_stack -= 1;
  4998. goto apply_subr_rest_ok;
  4999. case (uintW)subr_argtype_2_0_rest: /* SUBR with 2 requireden and &rest */
  5000. if (args_on_stack<2) goto error_toofew;
  5001. args_on_stack -= 2;
  5002. goto apply_subr_rest_ok;
  5003. case (uintW)subr_argtype_3_0_rest: /* SUBR with 3 requireden and &rest */
  5004. if (args_on_stack<3) goto error_toofew;
  5005. args_on_stack -= 3;
  5006. goto apply_subr_rest_ok;
  5007. case (uintW)subr_argtype_0_0_key: /* SUBR with &key */
  5008. if (args_on_stack==0) goto unbound_optional_key_0;
  5009. else goto apply_subr_key;
  5010. case (uintW)subr_argtype_1_0_key: /* SUBR with 1 required and &key */
  5011. if (args_on_stack==1) goto unbound_optional_key_0;
  5012. else if (args_on_stack<1) goto error_toofew;
  5013. else { args_on_stack -= 1; goto apply_subr_key; }
  5014. case (uintW)subr_argtype_2_0_key: /* SUBR with 2 required and &key */
  5015. if (args_on_stack==2) goto unbound_optional_key_0;
  5016. else if (args_on_stack<2) goto error_toofew;
  5017. else { args_on_stack -= 2; goto apply_subr_key; }
  5018. case (uintW)subr_argtype_3_0_key: /* SUBR with 3 required and &key */
  5019. if (args_on_stack==3) goto unbound_optional_key_0;
  5020. else if (args_on_stack<3) goto error_toofew;
  5021. else { args_on_stack -= 3; goto apply_subr_key; }
  5022. case (uintW)subr_argtype_4_0_key: /* SUBR with 4 required and &key */
  5023. if (args_on_stack==4) goto unbound_optional_key_0;
  5024. else if (args_on_stack<4) goto error_toofew;
  5025. else { args_on_stack -= 4; goto apply_subr_key; }
  5026. case (uintW)subr_argtype_0_1_key: /* SUBR with 1 optional and &key */
  5027. switch (args_on_stack) {
  5028. case 0: goto unbound_optional_key_1;
  5029. case 1: goto unbound_optional_key_0;
  5030. default: args_on_stack -= 1; goto apply_subr_key;
  5031. }
  5032. case (uintW)subr_argtype_1_1_key:
  5033. /* SUBR with 1 required argument, 1 optional argument and &key */
  5034. switch (args_on_stack) {
  5035. case 0: goto error_toofew;
  5036. case 1: goto unbound_optional_key_1;
  5037. case 2: goto unbound_optional_key_0;
  5038. default: args_on_stack -= 2; goto apply_subr_key;
  5039. }
  5040. case (uintW)subr_argtype_1_2_key:
  5041. /* SUBR with 1 required argument, 2 optional arguments and &key */
  5042. switch (args_on_stack) {
  5043. case 0: goto error_toofew;
  5044. case 1: goto unbound_optional_key_2;
  5045. case 2: goto unbound_optional_key_1;
  5046. case 3: goto unbound_optional_key_0;
  5047. default: args_on_stack -= 3; goto apply_subr_key;
  5048. }
  5049. unbound_optional_key_2: /* Still 2 optional Arguments, but args_on_stack=0 */
  5050. { pushSTACK(unbound); }
  5051. unbound_optional_key_1: /* Still 1 optional Argument, but args_on_stack=0 */
  5052. { pushSTACK(unbound); }
  5053. unbound_optional_key_0: /* Before the Keywords is args_on_stack=0 */
  5054. {
  5055. var uintC count;
  5056. dotimesC(count,TheSubr(fun)->key_count, { pushSTACK(unbound); } );
  5057. }
  5058. goto apply_subr_norest;
  5059. default: NOTREACHED;
  5060. #undef OPT_ARG
  5061. #undef REQ_ARG
  5062. }
  5063. /* Now the general Version: */
  5064. {
  5065. var uintC key_count;
  5066. {
  5067. var uintC req_count = TheSubr(fun)->req_count;
  5068. var uintC opt_count = TheSubr(fun)->opt_count;
  5069. key_count = TheSubr(fun)->key_count;
  5070. if (args_on_stack < req_count)
  5071. /* fewer Arguments than demanded */
  5072. goto error_toofew;
  5073. args_on_stack -= req_count; /* remaining number */
  5074. if (args_on_stack <= opt_count) {
  5075. /* Arguments in Stack don't last for the optional ones */
  5076. opt_count = opt_count - args_on_stack; /* as many as these must go on STACK */
  5077. if (opt_count + key_count > 0) {
  5078. /* reserve space on STACK: */
  5079. get_space_on_STACK(sizeof(gcv_object_t) * (uintL)(opt_count + key_count));
  5080. /* All further count optional parameters receive the "value"
  5081. #<UNBOUND>, including the Keyword-parameters: */
  5082. var uintC count;
  5083. dotimespC(count,opt_count + key_count, { pushSTACK(unbound); } );
  5084. }
  5085. if (TheSubr(fun)->rest_flag == subr_rest) { /* &REST-Flag? */
  5086. /* yes -> 0 additional Arguments: */
  5087. argcount = 0; rest_args_pointer = args_end_pointer;
  5088. goto apply_subr_rest;
  5089. } else {
  5090. /* no -> nothing to do */
  5091. goto apply_subr_norest;
  5092. }
  5093. }
  5094. args_on_stack -= opt_count; /* remaining number (> 0) */
  5095. if (TheSubr(fun)->key_flag == subr_nokey) {
  5096. /* SUBR without KEY */
  5097. if (TheSubr(fun)->rest_flag == subr_norest)
  5098. /* SUBR without REST or KEY */
  5099. goto error_toomany; /* still Arguments! */
  5100. else
  5101. /* SUBR with only REST, without KEY */
  5102. goto apply_subr_rest_ok;
  5103. } else
  5104. /* SUBR with Keywords. */
  5105. goto apply_subr_key_;
  5106. }
  5107. apply_subr_key:
  5108. key_count = TheSubr(fun)->key_count;
  5109. apply_subr_key_:
  5110. /* shift down remaining arguments in STACK and thus
  5111. create room for the Keyword-parameters: */
  5112. argcount = args_on_stack; /* (> 0) */
  5113. get_space_on_STACK(sizeof(gcv_object_t) * (uintL)key_count);
  5114. {
  5115. var gcv_object_t* new_args_end_pointer = args_end_pointer STACKop -(uintP)key_count;
  5116. var gcv_object_t* ptr1 = args_end_pointer;
  5117. var gcv_object_t* ptr2 = new_args_end_pointer;
  5118. var uintC count;
  5119. dotimespC(count,args_on_stack, { BEFORE(ptr2) = BEFORE(ptr1); } );
  5120. key_args_pointer = ptr1;
  5121. rest_args_pointer = ptr2;
  5122. dotimesC(count,key_count, { NEXT(ptr1) = unbound; } );
  5123. set_args_end_pointer(new_args_end_pointer);
  5124. }
  5125. /* assign Keywords and poss. discard remaining Arguments: */
  5126. match_subr_key(fun,argcount,key_args_pointer,rest_args_pointer);
  5127. if (TheSubr(fun)->rest_flag != subr_norest)
  5128. /* SUBR with &REST-Flag: */
  5129. goto apply_subr_rest;
  5130. else
  5131. /* SUBR without &REST-Flag: */
  5132. goto apply_subr_norest;
  5133. }
  5134. apply_subr_rest_ok:
  5135. argcount = args_on_stack;
  5136. rest_args_pointer = args_end_pointer STACKop argcount;
  5137. apply_subr_rest:
  5138. with_saved_back_trace_subr(fun,STACK,
  5139. TheSubr(fun)->req_count + TheSubr(fun)->opt_count + argcount,
  5140. (*(subr_rest_function_t*)(TheSubr(fun)->function))(argcount,rest_args_pointer); );
  5141. goto done;
  5142. apply_subr_norest:
  5143. with_saved_back_trace_subr(fun,STACK,args_on_stack,
  5144. (*(subr_norest_function_t*)(TheSubr(fun)->function))(); );
  5145. done:
  5146. CHECK_STACK_S(args_end_pointer,fun);
  5147. return; /* finished */
  5148. /* Gathered error-messages: */
  5149. error_count:
  5150. if (args_on_stack < TheSubr(fun)->req_count)
  5151. goto error_toofew; /* too few Arguments */
  5152. else
  5153. goto error_toomany; /* too many Arguments */
  5154. error_toofew: { error_subr_toofew(fun,NIL); }
  5155. error_toomany: { error_subr_toomany(fun); }
  5156. }
  5157. /* In FUNCALL: Applies a Closure to Arguments, cleans up STACK
  5158. and returns the values.
  5159. funcall_closure(fun,args_on_stack);
  5160. > fun: function, a Closure
  5161. > Argumente: args_on_stack Arguments on STACK
  5162. < STACK: cleaned up (i.e. STACK is increased by args_on_stack)
  5163. < mv_count/mv_space: values
  5164. changes STACK, can trigger GC */
  5165. local maygc Values funcall_closure (object closure, uintC args_on_stack)
  5166. {
  5167. TRACE_CALL(closure,'F','C');
  5168. if (simple_bit_vector_p(Atype_8Bit,TheClosure(closure)->clos_codevec)) {
  5169. /* closure is a compiled Closure */
  5170. #if STACKCHECKC
  5171. var gcv_object_t* args_pointer = args_end_pointer STACKop args_on_stack; /* Pointer to the Arguments */
  5172. #endif
  5173. var object codevec = TheCclosure(closure)->clos_codevec; /* Code-Vector */
  5174. var gcv_object_t* key_args_pointer; /* Pointer to the &key */
  5175. var gcv_object_t* rest_args_pointer; /* Pointer to the remaining Arguments */
  5176. var uintL argcount; /* number of remaining Arguments */
  5177. check_SP(); check_STACK();
  5178. /* store arguments in STACK:
  5179. First a Dispatch for the most important cases: */
  5180. switch (TheCodevec(codevec)->ccv_signature) {
  5181. case (uintB)cclos_argtype_0_0: /* no Arguments */
  5182. if (!(args_on_stack==0)) goto error_toomany;
  5183. goto apply_cclosure_nokey;
  5184. case (uintB)cclos_argtype_1_0: /* 1 required argument */
  5185. if (!(args_on_stack==1)) goto error_count;
  5186. goto apply_cclosure_nokey;
  5187. case (uintB)cclos_argtype_2_0: /* 2 required arguments */
  5188. if (!(args_on_stack==2)) goto error_count;
  5189. goto apply_cclosure_nokey;
  5190. case (uintB)cclos_argtype_3_0: /* 3 required arguments */
  5191. if (!(args_on_stack==3)) goto error_count;
  5192. goto apply_cclosure_nokey;
  5193. case (uintB)cclos_argtype_4_0: /* 4 required arguments */
  5194. if (!(args_on_stack==4)) goto error_count;
  5195. goto apply_cclosure_nokey;
  5196. case (uintB)cclos_argtype_5_0: /* 5 required arguments */
  5197. if (!(args_on_stack==5)) goto error_count;
  5198. goto apply_cclosure_nokey;
  5199. case (uintB)cclos_argtype_0_1: /* 1 optional argument */
  5200. if (args_on_stack==1) goto apply_cclosure_nokey;
  5201. else if (args_on_stack>1) goto error_toomany;
  5202. else { pushSTACK(unbound); goto apply_cclosure_nokey; }
  5203. case (uintB)cclos_argtype_1_1: /* 1 required and 1 optional */
  5204. if (args_on_stack==2) goto apply_cclosure_nokey;
  5205. else if (args_on_stack>2) goto error_toomany;
  5206. else if (args_on_stack==0) goto error_toofew;
  5207. else { pushSTACK(unbound); goto apply_cclosure_nokey; }
  5208. case (uintB)cclos_argtype_2_1: /* 2 required and 1 optional */
  5209. if (args_on_stack==3) goto apply_cclosure_nokey;
  5210. else if (args_on_stack>3) goto error_toomany;
  5211. else if (args_on_stack<2) goto error_toofew;
  5212. else { pushSTACK(unbound); goto apply_cclosure_nokey; }
  5213. case (uintB)cclos_argtype_3_1: /* 3 required and 1 optional */
  5214. if (args_on_stack==4) goto apply_cclosure_nokey;
  5215. else if (args_on_stack>4) goto error_toomany;
  5216. else if (args_on_stack<3) goto error_toofew;
  5217. else { pushSTACK(unbound); goto apply_cclosure_nokey; }
  5218. case (uintB)cclos_argtype_4_1: /* 4 required and 1 optional */
  5219. if (args_on_stack==5) goto apply_cclosure_nokey;
  5220. else if (args_on_stack>5) goto error_toomany;
  5221. else if (args_on_stack<4) goto error_toofew;
  5222. else { pushSTACK(unbound); goto apply_cclosure_nokey; }
  5223. case (uintB)cclos_argtype_0_2: /* 2 optional arguments */
  5224. switch (args_on_stack) {
  5225. case 0: { pushSTACK(unbound); }
  5226. case 1: { pushSTACK(unbound); }
  5227. case 2: goto apply_cclosure_nokey;
  5228. default: goto error_toomany;
  5229. }
  5230. case (uintB)cclos_argtype_1_2: /* 1 required and 2 optional */
  5231. switch (args_on_stack) {
  5232. case 0: goto error_toofew;
  5233. case 1: { pushSTACK(unbound); }
  5234. case 2: { pushSTACK(unbound); }
  5235. case 3: goto apply_cclosure_nokey;
  5236. default: goto error_toomany;
  5237. }
  5238. case (uintB)cclos_argtype_2_2: /* 2 required and 2 optional */
  5239. switch (args_on_stack) {
  5240. case 0: case 1: goto error_toofew;
  5241. case 2: { pushSTACK(unbound); }
  5242. case 3: { pushSTACK(unbound); }
  5243. case 4: goto apply_cclosure_nokey;
  5244. default: goto error_toomany;
  5245. }
  5246. case (uintB)cclos_argtype_3_2: /* 3 required and 2 optional */
  5247. switch (args_on_stack) {
  5248. case 0: case 1: case 2: goto error_toofew;
  5249. case 3: { pushSTACK(unbound); }
  5250. case 4: { pushSTACK(unbound); }
  5251. case 5: goto apply_cclosure_nokey;
  5252. default: goto error_toomany;
  5253. }
  5254. case (uintB)cclos_argtype_0_3: /* 3 optional arguments */
  5255. switch (args_on_stack) {
  5256. case 0: { pushSTACK(unbound); }
  5257. case 1: { pushSTACK(unbound); }
  5258. case 2: { pushSTACK(unbound); }
  5259. case 3: goto apply_cclosure_nokey;
  5260. default: goto error_toomany;
  5261. }
  5262. case (uintB)cclos_argtype_1_3: /* 1 required and 3 optional */
  5263. switch (args_on_stack) {
  5264. case 0: goto error_toofew;
  5265. case 1: { pushSTACK(unbound); }
  5266. case 2: { pushSTACK(unbound); }
  5267. case 3: { pushSTACK(unbound); }
  5268. case 4: goto apply_cclosure_nokey;
  5269. default: goto error_toomany;
  5270. }
  5271. case (uintB)cclos_argtype_2_3: /* 2 required and 3 optional */
  5272. switch (args_on_stack) {
  5273. case 0: case 1: goto error_toofew;
  5274. case 2: { pushSTACK(unbound); }
  5275. case 3: { pushSTACK(unbound); }
  5276. case 4: { pushSTACK(unbound); }
  5277. case 5: goto apply_cclosure_nokey;
  5278. default: goto error_toomany;
  5279. }
  5280. case (uintB)cclos_argtype_0_4: /* 4 optional arguments */
  5281. switch (args_on_stack) {
  5282. case 0: { pushSTACK(unbound); }
  5283. case 1: { pushSTACK(unbound); }
  5284. case 2: { pushSTACK(unbound); }
  5285. case 3: { pushSTACK(unbound); }
  5286. case 4: goto apply_cclosure_nokey;
  5287. default: goto error_toomany;
  5288. }
  5289. case (uintB)cclos_argtype_1_4: /* 1 required and 4 optional */
  5290. switch (args_on_stack) {
  5291. case 0: goto error_toofew;
  5292. case 1: { pushSTACK(unbound); }
  5293. case 2: { pushSTACK(unbound); }
  5294. case 3: { pushSTACK(unbound); }
  5295. case 4: { pushSTACK(unbound); }
  5296. case 5: goto apply_cclosure_nokey;
  5297. default: goto error_toomany;
  5298. }
  5299. case (uintB)cclos_argtype_0_5: /* 5 optional arguments */
  5300. switch (args_on_stack) {
  5301. case 0: { pushSTACK(unbound); }
  5302. case 1: { pushSTACK(unbound); }
  5303. case 2: { pushSTACK(unbound); }
  5304. case 3: { pushSTACK(unbound); }
  5305. case 4: { pushSTACK(unbound); }
  5306. case 5: goto apply_cclosure_nokey;
  5307. default: goto error_toomany;
  5308. }
  5309. case (uintB)cclos_argtype_0_0_rest: /* no Arguments, &rest */
  5310. goto apply_cclosure_rest_nokey;
  5311. case (uintB)cclos_argtype_1_0_rest: /* 1 required + &rest */
  5312. if (args_on_stack==0) goto error_toofew;
  5313. args_on_stack -= 1;
  5314. goto apply_cclosure_rest_nokey;
  5315. case (uintB)cclos_argtype_2_0_rest: /* 2 required + &rest */
  5316. if (args_on_stack<2) goto error_toofew;
  5317. args_on_stack -= 2;
  5318. goto apply_cclosure_rest_nokey;
  5319. case (uintB)cclos_argtype_3_0_rest: /* 3 required + &rest */
  5320. if (args_on_stack<3) goto error_toofew;
  5321. args_on_stack -= 3;
  5322. goto apply_cclosure_rest_nokey;
  5323. case (uintB)cclos_argtype_4_0_rest: /* 4 required + &rest */
  5324. if (args_on_stack<4) goto error_toofew;
  5325. args_on_stack -= 4;
  5326. goto apply_cclosure_rest_nokey;
  5327. case (uintB)cclos_argtype_0_0_key: /* only &key */
  5328. if (args_on_stack==0) goto unbound_optional_key_0;
  5329. else goto apply_cclosure_key_withargs;
  5330. case (uintB)cclos_argtype_1_0_key: /* 1 required argument, &key */
  5331. if (args_on_stack==1) goto unbound_optional_key_0;
  5332. else if (args_on_stack<1) goto error_toofew;
  5333. else { args_on_stack -= 1; goto apply_cclosure_key_withargs; }
  5334. case (uintB)cclos_argtype_2_0_key: /* 2 required arguments, &key */
  5335. if (args_on_stack==2) goto unbound_optional_key_0;
  5336. else if (args_on_stack<2) goto error_toofew;
  5337. else { args_on_stack -= 2; goto apply_cclosure_key_withargs; }
  5338. case (uintB)cclos_argtype_3_0_key: /* 3 required arguments, &key */
  5339. if (args_on_stack==3) goto unbound_optional_key_0;
  5340. else if (args_on_stack<3) goto error_toofew;
  5341. else { args_on_stack -= 3; goto apply_cclosure_key_withargs; }
  5342. case (uintB)cclos_argtype_4_0_key: /* 4 required arguments, &key */
  5343. if (args_on_stack==4) goto unbound_optional_key_0;
  5344. else if (args_on_stack<4) goto error_toofew;
  5345. else { args_on_stack -= 4; goto apply_cclosure_key_withargs; }
  5346. case (uintB)cclos_argtype_0_1_key: /* 1 optional argument, &key */
  5347. switch (args_on_stack) {
  5348. case 0: goto unbound_optional_key_1;
  5349. case 1: goto unbound_optional_key_0;
  5350. default: args_on_stack -= 1; goto apply_cclosure_key_withargs;
  5351. }
  5352. case (uintB)cclos_argtype_1_1_key:
  5353. /* 1 required argument and 1 optional argument, &key */
  5354. switch (args_on_stack) {
  5355. case 0: goto error_toofew;
  5356. case 1: goto unbound_optional_key_1;
  5357. case 2: goto unbound_optional_key_0;
  5358. default: args_on_stack -= 2; goto apply_cclosure_key_withargs;
  5359. }
  5360. case (uintB)cclos_argtype_2_1_key:
  5361. /* 2 required arguments and 1 optional argument, &key */
  5362. switch (args_on_stack) {
  5363. case 0: case 1: goto error_toofew;
  5364. case 2: goto unbound_optional_key_1;
  5365. case 3: goto unbound_optional_key_0;
  5366. default: args_on_stack -= 3; goto apply_cclosure_key_withargs;
  5367. }
  5368. case (uintB)cclos_argtype_3_1_key:
  5369. /* 3 required arguments and 1 optional argument, &key */
  5370. switch (args_on_stack) {
  5371. case 0: case 1: case 2: goto error_toofew;
  5372. case 3: goto unbound_optional_key_1;
  5373. case 4: goto unbound_optional_key_0;
  5374. default: args_on_stack -= 4; goto apply_cclosure_key_withargs;
  5375. }
  5376. case (uintB)cclos_argtype_0_2_key: /* 2 optional arguments, &key */
  5377. switch (args_on_stack) {
  5378. case 0: goto unbound_optional_key_2;
  5379. case 1: goto unbound_optional_key_1;
  5380. case 2: goto unbound_optional_key_0;
  5381. default: args_on_stack -= 2; goto apply_cclosure_key_withargs;
  5382. }
  5383. case (uintB)cclos_argtype_1_2_key:
  5384. /* 1 required argument and 2 optional arguments, &key */
  5385. switch (args_on_stack) {
  5386. case 0: goto error_toofew;
  5387. case 1: goto unbound_optional_key_2;
  5388. case 2: goto unbound_optional_key_1;
  5389. case 3: goto unbound_optional_key_0;
  5390. default: args_on_stack -= 3; goto apply_cclosure_key_withargs;
  5391. }
  5392. case (uintB)cclos_argtype_2_2_key:
  5393. /* 2 required arguments and 2 optional arguments, &key */
  5394. switch (args_on_stack) {
  5395. case 0: case 1: goto error_toofew;
  5396. case 2: goto unbound_optional_key_2;
  5397. case 3: goto unbound_optional_key_1;
  5398. case 4: goto unbound_optional_key_0;
  5399. default: args_on_stack -= 4; goto apply_cclosure_key_withargs;
  5400. }
  5401. case (uintB)cclos_argtype_0_3_key: /* 3 optional arguments, &key */
  5402. switch (args_on_stack) {
  5403. case 0: goto unbound_optional_key_3;
  5404. case 1: goto unbound_optional_key_2;
  5405. case 2: goto unbound_optional_key_1;
  5406. case 3: goto unbound_optional_key_0;
  5407. default: args_on_stack -= 3; goto apply_cclosure_key_withargs;
  5408. }
  5409. case (uintB)cclos_argtype_1_3_key:
  5410. /* 1 required argument and 3 optional arguments, &key */
  5411. switch (args_on_stack) {
  5412. case 0: goto error_toofew;
  5413. case 1: goto unbound_optional_key_3;
  5414. case 2: goto unbound_optional_key_2;
  5415. case 3: goto unbound_optional_key_1;
  5416. case 4: goto unbound_optional_key_0;
  5417. default: args_on_stack -= 4; goto apply_cclosure_key_withargs;
  5418. }
  5419. case (uintB)cclos_argtype_0_4_key: /* 4 optional arguments, &key */
  5420. switch (args_on_stack) {
  5421. case 0: goto unbound_optional_key_4;
  5422. case 1: goto unbound_optional_key_3;
  5423. case 2: goto unbound_optional_key_2;
  5424. case 3: goto unbound_optional_key_1;
  5425. case 4: goto unbound_optional_key_0;
  5426. default: args_on_stack -= 4; goto apply_cclosure_key_withargs;
  5427. }
  5428. unbound_optional_key_4: /* Still 4 optionals, but args_on_stack=0 */
  5429. { pushSTACK(unbound); }
  5430. unbound_optional_key_3: /* Still 3 optionals, but args_on_stack=0 */
  5431. { pushSTACK(unbound); }
  5432. unbound_optional_key_2: /* Still 2 optionals, but args_on_stack=0 */
  5433. { pushSTACK(unbound); }
  5434. unbound_optional_key_1: /* Still 1 optional, but args_on_stack=0 */
  5435. { pushSTACK(unbound); }
  5436. unbound_optional_key_0: /* Before the Keywords is args_on_stack=0 */
  5437. goto apply_cclosure_key_noargs;
  5438. case (uintB)cclos_argtype_default:
  5439. /* General Version */
  5440. break;
  5441. default: NOTREACHED;
  5442. }
  5443. /* Now the general version: */
  5444. {
  5445. var uintB flags;
  5446. {
  5447. var uintC req_count = TheCodevec(codevec)->ccv_numreq; /* number of required Parameters */
  5448. var uintC opt_count = TheCodevec(codevec)->ccv_numopt; /* number of optional Parameters */
  5449. flags = TheCodevec(codevec)->ccv_flags; /* Flags */
  5450. if (args_on_stack < req_count)
  5451. /* fewer Arguments than demanded */
  5452. goto error_toofew;
  5453. args_on_stack -= req_count; /* remaining number */
  5454. if (args_on_stack <= opt_count) {
  5455. /* Arguments in Stack don't last for the optional ones */
  5456. opt_count = opt_count - args_on_stack; /* as many as these must go on STACK */
  5457. if (opt_count > 0) {
  5458. /* reserve space on STACK: */
  5459. get_space_on_STACK(sizeof(gcv_object_t) * (uintL)opt_count);
  5460. /* All further count optional parameters receive the "value"
  5461. #<UNBOUND>, the &REST-parameter receives NIL,
  5462. the Keyword-parameters receive the value #<UNBOUND> : */
  5463. var uintC count;
  5464. dotimespC(count,opt_count, { pushSTACK(unbound); } );
  5465. }
  5466. if (flags & bit(0)) /* &REST-Flag? */
  5467. pushSTACK(NIL); /* yes -> initialize with NIL */
  5468. if (flags & bit(7)) /* &KEY-Flag? */
  5469. goto apply_cclosure_key_noargs;
  5470. else
  5471. goto apply_cclosure_nokey;
  5472. }
  5473. args_on_stack -= opt_count; /* remaining number */
  5474. if (flags & bit(7)) /* Key-Flag? */
  5475. goto apply_cclosure_key_withargs_;
  5476. else if (flags & bit(0))
  5477. goto apply_cclosure_rest_nokey;
  5478. else {
  5479. /* Closure without REST or KEY */
  5480. if (args_on_stack>0) /* still arguments? */
  5481. goto error_toomany;
  5482. goto apply_cclosure_nokey;
  5483. }
  5484. }
  5485. apply_cclosure_key_noargs:
  5486. {
  5487. var uintC key_count = TheCodevec(codevec)->ccv_numkey; /* number of Keyword-Parameters */
  5488. if (key_count > 0) {
  5489. get_space_on_STACK(sizeof(gcv_object_t) * (uintL)key_count);
  5490. var uintC count;
  5491. dotimespC(count,key_count, { pushSTACK(unbound); } ); /* initialize with #<UNBOUND> */
  5492. }
  5493. goto apply_cclosure_key;
  5494. }
  5495. apply_cclosure_key_withargs:
  5496. flags = TheCodevec(codevec)->ccv_flags; /* initialize Flags! */
  5497. apply_cclosure_key_withargs_:
  5498. /* Closure with Keywords */
  5499. {
  5500. var uintC key_count = TheCodevec(codevec)->ccv_numkey; /* number of Keyword-Parameters */
  5501. /* shift down remaining arguments in STACK and thus
  5502. create room for the Keyword-parameters
  5503. (and poss. Rest-parameters): */
  5504. var uintL shift = key_count;
  5505. if (flags & bit(0))
  5506. shift++; /* poss. 1 more for Rest-Parameter */
  5507. argcount = args_on_stack;
  5508. get_space_on_STACK(sizeof(gcv_object_t) * shift);
  5509. var gcv_object_t* new_args_end_pointer = args_end_pointer STACKop -(uintP)shift;
  5510. var gcv_object_t* ptr1 = args_end_pointer;
  5511. var gcv_object_t* ptr2 = new_args_end_pointer;
  5512. var uintC count;
  5513. dotimesC(count,args_on_stack, { BEFORE(ptr2) = BEFORE(ptr1); } );
  5514. if (flags & bit(0))
  5515. NEXT(ptr1) = unbound; /* Rest-Parameter */
  5516. key_args_pointer = ptr1;
  5517. rest_args_pointer = ptr2;
  5518. dotimesC(count,key_count, { NEXT(ptr1) = unbound; } );
  5519. set_args_end_pointer(new_args_end_pointer);
  5520. }
  5521. /* assign Keywords, build Rest-Parameter
  5522. and poss. discard remaining arguments: */
  5523. closure = match_cclosure_key(closure,argcount,key_args_pointer,rest_args_pointer);
  5524. codevec = TheCclosure(closure)->clos_codevec;
  5525. apply_cclosure_key:
  5526. interpret_bytecode(closure,codevec,CCV_START_KEY); /* process Bytecode starting at Byte 12 */
  5527. goto done;
  5528. }
  5529. apply_cclosure_rest_nokey:
  5530. /* Closure with only REST, without KEY:
  5531. still must cons args_on_stack arguments from stack Stack: */
  5532. { pushSTACK(NIL); }
  5533. if (args_on_stack > 0) {
  5534. pushSTACK(closure); /* Closure must be saved */
  5535. dotimesC(args_on_stack,args_on_stack, {
  5536. var object new_cons = allocate_cons();
  5537. Cdr(new_cons) = STACK_1;
  5538. Car(new_cons) = STACK_2; /* cons next argument to it */
  5539. STACK_2 = new_cons;
  5540. STACK_1 = STACK_0; skipSTACK(1);
  5541. });
  5542. closure = popSTACK(); codevec = TheCclosure(closure)->clos_codevec;
  5543. }
  5544. apply_cclosure_nokey: /* jump to Closure without &KEY: */
  5545. interpret_bytecode(closure,codevec,CCV_START_NONKEY); /* process Bytecode starting at Byte 8 */
  5546. done:
  5547. CHECK_STACK_C(args_end_pointer,closure);
  5548. return; /* finished */
  5549. error_count: /* collected error-messages: */
  5550. if (args_on_stack < TheCodevec(codevec)->ccv_numreq)
  5551. goto error_toofew; /* too few arguments */
  5552. else
  5553. goto error_toomany; /* too many arguments */
  5554. error_toofew: { error_closure_toofew(closure,NIL); }
  5555. error_toomany: { error_closure_toomany(closure); }
  5556. } else {
  5557. /* closure is an interpreted Closure */
  5558. var gcv_object_t* args_pointer = args_end_pointer STACKop args_on_stack;
  5559. with_saved_back_trace_iclosure(closure,args_pointer,args_on_stack,
  5560. funcall_iclosure(closure,args_pointer,args_on_stack); );
  5561. }
  5562. }
  5563. /* ---------------------- BYTECODE-INTERPRETER ---------------------- */
  5564. /* Interpretes the bytecode of a compiled Closure.
  5565. interpret_bytecode_(closure,codeptr,byteptr);
  5566. > closure: compiled closure
  5567. > codeptr: its Codevector, a Simple-Bit-Vector, pointable
  5568. > byteptr: Start-Bytecodepointer
  5569. < mv_count/mv_space: values
  5570. changes STACK, can trigger GC
  5571. Syntax of local labels in GNU-C assembler-statements: */
  5572. #if (defined(GNU) || defined(INTEL)) && !defined(NO_ASM)
  5573. /* LD(x) defines Label with number x
  5574. LR(x,f) references label with number x forwards
  5575. LR(x,b) references label with number x backwards
  5576. The scope of the labels is only one assembler-statement. */
  5577. #if defined(I80386) && !defined(UNIX_NEXTSTEP)
  5578. #ifdef ASM_UNDERSCORE
  5579. #define LD(nr) "LASM%=X" STRING(nr)
  5580. #define LR(nr,fb) "LASM%=X" STRING(nr)
  5581. #else
  5582. #define LD(nr) ".LASM%=X" STRING(nr)
  5583. #define LR(nr,fb) ".LASM%=X" STRING(nr)
  5584. #endif
  5585. #elif defined(ARM)
  5586. #define LD(nr) "LASM%=X" STRING(nr)
  5587. #define LR(nr,fb) "LASM%=X" STRING(nr)
  5588. #else
  5589. #define LD(nr) STRING(nr)
  5590. #define LR(nr,fb) STRING(nr) STRING(fb)
  5591. #endif
  5592. #endif
  5593. /* Persuade GNU-C, to keep closure and byteptr in registers: */
  5594. #ifdef GNU
  5595. #ifdef MC680X0
  5596. #define closure_register "a2"
  5597. #define byteptr_register "a3"
  5598. #endif
  5599. #ifdef SPARC
  5600. #define closure_register "%l0"
  5601. #define byteptr_register "%l1"
  5602. #endif
  5603. #ifdef I80386
  5604. #if (__GNUC__ >= 2) /* The register-names have changed */
  5605. #define byteptr_register "%edi"
  5606. #else
  5607. #define byteptr_register "di"
  5608. #endif
  5609. #endif
  5610. #ifdef ARM
  5611. /* Code is better without defining registers for closure and byteptr,
  5612. says Peter Burwood.
  5613. not define closure_register "%r6"
  5614. not define byteptr_register "%r7"
  5615. We have assembler macros below, but if they are used with gcc-2.7.2.1,
  5616. (setf cdddr) is miscompiled. So here we temporarily disable them. */
  5617. #ifndef NO_ASM
  5618. #define NO_ASM
  5619. #endif
  5620. #endif
  5621. #ifdef DECALPHA
  5622. #define byteptr_register "$14"
  5623. #endif
  5624. #if defined(WIDE) && !defined(WIDE_HARD)
  5625. /* An `object' does not fit into a single register, GCC is overcharged. */
  5626. #undef closure_register
  5627. #endif
  5628. #endif
  5629. #ifndef closure_register
  5630. #define closure_in closure
  5631. #endif
  5632. #ifndef byteptr_register
  5633. #define byteptr_in byteptr
  5634. #endif
  5635. #ifdef DEBUG_BYTECODE
  5636. #define GOTO_ERROR(label) \
  5637. do { \
  5638. fprintf(stderr,"\n[%s:%d] ",__FILE__,__LINE__); \
  5639. goto label; \
  5640. } while(0)
  5641. #define DEBUG_CHECK_BYTEPTR(nb) do { \
  5642. var const uintL b = nb - codeptr->data; \
  5643. if ((b < byteptr_min) || (b > byteptr_max)) { \
  5644. var uintL bp = byteptr - codeptr->data; \
  5645. fprintf(stderr,"\n[%s:%d] ",__FILE__,__LINE__); \
  5646. byteptr_bad_jump = b - bp; \
  5647. /*nobject_out(stderr,closure);*/ \
  5648. /*fprintf(stderr," jump by %d takes %d outside [%d;%d]",byteptr_bad_jump,bp,byteptr_min,byteptr_max);*/ \
  5649. goto error_byteptr; \
  5650. }} while(0)
  5651. #else
  5652. #define GOTO_ERROR(label) goto label
  5653. #define DEBUG_CHECK_BYTEPTR(b) do{}while(0)
  5654. #endif
  5655. local /*maygc*/ Values interpret_bytecode_ (object closure_in, Sbvector codeptr,
  5656. const uintB* byteptr_in)
  5657. {
  5658. GCTRIGGER_IF(true, {
  5659. if (*byteptr_in == cod_handler_begin_push)
  5660. GCTRIGGER3(closure_in,handler_args.condition,handler_args.spdepth);
  5661. else
  5662. GCTRIGGER1(closure_in);
  5663. });
  5664. #if STACKCHECKC || defined(DEBUG_BYTECODE)
  5665. var const uintL byteptr_min = ((Codevec)codeptr)->ccv_flags & bit(7)
  5666. ? CCV_START_KEY : CCV_START_NONKEY;
  5667. #endif
  5668. #ifdef DEBUG_BYTECODE
  5669. var const uintL byteptr_max = sbvector_length(codeptr)-1;
  5670. var sintL byteptr_bad_jump;
  5671. #endif
  5672. /* situate argument closure in register: */
  5673. #ifdef closure_register
  5674. var object closure __asm__(closure_register);
  5675. closure = closure_in;
  5676. #endif
  5677. /* situate argument byteptr in register: */
  5678. #ifdef byteptr_register
  5679. var register const uintB* byteptr __asm__(byteptr_register);
  5680. byteptr = byteptr_in;
  5681. #endif
  5682. TRACE_CALL(closure,'B','C');
  5683. /* situate closure in STACK, below the arguments: */
  5684. var gcv_object_t* closureptr = (pushSTACK(closure), &STACK_0);
  5685. #ifndef FAST_SP
  5686. /* If there is no fast SP-Access, one has to introduce
  5687. an extra pointer: */
  5688. var uintL private_SP_length =
  5689. (uintL)(((Codevec)codeptr)->ccv_spdepth_1)
  5690. + jmpbufsize * (uintL)(((Codevec)codeptr)->ccv_spdepth_jmpbufsize);
  5691. var DYNAMIC_ARRAY(private_SP_space,SPint,private_SP_length);
  5692. var SPint* private_SP = &private_SP_space[private_SP_length];
  5693. #undef SP_
  5694. #undef _SP_
  5695. #undef skipSP
  5696. #undef pushSP
  5697. #undef popSP
  5698. #define SP_(n) (private_SP[n])
  5699. #define _SP_(n) &SP_(n)
  5700. #define skipSP(n) (private_SP += (n))
  5701. #define pushSP(item) (*--private_SP = (item))
  5702. #define popSP(item_assignment) (item_assignment *private_SP++)
  5703. #endif
  5704. /* var JMPBUF_on_SP(name); allocates a sp_jmp_buf in SP.
  5705. FREE_JMPBUF_on_SP(); deallocates it.
  5706. finish_entry_frame_1(frametype,returner,reentry_statement); is like
  5707. finish_entry_frame(frametype,returner,,reentry_statement); but
  5708. also private_SP is saved. */
  5709. #ifndef FAST_SP
  5710. #define JMPBUF_on_SP(name) \
  5711. sp_jmp_buf* name = (sp_jmp_buf*)(private_SP -= jmpbufsize);
  5712. #define FREE_JMPBUF_on_SP() \
  5713. private_SP += jmpbufsize;
  5714. #define finish_entry_frame_1(frametype,returner,reentry_statement) \
  5715. finish_entry_frame(frametype,*returner, /* On entry: returner = private_SP */ \
  5716. returner = (sp_jmp_buf*) , /* returner is set again on return */ \
  5717. { private_SP = (SPint*)returner; reentry_statement }) /* and private_SP is reconstructed */
  5718. #else
  5719. #ifdef SP_DOWN
  5720. #define JMPBUF_on_SP(name) \
  5721. sp_jmp_buf* name; \
  5722. {var SPint* sp = (SPint*)SP(); \
  5723. sp -= jmpbufsize; \
  5724. setSP(sp); \
  5725. name = (sp_jmp_buf*)&sp[SPoffset];}
  5726. #endif
  5727. #ifdef SP_UP
  5728. #define JMPBUF_on_SP(name) \
  5729. sp_jmp_buf* name; \
  5730. {var SPint* sp = (SPint*)SP(); \
  5731. name = (sp_jmp_buf*)&sp[SPoffset+1]; \
  5732. sp += jmpbufsize; \
  5733. setSP(sp);}
  5734. #endif
  5735. #define FREE_JMPBUF_on_SP() \
  5736. skipSP(jmpbufsize);
  5737. #define finish_entry_frame_1(frametype,returner,reentry_statement) \
  5738. finish_entry_frame(frametype,*returner,,reentry_statement)
  5739. #endif
  5740. #ifdef FAST_DISPATCH
  5741. static void* const cod_labels[] = {
  5742. #define BYTECODE(code) &&code,
  5743. #include "bytecode.c"
  5744. #undef BYTECODE
  5745. };
  5746. #endif
  5747. /* next Byte to be interpreted
  5748. > mv_count/mv_space: current values
  5749. > closureptr: pointer to the compiled closure on Stack
  5750. > closure: compiled closure
  5751. > codeptr: its codevector, a Simple-Bit-Vektor, pointable
  5752. (no LISP-object, but nevertheless endangered by GC!)
  5753. > byteptr: pointer to the next byte in code
  5754. (no LISP-object, but nevertheless endangered by GC!) */
  5755. next_byte:
  5756. /* definition by cases, according to byte to be interpreted byte */
  5757. #ifndef FAST_DISPATCH
  5758. switch (*byteptr++)
  5759. #define CASE case (uintB)
  5760. #else /* FAST_DISPATCH */
  5761. /* This is faster by about 2%, because the index-check is dropped. */
  5762. goto *cod_labels[*byteptr++];
  5763. #define CASE
  5764. #ifdef FAST_DISPATCH_THREADED
  5765. /* The jump-statement goto next_byte; can be omitted: */
  5766. #define next_byte *cod_labels[*byteptr++]
  5767. #endif
  5768. #endif
  5769. {
  5770. /* Operand-Fetch:
  5771. next Byte:
  5772. Bit 7 = 0 --> Bits 6..0 are the Operand (7 Bits).
  5773. Bit 7 = 1 --> Bits 6..0 and next Byte form the
  5774. Operand (15 Bits).
  5775. For jump-distances: Should this be =0, the next
  5776. 4 Bytes form the Operand
  5777. (32 Bits).
  5778. Macro B_operand(where);
  5779. moves the next Operand (a Byte as Unsigned Integer)
  5780. to (uintL)where and advances bytecodepointer. */
  5781. #define B_operand(where) \
  5782. { where = *byteptr++; }
  5783. /* Macro U_operand(where);
  5784. moves the next Operand (an Unsigned Integer)
  5785. to (uintL)where or (uintC)where
  5786. and advances the Bytecodepointer. */
  5787. #define U_operand(where) \
  5788. { where = *byteptr++; /* read first Byte */ \
  5789. if ((uintB)where & bit(7)) /* Bit 7 set? */ \
  5790. { where &= ~bit(7); /* yes -> delete */ \
  5791. where = where << 8; \
  5792. where |= *byteptr++; /* and read next Byte */ \
  5793. } }
  5794. #if defined(GNU) && defined(MC680X0) && !defined(NO_ASM)
  5795. #undef U_operand
  5796. #define U_operand(where) \
  5797. __asm__( \
  5798. "moveq #0,%0" "\n\t" \
  5799. "moveb %1@+,%0" "\n\t" \
  5800. "bpl 1f" "\n\t" \
  5801. "addb %0,%0" "\n\t" \
  5802. "lslw #7,%0" "\n\t" \
  5803. "moveb %1@+,%0" "\n" \
  5804. "1:" \
  5805. : "=d" (where), "=a" (byteptr) : "1" (byteptr) )
  5806. #endif
  5807. #if defined(GNU) && defined(SPARC) && !defined(NO_ASM)
  5808. #undef U_operand
  5809. #define U_operand(where) \
  5810. { var uintL dummy; \
  5811. __asm__( \
  5812. "ldub [%1],%0" "\n\t" \
  5813. "andcc %0,0x80,%%g0" "\n\t" \
  5814. "be 1f" "\n\t" \
  5815. " add %1,1,%1" "\n\t" \
  5816. "sll %0,25,%2" "\n\t" \
  5817. "ldub [%1],%0" "\n\t" \
  5818. "srl %2,17,%2" "\n\t" \
  5819. "add %1,1,%1" "\n\t" \
  5820. "or %0,%2,%0" "\n" \
  5821. "1:" \
  5822. : "=r" (where), "=r" (byteptr), "=r" (dummy) : "1" (byteptr) : "ccr" ); \
  5823. }
  5824. #endif
  5825. #if (defined(GNU) || defined(INTEL)) && defined(I80386) && !defined(NO_ASM)
  5826. #if 0
  5827. /* In earlier times, the GNU assembler assembled
  5828. "testb %edx,%edx" as "testb %dl,%dl". This made possible to
  5829. produce the output in any register. */
  5830. #define OUT_EAX "=q"
  5831. #define EAX "%0"
  5832. #define AL "%0"
  5833. #else
  5834. /* Now "testb %edx,%edx" is invalid everywhere. The macros must
  5835. put their result in %eax. */
  5836. #define OUT_EAX "=a"
  5837. #define EAX "%%eax"
  5838. #define AL "%%al"
  5839. #endif
  5840. #undef U_operand
  5841. #define U_operand(where) \
  5842. __asm__( \
  5843. "movzbl (%1),"EAX "\n\t" \
  5844. "incl %1" "\n\t" \
  5845. "testb "AL","AL "\n\t" \
  5846. "jge "LR(1,f) "\n\t" \
  5847. "andb $127,"AL "\n\t" \
  5848. "sall $8,"EAX "\n\t" \
  5849. "movb (%1),"AL "\n\t" \
  5850. "incl %1" "\n" \
  5851. LD(1)":" \
  5852. : OUT_EAX (where), "=r" (byteptr) : "1" (byteptr) );
  5853. /* Caution: 1. The Sun Assembler doesn't know this Syntax for local labels.
  5854. That's why we generate our local labels ourselves.
  5855. Caution: 2. ccr is changed. How is this to be declared?? */
  5856. #endif
  5857. #if defined(GNU) && defined(ARM) && !defined(NO_ASM)
  5858. /* Macros written by Peter Burwood.
  5859. Two versions. Which one to choose?
  5860. instructions short case long case
  5861. v1: 5 2 + 3 skipped 5
  5862. v2: 5 3 + 2 skipped 4 + 1 skipped
  5863. Let's choose the first one. 1-byte operands are most frequent. */
  5864. #undef U_operand
  5865. #define U_operand(where) /* (v1) */ \
  5866. { var uintL dummy; \
  5867. __asm__( \
  5868. "ldrb %0,[%1],#1" "\n\t" \
  5869. "tst %0,#0x80" "\n\t" \
  5870. "bicne %0,%0,#0x80" "\n\t" \
  5871. "ldrneb %2,[%1],#1" "\n\t" \
  5872. "orrne %0,%2,%0,LSL#8" \
  5873. : "=r" (where), "=r" (byteptr), "=r" (dummy) : "1" (byteptr) : "cc" ); \
  5874. }
  5875. #if 0
  5876. #undef U_operand
  5877. #define U_operand(where) /* (v2) */ \
  5878. { var uintL dummy; \
  5879. __asm__( \
  5880. "ldrb %0,[%1],#1" "\n\t" \
  5881. "movs %0,%0,LSL#25" "\n\t" \
  5882. "movcc %0,%0,LSR#25" "\n\t" \
  5883. "ldrcsb %2,[%1],#1" "\n\t" \
  5884. "orrcs %0,%2,%0,LSR#17" \
  5885. : "=r" (where), "=r" (byteptr), "=r" (dummy) : "1" (byteptr) : "cc" ); \
  5886. }
  5887. #endif
  5888. #endif
  5889. /* Macro S_operand(where);
  5890. moves the next Operand (a Signed Integer)
  5891. to (uintL)where and advances the bytecodepointer. */
  5892. #define S_operand(where) \
  5893. { where = *byteptr++; /* read first byte */ \
  5894. if ((uintB)where & bit(7)) \
  5895. /* Bit 7 was set */ \
  5896. { where = where << 8; \
  5897. where |= *byteptr++; /* subjoin next Byte */ \
  5898. /* Sign-Extend from 15 to 32 Bits: */ \
  5899. where = (sintL)((sintL)(sintWL)((sintWL)where << (intWLsize-15)) >> (intWLsize-15)); \
  5900. if (where == 0) \
  5901. /* special case: 2-Byte-Operand = 0 -> 6-Byte-Operand */ \
  5902. { where = (uintL)( ((uintWL)(byteptr[0]) << 8) \
  5903. | (uintWL)(byteptr[1]) \
  5904. ) << 16 \
  5905. | (uintL)( ((uintWL)(byteptr[2]) << 8) \
  5906. | (uintWL)(byteptr[3]) \
  5907. ); \
  5908. byteptr += 4; \
  5909. } } \
  5910. else \
  5911. /* Bit 7 was deleted */ \
  5912. { /* Sign-Extend from 7 to 32 Bits: */ \
  5913. where = (sintL)((sintL)(sintBWL)((sintBWL)where << (intBWLsize-7)) >> (intBWLsize-7)); \
  5914. } \
  5915. }
  5916. #if defined(GNU) && defined(MC680X0) && !defined(NO_ASM)
  5917. #undef S_operand
  5918. #define S_operand(where) \
  5919. __asm__( \
  5920. "moveb %1@+,%0" "\n\t" \
  5921. "bpl 1f" "\n\t" \
  5922. "lslw #8,%0" "\n\t" \
  5923. "moveb %1@+,%0" "\n\t" \
  5924. "addw %0,%0" "\n\t" \
  5925. "asrw #1,%0" "\n\t" \
  5926. "bne 2f" "\n\t" \
  5927. "moveb %1@(2),%0" "\n\t" \
  5928. "swap %0" "\n\t" \
  5929. "moveb %1@+,%0" "\n\t" \
  5930. "lsll #8,%0" "\n\t" \
  5931. "moveb %1@,%0" "\n\t" \
  5932. "swap %0" "\n\t" \
  5933. "addql #2,%0" "\n\t" \
  5934. "moveb %1@+,%0" "\n\t" \
  5935. "jra 3f" "\n" \
  5936. "1:" "\t" \
  5937. "addb %0,%0" "\n\t" \
  5938. "asrb #1,%0" "\n\t" \
  5939. "extw %0" "\n" \
  5940. "2:" "\t" \
  5941. "extl %0" "\n" \
  5942. "3:" \
  5943. : "=d" (where), "=a" (byteptr) : "1" (byteptr) )
  5944. #endif
  5945. #if defined(GNU) && defined(SPARC) && !defined(NO_ASM)
  5946. #undef S_operand
  5947. #define S_operand(where) \
  5948. { var uintL dummy; \
  5949. __asm__( \
  5950. "ldub [%1],%0" "\n\t" \
  5951. "andcc %0,0x80,%%g0" "\n\t" \
  5952. "be 2f" "\n\t" \
  5953. " add %1,1,%1" "\n\t" \
  5954. "sll %0,25,%2" "\n\t" \
  5955. "ldub [%1],%0" "\n\t" \
  5956. "sra %2,17,%2" "\n\t" \
  5957. "orcc %2,%0,%0" "\n\t" \
  5958. "bne 3f" "\n\t" \
  5959. " add %1,1,%1" "\n\t" \
  5960. "ldub [%1],%0" "\n\t" \
  5961. "sll %0,24,%2" "\n\t" \
  5962. "ldub [%1+1],%0" "\n\t" \
  5963. "sll %0,16,%0" "\n\t" \
  5964. "or %2,%0,%2" "\n\t" \
  5965. "ldub [%1+2],%0" "\n\t" \
  5966. "sll %0,8,%0" "\n\t" \
  5967. "or %2,%0,%2" "\n\t" \
  5968. "ldub [%1+3],%0" "\n\t" \
  5969. "or %2,%0,%0" "\n\t" \
  5970. "b 3f" "\n\t" \
  5971. " add %1,4,%1" "\n" \
  5972. "2:" "\t" \
  5973. "sll %0,25,%0" "\n\t" \
  5974. "sra %0,25,%0" "\n" \
  5975. "3:" "\t" \
  5976. : "=r" (where), "=r" (byteptr), "=r" (dummy) : "1" (byteptr) : "ccr" ); \
  5977. }
  5978. #endif
  5979. #if (defined(GNU) || defined(INTEL)) && defined(I80386) && !defined(NO_ASM)
  5980. #undef S_operand
  5981. #define S_operand(where) \
  5982. __asm__( \
  5983. "movzbl (%1),"EAX "\n\t" \
  5984. "incl %1" "\n\t" \
  5985. "testb "AL","AL "\n\t" \
  5986. "jge "LR(1,f) "\n\t" \
  5987. "sall $8,"EAX "\n\t" \
  5988. "movb (%1),"AL "\n\t" \
  5989. "incl %1" "\n\t" \
  5990. "sall $17,"EAX "\n\t" \
  5991. "sarl $17,"EAX "\n\t" \
  5992. "jne "LR(2,f) "\n\t" \
  5993. "movb (%1),"AL "\n\t" \
  5994. "sall $8,"EAX "\n\t" \
  5995. "movb 1(%1),"AL "\n\t" \
  5996. "sall $8,"EAX "\n\t" \
  5997. "movb 2(%1),"AL "\n\t" \
  5998. "sall $8,"EAX "\n\t" \
  5999. "movb 3(%1),"AL "\n\t" \
  6000. "addl $4,"EAX "\n\t" \
  6001. "jmp "LR(2,f) "\n" \
  6002. LD(1)":" "\t" \
  6003. "sall $25,"EAX "\n\t" \
  6004. "sarl $25,"EAX "\n" \
  6005. LD(2)":" \
  6006. : OUT_EAX (where), "=r" (byteptr) : "1" (byteptr) );
  6007. #endif
  6008. #if defined(GNU) && defined(ARM) && !defined(NO_ASM)
  6009. /* Macro written by Peter Burwood. */
  6010. #undef S_operand
  6011. #define S_operand(where) \
  6012. { var uintL dummy; \
  6013. __asm__( \
  6014. "ldrb %0,[%1],#1" "\n\t" \
  6015. "movs %0,%0,LSL#25" "\n\t" \
  6016. "movcc %0,%0,ASR#25" "\n\t" \
  6017. "bcc "LR(1,f) "\n\t" \
  6018. "ldrb %2,[%1],#1" "\n\t" \
  6019. "orr %0,%0,%2,LSL#17" "\n\t" \
  6020. "movs %0,%0,ASR#17" "\n\t" \
  6021. "bne "LR(1,f) "\n\t" \
  6022. "ldrb %0,[%1],#1" "\n\t" \
  6023. "ldrb %2,[%1],#1" "\n\t" \
  6024. "orr %0,%2,%0,LSL#8" "\n\t" \
  6025. "ldrb %2,[%1],#1" "\n\t" \
  6026. "orr %0,%2,%0,LSL#8" "\n\t" \
  6027. "ldrb %2,[%1],#1" "\n\t" \
  6028. "orr %0,%2,%0,LSL#8" "\n" \
  6029. LD(1)":" \
  6030. : "=r" (where), "=r" (byteptr), "=r" (dummy) : "1" (byteptr) : "cc" ); \
  6031. }
  6032. #endif
  6033. /* Macro S_operand_ignore();
  6034. skips the next Operand (a Signed Integer)
  6035. and advances the bytecodepointer. */
  6036. #define S_operand_ignore() \
  6037. { var uintB where = *byteptr++; /* read first byte */ \
  6038. if ((uintB)where & bit(7)) \
  6039. /* Bit 7 was set */ \
  6040. { if ((uintB)((where<<1) | *byteptr++) == 0) /* next Byte */ \
  6041. /* special case: 2-Byte-Operand = 0 -> 6-Byte-Operand */ \
  6042. { byteptr += 4; } \
  6043. } }
  6044. #if defined(GNU) && defined(MC680X0) && !defined(NO_ASM)
  6045. #undef S_operand_ignore
  6046. #define S_operand_ignore() \
  6047. { var uintB where; \
  6048. __asm__( \
  6049. "moveb %1@+,%0" "\n\t" \
  6050. "bpl 1f" "\n\t" \
  6051. "addb %0,%0" "\n\t" \
  6052. "orb %1@+,%0" "\n\t" \
  6053. "bne 1f" "\n\t" \
  6054. "addql #4,%1" "\n" \
  6055. "1:" \
  6056. : "=d" (where), "=a" (byteptr) : "1" (byteptr) ); \
  6057. }
  6058. #endif
  6059. #if defined(GNU) && defined(SPARC) && !defined(NO_ASM)
  6060. #undef S_operand_ignore
  6061. #define S_operand_ignore() \
  6062. { var uintL where; \
  6063. var uintL dummy; \
  6064. __asm__( \
  6065. "ldub [%1],%0" "\n\t" \
  6066. "andcc %0,0x80,%%g0" "\n\t" \
  6067. "be 1f" "\n\t" \
  6068. " add %1,1,%1" "\n\t" \
  6069. "sll %0,1,%2" "\n\t" \
  6070. "ldub [%1],%0" "\n\t" \
  6071. "orcc %2,%0,%0" "\n\t" \
  6072. "bne 1f" "\n\t" \
  6073. " add %1,1,%1" "\n\t" \
  6074. "add %1,4,%1" "\n" \
  6075. "1:" \
  6076. : "=r" (where), "=r" (byteptr), "=r" (dummy) : "1" (byteptr) : "ccr" ); \
  6077. }
  6078. #endif
  6079. #if defined(GNU) && defined(ARM) && !defined(NO_ASM)
  6080. /* Macro written by Peter Burwood. */
  6081. #undef S_operand_ignore
  6082. #define S_operand_ignore() \
  6083. { var uintL where; \
  6084. var uintL dummy; \
  6085. __asm__( \
  6086. "ldrb %0,[%1],#1" "\n\t" \
  6087. "movs %0,%0,LSL#25" "\n\t" \
  6088. "bcc "LR(1,f) "\n\t" \
  6089. "ldrb %2,[%1],#1" "\n\t" \
  6090. "orrs %0,%2,%0,LSR#24" "\n\t" \
  6091. "addeq %1,%1,#4" "\n" \
  6092. LD(1)":" \
  6093. : "=r" (where), "=r" (byteptr), "=r" (dummy) : "1" (byteptr) : "cc" ); \
  6094. }
  6095. #endif
  6096. /* Macro L_operand(where);
  6097. moves the next Operand (a Label)
  6098. to (uintB*)where and advances the bytecodepointer. */
  6099. #define L_operand(Lwhere) \
  6100. { var uintL where; /* variable for the displacement */ \
  6101. S_operand(where); /* Displacement */ \
  6102. Lwhere = byteptr + (sintL)where; /* add */ \
  6103. }
  6104. /* Macro L_operand_ignore();
  6105. skips the next Operand (a Label)
  6106. and advances the Bytecodepointer. */
  6107. #define L_operand_ignore() S_operand_ignore()
  6108. /* Each of the bytecodes is interpreted:
  6109. for the most part: mv_count/mv_space = values,
  6110. closureptr = pointer to the compiled closure in Stack,
  6111. closure = compiled closure,
  6112. codeptr = pointer to its codevector,
  6113. byteptr = pointer to the next Byte in code.
  6114. (byteptr is no LISP-object, but nevertheless endangered by GC!
  6115. To make it GC-invariant, substract CODEPTR from it.
  6116. If one then adds Fixnum_0 to it,
  6117. one receives the bytenumber as Fixnum.) */
  6118. #if 0
  6119. #define CODEPTR (&codeptr->data[0])
  6120. #else /* returns more efficient Code */
  6121. #define CODEPTR (uintB*)(codeptr)
  6122. #endif
  6123. /* store context-information:
  6124. If sth. is called, that can trigger a GC, this must be framed within
  6125. with_saved_context( ... ) . */
  6126. #define with_saved_context(statement) \
  6127. { var uintL index = byteptr - CODEPTR; \
  6128. statement; \
  6129. closure = *closureptr; /* fetch Closure from Stack */ \
  6130. codeptr = TheSbvector(TheCclosure(closure)->clos_codevec); \
  6131. byteptr = CODEPTR + index; \
  6132. }
  6133. /* ------------------- (1) Constants ----------------------- */
  6134. CASE cod_nil: code_nil: { /* (NIL) */
  6135. VALUES1(NIL);
  6136. } goto next_byte;
  6137. CASE cod_nil_push: { /* (NIL&PUSH) */
  6138. pushSTACK(NIL);
  6139. } goto next_byte;
  6140. CASE cod_push_nil: { /* (PUSH-NIL n) */
  6141. var uintC n;
  6142. U_operand(n);
  6143. dotimesC(n,n, { pushSTACK(NIL); } );
  6144. } goto next_byte;
  6145. CASE cod_t: code_t: { /* (T) */
  6146. VALUES1(T);
  6147. } goto next_byte;
  6148. CASE cod_t_push: { /* (T&PUSH) */
  6149. pushSTACK(T);
  6150. } goto next_byte;
  6151. CASE cod_const: { /* (CONST n) */
  6152. var uintL n;
  6153. U_operand(n);
  6154. VALUES1(TheCclosure(closure)->clos_consts[n]);
  6155. } goto next_byte;
  6156. CASE cod_const_push: { /* (CONST&PUSH n) */
  6157. var uintL n;
  6158. U_operand(n);
  6159. pushSTACK(TheCclosure(closure)->clos_consts[n]);
  6160. } goto next_byte;
  6161. /* ------------------- (2) static Variables ----------------------- */
  6162. CASE cod_load: { /* (LOAD n) */
  6163. var uintL n;
  6164. U_operand(n);
  6165. VALUES1(STACK_(n));
  6166. } goto next_byte;
  6167. CASE cod_load_push: { /* (LOAD&PUSH n) */
  6168. var uintL n;
  6169. U_operand(n);
  6170. pushSTACK(STACK_(n));
  6171. } goto next_byte;
  6172. CASE cod_loadi: { /* (LOADI k1 k2 n) */
  6173. var uintL k1;
  6174. var uintL k2;
  6175. var uintL n;
  6176. U_operand(k1);
  6177. U_operand(k2);
  6178. U_operand(n);
  6179. var gcv_object_t* FRAME = (gcv_object_t*) SP_(k1+jmpbufsize*k2);
  6180. VALUES1(FRAME_(n));
  6181. } goto next_byte;
  6182. CASE cod_loadi_push: { /* (LOADI&PUSH k1 k2 n) */
  6183. var uintL k1;
  6184. var uintL k2;
  6185. var uintL n;
  6186. U_operand(k1);
  6187. U_operand(k2);
  6188. U_operand(n);
  6189. var gcv_object_t* FRAME = (gcv_object_t*) SP_(k1+jmpbufsize*k2);
  6190. pushSTACK(FRAME_(n));
  6191. } goto next_byte;
  6192. CASE cod_loadc: { /* (LOADC n m) */
  6193. var uintL n;
  6194. var uintL m;
  6195. U_operand(n);
  6196. U_operand(m);
  6197. VALUES1(TheSvector(STACK_(n))->data[1+m]);
  6198. } goto next_byte;
  6199. CASE cod_loadc_push: { /* (LOADC&PUSH n m) */
  6200. var uintL n;
  6201. var uintL m;
  6202. U_operand(n);
  6203. U_operand(m);
  6204. pushSTACK(TheSvector(STACK_(n))->data[1+m]);
  6205. } goto next_byte;
  6206. CASE cod_loadv: { /* (LOADV k m) */
  6207. var uintC k;
  6208. var uintL m;
  6209. U_operand(k);
  6210. U_operand(m);
  6211. var object venv = TheCclosure(closure)->clos_venv; /* VenvConst */
  6212. /* take (svref ... 0) k times: */
  6213. dotimesC(k,k, { venv = TheSvector(venv)->data[0]; } );
  6214. /* fetch (svref ... m) : */
  6215. VALUES1(TheSvector(venv)->data[m]);
  6216. } goto next_byte;
  6217. CASE cod_loadv_push: { /* (LOADV&PUSH k m) */
  6218. var uintC k;
  6219. var uintL m;
  6220. U_operand(k);
  6221. U_operand(m);
  6222. var object venv = TheCclosure(closure)->clos_venv; /* VenvConst */
  6223. /* take (svref ... 0) k times: */
  6224. dotimesC(k,k, { venv = TheSvector(venv)->data[0]; } );
  6225. /* fetch (svref ... m) : */
  6226. pushSTACK(TheSvector(venv)->data[m]);
  6227. } goto next_byte;
  6228. CASE cod_loadic: { /* (LOADIC k1 k2 n m) */
  6229. var uintL k1;
  6230. var uintL k2;
  6231. var uintL n;
  6232. var uintL m;
  6233. U_operand(k1);
  6234. U_operand(k2);
  6235. U_operand(n);
  6236. U_operand(m);
  6237. var gcv_object_t* FRAME = (gcv_object_t*) SP_(k1+jmpbufsize*k2);
  6238. VALUES1(TheSvector(FRAME_(n))->data[1+m]);
  6239. } goto next_byte;
  6240. CASE cod_store: store: { /* (STORE n) */
  6241. var uintL n;
  6242. U_operand(n);
  6243. VALUES1(STACK_(n) = value1);
  6244. } goto next_byte;
  6245. CASE cod_pop_store: { /* (POP&STORE n) */
  6246. var uintL n;
  6247. U_operand(n);
  6248. var object obj = popSTACK();
  6249. VALUES1(STACK_(n) = obj);
  6250. } goto next_byte;
  6251. CASE cod_storei: { /* (STOREI k1 k2 n) */
  6252. var uintL k1;
  6253. var uintL k2;
  6254. var uintL n;
  6255. U_operand(k1);
  6256. U_operand(k2);
  6257. U_operand(n);
  6258. var gcv_object_t* FRAME = (gcv_object_t*) SP_(k1+jmpbufsize*k2);
  6259. VALUES1(FRAME_(n) = value1);
  6260. } goto next_byte;
  6261. CASE cod_load_storec: { /* (LOAD&STOREC k m n) */
  6262. var uintL k;
  6263. U_operand(k);
  6264. value1 = STACK_(k);
  6265. } /* FALLTHROUGH */
  6266. CASE cod_storec: { /* (STOREC n m) */
  6267. var uintL n;
  6268. var uintL m;
  6269. U_operand(n);
  6270. U_operand(m);
  6271. TheSvector(STACK_(n))->data[1+m] = value1; mv_count=1;
  6272. } goto next_byte;
  6273. CASE cod_storev: { /* (STOREV k m) */
  6274. var uintC k;
  6275. var uintL m;
  6276. U_operand(k);
  6277. U_operand(m);
  6278. var object venv = TheCclosure(closure)->clos_venv; /* VenvConst */
  6279. /* take (svref ... 0) k times: */
  6280. dotimesC(k,k, { venv = TheSvector(venv)->data[0]; } );
  6281. /* save (svref ... m) : */
  6282. TheSvector(venv)->data[m] = value1; mv_count=1;
  6283. } goto next_byte;
  6284. CASE cod_storeic: { /* (STOREIC k1 k2 n m) */
  6285. var uintL k1;
  6286. var uintL k2;
  6287. var uintL n;
  6288. var uintL m;
  6289. U_operand(k1);
  6290. U_operand(k2);
  6291. U_operand(n);
  6292. U_operand(m);
  6293. var gcv_object_t* FRAME = (gcv_object_t*) SP_(k1+jmpbufsize*k2);
  6294. TheSvector(FRAME_(n))->data[1+m] = value1; mv_count=1;
  6295. } goto next_byte;
  6296. /* ------------------- (3) dynamic Variables ----------------------- */
  6297. CASE cod_getvalue: { /* (GETVALUE n) */
  6298. var uintL n;
  6299. U_operand(n);
  6300. var object symbol = TheCclosure(closure)->clos_consts[n];
  6301. /* The Compiler has already checked, that it's a Symbol. */
  6302. if (!boundp(Symbol_value(symbol))) {
  6303. pushSTACK(symbol); /* CELL-ERROR slot NAME */
  6304. pushSTACK(symbol); pushSTACK(Closure_name(closure));
  6305. error(unbound_variable,GETTEXT("~S: symbol ~S has no value"));
  6306. }
  6307. VALUES1(Symbol_value(symbol));
  6308. } goto next_byte;
  6309. CASE cod_getvalue_push: { /* (GETVALUE&PUSH n) */
  6310. var uintL n;
  6311. U_operand(n);
  6312. var object symbol = TheCclosure(closure)->clos_consts[n];
  6313. /* The Compiler has already checked, that it's a Symbol. */
  6314. if (!boundp(Symbol_value(symbol))) {
  6315. pushSTACK(symbol); /* CELL-ERROR slot NAME */
  6316. pushSTACK(symbol); pushSTACK(Closure_name(closure));
  6317. error(unbound_variable,GETTEXT("~S: symbol ~S has no value"));
  6318. }
  6319. pushSTACK(Symbol_value(symbol));
  6320. } goto next_byte;
  6321. CASE cod_setvalue: { /* (SETVALUE n) */
  6322. var uintL n;
  6323. U_operand(n);
  6324. var object symbol = TheCclosure(closure)->clos_consts[n];
  6325. /* The Compiler has already checked, that it's a Symbol. */
  6326. if (constant_var_p(TheSymbol(symbol))) {
  6327. pushSTACK(symbol); pushSTACK(Closure_name(closure));
  6328. error(error_condition,GETTEXT("~S: assignment to constant symbol ~S is impossible"));
  6329. }
  6330. Symbol_value(symbol) = value1; mv_count=1;
  6331. } goto next_byte;
  6332. CASE cod_bind: { /* (BIND n) */
  6333. var uintL n;
  6334. U_operand(n);
  6335. dynamic_bind(TheCclosure(closure)->clos_consts[n],value1);
  6336. } goto next_byte;
  6337. CASE cod_unbind1: /* (UNBIND1) */
  6338. #if STACKCHECKC
  6339. if (!(framecode(STACK_0) == DYNBIND_frame_info))
  6340. GOTO_ERROR(error_STACK_putt);
  6341. #endif
  6342. { /* unwind variable-binding-frame: */
  6343. var gcv_object_t* new_STACK = topofframe(STACK_0); /* pointer above frame */
  6344. var gcv_object_t* frame_end = STACKpointable(new_STACK);
  6345. var gcv_object_t* bindingptr = &STACK_1; /* begin of bindings */
  6346. /* bindingptr loops upwards through the bindings */
  6347. while (bindingptr != frame_end) {
  6348. /* write back old value: */
  6349. Symbol_value(*(bindingptr STACKop 0)) = *(bindingptr STACKop 1);
  6350. bindingptr skipSTACKop 2; /* next binding */
  6351. }
  6352. /* set STACK newly, thus unwind frame: */
  6353. setSTACK(STACK = new_STACK);
  6354. } goto next_byte;
  6355. CASE cod_unbind: { /* (UNBIND n) */
  6356. var uintC n;
  6357. U_operand(n); /* n>0 */
  6358. var gcv_object_t* FRAME = STACK;
  6359. do {
  6360. #if STACKCHECKC
  6361. if (!(framecode(FRAME_(0)) == DYNBIND_frame_info))
  6362. GOTO_ERROR(error_STACK_putt);
  6363. #endif
  6364. /* unwind variable-binding-frame: */
  6365. var gcv_object_t* new_FRAME = topofframe(FRAME_(0)); /* pointer above frame */
  6366. var gcv_object_t* frame_end = STACKpointable(new_FRAME);
  6367. var gcv_object_t* bindingptr = &FRAME_(1); /* begin of the bindings */
  6368. /* bindingptr loops upwards through the bindings */
  6369. while (bindingptr != frame_end) {
  6370. /* write back old value: */
  6371. Symbol_value(*(bindingptr STACKop 0)) = *(bindingptr STACKop 1);
  6372. bindingptr skipSTACKop 2; /* next binding */
  6373. }
  6374. FRAME = new_FRAME;
  6375. } while (--n != 0);
  6376. setSTACK(STACK = FRAME); /* set STACK newly */
  6377. } goto next_byte;
  6378. CASE cod_progv: { /* (PROGV) */
  6379. var object vallist = value1; /* value-list */
  6380. var object symlist = popSTACK(); /* symbol-list */
  6381. pushSP((aint)STACK); /* push STACK into SP */
  6382. with_saved_context( progv(symlist,vallist); ); /* build frame */
  6383. } goto next_byte;
  6384. /* ------------------- (4) Stackoperations ----------------------- */
  6385. CASE cod_push: /* (PUSH) */
  6386. pushSTACK(value1);
  6387. goto next_byte;
  6388. CASE cod_pop: /* (POP) */
  6389. VALUES1(popSTACK());
  6390. goto next_byte;
  6391. CASE cod_skip: { /* (SKIP n) */
  6392. var uintL n;
  6393. U_operand(n);
  6394. skipSTACK(n);
  6395. } goto next_byte;
  6396. CASE cod_skipi: { /* (SKIPI k1 k2 n) */
  6397. var uintL k1;
  6398. var uintL k2;
  6399. var uintL n;
  6400. U_operand(k1);
  6401. U_operand(k2);
  6402. U_operand(n);
  6403. skipSP(k1+jmpbufsize*k2);
  6404. var gcv_object_t* newSTACK;
  6405. popSP( newSTACK = (gcv_object_t*) );
  6406. setSTACK(STACK = newSTACK STACKop n);
  6407. } goto next_byte;
  6408. CASE cod_skipsp: { /* (SKIPSP k1 k2) */
  6409. var uintL k1;
  6410. var uintL k2;
  6411. U_operand(k1);
  6412. U_operand(k2);
  6413. skipSP(k1+jmpbufsize*k2);
  6414. } goto next_byte;
  6415. /* ------------------- (5) Control Flow and Jumps --------------------- */
  6416. CASE cod_skip_ret: { /* (SKIP&RET n) */
  6417. var uintL n;
  6418. U_operand(n);
  6419. skipSTACK(n);
  6420. } goto finished; /* return (jump) to caller */
  6421. CASE cod_skip_retgf: { /* (SKIP&RETGF n) */
  6422. var uintL n;
  6423. U_operand(n);
  6424. if (((Codevec)codeptr)->ccv_flags & bit(3)) { /* call inhibition? */
  6425. skipSTACK(n);
  6426. mv_count=1;
  6427. goto finished; /* return (jump) to caller */
  6428. }
  6429. /* It is known (refer to clos.lisp), that this function
  6430. has no optional parameters, but poss. Rest-parameters.
  6431. If there's no Rest-parameter: (FUNCALL value1 arg1 ... argr)
  6432. If there's a Rest-Parameter: (APPLY value1 arg1 ... argr restarg) */
  6433. var uintL r = ((Codevec)codeptr)->ccv_numreq;
  6434. n -= r;
  6435. if (((Codevec)codeptr)->ccv_flags & bit(0)) {
  6436. skipSTACK(n-1); apply(value1,r,popSTACK());
  6437. } else {
  6438. skipSTACK(n); funcall(value1,r);
  6439. } goto finished; /* return (jump) to caller */
  6440. }
  6441. #define JMP() \
  6442. { var const uintB* label_byteptr; \
  6443. L_operand(label_byteptr); \
  6444. DEBUG_CHECK_BYTEPTR(label_byteptr); \
  6445. byteptr = label_byteptr; \
  6446. goto next_byte; \
  6447. }
  6448. #define NOTJMP() \
  6449. { L_operand_ignore(); goto next_byte; }
  6450. jmp1: mv_count=1;
  6451. CASE cod_jmp: jmp: /* (JMP label) */
  6452. JMP();
  6453. CASE cod_jmpif: /* (JMPIF label) */
  6454. if (!nullp(value1)) goto jmp;
  6455. notjmp:
  6456. NOTJMP();
  6457. CASE cod_jmpifnot: /* (JMPIFNOT label) */
  6458. if (nullp(value1)) goto jmp;
  6459. NOTJMP();
  6460. CASE cod_jmpif1: /* (JMPIF1 label) */
  6461. if (!nullp(value1)) goto jmp1;
  6462. NOTJMP();
  6463. CASE cod_jmpifnot1: /* (JMPIFNOT1 label) */
  6464. if (nullp(value1)) goto jmp1;
  6465. NOTJMP();
  6466. CASE cod_jmpifatom: /* (JMPIFATOM label) */
  6467. if (atomp(value1)) goto jmp;
  6468. NOTJMP();
  6469. CASE cod_jmpifconsp: /* (JMPIFCONSP label) */
  6470. if (consp(value1)) goto jmp;
  6471. NOTJMP();
  6472. CASE cod_jmpifeq: /* (JMPIFEQ label) */
  6473. if (eq(popSTACK(),value1)) goto jmp;
  6474. NOTJMP();
  6475. CASE cod_jmpifnoteq: /* (JMPIFNOTEQ label) */
  6476. if (!eq(popSTACK(),value1)) goto jmp;
  6477. NOTJMP();
  6478. CASE cod_jmpifeqto: { /* (JMPIFEQTO n label) */
  6479. var uintL n;
  6480. U_operand(n);
  6481. if (eq(popSTACK(),TheCclosure(closure)->clos_consts[n])) goto jmp;
  6482. } NOTJMP();
  6483. CASE cod_jmpifnoteqto: { /* (JMPIFNOTEQTO n label) */
  6484. var uintL n;
  6485. U_operand(n);
  6486. if (!eq(popSTACK(),TheCclosure(closure)->clos_consts[n])) goto jmp;
  6487. } NOTJMP();
  6488. CASE cod_jmphash: { /* (JMPHASH n label) */
  6489. var uintL n;
  6490. U_operand(n);
  6491. var object hashvalue = /* search value1 in the Hash-table */
  6492. gethash(value1,TheCclosure(closure)->clos_consts[n],false);
  6493. if (eq(hashvalue,nullobj))
  6494. goto jmp; /* not found -> jump to label */
  6495. else { /* interpret found Fixnum as label: */
  6496. DEBUG_CHECK_BYTEPTR(byteptr + fixnum_to_V(hashvalue));
  6497. byteptr += fixnum_to_V(hashvalue);
  6498. }
  6499. } goto next_byte;
  6500. CASE cod_jmphashv: { /* (JMPHASHV n label) */
  6501. var uintL n;
  6502. U_operand(n);
  6503. var object hashvalue = /* search value1 in the Hash-table */
  6504. gethash(value1,TheSvector(TheCclosure(closure)->clos_consts[0])->data[n],false);
  6505. if (eq(hashvalue,nullobj))
  6506. goto jmp; /* not found -> jump to label */
  6507. else { /* interpret found Fixnum as label: */
  6508. DEBUG_CHECK_BYTEPTR(byteptr + fixnum_to_V(hashvalue));
  6509. byteptr += fixnum_to_V(hashvalue);
  6510. }
  6511. } goto next_byte;
  6512. /* executes a (JSR label)-command. */
  6513. #define JSR() \
  6514. check_STACK(); check_SP(); \
  6515. { var const uintB* label_byteptr; \
  6516. L_operand(label_byteptr); \
  6517. with_saved_context( \
  6518. with_saved_back_trace_cclosure(closure, \
  6519. interpret_bytecode_(closure,codeptr,label_byteptr); \
  6520. )); \
  6521. }
  6522. CASE cod_jsr: /* (JSR label) */
  6523. JSR();
  6524. goto next_byte;
  6525. CASE cod_jsr_push: /* (JSR&PUSH label) */
  6526. JSR(); pushSTACK(value1);
  6527. goto next_byte;
  6528. CASE cod_jmptail: { /* (JMPTAIL m n label) */
  6529. var uintL m;
  6530. var uintL n;
  6531. U_operand(m);
  6532. U_operand(n);
  6533. /* It is n>=m. Copy m stack-entries upwards by n-m : */
  6534. var gcv_object_t* ptr1 = STACK STACKop m;
  6535. var gcv_object_t* ptr2 = STACK STACKop n;
  6536. var uintC count;
  6537. dotimesC(count,m, { NEXT(ptr2) = NEXT(ptr1); } );
  6538. /* Now ptr1 = STACK and ptr2 = STACK STACKop (n-m). */
  6539. *(closureptr = &NEXT(ptr2)) = closure; /* store closure in stack */
  6540. setSTACK(STACK = ptr2); /* shorten STACK */
  6541. } JMP(); /* jump to label */
  6542. /* ------------------- (6) Environments and Closures -------------------- */
  6543. CASE cod_venv: /* (VENV) */
  6544. /* fetch VenvConst from the closure: */
  6545. VALUES1(TheCclosure(closure)->clos_venv);
  6546. goto next_byte;
  6547. CASE cod_make_vector1_push: { /* (MAKE-VECTOR1&PUSH n) */
  6548. var uintL n;
  6549. U_operand(n);
  6550. pushSTACK(value1);
  6551. /* create vector: */
  6552. var object vec;
  6553. with_saved_context( { vec = allocate_vector(n+1); } );
  6554. /* fill first element: */
  6555. TheSvector(vec)->data[0] = STACK_0;
  6556. STACK_0 = vec;
  6557. } goto next_byte;
  6558. CASE cod_copy_closure: { /* (COPY-CLOSURE m n) */
  6559. var object oldclos;
  6560. { /* fetch closure to be copied: */
  6561. var uintL m;
  6562. U_operand(m);
  6563. oldclos = TheCclosure(closure)->clos_consts[m];
  6564. }
  6565. /* allocate closure of equal length: */
  6566. var object newclos;
  6567. pushSTACK(oldclos);
  6568. with_saved_context(newclos = allocate_cclosure_copy(oldclos););
  6569. oldclos = popSTACK();
  6570. /* copy contents of the old closure into the new one: */
  6571. do_cclosure_copy(newclos,oldclos);
  6572. { /* copy stack content into the new closure: */
  6573. var uintL n;
  6574. U_operand(n);
  6575. var gcv_object_t* newptr = &TheCclosure(newclos)->clos_consts[n];
  6576. dotimespL(n,n, { *--newptr = popSTACK(); } );
  6577. }
  6578. VALUES1(newclos);
  6579. } goto next_byte;
  6580. CASE cod_copy_closure_push: { /* (COPY-CLOSURE&PUSH m n) */
  6581. var object oldclos;
  6582. { /* fetch closure to be copied: */
  6583. var uintL m;
  6584. U_operand(m);
  6585. oldclos = TheCclosure(closure)->clos_consts[m];
  6586. }
  6587. /* allocate closure of equal length: */
  6588. var object newclos;
  6589. pushSTACK(oldclos);
  6590. with_saved_context(newclos = allocate_cclosure_copy(oldclos););
  6591. oldclos = popSTACK();
  6592. /* copy contents of the old closure into the new one: */
  6593. do_cclosure_copy(newclos,oldclos);
  6594. { /* copy stack content into the new closure: */
  6595. var uintL n;
  6596. U_operand(n);
  6597. var gcv_object_t* newptr = &TheCclosure(newclos)->clos_consts[n];
  6598. dotimespL(n,n, { *--newptr = popSTACK(); } );
  6599. }
  6600. pushSTACK(newclos);
  6601. } goto next_byte;
  6602. /* ------------------- (7) Function Calls -----------------------
  6603. executes (CALL k n)-command. */
  6604. #define CALL() \
  6605. { var uintC k; /* number of arguments */ \
  6606. var uintL n; \
  6607. U_operand(k); \
  6608. U_operand(n); \
  6609. with_saved_context( \
  6610. funcall(TheCclosure(closure)->clos_consts[n],k); \
  6611. ); \
  6612. }
  6613. /* executes (CALL0 n)-command. */
  6614. #define CALL0() \
  6615. { var uintL n; \
  6616. U_operand(n); \
  6617. with_saved_context( \
  6618. funcall(TheCclosure(closure)->clos_consts[n],0); \
  6619. ); \
  6620. }
  6621. /* executes (CALL1 n)-command. */
  6622. #define CALL1() \
  6623. { var uintL n; \
  6624. U_operand(n); \
  6625. with_saved_context( \
  6626. funcall(TheCclosure(closure)->clos_consts[n],1); \
  6627. ); \
  6628. }
  6629. /* executes (CALL2 n)-command. */
  6630. #define CALL2() \
  6631. { var uintL n; \
  6632. U_operand(n); \
  6633. with_saved_context( \
  6634. funcall(TheCclosure(closure)->clos_consts[n],2); \
  6635. ); \
  6636. }
  6637. /* executes (CALLS1 n)-command. */
  6638. #define CALLS1() \
  6639. { var uintL n; \
  6640. B_operand(n); \
  6641. /* The compiler has already done the argument-check. */ \
  6642. {var Subr fun = FUNTAB1[n]; \
  6643. with_saved_context( \
  6644. with_saved_back_trace_subr(subr_tab_ptr_as_object(fun),STACK,-1, \
  6645. (*(subr_norest_function_t*)(fun->function))(); \
  6646. )); \
  6647. }}
  6648. /* executes (CALLS2 n)-command. */
  6649. #define CALLS2() \
  6650. { var uintL n; \
  6651. B_operand(n); \
  6652. /* The compiler has already done the argument-check. */ \
  6653. {var Subr fun = FUNTAB2[n]; \
  6654. with_saved_context( \
  6655. with_saved_back_trace_subr(subr_tab_ptr_as_object(fun),STACK,-1, \
  6656. (*(subr_norest_function_t*)(fun->function))(); \
  6657. )); \
  6658. }} \
  6659. /* executes (CALLSR m n)-command. */
  6660. #define CALLSR() \
  6661. { var uintL m; \
  6662. var uintL n; \
  6663. U_operand(m); \
  6664. B_operand(n); \
  6665. /* The compiler has already done the argument-check. */ \
  6666. {var Subr fun = FUNTABR[n]; \
  6667. with_saved_context( \
  6668. with_saved_back_trace_subr(subr_tab_ptr_as_object(fun),STACK,-1, \
  6669. (*(subr_rest_function_t*)(fun->function))(m,args_end_pointer STACKop m); \
  6670. )); \
  6671. }}
  6672. CASE cod_call: /* (CALL k n) */
  6673. CALL();
  6674. goto next_byte;
  6675. CASE cod_call_push: /* (CALL&PUSH k n) */
  6676. CALL(); pushSTACK(value1);
  6677. goto next_byte;
  6678. CASE cod_call0: /* (CALL0 n) */
  6679. CALL0();
  6680. goto next_byte;
  6681. CASE cod_call1: /* (CALL1 n) */
  6682. CALL1();
  6683. goto next_byte;
  6684. CASE cod_call1_push: /* (CALL1&PUSH n) */
  6685. CALL1(); pushSTACK(value1);
  6686. goto next_byte;
  6687. CASE cod_call2: /* (CALL2 n) */
  6688. CALL2();
  6689. goto next_byte;
  6690. CASE cod_call2_push: /* (CALL2&PUSH n) */
  6691. CALL2(); pushSTACK(value1);
  6692. goto next_byte;
  6693. CASE cod_calls1: /* (CALLS1 n) */
  6694. CALLS1();
  6695. goto next_byte;
  6696. CASE cod_calls1_push: /* (CALLS1&PUSH n) */
  6697. CALLS1(); pushSTACK(value1);
  6698. goto next_byte;
  6699. CASE cod_calls2: /* (CALLS2 n) */
  6700. CALLS2();
  6701. goto next_byte;
  6702. CASE cod_calls2_push: /* (CALLS2&PUSH n) */
  6703. CALLS2(); pushSTACK(value1);
  6704. goto next_byte;
  6705. CASE cod_callsr: /* (CALLSR m n) */
  6706. CALLSR();
  6707. goto next_byte;
  6708. CASE cod_callsr_push: /* (CALLSR&PUSH m n) */
  6709. CALLSR(); pushSTACK(value1);
  6710. goto next_byte;
  6711. /* executes a (CALLC)-command. */
  6712. #define CALLC() \
  6713. { check_STACK(); check_SP(); /* check STACK and SP */ \
  6714. with_saved_context( \
  6715. /* interprete compiled closure starting at Byte 8 */ \
  6716. interpret_bytecode(value1,TheCclosure(value1)->clos_codevec,CCV_START_NONKEY); \
  6717. ); \
  6718. }
  6719. /* executes a (CALLCKEY)-command. */
  6720. #define CALLCKEY() \
  6721. { check_STACK(); check_SP(); /* check STACK and SP */ \
  6722. with_saved_context( \
  6723. /* interprete compiled closure starting at Byte 12: */ \
  6724. interpret_bytecode(value1,TheCclosure(value1)->clos_codevec,CCV_START_KEY); \
  6725. ); \
  6726. }
  6727. CASE cod_callc: /* (CALLC) */
  6728. CALLC();
  6729. goto next_byte;
  6730. CASE cod_callc_push: /* (CALLC&PUSH) */
  6731. CALLC(); pushSTACK(value1);
  6732. goto next_byte;
  6733. CASE cod_callckey: /* (CALLCKEY) */
  6734. CALLCKEY();
  6735. goto next_byte;
  6736. CASE cod_callckey_push: /* (CALLCKEY&PUSH) */
  6737. CALLCKEY(); pushSTACK(value1);
  6738. goto next_byte;
  6739. CASE cod_funcall: { /* (FUNCALL n) */
  6740. var uintL n;
  6741. U_operand(n);
  6742. var object fun = STACK_(n); /* Function */
  6743. with_saved_context( funcall(fun,n); ); /* call Function */
  6744. skipSTACK(1); /* discard function from Stack */
  6745. } goto next_byte;
  6746. CASE cod_funcall_push: { /* (FUNCALL&PUSH n) */
  6747. var uintL n;
  6748. U_operand(n);
  6749. var object fun = STACK_(n); /* Function */
  6750. with_saved_context( funcall(fun,n); ); /* call Function */
  6751. STACK_0 = value1; /* replace Function in Stack by value */
  6752. } goto next_byte;
  6753. CASE cod_apply: { /* (APPLY n) */
  6754. var uintL n;
  6755. U_operand(n);
  6756. var object fun = STACK_(n); /* Function */
  6757. with_saved_context( apply(fun,n,value1); ); /* call Function */
  6758. skipSTACK(1); /* discard Function from Stack */
  6759. } goto next_byte;
  6760. CASE cod_apply_push: { /* (APPLY&PUSH n) */
  6761. var uintL n;
  6762. U_operand(n);
  6763. var object fun = STACK_(n); /* Function */
  6764. with_saved_context( apply(fun,n,value1); ); /* call Function */
  6765. STACK_0 = value1; /* replace Function in Stack by value */
  6766. } goto next_byte;
  6767. /* ---------------- (8) optional and Keyword-arguments ---------------- */
  6768. CASE cod_push_unbound: { /* (PUSH-UNBOUND n) */
  6769. var uintC n;
  6770. U_operand(n);
  6771. dotimesC(n,n, { pushSTACK(unbound); } );
  6772. } goto next_byte;
  6773. CASE cod_unlist: { /* (UNLIST n m) */
  6774. var uintC n;
  6775. var uintC m;
  6776. U_operand(n);
  6777. U_operand(m);
  6778. var object l = value1;
  6779. if (n > 0)
  6780. do {
  6781. if (atomp(l)) goto unlist_unbound;
  6782. pushSTACK(Car(l)); l = Cdr(l);
  6783. } while (--n != 0);
  6784. if (atomp(l))
  6785. goto next_byte;
  6786. else
  6787. error_apply_toomany(S(lambda));
  6788. unlist_unbound:
  6789. if (n > m) error_apply_toofew(S(lambda),l);
  6790. do { pushSTACK(unbound); } while (--n != 0);
  6791. } goto next_byte;
  6792. CASE cod_unliststar: { /* (UNLIST* n m) */
  6793. var uintC n;
  6794. var uintC m;
  6795. U_operand(n);
  6796. U_operand(m);
  6797. var object l = value1;
  6798. do {
  6799. if (atomp(l)) goto unliststar_unbound;
  6800. pushSTACK(Car(l)); l = Cdr(l);
  6801. } while (--n != 0);
  6802. pushSTACK(l);
  6803. goto next_byte;
  6804. unliststar_unbound:
  6805. if (n > m) error_apply_toofew(S(lambda),l);
  6806. do { pushSTACK(unbound); } while (--n != 0);
  6807. pushSTACK(NIL);
  6808. } goto next_byte;
  6809. CASE cod_jmpifboundp: { /* (JMPIFBOUNDP n label) */
  6810. var uintL n;
  6811. U_operand(n);
  6812. var object obj = STACK_(n);
  6813. if (!boundp(obj)) goto notjmp;
  6814. VALUES1(obj);
  6815. } JMP();
  6816. CASE cod_boundp: { /* (BOUNDP n) */
  6817. var uintL n;
  6818. U_operand(n);
  6819. var object obj = STACK_(n);
  6820. if (!boundp(obj)) goto code_nil; else goto code_t;
  6821. }
  6822. CASE cod_unbound_nil: { /* (UNBOUND->NIL n) */
  6823. var uintL n;
  6824. U_operand(n);
  6825. if (!boundp(STACK_(n))) { STACK_(n) = NIL; }
  6826. } goto next_byte;
  6827. /* ------------------- (9) Treatment of multiple values -------------- */
  6828. CASE cod_values0: /* (VALUES0) */
  6829. VALUES0;
  6830. goto next_byte;
  6831. CASE cod_values1: /* (VALUES1) */
  6832. mv_count = 1;
  6833. goto next_byte;
  6834. CASE cod_stack_to_mv: { /* (STACK-TO-MV n) */
  6835. var uintL n;
  6836. U_operand(n);
  6837. if (n >= mv_limit) GOTO_ERROR(error_toomany_values);
  6838. STACK_to_mv(n);
  6839. } goto next_byte;
  6840. CASE cod_mv_to_stack: /* (MV-TO-STACK) */
  6841. mv_to_STACK(); /* push values on Stack */
  6842. goto next_byte;
  6843. CASE cod_nv_to_stack: { /* (NV-TO-STACK n) */
  6844. var uintL n;
  6845. U_operand(n);
  6846. /* test for Stack-Overflow: */
  6847. get_space_on_STACK(n*sizeof(gcv_object_t));
  6848. /* push n values in the Stack: */
  6849. var uintC count = mv_count;
  6850. if (n==0) goto nv_to_stack_end; /* no value desired -> finished */
  6851. /* at least 1 value desired */
  6852. pushSTACK(value1);
  6853. n--; if (n==0) goto nv_to_stack_end; /* only 1 value desired -> finished */
  6854. if (count<=1) goto nv_to_stack_fill; /* only 1 value present -> fill with NILs */
  6855. count--;
  6856. { /* at least 2 values desired and present */
  6857. var object* mvp = &mv_space[1];
  6858. while (1) {
  6859. pushSTACK(*mvp++);
  6860. n--; if (n==0) goto nv_to_stack_end; /* no further value desired -> finished */
  6861. count--; if (count==0) goto nv_to_stack_fill; /* no further value present -> fill with NILs */
  6862. }
  6863. }
  6864. nv_to_stack_fill: /* fill up with n>0 NILs as additional values: */
  6865. dotimespL(n,n, { pushSTACK(NIL); } );
  6866. nv_to_stack_end: ;
  6867. } goto next_byte;
  6868. CASE cod_mv_to_list: /* (MV-TO-LIST) */
  6869. with_saved_context(
  6870. /* push values on Stack and handicraft list out of it: */
  6871. mv_to_list();
  6872. );
  6873. VALUES1(popSTACK());
  6874. goto next_byte;
  6875. CASE cod_list_to_mv: /* (LIST-TO-MV) */
  6876. list_to_mv(value1, GOTO_ERROR(error_toomany_values));
  6877. goto next_byte;
  6878. CASE cod_mvcallp: /* (MVCALLP) */
  6879. pushSP((aint)STACK); /* save STACK */
  6880. pushSTACK(value1); /* save function to be executed */
  6881. goto next_byte;
  6882. CASE cod_mvcall: { /* (MVCALL) */
  6883. var gcv_object_t* FRAME; popSP( FRAME = (gcv_object_t*) ); /* Pointer to Arguments and Function */
  6884. var object fun = NEXT(FRAME); /* Function */
  6885. with_saved_context({
  6886. var uintL argcount = /* number of arguments on stack */
  6887. STACK_item_count(STACK,FRAME);
  6888. if (((uintL)~(uintL)0 > ca_limit_1) && (argcount > ca_limit_1)) {
  6889. pushSTACK(fun);
  6890. pushSTACK(S(multiple_value_call));
  6891. /* ANSI CL 3.5.1.3. wants a PROGRAM-ERROR here. */
  6892. error(program_error,
  6893. GETTEXT("~S: too many arguments given to ~S"));
  6894. }
  6895. /* apply Function, lift Stack until below the Function: */
  6896. funcall(fun,argcount);
  6897. skipSTACK(1); /* discard Function from STACK */
  6898. });
  6899. } goto next_byte;
  6900. /* ------------------- (10) BLOCK ----------------------- */
  6901. CASE cod_block_open: { /* (BLOCK-OPEN n label) */
  6902. /* occupies 3 STACK-entries and 1 SP-jmp_buf-entry and 2 SP-entries */
  6903. var uintL n;
  6904. var sintL label_dist;
  6905. U_operand(n);
  6906. S_operand(label_dist);
  6907. /* create Block_Cons: */
  6908. var object block_cons;
  6909. with_saved_context(
  6910. block_cons = allocate_cons();
  6911. label_dist += index; /* CODEPTR+label_dist is the jump destination */
  6912. );
  6913. /* fill Block-Cons: (CONST n) as CAR */
  6914. Car(block_cons) = TheCclosure(closure)->clos_consts[n];
  6915. /* jump destination into SP: */
  6916. pushSP(label_dist); pushSP((aint)closureptr);
  6917. { /* build up CBLOCK-Frame: */
  6918. var gcv_object_t* top_of_frame = STACK; /* Pointer above Frame */
  6919. pushSTACK(block_cons); /* Cons ( (CONST n) . ...) */
  6920. var JMPBUF_on_SP(returner); /* memorize return-point */
  6921. finish_entry_frame_1(CBLOCK,returner, goto block_return; );
  6922. }
  6923. /* store Framepointer in Block-Cons: */
  6924. Cdr(block_cons) = make_framepointer(STACK);
  6925. } goto next_byte;
  6926. block_return: { /* jump to this label takes place, if the previously
  6927. built CBLOCK-Frame has catched a RETURN-FROM. */
  6928. FREE_JMPBUF_on_SP();
  6929. skipSTACK(2); /* unwind CBLOCK-Frame and mark */
  6930. Cdr(popSTACK()) = disabled; /* Block-Cons as Disabled */
  6931. var uintL index;
  6932. /* get closure back, byteptr:=label_byteptr : */
  6933. popSP(closureptr = (gcv_object_t*) ); popSP(index = );
  6934. closure = *closureptr; /* fetch Closure from Stack */
  6935. codeptr = TheSbvector(TheCclosure(closure)->clos_codevec);
  6936. DEBUG_CHECK_BYTEPTR(CODEPTR + index);
  6937. byteptr = CODEPTR + index;
  6938. } goto next_byte; /* continue interpretation at Label */
  6939. CASE cod_block_close: /* (BLOCK-CLOSE) */
  6940. /* unwind CBLOCK-Frame: */
  6941. #if STACKCHECKC
  6942. if (!(framecode(STACK_0) == CBLOCK_frame_info))
  6943. GOTO_ERROR(error_STACK_putt);
  6944. #endif
  6945. {
  6946. FREE_JMPBUF_on_SP();
  6947. skipSTACK(2); /* unwind CBLOCK-Frame and mark */
  6948. Cdr(popSTACK()) = disabled; /* Block-Cons as Disabled */
  6949. skipSP(2); /* we know Destination-Closureptr and Destination-Label */
  6950. } goto next_byte; /* at Label continue interpretation */
  6951. CASE cod_return_from: { /* (RETURN-FROM n) */
  6952. var uintL n;
  6953. U_operand(n);
  6954. var object block_cons = TheCclosure(closure)->clos_consts[n];
  6955. if (eq(Cdr(block_cons),disabled))
  6956. error_block_left(Car(block_cons));
  6957. /* unwind upto Block-Frame, then jump to its routine for freeing: */
  6958. #ifndef FAST_SP
  6959. FREE_DYNAMIC_ARRAY(private_SP_space);
  6960. #endif
  6961. unwind_upto(uTheFramepointer(Cdr(block_cons)));
  6962. }
  6963. CASE cod_return_from_i: { /* (RETURN-FROM-I k1 k2 n) */
  6964. var uintL k1;
  6965. var uintL k2;
  6966. var uintL n;
  6967. U_operand(k1);
  6968. U_operand(k2);
  6969. U_operand(n);
  6970. var gcv_object_t* FRAME = (gcv_object_t*) SP_(k1+jmpbufsize*k2);
  6971. var object block_cons = FRAME_(n);
  6972. if (eq(Cdr(block_cons),disabled))
  6973. error_block_left(Car(block_cons));
  6974. /* unwind upto Block-Frame, then jump to its routine for freeing: */
  6975. #ifndef FAST_SP
  6976. FREE_DYNAMIC_ARRAY(private_SP_space);
  6977. #endif
  6978. unwind_upto(uTheFramepointer(Cdr(block_cons)));
  6979. }
  6980. /* ------------------- (11) TAGBODY ----------------------- */
  6981. CASE cod_tagbody_open: { /* (TAGBODY-OPEN n label1 ... labelm) */
  6982. /* occupies 3+m STACK-Entries and 1 SP-jmp_buf-Entry and 1 SP-Entry */
  6983. var uintL n;
  6984. U_operand(n);
  6985. /* create Tagbody-Cons: */
  6986. var object tagbody_cons;
  6987. with_saved_context(tagbody_cons = allocate_cons(););
  6988. { /* fill Tagbody-Cons: Tag-Vector (CONST n) as CAR */
  6989. var object tag_vector = TheCclosure(closure)->clos_consts[n];
  6990. var uintL m = Svector_length(tag_vector);
  6991. Car(tagbody_cons) = tag_vector;
  6992. get_space_on_STACK(m*sizeof(gcv_object_t)); /* allocate space */
  6993. /* push all labeli as Fixnums on the STACK: */
  6994. var uintL count;
  6995. dotimespL(count,m, {
  6996. var const uintB* label_byteptr;
  6997. L_operand(label_byteptr);
  6998. pushSTACK(fixnum(label_byteptr - CODEPTR));
  6999. });
  7000. }
  7001. /* jump destination in the SP: */
  7002. pushSP((aint)closureptr);
  7003. { /* build upCTAGBODY-Frame: */
  7004. var gcv_object_t* top_of_frame = STACK; /* Pointer above Frame */
  7005. pushSTACK(tagbody_cons); /* Cons ( (CONST n) . ...) */
  7006. var JMPBUF_on_SP(returner); /* memorize return-point */
  7007. finish_entry_frame_1(CTAGBODY,returner, goto tagbody_go; );
  7008. }
  7009. /* store Framepointer in Tagbody-Cons: */
  7010. Cdr(tagbody_cons) = make_framepointer(STACK);
  7011. } goto next_byte;
  7012. tagbody_go: { /* jump to this label takes place, if the previously
  7013. built CTAGBODY-Frame has catched a GO to Label nr. i. */
  7014. var uintL m = Svector_length(Car(STACK_2)); /* Number of Labels */
  7015. /* (I could also declare the m above as 'auto' and use it here.) */
  7016. var uintL i = posfixnum_to_V(value1); /* Number of Labels */
  7017. var uintL index = posfixnum_to_V(STACK_((m-i)+3)); /* labeli */
  7018. /* get closure back, byteptr:=labeli_byteptr : */
  7019. closureptr = (gcv_object_t*) SP_(jmpbufsize+0);
  7020. closure = *closureptr; /* fetch Closure from Stack */
  7021. codeptr = TheSbvector(TheCclosure(closure)->clos_codevec);
  7022. DEBUG_CHECK_BYTEPTR(CODEPTR + index);
  7023. byteptr = CODEPTR + index;
  7024. } goto next_byte; /* continue interpretation at Label i */
  7025. CASE cod_tagbody_close_nil: /* (TAGBODY-CLOSE-NIL) */
  7026. VALUES1(NIL); /* value of Tagbody is NIL */
  7027. CASE cod_tagbody_close: /* (TAGBODY-CLOSE) */
  7028. /* unwind CTAGBODY-Frame: */
  7029. #if STACKCHECKC
  7030. if (!(framecode(STACK_0) == CTAGBODY_frame_info))
  7031. GOTO_ERROR(error_STACK_putt);
  7032. #endif
  7033. {
  7034. FREE_JMPBUF_on_SP();
  7035. var object tagbody_cons = STACK_2; /* Tagbody-Cons */
  7036. Cdr(tagbody_cons) = disabled; /* mark as Disabled */
  7037. skipSTACK(3+Svector_length(Car(tagbody_cons)));
  7038. skipSP(1);
  7039. } goto next_byte;
  7040. CASE cod_go: { /* (GO n l) */
  7041. var uintL n;
  7042. var uintL l;
  7043. U_operand(n);
  7044. U_operand(l);
  7045. var object tagbody_cons = /* (CONST n) */
  7046. TheCclosure(closure)->clos_consts[n];
  7047. if (eq(Cdr(tagbody_cons),disabled)) {
  7048. var object tag_vector = Car(tagbody_cons);
  7049. pushSTACK(tag_vector);
  7050. pushSTACK(TheSvector(tag_vector)->data[l]); /* label l */
  7051. pushSTACK(S(go));
  7052. error(control_error,GETTEXT("(~S ~S): the tagbody of the tags ~S has already been left"));
  7053. }
  7054. /* value passed to the Tagbody:
  7055. For CTAGBODY-Frames: 1+l as Fixnum,
  7056. For ITAGBODY-Frames: the form-list for Tag nr. l. */
  7057. var gcv_object_t* FRAME = uTheFramepointer(Cdr(tagbody_cons));
  7058. VALUES1(framecode(FRAME_(0)) == CTAGBODY_frame_info
  7059. ? fixnum(1+l)
  7060. : (object)FRAME_(frame_bindings+2*l+1));
  7061. /* unwind upto Tagbody-Frame, then jump to its Routine,
  7062. which then jumps to Label l: */
  7063. #ifndef FAST_SP
  7064. FREE_DYNAMIC_ARRAY(private_SP_space);
  7065. #endif
  7066. unwind_upto(FRAME);
  7067. }
  7068. CASE cod_go_i: { /* (GO-I k1 k2 n l) */
  7069. var uintL k1;
  7070. var uintL k2;
  7071. var uintL n;
  7072. var uintL l;
  7073. U_operand(k1);
  7074. U_operand(k2);
  7075. U_operand(n);
  7076. U_operand(l);
  7077. var gcv_object_t* FRAME = (gcv_object_t*) SP_(k1+jmpbufsize*k2);
  7078. var object tagbody_cons = FRAME_(n);
  7079. if (eq(Cdr(tagbody_cons),disabled)) {
  7080. var object tag_vector = Car(tagbody_cons);
  7081. pushSTACK(tag_vector);
  7082. pushSTACK(TheSvector(tag_vector)->data[l]); /* label l */
  7083. pushSTACK(S(go));
  7084. error(control_error,GETTEXT("(~S ~S): the tagbody of the tags ~S has already been left"));
  7085. }
  7086. /* value passed to Tagbody:
  7087. For CTAGBODY-Frames 1+l as Fixnum. */
  7088. FRAME = uTheFramepointer(Cdr(tagbody_cons));
  7089. VALUES1(fixnum(1+l));
  7090. /* unwind upto Tagbody-Frame, then jump to its Routine,
  7091. which then jumps to Label l: */
  7092. #ifndef FAST_SP
  7093. FREE_DYNAMIC_ARRAY(private_SP_space);
  7094. #endif
  7095. unwind_upto(FRAME);
  7096. }
  7097. /* ------------------- (12) CATCH and THROW ----------------------- */
  7098. CASE cod_catch_open: /* (CATCH-OPEN label) */
  7099. { /* occupies 3 STACK-Entries and 1 SP-jmp_buf-Entry and 2 SP-Entries */
  7100. var const uintB* label_byteptr;
  7101. L_operand(label_byteptr);
  7102. /* save closureptr, label_byteptr: */
  7103. pushSP(label_byteptr - CODEPTR); pushSP((aint)closureptr);
  7104. }
  7105. { /* build up Frame: */
  7106. var gcv_object_t* top_of_frame = STACK;
  7107. pushSTACK(value1); /* Tag */
  7108. var JMPBUF_on_SP(returner); /* memorize return-point */
  7109. finish_entry_frame_1(CATCH,returner, goto catch_return; );
  7110. } goto next_byte;
  7111. catch_return: { /* jump to this label takes place, if the previoulsy
  7112. built Catch-Frame has catched a Throw. */
  7113. FREE_JMPBUF_on_SP();
  7114. skipSTACK(3); /* unwind CATCH-Frame */
  7115. var uintL index;
  7116. /* get closure back, byteptr:=label_byteptr : */
  7117. popSP(closureptr = (gcv_object_t*) ); popSP(index = );
  7118. closure = *closureptr; /* fetch Closure from Stack */
  7119. codeptr = TheSbvector(TheCclosure(closure)->clos_codevec);
  7120. DEBUG_CHECK_BYTEPTR(CODEPTR + index);
  7121. byteptr = CODEPTR + index;
  7122. } goto next_byte; /* continue interpretation at Label */
  7123. CASE cod_catch_close: /* (CATCH-CLOSE) */
  7124. /* a CATCH-Frame has to come: */
  7125. #if STACKCHECKC
  7126. if (!(framecode(STACK_0) == CATCH_frame_info))
  7127. GOTO_ERROR(error_STACK_putt);
  7128. #endif
  7129. FREE_JMPBUF_on_SP();
  7130. #if STACKCHECKC
  7131. if (!(closureptr == (gcv_object_t*)SP_(0))) /* that Closureptr must be the current one */
  7132. GOTO_ERROR(error_STACK_putt);
  7133. #endif
  7134. skipSP(2); skipSTACK(3); /* unwind CATCH-Frame */
  7135. goto next_byte;
  7136. CASE cod_throw: { /* (THROW) */
  7137. var object tag = popSTACK();
  7138. throw_to(tag);
  7139. pushSTACK(tag);
  7140. pushSTACK(S(throw));
  7141. error(control_error,GETTEXT("~S: there is no CATCHer for tag ~S"));
  7142. }
  7143. /* ------------------- (13) UNWIND-PROTECT ----------------------- */
  7144. CASE cod_uwp_open: /* (UNWIND-PROTECT-OPEN label) */
  7145. { /* occupies 2 STACK-Entries and 1 SP-jmp_buf-Entry and 2 SP-Entries */
  7146. var const uintB* label_byteptr;
  7147. L_operand(label_byteptr);
  7148. /* save closureptr, label_byteptr: */
  7149. pushSP(label_byteptr - CODEPTR); pushSP((aint)closureptr);
  7150. }
  7151. { /* build Frame: */
  7152. var gcv_object_t* top_of_frame = STACK;
  7153. var JMPBUF_on_SP(returner); /* memorize return-point */
  7154. finish_entry_frame_1(UNWIND_PROTECT,returner, goto throw_save; );
  7155. } goto next_byte;
  7156. throw_save: /* jump to this label takes place, if the previously
  7157. built Unwind-Protect-Frame has stopped a Throw.
  7158. unwind_protect_to_save is to be saved and jumped to at the end. */
  7159. #if STACKCHECKC
  7160. if (!(framecode(STACK_0) == UNWIND_PROTECT_frame_info)) {
  7161. error(serious_condition,GETTEXT("STACK corrupted"));
  7162. }
  7163. #endif
  7164. /* unwind Frame: */
  7165. FREE_JMPBUF_on_SP();
  7166. skipSTACK(2);
  7167. {
  7168. var uintL index;
  7169. /* get closure back, byteptr:=label_byteptr : */
  7170. popSP(closureptr = (gcv_object_t*) );
  7171. popSP(index = );
  7172. /* save unwind_protect_to_save: */
  7173. pushSP((aint)unwind_protect_to_save.fun);
  7174. pushSP((aint)unwind_protect_to_save.upto_frame);
  7175. pushSP((aint)STACK); /* push Pointer above Frame additionally on the SP */
  7176. /* move all values to the Stack: */
  7177. mv_to_STACK();
  7178. /* execute Cleanup-Forms: */
  7179. closure = *closureptr; /* fetch Closure from Stack */
  7180. codeptr = TheSbvector(TheCclosure(closure)->clos_codevec);
  7181. DEBUG_CHECK_BYTEPTR(CODEPTR + index);
  7182. byteptr = CODEPTR + index;
  7183. } goto next_byte;
  7184. CASE cod_uwp_normal_exit: /* (UNWIND-PROTECT-NORMAL-EXIT) */
  7185. #if STACKCHECKC
  7186. if (!(framecode(STACK_0) == UNWIND_PROTECT_frame_info))
  7187. GOTO_ERROR(error_STACK_putt);
  7188. if (!(closureptr == (gcv_object_t*)SP_(jmpbufsize+0))) /* that Closureptr must be the current one */
  7189. GOTO_ERROR(error_STACK_putt);
  7190. #endif
  7191. /* unwind Frame:
  7192. nothing to do, because closure and byteptr stay unmodified. */
  7193. FREE_JMPBUF_on_SP(); skipSP(2);
  7194. skipSTACK(2);
  7195. /* dummy value for 'unwind_protect_to_save': */
  7196. pushSP((aint)NULL); pushSP((aint)NULL); /* NULL,NULL -> uwp_continue */
  7197. pushSP((aint)STACK); /* push Pointer above Frame additionally on the SP */
  7198. /* move all values to the Stack: */
  7199. mv_to_STACK();
  7200. /* execute Cleanup-Forms: */
  7201. goto next_byte;
  7202. CASE cod_uwp_close: /* (UNWIND-PROTECT-CLOSE) */
  7203. { /* jump to this label takes place at the end of the Cleanup-Forms. */
  7204. var gcv_object_t* oldSTACK; /* value of STACK before saveing the values */
  7205. popSP( oldSTACK = (gcv_object_t*) );
  7206. var uintL mvcount = /* number of saved values on Stack */
  7207. STACK_item_count(STACK,oldSTACK);
  7208. if (mvcount >= mv_limit) GOTO_ERROR(error_toomany_values);
  7209. STACK_to_mv(mvcount);
  7210. }
  7211. { /* return to the saved unwind_protect_to_save.fun : */
  7212. var restartf_t fun;
  7213. var gcv_object_t* arg;
  7214. popSP( arg = (gcv_object_t*) ); popSP( fun = (restartf_t) );
  7215. /* return to uwp_continue or uwp_jmpback or unwind_upto: */
  7216. if (fun != NULL) {
  7217. (*fun)(arg); /* return to unwind_upto or similar. */
  7218. NOTREACHED;
  7219. }
  7220. if (arg == (gcv_object_t*)NULL) {
  7221. /* uwp_continue:
  7222. jump to this label takes place, if after the execution of
  7223. the Cleanup-Forms simply interpretation shall continue. */
  7224. goto next_byte;
  7225. } else {
  7226. /* uwp_jmpback:
  7227. jump to this label takes place, if after the execution of
  7228. the Cleanup-Forms interpretation shall continue at the old
  7229. location in the same Closure. */
  7230. DEBUG_CHECK_BYTEPTR(CODEPTR + (uintP)arg);
  7231. byteptr = CODEPTR + (uintP)arg;
  7232. goto next_byte;
  7233. }
  7234. }
  7235. CASE cod_uwp_cleanup: /* (UNWIND-PROTECT-CLEANUP) */
  7236. /* this is executed, if within the same Closure an execution
  7237. of the Cleanup-Code is necessary. */
  7238. #if STACKCHECKC
  7239. if (!(framecode(STACK_0) == UNWIND_PROTECT_frame_info))
  7240. GOTO_ERROR(error_STACK_putt);
  7241. if (!(closureptr == (gcv_object_t*)SP_(jmpbufsize+0))) /* that Closureptr must be the current one */
  7242. GOTO_ERROR(error_STACK_putt);
  7243. #endif
  7244. { /* closure remains, byteptr:=label_byteptr : */
  7245. var uintL index = SP_(jmpbufsize+1);
  7246. /* unwind Frame: */
  7247. FREE_JMPBUF_on_SP(); skipSP(2);
  7248. skipSTACK(2);
  7249. /* Dummy-values for 'unwind_protect_to_save': */
  7250. pushSP((aint)NULL); /* NULL -> uwp_jmpback */
  7251. pushSP(byteptr - CODEPTR);
  7252. pushSP((aint)STACK); /* push Pointer above Frame additionally on the SP */
  7253. /* move all values to the Stack: */
  7254. mv_to_STACK();
  7255. /* execute Cleanup-Forms: */
  7256. DEBUG_CHECK_BYTEPTR(CODEPTR + index);
  7257. byteptr = CODEPTR + index;
  7258. } goto next_byte;
  7259. /* ------------------- (14) HANDLER-BIND ----------------------- */
  7260. CASE cod_handler_open: { /* (HANDLER-OPEN n) */
  7261. /* occupies 4 STACK-Entries */
  7262. var uintL n;
  7263. U_operand(n);
  7264. /* build up Frame: */
  7265. var gcv_object_t* top_of_frame = STACK; /* Pointer above Frame */
  7266. pushSTACK(TheCclosure(closure)->clos_consts[n]);
  7267. pushSTACK(closure);
  7268. pushSTACK(fake_gcv_object((aint)(_SP_(0))));
  7269. finish_frame(HANDLER);
  7270. } goto next_byte;
  7271. CASE cod_handler_begin_push: /* (HANDLER-BEGIN&PUSH) */
  7272. /* builds up SP newly, occupies 1 SP-Entry and
  7273. starts a new STACK-Region. */
  7274. {
  7275. var uintL count = (uintL)posfixnum_to_V(Car(handler_args.spdepth))
  7276. + jmpbufsize * (uintL)posfixnum_to_V(Cdr(handler_args.spdepth));
  7277. if (count > 0) {
  7278. var SPint* oldsp = handler_args.sp; /* was formerly &SP_(0) */
  7279. /* copy oldsp[0..count-1] to the current SP: */
  7280. oldsp skipSPop count;
  7281. dotimespL(count,count, { oldsp skipSPop -1; pushSP(*oldsp); } );
  7282. }
  7283. }
  7284. pushSP((aint)handler_args.stack); /* Pointer above Handler-Frame */
  7285. VALUES1(handler_args.condition);
  7286. pushSTACK(value1);
  7287. goto next_byte;
  7288. /* ------------------- (15) a few Functions ----------------------- */
  7289. CASE cod_not: /* (NOT) */
  7290. if (nullp(value1)) goto code_t; else goto code_nil;
  7291. CASE cod_eq: /* (EQ) */
  7292. if (!eq(value1,popSTACK())) goto code_nil; else goto code_t;
  7293. CASE cod_car: { /* (CAR) */
  7294. var object arg = value1;
  7295. if (consp(arg)) {
  7296. value1 = Car(arg); /* CAR of a Cons */
  7297. } else if (nullp(arg)) {
  7298. /* (CAR NIL) = NIL: value1 remains NIL */
  7299. } else
  7300. with_saved_back_trace_subr(L(car),STACK STACKop -1,-1,
  7301. error_list(arg); );
  7302. mv_count=1;
  7303. } goto next_byte;
  7304. CASE cod_car_push: { /* (CAR&PUSH) */
  7305. var object arg = value1;
  7306. if (consp(arg)) {
  7307. pushSTACK(Car(arg)); /* CAR of a Cons */
  7308. } else if (nullp(arg)) {
  7309. pushSTACK(arg); /* (CAR NIL) = NIL */
  7310. } else
  7311. with_saved_back_trace_subr(L(car),STACK STACKop -1,-1,
  7312. error_list(arg); );
  7313. } goto next_byte;
  7314. CASE cod_load_car_push: { /* (LOAD&CAR&PUSH n) */
  7315. var uintL n;
  7316. U_operand(n);
  7317. var object arg = STACK_(n);
  7318. if (consp(arg)) {
  7319. pushSTACK(Car(arg)); /* CAR of a Cons */
  7320. } else if (nullp(arg)) {
  7321. pushSTACK(arg); /* (CAR NIL) = NIL */
  7322. } else
  7323. with_saved_back_trace_subr(L(car),STACK STACKop -1,-1,
  7324. error_list(arg); );
  7325. } goto next_byte;
  7326. CASE cod_load_car_store: { /* (LOAD&CAR&STORE m n) */
  7327. var uintL m;
  7328. var uintL n;
  7329. U_operand(m);
  7330. U_operand(n);
  7331. var object arg = STACK_(m);
  7332. if (consp(arg)) {
  7333. STACK_(n) = value1 = Car(arg); /* CAR of a Cons */
  7334. } else if (nullp(arg)) {
  7335. STACK_(n) = value1 = arg; /* (CAR NIL) = NIL */
  7336. } else
  7337. with_saved_back_trace_subr(L(car),STACK STACKop -1,-1,
  7338. error_list(arg); );
  7339. mv_count=1;
  7340. } goto next_byte;
  7341. CASE cod_cdr: { /* (CDR) */
  7342. var object arg = value1;
  7343. if (consp(arg)) {
  7344. value1 = Cdr(arg); /* CDR of a Cons */
  7345. } else if (nullp(arg)) {
  7346. /* (CDR NIL) = NIL: value1 remains NIL */
  7347. } else
  7348. with_saved_back_trace_subr(L(cdr),STACK STACKop -1,-1,
  7349. error_list(arg); );
  7350. mv_count=1;
  7351. } goto next_byte;
  7352. CASE cod_cdr_push: { /* (CDR&PUSH) */
  7353. var object arg = value1;
  7354. if (consp(arg)) {
  7355. pushSTACK(Cdr(arg)); /* CDR of a Cons */
  7356. } else if (nullp(arg)) {
  7357. pushSTACK(arg); /* (CDR NIL) = NIL */
  7358. } else
  7359. with_saved_back_trace_subr(L(cdr),STACK STACKop -1,-1,
  7360. error_list(arg); );
  7361. } goto next_byte;
  7362. CASE cod_load_cdr_push: { /* (LOAD&CDR&PUSH n) */
  7363. var uintL n;
  7364. U_operand(n);
  7365. var object arg = STACK_(n);
  7366. if (consp(arg)) {
  7367. pushSTACK(Cdr(arg)); /* CDR of a Cons */
  7368. } else if (nullp(arg)) {
  7369. pushSTACK(arg); /* (CDR NIL) = NIL */
  7370. } else
  7371. with_saved_back_trace_subr(L(cdr),STACK STACKop -1,-1,
  7372. error_list(arg); );
  7373. } goto next_byte;
  7374. CASE cod_load_cdr_store: { /* (LOAD&CDR&STORE n) */
  7375. var uintL n;
  7376. U_operand(n);
  7377. var gcv_object_t* arg_ = &STACK_(n);
  7378. var object arg = *arg_;
  7379. if (consp(arg)) {
  7380. *arg_ = value1 = Cdr(arg); /* CDR of a Cons */
  7381. } else if (nullp(arg)) {
  7382. value1 = arg; /* (CDR NIL) = NIL */
  7383. } else
  7384. with_saved_back_trace_subr(L(cdr),STACK STACKop -1,-1,
  7385. error_list(arg); );
  7386. mv_count=1;
  7387. } goto next_byte;
  7388. CASE cod_cons: { /* (CONS) */
  7389. pushSTACK(value1);
  7390. /* request Cons: */
  7391. var object new_cons;
  7392. with_saved_context( { new_cons = allocate_cons(); } );
  7393. /* fill Cons: */
  7394. Cdr(new_cons) = popSTACK();
  7395. Car(new_cons) = popSTACK();
  7396. VALUES1(new_cons);
  7397. } goto next_byte;
  7398. CASE cod_cons_push: { /* (CONS&PUSH) */
  7399. pushSTACK(value1);
  7400. /* request Cons: */
  7401. var object new_cons;
  7402. with_saved_context( { new_cons = allocate_cons(); } );
  7403. /* fill Cons: */
  7404. Cdr(new_cons) = popSTACK();
  7405. Car(new_cons) = STACK_0;
  7406. STACK_0 = new_cons;
  7407. } goto next_byte;
  7408. CASE cod_load_cons_store: { /* (LOAD&CONS&STORE n) */
  7409. var uintL n;
  7410. U_operand(n);
  7411. /* request Cons: */
  7412. var object new_cons;
  7413. with_saved_context( { new_cons = allocate_cons(); } );
  7414. /* fill Cons: */
  7415. Car(new_cons) = popSTACK();
  7416. var gcv_object_t* arg_ = &STACK_(n);
  7417. Cdr(new_cons) = *arg_;
  7418. VALUES1(*arg_ = new_cons);
  7419. } goto next_byte;
  7420. {var object symbol;
  7421. var object fdef;
  7422. #define CHECK_FDEF() \
  7423. if (!symbolp(symbol)) \
  7424. with_saved_back_trace_subr(L(symbol_function),STACK STACKop -1,-1, \
  7425. symbol = check_symbol(symbol); ); \
  7426. fdef = Symbol_function(symbol); \
  7427. if (!boundp(fdef)) \
  7428. /* (symbol may be not the actual function-name, for e.g. \
  7429. (FUNCTION (SETF FOO)) shows as (SYMBOL-FUNCTION '#:|(SETF FOO)|),\
  7430. but that should be enough for the error message.) */ \
  7431. fdef = check_fdefinition(symbol,S(symbol_function))
  7432. CASE cod_symbol_function: /* (SYMBOL-FUNCTION) */
  7433. symbol = value1;
  7434. CHECK_FDEF();
  7435. VALUES1(fdef);
  7436. goto next_byte;
  7437. CASE cod_const_symbol_function: { /* (CONST&SYMBOL-FUNCTION n) */
  7438. var uintL n;
  7439. U_operand(n);
  7440. symbol = TheCclosure(closure)->clos_consts[n];
  7441. } CHECK_FDEF();
  7442. VALUES1(fdef);
  7443. goto next_byte;
  7444. CASE cod_const_symbol_function_push: { /* (CONST&SYMBOL-FUNCTION&PUSH n) */
  7445. var uintL n;
  7446. U_operand(n);
  7447. symbol = TheCclosure(closure)->clos_consts[n];
  7448. } CHECK_FDEF();
  7449. pushSTACK(fdef);
  7450. goto next_byte;
  7451. CASE cod_const_symbol_function_store: { /* (CONST&SYMBOL-FUNCTION&STORE n k) */
  7452. var uintL n;
  7453. U_operand(n);
  7454. symbol = TheCclosure(closure)->clos_consts[n];
  7455. } CHECK_FDEF(); {
  7456. var uintL k;
  7457. U_operand(k);
  7458. STACK_(k) = value1 = fdef; mv_count=1;
  7459. } goto next_byte;
  7460. }
  7461. {var object vec; var object index;
  7462. CASE cod_svref: /* (SVREF) */
  7463. /* STACK_0 must be a Simple-Vector: */
  7464. if (!simple_vector_p(STACK_0)) goto svref_not_a_svector;
  7465. vec = popSTACK(); /* Simple-Vector */
  7466. index = value1;
  7467. { /* and the Index must be Fixnum >= 0, < length(vec) : */
  7468. var uintV i;
  7469. if (!(posfixnump(index)
  7470. && ((i = posfixnum_to_V(index)) < Svector_length(vec))))
  7471. goto svref_not_an_index;
  7472. VALUES1(TheSvector(vec)->data[i]); /* indexed Element as value */
  7473. } goto next_byte;
  7474. CASE cod_svset: /* (SVSET) */
  7475. /* STACK_0 must be a Simple-Vector: */
  7476. if (!simple_vector_p(STACK_0)) goto svref_not_a_svector;
  7477. vec = popSTACK(); /* Simple-Vector */
  7478. index = value1;
  7479. { /* and the Index must be a Fixnum >=0, <Length(vec) : */
  7480. var uintV i;
  7481. if (!(posfixnump(index)
  7482. && ((i = posfixnum_to_V(index)) < Svector_length(vec))))
  7483. goto svref_not_an_index;
  7484. VALUES1(TheSvector(vec)->data[i] = popSTACK()); /* put in new element */
  7485. } goto next_byte;
  7486. svref_not_a_svector: /* Non-Simple-Vector in STACK_0 */
  7487. { error_no_svector(S(svref),STACK_0); }
  7488. svref_not_an_index: /* unsuitable Index in index, for Vector vec */
  7489. pushSTACK(vec);
  7490. pushSTACK(index);
  7491. pushSTACK(index); /* TYPE-ERROR slot DATUM */
  7492. {
  7493. var object tmp;
  7494. pushSTACK(S(integer)); pushSTACK(Fixnum_0); pushSTACK(UL_to_I(Svector_length(vec)));
  7495. tmp = listof(1); pushSTACK(tmp); tmp = listof(3);
  7496. pushSTACK(tmp); /* TYPE-ERROR slot EXPECTED-TYPE */
  7497. }
  7498. pushSTACK(STACK_(1+2)); /* vec */
  7499. pushSTACK(STACK_(0+3)); /* index */
  7500. pushSTACK(S(svref));
  7501. error(type_error,GETTEXT("~S: ~S is not a correct index into ~S"));
  7502. }
  7503. CASE cod_list: { /* (LIST n) */
  7504. var uintC n;
  7505. U_operand(n);
  7506. with_saved_context( { value1 = listof(n); mv_count=1; } );
  7507. } goto next_byte;
  7508. CASE cod_list_push: { /* (LIST&PUSH n) */
  7509. var uintC n;
  7510. U_operand(n);
  7511. with_saved_context( { object res = listof(n); pushSTACK(res); } );
  7512. } goto next_byte;
  7513. CASE cod_liststar: { /* (LIST* n) */
  7514. var uintC n;
  7515. U_operand(n);
  7516. with_saved_context({
  7517. pushSTACK(value1);
  7518. dotimespC(n,n, {
  7519. var object new_cons = allocate_cons();
  7520. Cdr(new_cons) = popSTACK();
  7521. Car(new_cons) = STACK_0;
  7522. STACK_0 = new_cons;
  7523. });
  7524. value1 = popSTACK(); mv_count=1;
  7525. });
  7526. } goto next_byte;
  7527. CASE cod_liststar_push: { /* (LIST*&PUSH n) */
  7528. var uintC n;
  7529. U_operand(n);
  7530. with_saved_context({
  7531. pushSTACK(value1);
  7532. dotimespC(n,n, {
  7533. var object new_cons = allocate_cons();
  7534. Cdr(new_cons) = popSTACK();
  7535. Car(new_cons) = STACK_0;
  7536. STACK_0 = new_cons;
  7537. });
  7538. });
  7539. } goto next_byte;
  7540. /* ------------------- (16) combined Operations ----------------------- */
  7541. CASE cod_nil_store: { /* (NIL&STORE n) */
  7542. var uintL n;
  7543. U_operand(n);
  7544. STACK_(n) = value1 = NIL; mv_count=1;
  7545. } goto next_byte;
  7546. CASE cod_t_store: { /* (T&STORE n) */
  7547. var uintL n;
  7548. U_operand(n);
  7549. STACK_(n) = value1 = T; mv_count=1;
  7550. } goto next_byte;
  7551. CASE cod_calls1_store: /* (CALLS1&STORE n k) */
  7552. CALLS1();
  7553. goto store;
  7554. CASE cod_calls2_store: /* (CALLS2&STORE n k) */
  7555. CALLS2();
  7556. goto store;
  7557. CASE cod_callsr_store: /* (CALLSR&STORE m n k) */
  7558. CALLSR();
  7559. goto store;
  7560. /* Increment. Optimized specifically for Fixnums >=0. */
  7561. #define INC(arg,statement) \
  7562. { if (posfixnump(arg) /* Fixnum >= 0 and < most-positive-fixnum ? */ \
  7563. && !eq(arg,fixnum(vbitm(oint_data_len)-1))) { \
  7564. arg = fixnum_inc(arg,1); statement; \
  7565. } else { \
  7566. with_saved_context( \
  7567. /* funcall(L(plus_one),1): */ \
  7568. pushSTACK(arg); \
  7569. with_saved_back_trace_subr(L(plus_one),STACK,1, \
  7570. { C_plus_one(); }); \
  7571. ); \
  7572. arg = value1; \
  7573. } \
  7574. }
  7575. /* Decrement. Optimized specifically for Fixnums >=0. */
  7576. #define DEC(arg,statement) \
  7577. { if (posfixnump(arg) && !eq(arg,Fixnum_0)) { /* Fixnum > 0 ? */ \
  7578. arg = fixnum_inc(arg,-1); statement; \
  7579. } else { \
  7580. with_saved_context( \
  7581. /* funcall(L(minus_one),1): */ \
  7582. pushSTACK(arg); \
  7583. with_saved_back_trace_subr(L(minus_one),STACK,1, \
  7584. { C_minus_one(); }); \
  7585. ); \
  7586. arg = value1; \
  7587. } \
  7588. }
  7589. CASE cod_load_inc_push: { /* (LOAD&INC&PUSH n) */
  7590. var uintL n;
  7591. U_operand(n);
  7592. var object arg = STACK_(n);
  7593. INC(arg,); /* increment */
  7594. pushSTACK(arg);
  7595. } goto next_byte;
  7596. CASE cod_load_inc_store: { /* (LOAD&INC&STORE n) */
  7597. var uintL n;
  7598. U_operand(n);
  7599. var gcv_object_t* arg_ = &STACK_(n);
  7600. var object arg = *arg_;
  7601. INC(arg,mv_count=1); /* increment, one value */
  7602. value1 = *arg_ = arg;
  7603. } goto next_byte;
  7604. CASE cod_load_dec_push: { /* (LOAD&DEC&PUSH n) */
  7605. var uintL n;
  7606. U_operand(n);
  7607. var object arg = STACK_(n);
  7608. DEC(arg,); /* decrement */
  7609. pushSTACK(arg);
  7610. } goto next_byte;
  7611. CASE cod_load_dec_store: { /* (LOAD&DEC&STORE n) */
  7612. var uintL n;
  7613. U_operand(n);
  7614. var gcv_object_t* arg_ = &STACK_(n);
  7615. var object arg = *arg_;
  7616. DEC(arg,mv_count=1); /* decrement, one value */
  7617. value1 = *arg_ = arg;
  7618. } goto next_byte;
  7619. CASE cod_call1_jmpif: /* (CALL1&JMPIF n label) */
  7620. CALL1();
  7621. if (!nullp(value1)) goto jmp; else goto notjmp;
  7622. CASE cod_call1_jmpifnot: /* (CALL1&JMPIFNOT n label) */
  7623. CALL1();
  7624. if (nullp(value1)) goto jmp; else goto notjmp;
  7625. CASE cod_call2_jmpif: /* (CALL2&JMPIF n label) */
  7626. CALL2();
  7627. if (!nullp(value1)) goto jmp; else goto notjmp;
  7628. CASE cod_call2_jmpifnot: /* (CALL2&JMPIFNOT n label) */
  7629. CALL2();
  7630. if (nullp(value1)) goto jmp; else goto notjmp;
  7631. CASE cod_calls1_jmpif: /* (CALLS1&JMPIF n label) */
  7632. CALLS1();
  7633. if (!nullp(value1)) goto jmp; else goto notjmp;
  7634. CASE cod_calls1_jmpifnot: /* (CALLS1&JMPIFNOT n label) */
  7635. CALLS1();
  7636. if (nullp(value1)) goto jmp; else goto notjmp;
  7637. CASE cod_calls2_jmpif: /* (CALLS2&JMPIF n label) */
  7638. CALLS2();
  7639. if (!nullp(value1)) goto jmp; else goto notjmp;
  7640. CASE cod_calls2_jmpifnot: /* (CALLS2&JMPIFNOT n label) */
  7641. CALLS2();
  7642. if (nullp(value1)) goto jmp; else goto notjmp;
  7643. CASE cod_callsr_jmpif: /* (CALLSR&JMPIF m n label) */
  7644. CALLSR();
  7645. if (!nullp(value1)) goto jmp; else goto notjmp;
  7646. CASE cod_callsr_jmpifnot: /* (CALLSR&JMPIFNOT m n label) */
  7647. CALLSR();
  7648. if (nullp(value1)) goto jmp; else goto notjmp;
  7649. CASE cod_load_jmpif: { /* (LOAD&JMPIF n label) */
  7650. var uintL n;
  7651. U_operand(n);
  7652. mv_count=1;
  7653. if (!nullp(value1 = STACK_(n))) goto jmp; else goto notjmp;
  7654. }
  7655. CASE cod_load_jmpifnot: { /* (LOAD&JMPIFNOT n label) */
  7656. var uintL n;
  7657. U_operand(n);
  7658. mv_count=1;
  7659. if (nullp(value1 = STACK_(n))) goto jmp; else goto notjmp;
  7660. }
  7661. CASE cod_apply_skip_ret: { /* (APPLY&SKIP&RET n k) */
  7662. var uintL n;
  7663. var uintL k;
  7664. U_operand(n);
  7665. U_operand(k);
  7666. var object fun = STACK_(n); /* Function */
  7667. with_saved_context({
  7668. apply(fun,n,value1); /* call Function */
  7669. skipSTACK(k+1); /* discard Function and others from Stack */
  7670. goto finished; /* return (jump) to caller */
  7671. }); /* the context is not restored */
  7672. }
  7673. CASE cod_funcall_skip_retgf: { /* (FUNCALL&SKIP&RETGF n k) */
  7674. var uintL n;
  7675. var uintL k;
  7676. U_operand(n);
  7677. U_operand(k);
  7678. var object fun = STACK_(n); /* Function */
  7679. var uintL r = ((Codevec)codeptr)->ccv_numreq;
  7680. var uintB flags = ((Codevec)codeptr)->ccv_flags;
  7681. with_saved_context({
  7682. funcall(fun,n); /* call Function */
  7683. if (flags & bit(3)) { /* call inhibition? */
  7684. skipSTACK(k+1);
  7685. mv_count=1;
  7686. goto finished; /* return (jump) to caller */
  7687. }
  7688. k -= r;
  7689. if (flags & bit(0)) {
  7690. skipSTACK(k); apply(value1,r,popSTACK());
  7691. } else {
  7692. skipSTACK(k+1); funcall(value1,r);
  7693. }
  7694. goto finished; /* return (jump) to caller */
  7695. }); /* the context is not restored */
  7696. }
  7697. /* ------------------- (17) short codes ----------------------- */
  7698. CASE cod_load0: /* (LOAD.S 0) */
  7699. VALUES1(STACK_(0));
  7700. goto next_byte;
  7701. CASE cod_load1: /* (LOAD.S 1) */
  7702. VALUES1(STACK_(1));
  7703. goto next_byte;
  7704. CASE cod_load2: /* (LOAD.S 2) */
  7705. VALUES1(STACK_(2));
  7706. goto next_byte;
  7707. CASE cod_load3: /* (LOAD.S 3) */
  7708. VALUES1(STACK_(3));
  7709. goto next_byte;
  7710. CASE cod_load4: /* (LOAD.S 4) */
  7711. VALUES1(STACK_(4));
  7712. goto next_byte;
  7713. CASE cod_load5: /* (LOAD.S 5) */
  7714. VALUES1(STACK_(5));
  7715. goto next_byte;
  7716. CASE cod_load6: /* (LOAD.S 6) */
  7717. VALUES1(STACK_(6));
  7718. goto next_byte;
  7719. CASE cod_load7: /* (LOAD.S 7) */
  7720. VALUES1(STACK_(7));
  7721. goto next_byte;
  7722. CASE cod_load8: /* (LOAD.S 8) */
  7723. VALUES1(STACK_(8));
  7724. goto next_byte;
  7725. CASE cod_load9: /* (LOAD.S 9) */
  7726. VALUES1(STACK_(9));
  7727. goto next_byte;
  7728. CASE cod_load10: /* (LOAD.S 10) */
  7729. VALUES1(STACK_(10));
  7730. goto next_byte;
  7731. CASE cod_load11: /* (LOAD.S 11) */
  7732. VALUES1(STACK_(11));
  7733. goto next_byte;
  7734. CASE cod_load12: /* (LOAD.S 12) */
  7735. VALUES1(STACK_(12));
  7736. goto next_byte;
  7737. CASE cod_load13: /* (LOAD.S 13) */
  7738. VALUES1(STACK_(13));
  7739. goto next_byte;
  7740. CASE cod_load14: /* (LOAD.S 14) */
  7741. VALUES1(STACK_(14));
  7742. goto next_byte;
  7743. #if 0
  7744. CASE cod_load15: /* (LOAD.S 15) */
  7745. VALUES1(STACK_(15));
  7746. goto next_byte;
  7747. CASE cod_load16: /* (LOAD.S 16) */
  7748. VALUES1(STACK_(16));
  7749. goto next_byte;
  7750. CASE cod_load17: /* (LOAD.S 17) */
  7751. VALUES1(STACK_(17));
  7752. goto next_byte;
  7753. CASE cod_load18: /* (LOAD.S 18) */
  7754. VALUES1(STACK_(18));
  7755. goto next_byte;
  7756. CASE cod_load19: /* (LOAD.S 19) */
  7757. VALUES1(STACK_(19));
  7758. goto next_byte;
  7759. CASE cod_load20: /* (LOAD.S 20) */
  7760. VALUES1(STACK_(20));
  7761. goto next_byte;
  7762. CASE cod_load21: /* (LOAD.S 21) */
  7763. VALUES1(STACK_(21));
  7764. goto next_byte;
  7765. #endif
  7766. CASE cod_load_push0: /* (LOAD&PUSH.S 0) */
  7767. pushSTACK(STACK_(0));
  7768. goto next_byte;
  7769. CASE cod_load_push1: /* (LOAD&PUSH.S 1) */
  7770. pushSTACK(STACK_(1));
  7771. goto next_byte;
  7772. CASE cod_load_push2: /* (LOAD&PUSH.S 2) */
  7773. pushSTACK(STACK_(2));
  7774. goto next_byte;
  7775. CASE cod_load_push3: /* (LOAD&PUSH.S 3) */
  7776. pushSTACK(STACK_(3));
  7777. goto next_byte;
  7778. CASE cod_load_push4: /* (LOAD&PUSH.S 4) */
  7779. pushSTACK(STACK_(4));
  7780. goto next_byte;
  7781. CASE cod_load_push5: /* (LOAD&PUSH.S 5) */
  7782. pushSTACK(STACK_(5));
  7783. goto next_byte;
  7784. CASE cod_load_push6: /* (LOAD&PUSH.S 6) */
  7785. pushSTACK(STACK_(6));
  7786. goto next_byte;
  7787. CASE cod_load_push7: /* (LOAD&PUSH.S 7) */
  7788. pushSTACK(STACK_(7));
  7789. goto next_byte;
  7790. CASE cod_load_push8: /* (LOAD&PUSH.S 8) */
  7791. pushSTACK(STACK_(8));
  7792. goto next_byte;
  7793. CASE cod_load_push9: /* (LOAD&PUSH.S 9) */
  7794. pushSTACK(STACK_(9));
  7795. goto next_byte;
  7796. CASE cod_load_push10: /* (LOAD&PUSH.S 10) */
  7797. pushSTACK(STACK_(10));
  7798. goto next_byte;
  7799. CASE cod_load_push11: /* (LOAD&PUSH.S 11) */
  7800. pushSTACK(STACK_(11));
  7801. goto next_byte;
  7802. CASE cod_load_push12: /* (LOAD&PUSH.S 12) */
  7803. pushSTACK(STACK_(12));
  7804. goto next_byte;
  7805. CASE cod_load_push13: /* (LOAD&PUSH.S 13) */
  7806. pushSTACK(STACK_(13));
  7807. goto next_byte;
  7808. CASE cod_load_push14: /* (LOAD&PUSH.S 14) */
  7809. pushSTACK(STACK_(14));
  7810. goto next_byte;
  7811. CASE cod_load_push15: /* (LOAD&PUSH.S 15) */
  7812. pushSTACK(STACK_(15));
  7813. goto next_byte;
  7814. CASE cod_load_push16: /* (LOAD&PUSH.S 16) */
  7815. pushSTACK(STACK_(16));
  7816. goto next_byte;
  7817. CASE cod_load_push17: /* (LOAD&PUSH.S 17) */
  7818. pushSTACK(STACK_(17));
  7819. goto next_byte;
  7820. CASE cod_load_push18: /* (LOAD&PUSH.S 18) */
  7821. pushSTACK(STACK_(18));
  7822. goto next_byte;
  7823. CASE cod_load_push19: /* (LOAD&PUSH.S 19) */
  7824. pushSTACK(STACK_(19));
  7825. goto next_byte;
  7826. CASE cod_load_push20: /* (LOAD&PUSH.S 20) */
  7827. pushSTACK(STACK_(20));
  7828. goto next_byte;
  7829. CASE cod_load_push21: /* (LOAD&PUSH.S 21) */
  7830. pushSTACK(STACK_(21));
  7831. goto next_byte;
  7832. CASE cod_load_push22: /* (LOAD&PUSH.S 22) */
  7833. pushSTACK(STACK_(22));
  7834. goto next_byte;
  7835. CASE cod_load_push23: /* (LOAD&PUSH.S 23) */
  7836. pushSTACK(STACK_(23));
  7837. goto next_byte;
  7838. CASE cod_load_push24: /* (LOAD&PUSH.S 24) */
  7839. pushSTACK(STACK_(24));
  7840. goto next_byte;
  7841. CASE cod_const0: /* (CONST.S 0) */
  7842. VALUES1(TheCclosure(closure)->clos_consts[0]);
  7843. goto next_byte;
  7844. CASE cod_const1: /* (CONST.S 1) */
  7845. VALUES1(TheCclosure(closure)->clos_consts[1]);
  7846. goto next_byte;
  7847. CASE cod_const2: /* (CONST.S 2) */
  7848. VALUES1(TheCclosure(closure)->clos_consts[2]);
  7849. goto next_byte;
  7850. CASE cod_const3: /* (CONST.S 3) */
  7851. VALUES1(TheCclosure(closure)->clos_consts[3]);
  7852. goto next_byte;
  7853. CASE cod_const4: /* (CONST.S 4) */
  7854. VALUES1(TheCclosure(closure)->clos_consts[4]);
  7855. goto next_byte;
  7856. CASE cod_const5: /* (CONST.S 5) */
  7857. VALUES1(TheCclosure(closure)->clos_consts[5]);
  7858. goto next_byte;
  7859. CASE cod_const6: /* (CONST.S 6) */
  7860. VALUES1(TheCclosure(closure)->clos_consts[6]);
  7861. goto next_byte;
  7862. CASE cod_const7: /* (CONST.S 7) */
  7863. VALUES1(TheCclosure(closure)->clos_consts[7]);
  7864. goto next_byte;
  7865. CASE cod_const8: /* (CONST.S 8) */
  7866. VALUES1(TheCclosure(closure)->clos_consts[8]);
  7867. goto next_byte;
  7868. CASE cod_const9: /* (CONST.S 9) */
  7869. VALUES1(TheCclosure(closure)->clos_consts[9]);
  7870. goto next_byte;
  7871. CASE cod_const10: /* (CONST.S 10) */
  7872. VALUES1(TheCclosure(closure)->clos_consts[10]);
  7873. goto next_byte;
  7874. CASE cod_const11: /* (CONST.S 11) */
  7875. VALUES1(TheCclosure(closure)->clos_consts[11]);
  7876. goto next_byte;
  7877. CASE cod_const12: /* (CONST.S 12) */
  7878. VALUES1(TheCclosure(closure)->clos_consts[12]);
  7879. goto next_byte;
  7880. CASE cod_const13: /* (CONST.S 13) */
  7881. VALUES1(TheCclosure(closure)->clos_consts[13]);
  7882. goto next_byte;
  7883. CASE cod_const14: /* (CONST.S 14) */
  7884. VALUES1(TheCclosure(closure)->clos_consts[14]);
  7885. goto next_byte;
  7886. CASE cod_const15: /* (CONST.S 15) */
  7887. VALUES1(TheCclosure(closure)->clos_consts[15]);
  7888. goto next_byte;
  7889. CASE cod_const16: /* (CONST.S 16) */
  7890. VALUES1(TheCclosure(closure)->clos_consts[16]);
  7891. goto next_byte;
  7892. CASE cod_const17: /* (CONST.S 17) */
  7893. VALUES1(TheCclosure(closure)->clos_consts[17]);
  7894. goto next_byte;
  7895. CASE cod_const18: /* (CONST.S 18) */
  7896. VALUES1(TheCclosure(closure)->clos_consts[18]);
  7897. goto next_byte;
  7898. CASE cod_const19: /* (CONST.S 19) */
  7899. VALUES1(TheCclosure(closure)->clos_consts[19]);
  7900. goto next_byte;
  7901. CASE cod_const20: /* (CONST.S 20) */
  7902. VALUES1(TheCclosure(closure)->clos_consts[20]);
  7903. goto next_byte;
  7904. #if 0
  7905. CASE cod_const21: /* (CONST.S 21) */
  7906. VALUES1(TheCclosure(closure)->clos_consts[21]);
  7907. goto next_byte;
  7908. CASE cod_const22: /* (CONST.S 22) */
  7909. VALUES1(TheCclosure(closure)->clos_consts[22]);
  7910. goto next_byte;
  7911. CASE cod_const23: /* (CONST.S 23) */
  7912. VALUES1(TheCclosure(closure)->clos_consts[23]);
  7913. goto next_byte;
  7914. CASE cod_const24: /* (CONST.S 24) */
  7915. VALUES1(TheCclosure(closure)->clos_consts[24]);
  7916. goto next_byte;
  7917. #endif
  7918. CASE cod_const_push0: /* (CONST&PUSH.S 0) */
  7919. pushSTACK(TheCclosure(closure)->clos_consts[0]);
  7920. goto next_byte;
  7921. CASE cod_const_push1: /* (CONST&PUSH.S 1) */
  7922. pushSTACK(TheCclosure(closure)->clos_consts[1]);
  7923. goto next_byte;
  7924. CASE cod_const_push2: /* (CONST&PUSH.S 2) */
  7925. pushSTACK(TheCclosure(closure)->clos_consts[2]);
  7926. goto next_byte;
  7927. CASE cod_const_push3: /* (CONST&PUSH.S 3) */
  7928. pushSTACK(TheCclosure(closure)->clos_consts[3]);
  7929. goto next_byte;
  7930. CASE cod_const_push4: /* (CONST&PUSH.S 4) */
  7931. pushSTACK(TheCclosure(closure)->clos_consts[4]);
  7932. goto next_byte;
  7933. CASE cod_const_push5: /* (CONST&PUSH.S 5) */
  7934. pushSTACK(TheCclosure(closure)->clos_consts[5]);
  7935. goto next_byte;
  7936. CASE cod_const_push6: /* (CONST&PUSH.S 6) */
  7937. pushSTACK(TheCclosure(closure)->clos_consts[6]);
  7938. goto next_byte;
  7939. CASE cod_const_push7: /* (CONST&PUSH.S 7) */
  7940. pushSTACK(TheCclosure(closure)->clos_consts[7]);
  7941. goto next_byte;
  7942. CASE cod_const_push8: /* (CONST&PUSH.S 8) */
  7943. pushSTACK(TheCclosure(closure)->clos_consts[8]);
  7944. goto next_byte;
  7945. CASE cod_const_push9: /* (CONST&PUSH.S 9) */
  7946. pushSTACK(TheCclosure(closure)->clos_consts[9]);
  7947. goto next_byte;
  7948. CASE cod_const_push10: /* (CONST&PUSH.S 10) */
  7949. pushSTACK(TheCclosure(closure)->clos_consts[10]);
  7950. goto next_byte;
  7951. CASE cod_const_push11: /* (CONST&PUSH.S 11) */
  7952. pushSTACK(TheCclosure(closure)->clos_consts[11]);
  7953. goto next_byte;
  7954. CASE cod_const_push12: /* (CONST&PUSH.S 12) */
  7955. pushSTACK(TheCclosure(closure)->clos_consts[12]);
  7956. goto next_byte;
  7957. CASE cod_const_push13: /* (CONST&PUSH.S 13) */
  7958. pushSTACK(TheCclosure(closure)->clos_consts[13]);
  7959. goto next_byte;
  7960. CASE cod_const_push14: /* (CONST&PUSH.S 14) */
  7961. pushSTACK(TheCclosure(closure)->clos_consts[14]);
  7962. goto next_byte;
  7963. CASE cod_const_push15: /* (CONST&PUSH.S 15) */
  7964. pushSTACK(TheCclosure(closure)->clos_consts[15]);
  7965. goto next_byte;
  7966. CASE cod_const_push16: /* (CONST&PUSH.S 16) */
  7967. pushSTACK(TheCclosure(closure)->clos_consts[16]);
  7968. goto next_byte;
  7969. CASE cod_const_push17: /* (CONST&PUSH.S 17) */
  7970. pushSTACK(TheCclosure(closure)->clos_consts[17]);
  7971. goto next_byte;
  7972. CASE cod_const_push18: /* (CONST&PUSH.S 18) */
  7973. pushSTACK(TheCclosure(closure)->clos_consts[18]);
  7974. goto next_byte;
  7975. CASE cod_const_push19: /* (CONST&PUSH.S 19) */
  7976. pushSTACK(TheCclosure(closure)->clos_consts[19]);
  7977. goto next_byte;
  7978. CASE cod_const_push20: /* (CONST&PUSH.S 20) */
  7979. pushSTACK(TheCclosure(closure)->clos_consts[20]);
  7980. goto next_byte;
  7981. CASE cod_const_push21: /* (CONST&PUSH.S 21) */
  7982. pushSTACK(TheCclosure(closure)->clos_consts[21]);
  7983. goto next_byte;
  7984. CASE cod_const_push22: /* (CONST&PUSH.S 22) */
  7985. pushSTACK(TheCclosure(closure)->clos_consts[22]);
  7986. goto next_byte;
  7987. CASE cod_const_push23: /* (CONST&PUSH.S 23) */
  7988. pushSTACK(TheCclosure(closure)->clos_consts[23]);
  7989. goto next_byte;
  7990. CASE cod_const_push24: /* (CONST&PUSH.S 24) */
  7991. pushSTACK(TheCclosure(closure)->clos_consts[24]);
  7992. goto next_byte;
  7993. CASE cod_const_push25: /* (CONST&PUSH.S 25) */
  7994. pushSTACK(TheCclosure(closure)->clos_consts[25]);
  7995. goto next_byte;
  7996. CASE cod_const_push26: /* (CONST&PUSH.S 26) */
  7997. pushSTACK(TheCclosure(closure)->clos_consts[26]);
  7998. goto next_byte;
  7999. CASE cod_const_push27: /* (CONST&PUSH.S 27) */
  8000. pushSTACK(TheCclosure(closure)->clos_consts[27]);
  8001. goto next_byte;
  8002. CASE cod_const_push28: /* (CONST&PUSH.S 28) */
  8003. pushSTACK(TheCclosure(closure)->clos_consts[28]);
  8004. goto next_byte;
  8005. CASE cod_const_push29: /* (CONST&PUSH.S 29) */
  8006. pushSTACK(TheCclosure(closure)->clos_consts[29]);
  8007. goto next_byte;
  8008. #if 0
  8009. CASE cod_const_push30: /* (CONST&PUSH.S 30) */
  8010. pushSTACK(TheCclosure(closure)->clos_consts[30]);
  8011. goto next_byte;
  8012. CASE cod_const_push31: /* (CONST&PUSH.S 31) */
  8013. pushSTACK(TheCclosure(closure)->clos_consts[31]);
  8014. goto next_byte;
  8015. CASE cod_const_push32: /* (CONST&PUSH.S 32) */
  8016. pushSTACK(TheCclosure(closure)->clos_consts[32]);
  8017. goto next_byte;
  8018. #endif
  8019. CASE cod_store0: /* (STORE.S 0) */
  8020. STACK_(0) = value1; mv_count=1;
  8021. goto next_byte;
  8022. CASE cod_store1: /* (STORE.S 1) */
  8023. STACK_(1) = value1; mv_count=1;
  8024. goto next_byte;
  8025. CASE cod_store2: /* (STORE.S 2) */
  8026. STACK_(2) = value1; mv_count=1;
  8027. goto next_byte;
  8028. CASE cod_store3: /* (STORE.S 3) */
  8029. STACK_(3) = value1; mv_count=1;
  8030. goto next_byte;
  8031. CASE cod_store4: /* (STORE.S 4) */
  8032. STACK_(4) = value1; mv_count=1;
  8033. goto next_byte;
  8034. CASE cod_store5: /* (STORE.S 5) */
  8035. STACK_(5) = value1; mv_count=1;
  8036. goto next_byte;
  8037. CASE cod_store6: /* (STORE.S 6) */
  8038. STACK_(6) = value1; mv_count=1;
  8039. goto next_byte;
  8040. CASE cod_store7: /* (STORE.S 7) */
  8041. STACK_(7) = value1; mv_count=1;
  8042. goto next_byte;
  8043. #if 0
  8044. CASE cod_store8: /* (STORE.S 8) */
  8045. STACK_(8) = value1; mv_count=1;
  8046. goto next_byte;
  8047. CASE cod_store9: /* (STORE.S 9) */
  8048. STACK_(9) = value1; mv_count=1;
  8049. goto next_byte;
  8050. CASE cod_store10: /* (STORE.S 10) */
  8051. STACK_(10) = value1; mv_count=1;
  8052. goto next_byte;
  8053. CASE cod_store11: /* (STORE.S 11) */
  8054. STACK_(11) = value1; mv_count=1;
  8055. goto next_byte;
  8056. CASE cod_store12: /* (STORE.S 12) */
  8057. STACK_(12) = value1; mv_count=1;
  8058. goto next_byte;
  8059. CASE cod_store13: /* (STORE.S 13) */
  8060. STACK_(13) = value1; mv_count=1;
  8061. goto next_byte;
  8062. CASE cod_store14: /* (STORE.S 14) */
  8063. STACK_(14) = value1; mv_count=1;
  8064. goto next_byte;
  8065. CASE cod_store15: /* (STORE.S 15) */
  8066. STACK_(15) = value1; mv_count=1;
  8067. goto next_byte;
  8068. CASE cod_store16: /* (STORE.S 16) */
  8069. STACK_(16) = value1; mv_count=1;
  8070. goto next_byte;
  8071. CASE cod_store17: /* (STORE.S 17) */
  8072. STACK_(17) = value1; mv_count=1;
  8073. goto next_byte;
  8074. CASE cod_store18: /* (STORE.S 18) */
  8075. STACK_(18) = value1; mv_count=1;
  8076. goto next_byte;
  8077. CASE cod_store19: /* (STORE.S 19) */
  8078. STACK_(19) = value1; mv_count=1;
  8079. goto next_byte;
  8080. CASE cod_store20: /* (STORE.S 20) */
  8081. STACK_(20) = value1; mv_count=1;
  8082. goto next_byte;
  8083. CASE cod_store21: /* (STORE.S 21) */
  8084. STACK_(21) = value1; mv_count=1;
  8085. goto next_byte;
  8086. #endif
  8087. /* ------------------- miscellaneous ----------------------- */
  8088. #ifndef FAST_DISPATCH
  8089. default:
  8090. #endif
  8091. /* undefined Code */
  8092. #if defined(GNU) && defined(FAST_SP)
  8093. /* Undo the effect of -fomit-frame-pointer for this function,
  8094. hereby allowing utilization of %sp resp. %esp as private_SP: */
  8095. alloca(1);
  8096. #endif
  8097. pushSTACK(fixnum(byteptr-&codeptr->data[0]-1)); /* bad byte number */
  8098. pushSTACK(closure); /* Closure */
  8099. error(serious_condition,GETTEXT("undefined bytecode in ~S at byte ~S"));
  8100. #undef L_operand
  8101. #undef S_operand
  8102. #undef U_operand
  8103. #undef B_operand
  8104. #undef CASE
  8105. }
  8106. #if DEBUG_BYTECODE
  8107. error_byteptr: {
  8108. pushSTACK(fixnum(byteptr_max));
  8109. pushSTACK(fixnum(byteptr_min));
  8110. pushSTACK(fixnum(byteptr - codeptr->data));
  8111. pushSTACK(sfixnum(byteptr_bad_jump));
  8112. pushSTACK(closure);
  8113. error(error_condition,GETTEXT("~S: jump by ~S takes ~S outside [~S;~S]"));
  8114. }
  8115. #endif
  8116. error_toomany_values: {
  8117. pushSTACK(closure);
  8118. error(error_condition,GETTEXT("~S: too many return values"));
  8119. }
  8120. #if STACKCHECKC
  8121. error_STACK_putt: {
  8122. pushSTACK(fixnum(byteptr - codeptr->data - byteptr_min)); /* PC */
  8123. pushSTACK(closure); /* FUNC */
  8124. error(serious_condition,GETTEXT("Corrupted STACK in ~S at byte ~S"));
  8125. }
  8126. #endif
  8127. finished:
  8128. #undef FREE_JMPBUF_on_SP
  8129. #undef JMPBUF_on_SP
  8130. #ifndef FAST_SP
  8131. FREE_DYNAMIC_ARRAY(private_SP_space);
  8132. #endif
  8133. return;
  8134. }
  8135. /* UP: initialize hand-made compiled closures
  8136. init_cclosures();
  8137. can trigger GC */
  8138. global maygc void init_cclosures (void) {
  8139. /* Build #13Y(00 00 00 00 00 00 00 00 00 01 C5 19 01) ; (CONST 0) (SKIP&RET 1) */
  8140. {
  8141. var object codevec = allocate_bit_vector(Atype_8Bit,CCV_START_NONKEY+3);
  8142. TheCodevec(codevec)->ccv_spdepth_1 = 0;
  8143. TheCodevec(codevec)->ccv_spdepth_jmpbufsize = 0;
  8144. TheCodevec(codevec)->ccv_numreq = 0;
  8145. TheCodevec(codevec)->ccv_numopt = 0;
  8146. TheCodevec(codevec)->ccv_flags = 0;
  8147. TheCodevec(codevec)->ccv_signature = cclos_argtype_0_0;
  8148. TheSbvector(codevec)->data[CCV_START_NONKEY+0] = cod_const0;
  8149. TheSbvector(codevec)->data[CCV_START_NONKEY+1] = cod_skip_ret;
  8150. TheSbvector(codevec)->data[CCV_START_NONKEY+2] = 1;
  8151. O(constant_initfunction_code) = codevec;
  8152. }
  8153. /* Build #12Y(00 00 00 00 00 00 00 00 11 16 1B 7E) ; L0 (JMP L0) */
  8154. {
  8155. var object codevec = allocate_bit_vector(Atype_8Bit,CCV_START_NONKEY+2);
  8156. TheCodevec(codevec)->ccv_spdepth_1 = 0;
  8157. TheCodevec(codevec)->ccv_spdepth_jmpbufsize = 0;
  8158. TheCodevec(codevec)->ccv_numreq = 0;
  8159. TheCodevec(codevec)->ccv_numopt = 0;
  8160. TheCodevec(codevec)->ccv_flags = bit(4)|bit(0);
  8161. TheCodevec(codevec)->ccv_signature = cclos_argtype_0_0_rest;
  8162. TheSbvector(codevec)->data[CCV_START_NONKEY+0] = cod_jmp;
  8163. TheSbvector(codevec)->data[CCV_START_NONKEY+1] = 128 - 2;
  8164. O(endless_loop_code) = codevec;
  8165. }
  8166. }
  8167. #if defined(USE_JITC)
  8168. #if defined(lightning)
  8169. #include "lightning.c"
  8170. #else
  8171. #error USE_JITC: what is your JITC flavor?
  8172. #endif
  8173. #endif
  8174. /* where is check_SP() or check_STACK() to be inserted??
  8175. is nest_env supposed to receive its target-environment as parameter??
  8176. register-allocation in eval_subr and eval_cclosure etc.??
  8177. eliminate subr_self?? */