Discussion:
minimal CPS program?
Matt Wette
2018-05-22 03:25:43 UTC
Permalink
Hi All,

I'm trying to compile a minimal cps program. Can anyone provide this?

Here is what I have

(define (doit)
(parameterize ((label-counter 0)
(var-counter 0))
(with-cps empty-intmap
(letv init)
(letk kinit ,#f)
(letk ktail ($ktail))
(letk kbody ($kargs () () ($continue ktail #f ($const 1))))
(letk kclause ($kclause ('() '() #f '() #f) kbody #f))
($ ((lambda (cps)
(let ((init (build-cont ($kfun #f '() init ktail kclause))))
(with-cps (persistent-intmap (intmap-replace! cps kinit init))
kinit))))))))

(compile (doit) #:from 'cps #:to 'bytecode)

which generates

language/cps/types.scm:1646:7: In procedure visit-cont:
Throw to key `match-error' with args `("match" "no matching pattern" #<cps (ktail)>)'.

The cps (intmap) is

(0 . #<cps (kfun () 0 1 3)>)
(1 . #<cps (ktail)>)
(2 . #<cps (kargs () () (continue 1 (const 1)))>)
(3 . #<cps (kclause (() () #f () #f) 2)>)
Matt Wette
2018-05-23 02:48:25 UTC
Permalink
Post by Matt Wette
Hi All,
I'm trying to compile a minimal cps program.
Here is something that compiles:

(define (doit)
(parameterize ((label-counter 0)
(var-counter 0))
(with-cps empty-intmap
(letv init)
(letk kinit ,#f)
(letk ktail ($ktail))
(letk kbody ($kargs () () ($continue ktail #f ($values ()))))
(letk kclause ($kclause ('() '() #f '() #f) kbody #f))
($ ((lambda (cps)
(let ((init (build-cont ($kfun #f '() init ktail kclause))))
(with-cps (persistent-intmap (intmap-replace! cps kinit init))
kinit))))))))

Loading...