coalton-codegen compiles top-level Coalton forms and returns the generated Common Lisp code (without host type declarations) as a quoted s-expression.
Syntax
(coalton-codegen
⟨toplevel-form⟩*)
Semantics
coalton-codegenaccepts the same top-level forms ascoalton-toplevel(declare,define,define-type,define-struct,define-class,define-instance, etc.).- It runs the full Coalton compiler pipeline (parsing, type inference, specialization, inlining, monomorphization, scalar replacement, and Common Lisp code generation) with
coalton-impl/settings:*emit-type-annotations*bound tonil. - It expands to a quoted Common Lisp
(progn ...)form containing the generated code, so evaluating(coalton-codegen ...)returns the generated code as data without executing it or permanently updating*global-environment*.
Examples
(coalton-codegen
(declare double (Integer -> Integer))
(define (double x)
(+ x x)))
; => (PROGN
; (LOCALLY
; (DECLARE #+SBCL (OPTIMIZE (SB-C::TYPE-CHECK 0)))
; (COALTON-IMPL/GLOBAL-LEXICAL:DEFINE-GLOBAL-LEXICAL DOUBLE FUNCTION)
; (DEFUN DOUBLE (X-2)
; (DECLARE (IGNORABLE X-2))
; ...)
; (SETF DOUBLE #'DOUBLE))
; (VALUES))
Other notes
- For human-readable pretty-printed output without package prefixes on local symbols, use
pprint-coalton-codegen. - To include emitted Common Lisp
(declare (type ...)),(declaim (ftype ...)), and(the (values ...) ...)annotations, usecoalton-codegen-typesorpprint-coalton-codegen-types. - To inspect Coalton’s post-optimization internal AST before Common Lisp code generation, use
coalton-codegen-ast.