-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopy.scm
More file actions
31 lines (29 loc) · 973 Bytes
/
copy.scm
File metadata and controls
31 lines (29 loc) · 973 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
;;;; copy values into heap-memory
;
; - Note: x86_64 specific
(define (copy x)
(let ((table '())
(sh ($inline "mov rax, FIX(CELL_SHIFT)")))
(let walk ((x x))
(cond ((%fixnum? x) x)
((assq x table) => cdr)
(else
(let ((bits (%bits-of x))
(size (%size x))
(bytes (if (eq? 0 (bitwise-and bits #x10)) ; BYTEBLOCK_BIT
(arithmetic-shift size %cell-shift)
size))
(new (%allocate-block bits bytes #f size #t #f))
(start 0))
(set! table (cons (cons x new) table))
(cond ((eq? bytes size) ; vector-like?
(unless (eq? 0 (bitwise-and bits #x20)) ; SPECIAL_BIT
;; copy 1st slot
($inline "mov rax, [rax + CELLS(1)]; mov [r11 + CELLS(1)], rax" x new)
(set! start 1))
(do ((i start (%fx+ i 1)))
((%fx>=? i size))
(%slot-set! new i (walk (%slot-ref x i)))))
(else ; string-like
($inline "CALL copy_bytes" (cons x 0) (cons new 0) bytes)))
new))))))