[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
getting up to speed on CPS
From: |
Matt Wette |
Subject: |
getting up to speed on CPS |
Date: |
Wed, 16 May 2018 17:26:50 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 |
Hi All,
I've been wanting to dig into CPS for a while. I was able to put together the
following trivial
stuff to see what I can get out of Guile's CPS compiler. Below I include
reference for some
articles I have found. (I have not yet read Andy Wingo's blog posts yet, but
will.) And I managed
to get my hands on a copy of Appel's "Compiling with Continuations" book.
Learning this is more
like a term project than a homework assignment.
My interest is in looking at CPS for parallel computation. I found a couple
references. If any
of you know more about targeting parallel computation with CPS let me know.
Matt
(use-modules (ice-9 pretty-print))
(use-modules (language cps utils))
(use-modules (language cps intmap))
(define x1 '(and (foo 1) (bar 2)))
(define c1 (compile x1 #:to 'cps))
(for-each
(lambda (c) (simple-format #t "~S\n" c))
(intmap-fold-right acons c1 '()))
(0 . #<cps (kfun () 0 1 18)>)
(1 . #<cps (ktail)>)
(2 . #<cps (kargs (arg) (2) (continue 1 (call 1 2)))>)
(3 . #<cps (kargs (arg) (1) (continue 2 (const 2)))>)
(4 . #<cps (kargs (box) (3) (continue 3 (primcall box-ref 3)))>)
(5 . #<cps (kargs (bound?) (5) (continue 4 (primcall resolve 4 5)))>)
(6 . #<cps (kargs (name) (4) (continue 5 (const #t)))>)
(7 . #<cps (kargs (val) (6) (continue 1 (values 6)))>)
(8 . #<cps (kargs () () (continue 6 (const bar)))>)
(9 . #<cps (kargs () () (continue 7 (const #f)))>)
(10 . #<cps (kargs (arg rest) (7 8) (continue 9 (branch 8 (values 7))))>)
(11 . #<cps (kreceive (arg) rest 10)>)
(12 . #<cps (kargs (arg) (10) (continue 11 (call 9 10)))>)
(13 . #<cps (kargs (arg) (9) (continue 12 (const 1)))>)
(14 . #<cps (kargs (box) (11) (continue 13 (primcall box-ref 11)))>)
(15 . #<cps (kargs (bound?) (13) (continue 14 (primcall resolve 12 13)))>)
(16 . #<cps (kargs (name) (12) (continue 15 (const #t)))>)
(17 . #<cps (kargs () () (continue 16 (const foo)))>)
(18 . #<cps (kclause (() () #f () #f) 17)>)
scheme@(guile-user)>
Here are some references. Before you dig into "Compiling with Continuations
Continued" you might
want to get familiar with the ML (aka SML) programming language (maybe w/ smlnj
implementation). I
started with this paper but soon had to go back and read more background stuff
and read up on SML.
http://wingolog.org/archives/2011/07/12/static-single-assignment-for-functional-programmers
http://wingolog.org/archives/2014/01/12/a-continuation-passing-style-intermediate-language-for-guile
https://wingolog.org/archives/2015/07/27/cps-soup
https://www.microsoft.com/en-us/research/publication/compiling-with-continuations-continued/
http://matt.might.net/articles/cps-conversion/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- getting up to speed on CPS,
Matt Wette <=