-
Notifications
You must be signed in to change notification settings - Fork 70
/
faux-macros.lisp
110 lines (71 loc) · 3.78 KB
/
faux-macros.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
;;;; faux-macros.lisp
;;;;
;;;; Some macro definitions that are only valid inside of a COALTON (&
;;;; co.) macro, that aren't actually valid as a toplevel form in
;;;; Lisp.
(defpackage #:coalton-impl/faux-macros
(:use
#:cl)
(:local-nicknames
(#:rt #:coalton-impl/runtime)))
(in-package #:coalton-impl/faux-macros)
(defun error-coalton-only (name)
(error "The operator ~S is only valid in a Coalton expression." name))
(defmacro define-coalton-editor-macro (name lambda-list &optional (docstring ""))
"Define a macro so that Emacs and SLIME see it nicely, and so the forms indent properly. Not intended for actual use in Lisp code."
(check-type docstring string)
`(defmacro ,name ,lambda-list
,docstring
(declare (ignore ,@(remove-if (lambda (sym) (char= #\& (char (symbol-name sym) 0)))
lambda-list)))
(error-coalton-only ',name)))
;;; Top-Level Forms
(define-coalton-editor-macro coalton:define (var-or-fun &body body)
"Define a variable or function. (Coalton top-level operator.)")
(define-coalton-editor-macro coalton:define-type (name &body definition)
"Create a new algebraic data type named NAME. (Coalton top-level operator.)")
(define-coalton-editor-macro coalton:define-struct (name &body definition)
"Create a new sruct named NAME. (Coalton top-level operator.)")
(define-coalton-editor-macro coalton:declare (var type)
"Declare the type of a variable. (Coalton top-level operator.)")
(define-coalton-editor-macro coalton:define-class (class &body method-signatures)
"Define a new type class. (Coalton top-level operator.")
(define-coalton-editor-macro coalton:define-instance (instance &body method-definitions)
"Define an instance of a type class. (Coalton top-level operator.)")
(define-coalton-editor-macro coalton:lisp-toplevel (options &body lisp-toplevel-forms)
"Include lisp forms. (Coalton top-level operator.)")
(define-coalton-editor-macro coalton:specialize (name from-ty to-ty)
"Declare a specialization for a function. (Coalton top-level operator.)")
;;; Attributes
(define-coalton-editor-macro coalton:repr (type &optional arg)
"Annote a type definition with a runtime representation.")
(define-coalton-editor-macro coalton:monomorphize ()
"Mark a definition for monomorphization.")
;;; Other Constructions
(defmacro coalton:fn (vars &body form)
"A lambda abstraction callable within coalton."
(rt:construct-function-entry `(lambda ,vars ,@form) (length vars)))
(define-coalton-editor-macro coalton:let (bindings &body form)
"A lexical LET binding.")
(define-coalton-editor-macro coalton:lisp (type vars &body lisp-expr)
"An escape from Coalton into the Lisp world.")
(define-coalton-editor-macro coalton:match (expr &body patterns)
"Pattern matching construct.")
(define-coalton-editor-macro coalton:progn (&body body)
"A sequence of expressions.")
(define-coalton-editor-macro coalton:the (type expr)
"Declare that EXPR is of type TYPE.")
(define-coalton-editor-macro coalton:or (&rest args))
(define-coalton-editor-macro coalton:and (&rest args))
(define-coalton-editor-macro coalton:if (expr then else))
(define-coalton-editor-macro coalton:when (expr &body body))
(define-coalton-editor-macro coalton:unless (expr &body body))
(define-coalton-editor-macro coalton:cond (&rest clauses))
(define-coalton-editor-macro coalton:do (&body body))
(define-coalton-editor-macro coalton:return (&optional value))
(define-coalton-editor-macro coalton:loop (&body body))
(define-coalton-editor-macro coalton:while (test &body body))
(define-coalton-editor-macro coalton:while-let (pattern = test &body body))
(define-coalton-editor-macro coalton:for (pattern in iter &body body))
(define-coalton-editor-macro coalton:break (&optional label))
(define-coalton-editor-macro coalton:continue (&optional label))