fix JITted multi-valued `begin0' in a single-value context

and generate simpler code for constrained cases, including
 single-value contexts and ignored results

 Closes PR 11979
This commit is contained in:
Matthew Flatt 2011-06-16 17:33:16 -06:00
parent 26541ffbbd
commit 523cec90c6
2 changed files with 78 additions and 52 deletions

View File

@ -1371,6 +1371,23 @@
(test 10 dynamic-require ''set-local-dfs 'ten) (test 10 dynamic-require ''set-local-dfs 'ten)
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Test single-result checking in `begin0':
(let ()
(define (twice x) (printf "ouch\n") (values x x))
(define (pipeline2 . rfuns)
(let ([x (begin0 ((car rfuns) 1) 123)])
x))
(define (try f)
(call-with-values
(lambda () (with-handlers ([void values]) (f twice)))
(lambda xs xs)))
(test #t exn? (caar (map try (list pipeline2)))))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(report-errs) (report-errs)

View File

@ -1899,70 +1899,79 @@ int scheme_generate(Scheme_Object *obj, mz_jit_state *jitter, int is_tail, int w
seq = (Scheme_Sequence *)obj; seq = (Scheme_Sequence *)obj;
/* Evaluate first expression, and for consistency with bytecode /* Evaluate first expression: */
evaluation, allow multiple values. */ scheme_generate_non_tail(seq->array[0], jitter, multi_ok, 1, result_ignored);
scheme_generate_non_tail(seq->array[0], jitter, 1, 1, 0);
CHECK_LIMIT(); CHECK_LIMIT();
/* Save value(s) */ /* Save value(s) */
jit_movr_p(JIT_V1, JIT_R0); if (!result_ignored) {
mz_pushr_p(JIT_V1); mz_pushr_p(JIT_R0);
mz_pushr_p(JIT_V1); if (multi_ok) {
mz_pushr_p(JIT_V1); mz_pushr_p(JIT_R0);
mz_rs_sync(); mz_pushr_p(JIT_R0);
__START_SHORT_JUMPS__(1); mz_pushr_p(JIT_R0);
ref = jit_bnei_p(jit_forward(), JIT_R0, SCHEME_MULTIPLE_VALUES); mz_rs_sync();
CHECK_LIMIT(); __START_SHORT_JUMPS__(1);
/* Save away multiple values */ ref = jit_bnei_p(jit_forward(), JIT_R0, SCHEME_MULTIPLE_VALUES);
mz_popr_p(JIT_V1); /* sync'd below... */ CHECK_LIMIT();
mz_popr_p(JIT_V1); /* Save away multiple values */
mz_popr_p(JIT_V1); mz_popr_p(JIT_V1); /* sync'd below... */
mz_tl_ldi_p(JIT_R0, tl_scheme_current_thread); mz_popr_p(JIT_V1);
CHECK_LIMIT(); mz_popr_p(JIT_V1);
jit_ldxi_l(JIT_V1, JIT_R0, &((Scheme_Thread *)0x0)->ku.multiple.count); mz_tl_ldi_p(JIT_R0, tl_scheme_current_thread);
jit_lshi_l(JIT_V1, JIT_V1, 0x1); CHECK_LIMIT();
jit_ori_l(JIT_V1, JIT_V1, 0x1); jit_ldxi_l(JIT_V1, JIT_R0, &((Scheme_Thread *)0x0)->ku.multiple.count);
mz_pushr_p(JIT_V1); /* sync'd below */ jit_lshi_l(JIT_V1, JIT_V1, 0x1);
jit_ldxi_p(JIT_V1, JIT_R0, &((Scheme_Thread *)0x0)->ku.multiple.array); jit_ori_l(JIT_V1, JIT_V1, 0x1);
mz_pushr_p(JIT_V1); /* sync'd below */ mz_pushr_p(JIT_V1); /* sync'd below */
CHECK_LIMIT(); jit_ldxi_p(JIT_V1, JIT_R0, &((Scheme_Thread *)0x0)->ku.multiple.array);
(void)jit_movi_p(JIT_R1, 0x0); mz_pushr_p(JIT_V1); /* sync'd below */
mz_pushr_p(JIT_R1); /* pushing 0 indicates that multi-array follows */ CHECK_LIMIT();
/* If multi-value array is values buffer, zero out values buffer */ (void)jit_movi_p(JIT_R1, 0x0);
jit_ldxi_p(JIT_R2, JIT_R0, &((Scheme_Thread *)0x0)->values_buffer); mz_pushr_p(JIT_R1); /* pushing 0 indicates that multi-array follows */
mz_rs_sync(); /* If multi-value array is values buffer, zero out values buffer */
ref2 = jit_bner_p(jit_forward(), JIT_V1, JIT_R2); jit_ldxi_p(JIT_R2, JIT_R0, &((Scheme_Thread *)0x0)->values_buffer);
jit_stxi_p(&((Scheme_Thread *)0x0)->values_buffer, JIT_R0, JIT_R1); mz_rs_sync();
CHECK_LIMIT(); ref2 = jit_bner_p(jit_forward(), JIT_V1, JIT_R2);
jit_stxi_p(&((Scheme_Thread *)0x0)->values_buffer, JIT_R0, JIT_R1);
CHECK_LIMIT();
mz_patch_branch(ref);
mz_patch_branch(ref2);
__END_SHORT_JUMPS__(1);
}
}
/* evaluate remaining expressions */ /* evaluate remaining expressions */
mz_patch_branch(ref);
mz_patch_branch(ref2);
__END_SHORT_JUMPS__(1);
for (i = 1; i < seq->count; i++) { for (i = 1; i < seq->count; i++) {
scheme_generate_non_tail(seq->array[i], jitter, 1, 1, 1); /* sync's below */ scheme_generate_non_tail(seq->array[i], jitter, 1, 1, 1); /* sync's below */
CHECK_LIMIT(); CHECK_LIMIT();
} }
/* Restore values, if necessary */ /* Restore values, if necessary */
mz_popr_p(JIT_R0); if (!result_ignored) {
mz_popr_p(JIT_R1); mz_popr_p(JIT_R0);
mz_popr_p(JIT_R2); if (multi_ok) {
mz_rs_sync(); mz_popr_p(JIT_R1);
CHECK_LIMIT(); mz_popr_p(JIT_R2);
__START_TINY_JUMPS__(1); mz_rs_sync();
ref = jit_bnei_p(jit_forward(), JIT_R0, 0x0); CHECK_LIMIT();
CHECK_LIMIT(); __START_TINY_JUMPS__(1);
mz_tl_ldi_p(JIT_R0, tl_scheme_current_thread); ref = jit_bnei_p(jit_forward(), JIT_R0, 0x0);
jit_stxi_p(&((Scheme_Thread *)0x0)->ku.multiple.array, JIT_R0, JIT_R1); CHECK_LIMIT();
jit_rshi_ul(JIT_R2, JIT_R2, 0x1); mz_tl_ldi_p(JIT_R0, tl_scheme_current_thread);
jit_stxi_l(&((Scheme_Thread *)0x0)->ku.multiple.count, JIT_R0, JIT_R2); jit_stxi_p(&((Scheme_Thread *)0x0)->ku.multiple.array, JIT_R0, JIT_R1);
(void)jit_movi_p(JIT_R0, SCHEME_MULTIPLE_VALUES); jit_rshi_ul(JIT_R2, JIT_R2, 0x1);
jit_stxi_l(&((Scheme_Thread *)0x0)->ku.multiple.count, JIT_R0, JIT_R2);
(void)jit_movi_p(JIT_R0, SCHEME_MULTIPLE_VALUES);
mz_patch_branch(ref); mz_patch_branch(ref);
if (target != JIT_R0) __END_TINY_JUMPS__(1);
jit_movr_p(target, JIT_R0); }
__END_TINY_JUMPS__(1);
if (target != JIT_R0)
jit_movr_p(target, JIT_R0);
}
if (for_branch) finish_branch(jitter, target, for_branch); if (for_branch) finish_branch(jitter, target, for_branch);