diff options
author | Péter Diviánszky <divipp@gmail.com> | 2016-04-01 18:00:46 +0200 |
---|---|---|
committer | Péter Diviánszky <divipp@gmail.com> | 2016-04-01 18:00:46 +0200 |
commit | 497fd44cafdc76fe240fce848b9457d745a459e7 (patch) | |
tree | 715aca0e5b47a5a64eb3e099a8fb9a7ff9eff5e6 /doc | |
parent | 7fa3dea62d21c60deb38a083a2ea4f4a14da2bde (diff) |
document more ideas
Diffstat (limited to 'doc')
-rw-r--r-- | doc/guide.pandoc | 177 |
1 files changed, 123 insertions, 54 deletions
diff --git a/doc/guide.pandoc b/doc/guide.pandoc index b1636c13..39d4a85f 100644 --- a/doc/guide.pandoc +++ b/doc/guide.pandoc | |||
@@ -1,66 +1,103 @@ | |||
1 | % LambdaCube 3D compiler developer's documentation | 1 | % LambdaCube 3D compiler developer's documentation and ideas |
2 | |||
3 | The interface of the compiler | ||
4 | ============================ | ||
5 | |||
6 | Live coding system structure: | ||
7 | |||
8 | editor frame WebGL frame | ||
9 | | ^ ^ | ||
10 | source code| |errors | | ||
11 | | | & infos |pipeline description | ||
12 | v | | | ||
13 | compiler----------/ | ||
14 | |||
15 | Try online at [http://lambdacube3d.com/editor.html](http://lambdacube3d.com/editor.html) | ||
16 | |||
17 | 2 | ||
18 | Compiler structure | 3 | Compiler structure |
19 | ================== | 4 | ================== |
20 | 5 | ||
21 | Compiler tasks: | 6 | Main tasks of the compiler: |
22 | 7 | ||
23 | - find errors in source code | 8 | - find errors in source code |
24 | - eliminate abstractions | 9 | - semantic errors are ruled out by strong static typing |
25 | - optimizations | 10 | - code completion to avoid inferrable parts of code |
26 | - reduction, partial evaluation | 11 | - eliminate abstractions (normalization, reduction) |
27 | - multistage compilation | 12 | |
28 | - support incremental compilation | 13 | Additional tasks of the compiler: |
14 | |||
15 | - support modular development | ||
29 | - modules support | 16 | - modules support |
30 | - code generation* | ||
31 | - support livecoding | 17 | - support livecoding |
32 | - highlight errors | 18 | - highlight errors |
33 | - inferred types in tooltips | 19 | - inferred types in tooltips |
34 | - completion | 20 | - completion |
21 | - additional feedback for users | ||
35 | - show desugared source (on a separate tab) | 22 | - show desugared source (on a separate tab) |
36 | - show optimizations (how?) | 23 | - show optimizations (how?) |
37 | 24 | ||
38 | Design decisions | 25 | Design decisions |
39 | 26 | ||
40 | - lexing, parsing, scope checking and desugaring is done in the same phase, sharing the same state | 27 | - Code generation is not part of the compiler; it is done in the libraries. |
28 | This helps to keep the compiler smaller and separate domain specific code | ||
29 | - reflection support makes this possible | ||
30 | - be able to pattern match on different normal forms for more compact description of code generation | ||
31 | - a strong type system prevents most misuses, so ideally no error handling is needed during code generation | ||
32 | - compilation stages are tracked by the type system | ||
33 | - prevents even more misuses | ||
34 | - help to speed up compilation? | ||
35 | - support different optimization transformations in the libraries | ||
36 | - the compiler has just two phases | ||
37 | 1. lexing, parsing, scope checking and desugaring is done in the same phase, sharing the same state | ||
38 | 2. type checking & inference and normalization is done in the same phase, sharing the same state | ||
39 | |||
40 | Example: Compilation of graphics pipeline descriptions in two phases | ||
41 | -------------------------------------------------------------------- | ||
42 | |||
43 | | | ||
44 | | source code of code generator for the domain | ||
45 | | (e.g. code gen. for graphics pipeline descriptions) | ||
46 | v | ||
47 | lexer + parser + scope checking + desugaring | ||
48 | | | | ||
49 | | desugared source code | | ||
50 | v v | ||
51 | inference + normalization ------> halt with error message (phase #1) | ||
52 | | | ||
53 | | infos for library writers | ||
54 | |--------------------------> | ||
55 | | | ||
56 | | normalized code | ||
57 | | (code generator) | ||
58 | | | ||
59 | /---/ | ||
60 | | | ||
61 | | | | ||
62 | | | domain language source code | ||
63 | | | (e.g. main with type 'graphics pipeline description') | ||
64 | | v | ||
65 | | lexer + parser + scope checking + desugaring | ||
66 | | | | | ||
67 | | | desugared source code | | ||
68 | v v v | ||
69 | inference + normalization ------> halt with error message (phase #2) | ||
70 | (normalization includes reflection of domain lang. code) | ||
71 | | | ||
72 | | infos for live coding | ||
73 | |--------------------------> | ||
74 | | | ||
75 | | normalized code | ||
76 | | (e.g. graphics pipeline description) | ||
77 | v | ||
78 | |||
79 | |||
80 | Usecase: Live coding system overview | ||
81 | ---------------------------------- | ||
82 | |||
83 | |||
84 | editor frame WebGL frame | ||
85 | | ^ ^ | ||
86 | source code| |errors | | ||
87 | | | & infos |pipeline description | ||
88 | v | | | ||
89 | compiler----------/ | ||
90 | |||
91 | Try online at [http://lambdacube3d.com/editor.html](http://lambdacube3d.com/editor.html) | ||
41 | 92 | ||
42 | Compilation pipline: | ||
43 | 93 | ||
44 | | | ||
45 | | source code | ||
46 | v | ||
47 | lexer + parser + scope checking + desugaring | ||
48 | | | ||
49 | | desugared source code | ||
50 | v | ||
51 | inference | ||
52 | | | ||
53 | | typed & reduced code | ||
54 | v | ||
55 | code generator | ||
56 | | | ||
57 | | pipeline description | ||
58 | v | ||
59 | 94 | ||
60 | 95 | ||
61 | Modules support | 96 | Modules support |
62 | --------------- | 97 | --------------- |
63 | 98 | ||
99 | [Source code of the driver which handles modules](https://github.com/lambdacube3d/lambdacube-compiler/blob/master/src/LambdaCube/Compiler.hs) | ||
100 | |||
64 | Design decisions | 101 | Design decisions |
65 | 102 | ||
66 | - module header and body are parsed in two phases | 103 | - module header and body are parsed in two phases |
@@ -199,40 +236,72 @@ data Stmt | |||
199 | Type inference | 236 | Type inference |
200 | ============== | 237 | ============== |
201 | 238 | ||
239 | Tasks | ||
240 | |||
241 | - find semantic errors | ||
242 | - complete code | ||
243 | - infer types | ||
244 | - find out inferrable values | ||
245 | - construct witnesses for type class method invocation | ||
246 | - normalize code | ||
247 | - reduce expressions (beta-reduction) | ||
248 | - avoid infinite recursion (termination checking) | ||
249 | (this is not a priority at the moment) | ||
250 | |||
251 | |||
252 | - code completion is base on supporting hidden arguments | ||
253 | |||
254 | |||
255 | - eliminate abstractions | ||
256 | - reduction, partial evaluation | ||
257 | - optimizations | ||
258 | - type erasure | ||
259 | |||
260 | |||
261 | - optimizations | ||
262 | - type erasure | ||
263 | |||
202 | Design decisions | 264 | Design decisions |
203 | 265 | ||
204 | - use a dependently typed core language | 266 | - use a dependently typed core language (treat types as values) |
205 | - use metavariables | 267 | - all code completion task is done by inferring values of hidden variables in the following two intermangled phases: |
206 | - support hidden arguments | 268 | 1. make every hidden argument application explicit by inserting metavariables |
269 | 2. gradually eliminate metavariables during type checking | ||
207 | - use a rich environment | 270 | - use a rich environment |
208 | - use a zipper to move in the environment | 271 | - use a zipper to move around in the environment |
209 | - do type inference and reduction in one step | 272 | - do type inference and reduction in one step |
210 | - use labels to remember the beginning of right hand side instead of arity information | 273 | - use labels to remember the beginning of right hand side instead of arity information |
211 | - separate types and expressions | 274 | - separate types and expressions |
212 | - erease types when possible | 275 | - erease types when possible |
213 | 276 | ||
214 | Tasks | ||
215 | 277 | ||
216 | - find semantic errors | 278 | Rich environment |
217 | - insert metavariables | 279 | ---------------- |
218 | - eliminate all metavariables (supersede type inference) | 280 | |
219 | - reduce expressions (beta-reduction) | 281 | |
220 | - avoid infinite recursion during type checking (termination checking) - this is not a priority at the moment | 282 | |
283 | Solving metavariables | ||
284 | --------------------- | ||
285 | |||
286 | |||
287 | Insertions of metavariables | ||
288 | --------------------------- | ||
289 | |||
221 | 290 | ||
222 | 291 | ||
223 | Code generation | 292 | Code generation |
224 | =============== | 293 | =============== |
225 | 294 | ||
295 | Currently there is only one code generator, which is wired in the compiler and generates intermediate representation | ||
296 | (called IR or graphics pipeline description) | ||
297 | |||
226 | Tasks | 298 | Tasks |
227 | 299 | ||
228 | - generate pipeline | 300 | - generate graphics pipeline descriptions |
229 | 301 | ||
230 | Design decisions | 302 | Design decisions |
231 | 303 | ||
232 | - the type system should prevent all misuse, no error handling is needed (*) | ||
233 | - the result of inference should be very easy to deal with w.r. reduction | ||
234 | - use a custom data type which encapsulates expessions with types and De Bruijn environment | 304 | - use a custom data type which encapsulates expessions with types and De Bruijn environment |
235 | - use quoting to do code generation in the libraries (TODO) | ||
236 | 305 | ||
237 | 306 | ||
238 | 307 | ||