9.4.4.3 Building CPS

Unlike Tree-IL, the CPS language is built to be constructed and deconstructed with abstract macros instead of via procedural constructors or accessors, or instead of S-expression matching.

Deconstruction and matching is handled adequately by the match form from (ice-9 match). See Pattern Matching. Construction is handled by a set of mutually builder macros: build-term, build-cont, and build-exp.

In the following interface definitions, consider term and exp to be built by build-term or build-exp, respectively. Consider any other name to be evaluated as a Scheme expression. Many of these forms recognize unquote in some contexts, to splice in a previously-built value; see the specifications below for full details.

Scheme Syntax: build-term ,val
Scheme Syntax: build-term ($continue k src exp)
Scheme Syntax: build-exp ,val
Scheme Syntax: build-exp ($const val)
Scheme Syntax: build-exp ($prim name)
Scheme Syntax: build-exp ($fun kentry)
Scheme Syntax: build-exp ($const-fun kentry)
Scheme Syntax: build-exp ($code kentry)
Scheme Syntax: build-exp ($rec names syms funs)
Scheme Syntax: build-exp ($call proc (arg ...))
Scheme Syntax: build-exp ($call proc args)
Scheme Syntax: build-exp ($callk k proc (arg ...))
Scheme Syntax: build-exp ($callk k proc args)
Scheme Syntax: build-exp ($primcall name param (arg ...))
Scheme Syntax: build-exp ($primcall name param args)
Scheme Syntax: build-exp ($values (arg ...))
Scheme Syntax: build-exp ($values args)
Scheme Syntax: build-exp ($prompt escape? tag handler)
Scheme Syntax: build-term ($branch kf kt src op param (arg ...))
Scheme Syntax: build-term ($branch kf kt src op param args)
Scheme Syntax: build-term ($switch kf kt* src arg)
Scheme Syntax: build-term ($throw src op param (arg ...))
Scheme Syntax: build-term ($throw src op param args)
Scheme Syntax: build-term ($prompt k kh src escape? tag)
Scheme Syntax: build-cont ,val
Scheme Syntax: build-cont ($kargs (name ...) (sym ...) term)
Scheme Syntax: build-cont ($kargs names syms term)
Scheme Syntax: build-cont ($kreceive req rest kargs)
Scheme Syntax: build-cont ($kfun src meta self ktail kclause)
Scheme Syntax: build-cont ($kclause ,arity kbody kalt)
Scheme Syntax: build-cont ($kclause (req opt rest kw aok?) kbody)

Construct a CPS term, expression, or continuation.

There are a few more miscellaneous interfaces as well.

Scheme Procedure: make-arity req opt rest kw allow-other-keywords?

A procedural constructor for $arity objects.

Scheme Syntax: rewrite-term val (pat term) ...
Scheme Syntax: rewrite-exp val (pat exp) ...
Scheme Syntax: rewrite-cont val (pat cont) ...

Match val against the series of patterns pat..., using match. The body of the matching clause should be a template in the syntax of build-term, build-exp, or build-cont, respectively.