Commit | Line | Data |
---|---|---|
17e90c5e KN |
1 | ;;; Guile Low Intermediate Language |
2 | ||
88fed05d | 3 | ;; Copyright (C) 2001, 2009, 2010 Free Software Foundation, Inc. |
17e90c5e | 4 | |
53befeb7 NJ |
5 | ;;;; This library is free software; you can redistribute it and/or |
6 | ;;;; modify it under the terms of the GNU Lesser General Public | |
7 | ;;;; License as published by the Free Software Foundation; either | |
8 | ;;;; version 3 of the License, or (at your option) any later version. | |
9 | ;;;; | |
10 | ;;;; This library is distributed in the hope that it will be useful, | |
11 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | ;;;; Lesser General Public License for more details. | |
14 | ;;;; | |
15 | ;;;; You should have received a copy of the GNU Lesser General Public | |
16 | ;;;; License along with this library; if not, write to the Free Software | |
17 | ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
17e90c5e KN |
18 | |
19 | ;;; Code: | |
20 | ||
9ff56d9e | 21 | (define-module (language glil) |
b0b180d5 AW |
22 | #:use-module (system base syntax) |
23 | #:use-module (system base pmatch) | |
53e28ed9 | 24 | #:use-module ((srfi srfi-1) #:select (fold)) |
1a1a10d3 | 25 | #:export |
c850030f | 26 | (<glil-program> make-glil-program glil-program? |
476e3572 AW |
27 | glil-program-meta glil-program-body |
28 | ||
258344b4 AW |
29 | <glil-std-prelude> make-glil-std-prelude glil-std-prelude? |
30 | glil-std-prelude-nreq glil-std-prelude-nlocs glil-std-prelude-else-label | |
31 | ||
32 | <glil-opt-prelude> make-glil-opt-prelude glil-opt-prelude? | |
899d37a6 | 33 | glil-opt-prelude-nreq glil-opt-prelude-nopt glil-opt-prelude-rest |
258344b4 AW |
34 | glil-opt-prelude-nlocs glil-opt-prelude-else-label |
35 | ||
36 | <glil-kw-prelude> make-glil-kw-prelude glil-kw-prelude? | |
37 | glil-kw-prelude-nreq glil-kw-prelude-nopt glil-kw-prelude-kw | |
899d37a6 | 38 | glil-kw-prelude-allow-other-keys? glil-kw-prelude-rest |
258344b4 | 39 | glil-kw-prelude-nlocs glil-kw-prelude-else-label |
1e2a8c26 | 40 | |
01967b69 | 41 | <glil-bind> make-glil-bind glil-bind? |
bdaffda2 | 42 | glil-bind-vars |
01967b69 | 43 | |
d51406fe AW |
44 | <glil-mv-bind> make-glil-mv-bind glil-mv-bind? |
45 | glil-mv-bind-vars glil-mv-bind-rest | |
46 | ||
01967b69 AW |
47 | <glil-unbind> make-glil-unbind glil-unbind? |
48 | ||
49 | <glil-source> make-glil-source glil-source? | |
028e3d06 | 50 | glil-source-props |
17e90c5e | 51 | |
01967b69 AW |
52 | <glil-void> make-glil-void glil-void? |
53 | ||
54 | <glil-const> make-glil-const glil-const? | |
bdaffda2 | 55 | glil-const-obj |
17e90c5e | 56 | |
66d3e9a3 AW |
57 | <glil-lexical> make-glil-lexical glil-lexical? |
58 | glil-lexical-local? glil-lexical-boxed? glil-lexical-op glil-lexical-index | |
59 | ||
a1122f8c AW |
60 | <glil-toplevel> make-glil-toplevel glil-toplevel? |
61 | glil-toplevel-op glil-toplevel-name | |
9cc649b8 | 62 | |
fd358575 AW |
63 | <glil-module> make-glil-module glil-module? |
64 | glil-module-op glil-module-mod glil-module-name glil-module-public? | |
65 | ||
01967b69 | 66 | <glil-label> make-glil-label glil-label? |
bdaffda2 | 67 | glil-label-label |
01967b69 AW |
68 | |
69 | <glil-branch> make-glil-branch glil-branch? | |
efbd5892 | 70 | glil-branch-inst glil-branch-label |
01967b69 AW |
71 | |
72 | <glil-call> make-glil-call glil-call? | |
efbd5892 AW |
73 | glil-call-inst glil-call-nargs |
74 | ||
75 | <glil-mv-call> make-glil-mv-call glil-mv-call? | |
b0b180d5 | 76 | glil-mv-call-nargs glil-mv-call-ra |
17e90c5e | 77 | |
ea6b18e8 | 78 | <glil-prompt> make-glil-prompt glil-prompt? glil-prompt-label glil-prompt-escape-only? |
88fed05d | 79 | |
b0b180d5 | 80 | parse-glil unparse-glil)) |
ac99cb0c | 81 | |
b0b180d5 AW |
82 | (define (print-glil x port) |
83 | (format port "#<glil ~s>" (unparse-glil x))) | |
84 | ||
85 | (define-type (<glil> #:printer print-glil) | |
1086fabd | 86 | ;; Meta operations |
56164a5a | 87 | (<glil-program> meta body) |
258344b4 | 88 | (<glil-std-prelude> nreq nlocs else-label) |
899d37a6 AW |
89 | (<glil-opt-prelude> nreq nopt rest nlocs else-label) |
90 | (<glil-kw-prelude> nreq nopt rest kw allow-other-keys? nlocs else-label) | |
1086fabd AW |
91 | (<glil-bind> vars) |
92 | (<glil-mv-bind> vars rest) | |
93 | (<glil-unbind>) | |
028e3d06 | 94 | (<glil-source> props) |
1086fabd AW |
95 | ;; Objects |
96 | (<glil-void>) | |
97 | (<glil-const> obj) | |
98 | ;; Variables | |
66d3e9a3 | 99 | (<glil-lexical> local? boxed? op index) |
1086fabd AW |
100 | (<glil-toplevel> op name) |
101 | (<glil-module> op mod name public?) | |
102 | ;; Controls | |
103 | (<glil-label> label) | |
104 | (<glil-branch> inst label) | |
105 | (<glil-call> inst nargs) | |
88fed05d | 106 | (<glil-mv-call> nargs ra) |
ea6b18e8 | 107 | (<glil-prompt> label escape-only?)) |
17e90c5e KN |
108 | |
109 | \f | |
476e3572 | 110 | |
b0b180d5 AW |
111 | (define (parse-glil x) |
112 | (pmatch x | |
56164a5a AW |
113 | ((program ,meta . ,body) |
114 | (make-glil-program meta (map parse-glil body))) | |
258344b4 AW |
115 | ((std-prelude ,nreq ,nlocs ,else-label) |
116 | (make-glil-std-prelude nreq nlocs else-label)) | |
899d37a6 AW |
117 | ((opt-prelude ,nreq ,nopt ,rest ,nlocs ,else-label) |
118 | (make-glil-opt-prelude nreq nopt rest nlocs else-label)) | |
119 | ((kw-prelude ,nreq ,nopt ,rest ,kw ,allow-other-keys? ,nlocs ,else-label) | |
120 | (make-glil-kw-prelude nreq nopt rest kw allow-other-keys? nlocs else-label)) | |
b0b180d5 | 121 | ((bind . ,vars) (make-glil-bind vars)) |
594d9d4c | 122 | ((mv-bind ,vars ,rest) (make-glil-mv-bind vars rest)) |
b0b180d5 | 123 | ((unbind) (make-glil-unbind)) |
028e3d06 | 124 | ((source ,props) (make-glil-source props)) |
b0b180d5 AW |
125 | ((void) (make-glil-void)) |
126 | ((const ,obj) (make-glil-const obj)) | |
66d3e9a3 | 127 | ((lexical ,local? ,boxed? ,op ,index) (make-glil-lexical local? boxed? op index)) |
b0b180d5 AW |
128 | ((toplevel ,op ,name) (make-glil-toplevel op name)) |
129 | ((module public ,op ,mod ,name) (make-glil-module op mod name #t)) | |
130 | ((module private ,op ,mod ,name) (make-glil-module op mod name #f)) | |
84012ef4 | 131 | ((label ,label) (make-glil-label label)) |
b0b180d5 AW |
132 | ((branch ,inst ,label) (make-glil-branch inst label)) |
133 | ((call ,inst ,nargs) (make-glil-call inst nargs)) | |
134 | ((mv-call ,nargs ,ra) (make-glil-mv-call nargs ra)) | |
ea6b18e8 AW |
135 | ((prompt ,label ,escape-only?) |
136 | (make-glil-prompt label escape-only?)) | |
b0b180d5 AW |
137 | (else (error "invalid glil" x)))) |
138 | ||
139 | (define (unparse-glil glil) | |
67169b29 | 140 | (record-case glil |
17e90c5e | 141 | ;; meta |
56164a5a AW |
142 | ((<glil-program> meta body) |
143 | `(program ,meta ,@(map unparse-glil body))) | |
258344b4 AW |
144 | ((<glil-std-prelude> nreq nlocs else-label) |
145 | `(std-prelude ,nreq ,nlocs ,else-label)) | |
899d37a6 AW |
146 | ((<glil-opt-prelude> nreq nopt rest nlocs else-label) |
147 | `(opt-prelude ,nreq ,nopt ,rest ,nlocs ,else-label)) | |
148 | ((<glil-kw-prelude> nreq nopt rest kw allow-other-keys? nlocs else-label) | |
149 | `(kw-prelude ,nreq ,nopt ,rest ,kw ,allow-other-keys? ,nlocs ,else-label)) | |
b0b180d5 | 150 | ((<glil-bind> vars) `(bind ,@vars)) |
594d9d4c | 151 | ((<glil-mv-bind> vars rest) `(mv-bind ,vars ,rest)) |
b0b180d5 | 152 | ((<glil-unbind>) `(unbind)) |
028e3d06 | 153 | ((<glil-source> props) `(source ,props)) |
17e90c5e | 154 | ;; constants |
67169b29 AW |
155 | ((<glil-void>) `(void)) |
156 | ((<glil-const> obj) `(const ,obj)) | |
17e90c5e | 157 | ;; variables |
66d3e9a3 AW |
158 | ((<glil-lexical> local? boxed? op index) |
159 | `(lexical ,local? ,boxed? ,op ,index)) | |
a1122f8c | 160 | ((<glil-toplevel> op name) |
b0b180d5 | 161 | `(toplevel ,op ,name)) |
fd358575 | 162 | ((<glil-module> op mod name public?) |
b0b180d5 | 163 | `(module ,(if public? 'public 'private) ,op ,mod ,name)) |
17e90c5e | 164 | ;; controls |
53e28ed9 | 165 | ((<glil-label> label) `(label ,label)) |
b0b180d5 AW |
166 | ((<glil-branch> inst label) `(branch ,inst ,label)) |
167 | ((<glil-call> inst nargs) `(call ,inst ,nargs)) | |
88fed05d | 168 | ((<glil-mv-call> nargs ra) `(mv-call ,nargs ,ra)) |
ea6b18e8 AW |
169 | ((<glil-prompt> label escape-only?) |
170 | `(prompt ,label escape-only?)))) |