-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathunload-bits-asm.rkt
More file actions
33 lines (29 loc) · 946 Bytes
/
unload-bits-asm.rkt
File metadata and controls
33 lines (29 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#lang racket
(provide unload/free unload-value)
(require "types.rkt"
ffi/unsafe)
;; Answer* -> Answer
(define (unload/free a)
(match a
['err 'err]
[(cons h v) (begin0 (unload-value v)
(free h))]))
;; Value* -> Value
(define (unload-value v)
(match v
[(? imm-bits?) (bits->imm v)]
[(? box-bits? i)
(box (unload-value (heap-ref i)))]
[(? cons-bits? i)
(cons (unload-value (heap-ref (+ i (arithmetic-shift 1 imm-shift))))
(unload-value (heap-ref i)))]
[(? string-bits? i)
(let* ((n (unload-value (heap-ref i)))
(cs (map (lambda (j) (unload-value (heap-ref (+ i (* 8 j) 8)))) (build-list n values))))
(apply string cs))]
))
(define (untag i)
(arithmetic-shift (arithmetic-shift i (- (integer-length ptr-mask)))
(integer-length ptr-mask)))
(define (heap-ref i)
(ptr-ref (cast (untag i) _int64 _pointer) _uint64))