A categorical programming language
修订版 | 873bb278c3325ccf4b0144c07f98a4af52c801ec (tree) |
---|---|
时间 | 2021-10-16 04:02:28 |
作者 | Corbin <cds@corb...> |
Commiter | Corbin |
Improve draw command's memory usage.
@@ -1,4 +1,4 @@ | ||
1 | -(import (srfi 4) (srfi 6) (srfi 144) (srfi 189)) | |
1 | +(import (srfi 6) (srfi 144) (srfi 160 u8) (srfi 189)) | |
2 | 2 | (import (chicken condition) (chicken format) (chicken process-context) (chicken string)) |
3 | 3 | (import (matchable)) |
4 | 4 | (import (stb-image-write)) |
@@ -111,17 +111,20 @@ | ||
111 | 111 | (r (car color)) |
112 | 112 | (g (car (cdr color))) |
113 | 113 | (b (cdr (cdr color)))) |
114 | - (map finish-channel (list r g b)))) | |
115 | - | |
116 | -(define (count-to i) (if (eqv? 0 i) '() (cons (- i 1) (count-to (- i 1))))) | |
114 | + (list->u8vector (map finish-channel (list r g b))))) | |
117 | 115 | |
118 | 116 | (define ((draw-png program width height)) |
119 | - (let | |
117 | + (let* | |
120 | 118 | ((vp (viewport width height)) |
121 | - (indices (reverse (count-to (* width height))))) | |
122 | - (write-png (list->u8vector | |
123 | - (flatten (map (draw-pixel program vp) indices))) | |
124 | - width height 3))) | |
119 | + (drawable (draw-pixel program vp)) | |
120 | + (size (* width height)) | |
121 | + (channels 3) | |
122 | + (pixels | |
123 | + (do ((buf (make-u8vector (* size channels))) | |
124 | + (i 0 (+ i 1))) | |
125 | + ((eqv? i size) buf) | |
126 | + (u8vector-copy! buf (* i channels) (drawable i))))) | |
127 | + (write-png pixels width height channels))) | |
125 | 128 | |
126 | 129 | ; Run a program repeatedly and draw the results. |
127 | 130 | (define (cammy-draw program ty) |
@@ -5,7 +5,6 @@ | ||
5 | 5 | * list/append : [X] × [X] → [X] |
6 | 6 | * rat |
7 | 7 | * refactoring from the bikeshed: ignore -> ! |
8 | -* fun/const? Would be: (comp ignore @0) | |
9 | 8 | * Typechecker needs to handle holes |
10 | 9 | * Typechecker should handle polymorphism better |
11 | 10 | * Typechecker errors are inscrutable |