coalton-toplevel is the main entry point for compiling top-level Coalton definitions and declarations.
Syntax
(coalton-toplevel
⟨toplevel-form⟩...)
;; ⟨toplevel-form⟩ := ⟨declare-form⟩
;; | ⟨define-form⟩
;; | ⟨define-type-form⟩
;; | ⟨define-struct-form⟩
;; | ⟨define-type-alias-form⟩
;; | ⟨define-exception-form⟩
;; | ⟨define-resumption-form⟩
;; | ⟨define-class-form⟩
;; | ⟨define-instance-form⟩
;; | ⟨specialize-form⟩
;; | ⟨attribute-form⟩
;; | (progn ⟨toplevel-form⟩...)
;; | ⟨toplevel-macro-form⟩
;;
;; ⟨attribute-form⟩ := (repr :enum | :transparent | :lisp | :native ⟨lisp-type⟩)
;; | (derive ⟨class-name⟩+)
;; | (monomorphize)
;; | (inline)
;; | (overlap)
Semantics
coalton-toplevelcompiles a group of top-level Coalton forms as a single translation unit and installs their definitions into the global Coalton environment.- Forms within the same
coalton-toplevelmay be mutually recursive regardless of the order in which they are written. The compiler processes categories in stages, sorting definitions into strongly connected dependency components (SCCs):- Type, struct, exception, resumption, and type-alias definitions (
define-type,define-struct,define-exception,define-resumption,define-type-alias), along withreprandderiveattributes. - Type class definitions (
define-class). - Explicit and derived class instances (
define-instance). - Value and function declarations and definitions (
declare,define), along withinlineandmonomorphizeattributes. - Specialization rules (
specialize).
- Type, struct, exception, resumption, and type-alias definitions (
- Attributes (
repr,derive,monomorphize,inline,overlap) attach to the immediately following definition or declaration; a trailing attribute with no target form signals a parse error. - A top-level
(progn ⟨toplevel-form⟩...)splices its subforms into the enclosingcoalton-toplevelunit. - All defined names, constructors, and methods must be symbols interned in the current Common Lisp
*package*. - Standalone expressions are not valid top-level forms; use
coaltonto evaluate Coalton expressions.
Examples
(coalton-toplevel
(derive Eq Show)
(repr :enum)
(define-type Mode
Development
Release)
;; Mutually recursive functions can appear in any order
(declare even-count? (UFix -> Boolean))
(define (even-count? n)
(if (== n 0)
True
(odd-count? (- n 1))))
(declare odd-count? (UFix -> Boolean))
(define (odd-count? n)
(if (== n 0)
False
(even-count? (- n 1)))))
Other notes
- Each compiled
coalton-toplevelform emits a load-time check verifying that the FASL was compiled in the same compiler mode (developmentvs.release) as the running image. - Inside library source code when
:coalton-lisp-toplevelis present incl:*features*,coalton-toplevelalso accepts(lisp-toplevel () ⟨lisp-form⟩...)to splice raw Common Lisp top-level forms into the generated output. - To inspect the Common Lisp code generated by a
coalton-toplevelform, replacecoalton-toplevelwithpprint-coalton-codegen.