Skip to content

Commit ab7396e

Browse files
committed
Make interp work with runtime that inlcudes GC.
1 parent 7a211ea commit ab7396e

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

langs/a86/interp.rkt

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[asm-interp/io (-> (listof instruction?) string? any/c)])
66

77
(require "printer.rkt" "ast.rkt" "callback.rkt"
8-
(rename-in ffi/unsafe [-> _->]))
8+
(rename-in ffi/unsafe [-> _->]))
99
(require (submod "printer.rkt" private))
1010

1111
;; Assembly code is linked with object files in this parameter
@@ -47,7 +47,7 @@
4747

4848
(nasm t.s t.o)
4949
(ld t.o t.so)
50-
50+
5151
(define libt.so (ffi-lib t.so))
5252

5353
(define init-label
@@ -67,14 +67,24 @@
6767
(function-ptr (λ () (raise 'err)) (_fun _-> _void))))
6868

6969

70-
(define current-heap #f)
70+
(define current-heap #f)
71+
7172
;; allocate a heap
7273
(when (ffi-obj-ref "heap" libt.so (thunk #f))
7374
(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+
7888
(delete-file t.s)
7989
(delete-file t.o)
8090
(delete-file t.so)
@@ -96,9 +106,9 @@
96106
(current-out (fopen t.out "w"))
97107

98108
(define result
99-
(begin0
109+
(begin0
100110
(with-handlers ((symbol? identity))
101-
(guard-foreign-escape
111+
(guard-foreign-escape
102112
(if current-heap
103113
(cons (current-heap) (entry (current-heap)))
104114
(entry #f))))
@@ -114,10 +124,10 @@
114124
(delete-file t.in)
115125
(delete-file t.out)
116126
(cons result output))
117-
127+
118128
(begin0
119129
(with-handlers ((symbol? identity))
120-
(guard-foreign-escape
130+
(guard-foreign-escape
121131
(if current-heap
122132
(cons (current-heap) (entry (current-heap)))
123133
(entry #f))))
@@ -157,7 +167,7 @@
157167

158168
(define (ld:undef-symbol s)
159169
(ld:error
160-
(string-append
170+
(string-append
161171
(format "symbol ~a not defined in linked objects: ~a\n" s (current-objs))
162172
"use `current-objs` to link in object containing symbol definition.")))
163173

@@ -169,7 +179,7 @@
169179
(if (eq? (system-type 'os) 'macosx)
170180
""
171181
"-z defs "))
172-
(unless (parameterize ((current-error-port err-port))
182+
(unless (parameterize ((current-error-port err-port))
173183
(system (format "gcc ~a-v -shared ~a ~a -o ~a"
174184
-z-defs-maybe
175185
t.o objs t.so)))

0 commit comments

Comments
 (0)