|
5 | 5 | [asm-interp/io (-> (listof instruction?) string? any/c)]) |
6 | 6 |
|
7 | 7 | (require "printer.rkt" "ast.rkt" "callback.rkt" |
8 | | - (rename-in ffi/unsafe [-> _->])) |
| 8 | + (rename-in ffi/unsafe [-> _->])) |
9 | 9 | (require (submod "printer.rkt" private)) |
10 | 10 |
|
11 | 11 | ;; Assembly code is linked with object files in this parameter |
|
47 | 47 |
|
48 | 48 | (nasm t.s t.o) |
49 | 49 | (ld t.o t.so) |
50 | | - |
| 50 | + |
51 | 51 | (define libt.so (ffi-lib t.so)) |
52 | 52 |
|
53 | 53 | (define init-label |
|
67 | 67 | (function-ptr (λ () (raise 'err)) (_fun _-> _void)))) |
68 | 68 |
|
69 | 69 |
|
70 | | - (define current-heap #f) |
| 70 | + (define current-heap #f) |
| 71 | + |
71 | 72 | ;; allocate a heap |
72 | 73 | (when (ffi-obj-ref "heap" libt.so (thunk #f)) |
73 | 74 | (set! current-heap (make-c-parameter "heap" libt.so _pointer)) |
74 | | - (current-heap |
75 | | - ; IMPROVE ME: hard-coded heap size |
76 | | - (malloc _int64 10000 'raw))) |
77 | | - |
| 75 | + |
| 76 | + (if (ffi-obj-ref "from" libt.so (thunk #f)) |
| 77 | + (begin |
| 78 | + (current-heap |
| 79 | + ; IMPROVE ME: hard-coded heap size |
| 80 | + (malloc _int64 20000 'raw)) |
| 81 | + (set-ffi-obj! "from" libt.so _pointer (current-heap)) |
| 82 | + (set-ffi-obj! "to" libt.so _pointer (ptr-add (current-heap) 10000 _int64)) |
| 83 | + (set-ffi-obj! "types" libt.so _pointer (malloc _int32 10000))) |
| 84 | + (current-heap |
| 85 | + ; IMPROVE ME: hard-coded heap size |
| 86 | + (malloc _int64 10000 'raw)))) |
| 87 | + |
78 | 88 | (delete-file t.s) |
79 | 89 | (delete-file t.o) |
80 | 90 | (delete-file t.so) |
|
96 | 106 | (current-out (fopen t.out "w")) |
97 | 107 |
|
98 | 108 | (define result |
99 | | - (begin0 |
| 109 | + (begin0 |
100 | 110 | (with-handlers ((symbol? identity)) |
101 | | - (guard-foreign-escape |
| 111 | + (guard-foreign-escape |
102 | 112 | (if current-heap |
103 | 113 | (cons (current-heap) (entry (current-heap))) |
104 | 114 | (entry #f)))) |
|
114 | 124 | (delete-file t.in) |
115 | 125 | (delete-file t.out) |
116 | 126 | (cons result output)) |
117 | | - |
| 127 | + |
118 | 128 | (begin0 |
119 | 129 | (with-handlers ((symbol? identity)) |
120 | | - (guard-foreign-escape |
| 130 | + (guard-foreign-escape |
121 | 131 | (if current-heap |
122 | 132 | (cons (current-heap) (entry (current-heap))) |
123 | 133 | (entry #f)))) |
|
157 | 167 |
|
158 | 168 | (define (ld:undef-symbol s) |
159 | 169 | (ld:error |
160 | | - (string-append |
| 170 | + (string-append |
161 | 171 | (format "symbol ~a not defined in linked objects: ~a\n" s (current-objs)) |
162 | 172 | "use `current-objs` to link in object containing symbol definition."))) |
163 | 173 |
|
|
169 | 179 | (if (eq? (system-type 'os) 'macosx) |
170 | 180 | "" |
171 | 181 | "-z defs ")) |
172 | | - (unless (parameterize ((current-error-port err-port)) |
| 182 | + (unless (parameterize ((current-error-port err-port)) |
173 | 183 | (system (format "gcc ~a-v -shared ~a ~a -o ~a" |
174 | 184 | -z-defs-maybe |
175 | 185 | t.o objs t.so))) |
|
0 commit comments