diff options
| author | Rose Hogenson <rhogenson@posteo.net> | 2022-08-05 17:32:22 -0700 |
|---|---|---|
| committer | Rose Hogenson <rhogenson@posteo.net> | 2022-08-05 17:32:22 -0700 |
| commit | c458c02f3cbf24770a18e4e0e3ee2854b7bc0377 (patch) | |
| tree | 91357284ee3b0598cdaa8ef8f04132b5569180b7 /lib/csc/cps.csc | |
| parent | 9c28e5cf585653c57ce80f3a70a79e35a4fa7fa0 (diff) | |
| download | chromatopelma-c458c02f3cbf24770a18e4e0e3ee2854b7bc0377.tar.zst | |
Add call-with-values.
Diffstat (limited to 'lib/csc/cps.csc')
| -rw-r--r-- | lib/csc/cps.csc | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/csc/cps.csc b/lib/csc/cps.csc index 3c1e820..a3e829b 100644 --- a/lib/csc/cps.csc +++ b/lib/csc/cps.csc @@ -274,7 +274,26 @@ (make-primitive 'poke (list return-address argvec (make-constant 2)) '() (to-cps proc (lambda (f) - (make-apply f (list argvec)))))))))) + (make-apply f (list return-address argvec)))))))))) + ((% %call-builtin 'call-with-values (producer consumer)) + (define return-address (new-ref)) + (define consumer-func (new-ref)) + (define result (new-ref)) + (define results (new-ref)) + (define argvec (new-ref)) + (make-fix + (list (make-closure return-address (list result) + (continuation result)) + (make-closure consumer-func (list results) + (to-cps consumer + (lambda (c) + (make-apply c (list return-address results)))))) + (make-primitive 'alloc (list (make-constant 2)) (list argvec) + (make-primitive 'poke (list (make-constant 0) argvec (make-constant 0)) '() + (make-primitive 'poke (list (make-constant 0) argvec (make-constant 1)) '() + (to-cps producer + (lambda (p) + (make-apply p (list consumer-func argvec))))))))) ((% %call-builtin op args) (define returns-value? (not (memq op '(poke exit)))) (loop for arg in (reverse args) |
