This repository has been archived by the owner on Mar 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlisp.s
4903 lines (4040 loc) · 138 KB
/
lisp.s
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.include "macros.s"
.text
## R7RS
## 5.5. Record-type definitions
make_record: # k, type
prologue
assert_arity 2
assert_tag TAG_PAIR, %rdi, not_a_pair_string
assert_tag TAG_SYMBOL, %rsi, not_a_symbol_string
mov %rsi, %rbx
call_scm list_to_vector, %rdi
unbox_pointer_internal %rax
mov %bx, header_object_type(%rax)
tag TAG_OBJECT, %rax
return
record_ref: # record, k
assert_arity 2
assert_tag TAG_OBJECT, %rdi, not_a_record_string
assert_tag TAG_INT, %rsi, not_an_integer_string
unbox_pointer_internal %rdi
mov %esi, %esi
mov header_size(%rax,%rsi,POINTER_SIZE), %rax
ret
record_set: # record, k, obj
assert_arity 3
assert_tag TAG_OBJECT, %rdi, not_a_record_string
assert_tag TAG_INT, %rsi, not_an_integer_string
unbox_pointer_internal %rdi
mov %esi, %esi
mov %rdx, header_size(%rax,%rsi,POINTER_SIZE)
mov $VOID, %rax
ret
## 6. Standard procedures
## 6.1. Equivalence predicates
is_eq: # obj1, obj2
is_eqv: # obj1, obj2
assert_arity 2
eq_internal %rdi, %rsi
box_boolean_internal
ret
## 6.2. Numbers
## 6.2.6. Numerical operations
is_number: # obj
is_complex: # obj
is_real: # obj
is_rational: # obj
assert_arity 1
is_double_internal %rdi
je 1f
has_tag TAG_INT, %rdi
1: box_boolean_internal
ret
is_integer: # obj
assert_arity 1
movq %rdi, %xmm0
has_tag TAG_INT, %rdi, store=false
jne 1f
mov $TRUE, %rax
ret
1: is_double_internal %rdi
jne 2f
maybe_round_to_int
has_tag TAG_INT, %rax
box_boolean_internal
ret
2: mov $FALSE, %rax
ret
is_exact: # z
assert_arity 1
has_tag TAG_INT, %rdi
box_boolean_internal
ret
is_inexact: # z
assert_arity 1
is_double_internal %rdi
box_boolean_internal
ret
is_infinite: # z
minimal_prologue
assert_arity 1
is_double_internal %rdi
jne 1f
movq %rdi, %xmm0
call isinf
setnz %al
box_boolean_internal
return
1: return $FALSE
is_nan: # z
minimal_prologue
assert_arity 1
is_double_internal %rdi
jne 1f
movq %rdi, %xmm0
call isnan
setnz %al
box_boolean_internal
return
1: return $FALSE
equal: # z1, z2
binary_comparsion equals, sete, sete
equal_size:
.quad . - equal - RET_SIZE
less_than: # z1, z2
binary_comparsion less_than, setb, setl
less_than_size:
.quad . - less_than - RET_SIZE
greater_than: # z1, z2
binary_comparsion greater_than, seta, setg
greater_than_size:
.quad . - greater_than - RET_SIZE
less_than_or_equal: # z1, z2
binary_comparsion less_than_or_equals, setbe, setle
less_than_or_equal_size:
.quad . - less_than_or_equal - RET_SIZE
greater_than_or_equal: # z1, z2
binary_comparsion greater_than_or_equals, setae, setge
greater_than_or_equal_size:
.quad . - greater_than_or_equal - RET_SIZE
plus: # z1, z2
binary_op plus, addsd, add
plus_size:
.quad . - plus - RET_SIZE
minus: # z1, z2
binary_op minus, subsd, sub
minus_size:
.quad . - minus - RET_SIZE
multiply: # z1, z2
binary_op multiply, mulsd, imul
multiply_size:
.quad . - multiply - RET_SIZE
divide: # z1, z2
assert_arity 2
binary_op_jump divide
divide_int_int:
cvtsi2sd %edi, %xmm0
cvtsi2sd %esi, %xmm1
divsd %xmm1, %xmm0
maybe_round_to_int
jmp divide_return
divide_op:
divsd %xmm1, %xmm0
movq %xmm0, %rax
divide_return:
ret
divide_size:
.quad . - divide - RET_SIZE
quotient: # n1, n2
assert_arity 2
integer_division
box_int_internal
ret
remainder: # n1, n2
prologue
assert_arity 2
extract_binary_op
mov %rax, %rbx
integer_division
cmp $BINARY_OP_INT_INT, %rbx
jne 1f
box_int_internal %edx
return
1: cvtsi2sd %edx, %xmm0
return %xmm0
modulo: # n1, n2
prologue
assert_arity 2
extract_binary_op
mov %rax, %rbx
integer_division
test %edx, %edx
jz 1f
xor %esi, %edi
jns 1f
add %esi, %edx
1: cmp $BINARY_OP_INT_INT, %rbx
jne 2f
box_int_internal %edx
return
2: cvtsi2sd %edx, %xmm0
return %xmm0
floor_: # z
math_library_unary_call floor, return_int=true
ceiling_: # z
math_library_unary_call ceil, return_int=true
truncate_: # z
math_library_unary_call trunc, return_int=true
round_: # z
math_library_unary_call round, return_int=true
.irp name, exp, log, sin, cos, tan, asin, acos, atan
\name\()_: # z
math_library_unary_call \name
.endr
atan2_: # y, x
math_library_binary_call atan2
sqrt_: # z
math_library_unary_call sqrt, round=true
expt_: # z1, z2
math_library_binary_call pow, round=true
inexact: # z
assert_arity 1
has_tag TAG_INT, %rdi, store=false
jne 1f
cvtsi2sd %edi, %xmm0
movq %xmm0, %rax
ret
1: mov %rdi, %rax
ret
exact: # z
assert_arity 1
has_tag TAG_INT, %rdi, store=false
je 1f
movq %rdi, %xmm0
roundsd $ROUNDING_MODE_TRUNCATE, %xmm0, %xmm0
cvtsd2si %xmm0, %rax
box_int_internal
ret
1: mov %rdi, %rax
ret
## 6.2.7. Numerical input and output
number_to_string: # z, radix
minimal_prologue
optional_arg 2, $DECIMAL_RADIX_INT, %rsi
assert_tag TAG_INT, %rsi, not_an_integer_string
is_double_internal %rdi
je 1f
assert_tag TAG_INT, %rdi, not_a_number_string
call_fn integer_to_string_internal %rdi, %rsi
return
1: call_fn double_to_string, %rdi, %rsi
return
string_to_number: # string, radix
prologue tail
optional_arg 2, $DECIMAL_RADIX_INT, %rsi
assert_tag TAG_STRING, %rdi, not_a_string_string
assert_tag TAG_INT, %rsi, not_an_integer_string
mov %esi, %esi
unbox_pointer_internal %rdi, %rbx
add $header_size, %rbx
lea tail(%rsp), %r11
call_fn strtol, %rbx, %r11, %rsi
mov tail(%rsp), %r11
cmpb $NULL, (%r11)
jne 1f
box_int_internal
return
1: lea tail(%rsp), %r11
call_fn strtod, %rbx, %r11
mov tail(%rsp), %r11
cmpb $NULL, (%r11)
jne 2f
movq %xmm0, %rax
return
2: return $FALSE
## 6.3. Booleans
not: # obj
assert_arity 1
mov $FALSE, %rax
eq_internal %rax, %rdi
box_boolean_internal
ret
## 6.4. Pairs and lists
is_pair: # obj
assert_arity 1
is_nil_internal %rdi
jne 1f
mov $FALSE, %rax
ret
1: has_tag TAG_PAIR, %rdi
box_boolean_internal
ret
cons: # obj1, obj2
prologue
assert_arity 2
mov %rdi, %rbx
mov %rsi, %r12
call_fn gc_allocate_memory, $pair_size
movw $TAG_PAIR, header_object_type(%rax)
movl $pair_size, header_object_size(%rax)
mov %rbx, pair_car(%rax)
mov %r12, pair_cdr(%rax)
tag TAG_PAIR, %rax
register_for_gc
return
car: # pair
minimal_prologue
assert_arity 1
assert_pair %rdi
car %rdi
return
car_size:
.quad . - car - RET_SIZE
cdr: # pair
minimal_prologue
assert_arity 1
assert_pair %rdi
cdr %rdi
return
cdr_size:
.quad . - cdr - RET_SIZE
set_car: # pair, obj
minimal_prologue
assert_arity 2
assert_pair %rdi
unbox_pointer_internal %rdi
mov %rsi, pair_car(%rax)
mov $VOID, %rax
return
set_cdr: # pair, obj
minimal_prologue
assert_arity 2
assert_pair %rdi
unbox_pointer_internal %rdi
mov %rsi, pair_cdr(%rax)
mov $VOID, %rax
return
is_null: # obj
assert_arity 1
is_nil_internal %rdi, store=true
box_boolean_internal
ret
length: # list
prologue
assert_arity 1
assert_tag TAG_PAIR, %rdi, not_a_pair_string
mov %rdi, %rax
xor %ebx, %ebx
1: is_nil_internal %rax
je 2f
call_scm cdr, %rax
inc %rbx
jmp 1b
2: box_int_internal %ebx
return
append: # list1, list2
prologue
assert_arity 2
assert_tag TAG_PAIR, %rdi, not_a_pair_string
mov %rsi, %r12
call_scm reverse, %rdi
mov %rax, %rbx
1: is_nil_internal %rbx
je 2f
car %rbx, %rdi
call_scm cons, %rdi, %r12
mov %rax, %r12
cdr %rbx, %rbx
jmp 1b
2: return %r12
reverse: # list
prologue
assert_arity 1
assert_tag TAG_PAIR, %rdi, not_a_pair_string
mov %rdi, %rbx
mov $NIL, %r12
1: is_nil_internal %rbx
je 2f
car %rbx, %rdi
call_scm cons, %rdi, %r12
mov %rax, %r12
cdr %rbx, %rbx
jmp 1b
2: return %r12
## 6.5. Symbols
is_symbol: # obj
assert_arity 1
has_tag TAG_SYMBOL, %rdi
box_boolean_internal
ret
symbol_to_string: # symbol
assert_arity 1
assert_tag TAG_SYMBOL, %rdi, not_a_symbol_string
call_fn symbol_to_string_internal
ret
string_to_symbol: # string
prologue
assert_arity 1
assert_tag TAG_STRING, %rdi, not_a_string_string
unbox_pointer_internal %rdi, %r12
mov symbol_next_id, %rbx
1: test %rbx, %rbx
jz 2f
dec %rbx
mov symbol_table_names(,%rbx,POINTER_SIZE), %rax
unbox_pointer_internal %rax
test %rax, %rax
jz 1b
add $header_size, %rax
lea header_size(%r12), %r11
call_fn strcmp, %r11, %rax
jnz 1b
jmp 3f
2: mov symbol_next_id, %rbx
incq symbol_next_id
lea header_size(%r12), %r11
call_fn box_string, %r11
register_for_gc
mov %rax, symbol_table_names(,%rbx,POINTER_SIZE)
call_fn jit_maybe_add_to_constant_pool, %rax
3: tag TAG_SYMBOL, %rbx
return
## 6.6. Characters
is_char: # obj
assert_arity 1
is_eof_object_internal %rdi, store=false
je 1f
has_tag TAG_CHAR, %rdi
box_boolean_internal
ret
1: mov $FALSE, %rax
ret
char_to_integer: # char
assert_arity 1
assert_tag TAG_CHAR, %rdi, not_a_character_string
mov %edi, %eax
box_int_internal
ret
integer_to_char: # n
assert_arity 1
assert_tag TAG_INT, %rdi, not_an_integer_string
xor %eax, %eax
mov %di, %ax
tag TAG_CHAR, %rax
ret
is_char_alphabetic: # char
minimal_prologue
assert_arity 1
assert_tag TAG_CHAR, %rdi, not_a_character_string
mov %edi, %edi
call_fn isalpha, %rdi
setnz %al
box_boolean_internal
return
is_char_numeric: # char
minimal_prologue
assert_arity 1
assert_tag TAG_CHAR, %rdi, not_a_character_string
mov %edi, %edi
call_fn isdigit, %rdi
setnz %al
box_boolean_internal
return
is_char_whitespace: # char
minimal_prologue
assert_arity 1
assert_tag TAG_CHAR, %rdi, not_a_character_string
mov %edi, %edi
call_fn isspace, %rdi
setnz %al
box_boolean_internal
return
is_char_upper_case: # char
minimal_prologue
assert_arity 1
assert_tag TAG_CHAR, %rdi, not_a_character_string
mov %edi, %edi
call_fn isupper, %rdi
setnz %al
box_boolean_internal
return
is_char_lower_case: # char
minimal_prologue
assert_arity 1
assert_tag TAG_CHAR, %rdi, not_a_character_string
mov %edi, %edi
call_fn islower, %rdi
setnz %al
box_boolean_internal
return
char_upcase: # char
minimal_prologue
assert_arity 1
assert_tag TAG_CHAR, %rdi, not_a_character_string
mov %edi, %edi
call_fn toupper, %rdi
tag TAG_CHAR, %rax
return
char_downcase: # char
minimal_prologue
assert_arity 1
assert_tag TAG_CHAR, %rdi, not_a_character_string
mov %edi, %edi
call_fn tolower, %rdi
tag TAG_CHAR, %rax
return
## 6.7. Strings
is_string: # obj
assert_arity 1
has_tag TAG_STRING, %rdi
box_boolean_internal
ret
make_string: # k, fill
prologue
optional_arg 2, $SPACE_CHAR, %rsi
assert_tag TAG_INT, %rdi, not_an_integer_string
assert_tag TAG_CHAR, %rsi, not_a_character_string
mov %edi, %edi
mov %edi, %ebx
add $header_size, %edi
inc %edi
mov %rsi, %r12
call_fn gc_allocate_memory, %rdi
movw $TAG_STRING, header_object_type(%rax)
mov %ebx, header_object_size(%rax)
incl header_object_size(%rax)
movb $NULL, header_size(%rax,%rbx)
1: test %ebx, %ebx
jz 2f
dec %ebx
mov %r12b, header_size(%rax,%rbx,1)
jmp 1b
2: tag TAG_STRING, %rax
register_for_gc
return
string_length: # string
assert_arity 1
assert_tag TAG_STRING, %rdi, not_a_string_string
unbox_pointer_internal %rdi
mov header_object_size(%rax), %eax
dec %eax
box_int_internal %eax
ret
string_length_size:
.quad . - string_length - RET_SIZE
string_ref: # string, k
assert_arity 2
assert_tag TAG_STRING, %rdi, not_a_string_string
assert_tag TAG_INT, %rsi, not_an_integer_string
mov %esi, %esi
unbox_pointer_internal %rdi
assert_bounds %rax %esi, size_adjust=-1
movzxb header_size(%rax,%rsi), %eax
tag TAG_CHAR, %rax
ret
string_ref_size:
.quad . - string_ref - RET_SIZE
string_set: # string, k, char
assert_arity 3
assert_tag TAG_STRING, %rdi, not_a_string_string
assert_tag TAG_INT, %rsi, not_an_integer_string
assert_tag TAG_CHAR, %rdx, not_a_character_string
mov %esi, %esi
unbox_pointer_internal %rdi
assert_bounds %rax %esi, size_adjust=-1
mov %dl, header_size(%rax,%rsi)
mov $VOID, %rax
ret
string_set_size:
.quad . - string_set - RET_SIZE
is_string_equal: # string1, string2
string_comparator strcmp, setz
is_string_ci_equal: # string1, string2
string_comparator strcasecmp, setz
is_string_less_than: # string1, string2
string_comparator strcmp, setl
is_string_greater_than: # string1, string2
string_comparator strcmp, setg
is_string_less_than_or_equal: # string1, string2
string_comparator strcmp, setle
is_string_greater_than_or_equal: # string1, string2
string_comparator strcmp, setge
is_string_ci_less_than: # string1, string2
string_comparator strcasecmp, setl
is_string_ci_greater_than: # string1, string2
string_comparator strcasecmp, setg
is_string_ci_less_than_or_equal: # string1, string2
string_comparator strcasecmp, setle
is_string_ci_greater_than_or_equal: # string1, string2
string_comparator strcasecmp, setge
## 6.8. Vectors
is_vector: # obj
assert_arity 1
has_tag TAG_VECTOR, %rdi
box_boolean_internal %rax
ret
make_vector: # k, fill
prologue
optional_arg 2, $VOID, %rsi
assert_tag TAG_INT, %rdi, not_an_integer_string
mov %rsi, %r12
shl $POINTER_SIZE_SHIFT, %edi
mov %edi, %ebx
add $header_size, %edi
call_fn gc_allocate_memory, %rdi
movw $TAG_VECTOR, header_object_type(%rax)
mov %ebx, header_object_size(%rax)
2: test %ebx, %ebx
jz 3f
sub $POINTER_SIZE, %ebx
mov %r12, header_size(%rax,%rbx)
jmp 2b
3: tag TAG_VECTOR, %rax
register_for_gc
return
vector_length: # vector
assert_arity 1
assert_tag TAG_VECTOR, %rdi, not_a_vector_string
unbox_pointer_internal %rdi
mov header_object_size(%rax), %eax
shr $POINTER_SIZE_SHIFT, %eax
box_int_internal
ret
vector_length_size:
.quad . - vector_length - RET_SIZE
vector_ref: # vector, k
assert_arity 2
assert_tag TAG_VECTOR, %rdi, not_a_vector_string
assert_tag TAG_INT, %rsi, not_an_integer_string
unbox_pointer_internal %rdi
assert_bounds %rax, %esi, POINTER_SIZE_SHIFT
mov %esi, %esi
mov header_size(%rax,%rsi,POINTER_SIZE), %rax
ret
vector_ref_size:
.quad . - vector_ref - RET_SIZE
vector_set: # vector, k, obj
assert_arity 3
assert_tag TAG_VECTOR, %rdi, not_a_vector_string
assert_tag TAG_INT, %rsi, not_an_integer_string
unbox_pointer_internal %rdi
assert_bounds %rax, %esi, POINTER_SIZE_SHIFT
mov %esi, %esi
mov %rdx, header_size(%rax,%rsi,POINTER_SIZE)
mov $VOID, %rax
ret
vector_set_size:
.quad . - vector_set - RET_SIZE
list_to_vector: # list
prologue vec
assert_arity 1
mov %rdi, %r12
call_scm length, %rdi
mov %rax, %rdi
call_scm make_vector, %rdi, $VOID
mov %rax, vec(%rsp)
xor %ebx, %ebx
1: is_nil_internal %r12
je 2f
box_int_internal %ebx
mov %rax, %rsi
car %r12, %rdx
call_scm vector_set, vec(%rsp), %rsi, %rdx
cdr %r12, %r12
inc %rbx
jmp 1b
2: return vec(%rsp)
## 6.9. Bytevectors
is_bytevector: # obj
minimal_prologue
assert_arity 1
call_scm class_of, %rdi
eq_internal $TAG_BYTEVECTOR, %eax
box_boolean_internal %rax
return
make_bytevector: # k, byte
prologue
optional_arg 2, $ZERO_INT, %rsi
assert_tag TAG_INT, %rdi, not_an_integer_string
assert_tag TAG_INT, %rsi, not_an_integer_string
mov %rsi, %r12
mov %edi, %ebx
add $header_size, %edi
call_fn gc_allocate_memory, %rdi
movw $TAG_BYTEVECTOR, header_object_type(%rax)
mov %ebx, header_object_size(%rax)
1: test %ebx, %ebx
jz 2f
dec %ebx
mov %r12b, header_size(%rax,%rbx)
jmp 1b
2: tag TAG_OBJECT, %rax
register_for_gc
return
bytevector_length: # bytevector
assert_arity 1
assert_object %rdi, TAG_BYTEVECTOR, not_a_bytevector_string
unbox_pointer_internal %rdi
mov header_object_size(%rax), %eax
box_int_internal
ret
bytevector_length_size:
.quad . - bytevector_length - RET_SIZE
bytevector_u8_ref: # bytevector, k
assert_arity 2
assert_object %rdi, TAG_BYTEVECTOR, not_a_bytevector_string
assert_tag TAG_INT, %rsi, not_an_integer_string
unbox_pointer_internal %rdi
assert_bounds %rax, %esi
mov %esi, %esi
xor %r11d, %r11d
mov header_size(%rax,%rsi), %r11b
tag TAG_INT, %r11
ret
bytevector_u8_ref_size:
.quad . - bytevector_u8_ref - RET_SIZE
bytevector_u8_set: # bytevector, k, byte
assert_arity 3
assert_object %rdi, TAG_BYTEVECTOR, not_a_bytevector_string
assert_tag TAG_INT, %rsi, not_an_integer_string
assert_tag TAG_INT, %rdx, not_an_integer_string
unbox_pointer_internal %rdi
assert_bounds %rax, %esi
mov %esi, %esi
mov %dl, header_size(%rax,%rsi)
mov $VOID, %rax
ret
bytevector_u8_set_size:
.quad . - bytevector_u8_set - RET_SIZE
list_to_bytevector: # list
prologue vec
assert_arity 1
mov %rdi, %r12
call_scm length, %rdi
call_scm make_bytevector, %rax, $ZERO_INT
mov %rax, vec(%rsp)
xor %ebx, %ebx
1: is_nil_internal %r12
je 2f
box_int_internal %ebx
car %r12, %rdx
call_scm bytevector_u8_set, vec(%rsp), %rax, %rdx
cdr %r12, %r12
inc %rbx
jmp 1b
2: return vec(%rsp)
## 6.10. Control features
is_procedure: # obj
assert_arity 1
has_tag TAG_PROCEDURE, %rdi
box_boolean_internal
ret
apply: # proc, args
prologue
assert_arity 2
assert_tag TAG_PROCEDURE, %rdi, not_a_procedure_string
assert_tag TAG_PAIR, %rsi, not_a_pair_string
unbox_pointer_internal %rdi, %rbx
call_scm reverse, %rsi
mov %rax, %r12
call_scm length, %r12
mov %eax, %r10d
1: is_nil_internal %r12
je 2f
car %r12
push %rax
cdr %r12, %r12
jmp 1b
2: cmp $1, %r10d
jl 3f
pop %rdi
cmp $2, %r10d
jl 3f
pop %rsi
cmp $3, %r10d
jl 3f
pop %rdx
cmp $4, %r10d
jl 3f
pop %rcx
cmp $5, %r10d
jl 3f
pop %r8
cmp $6, %r10d
jl 3f
pop %r9
3: mov %r10d, %eax
mov %r10d, %r12d
call *%rbx
sub $MAX_REGISTER_ARGS, %r12d
js 4f
shl $POINTER_SIZE_SHIFT, %r12d
add %r12, %rsp
4: return
call_with_current_continuation: # proc
prologue stack_depth, continuation, dynamic_extent, rbx, r12, rbp
mov %rbx, rbx(%rsp)
mov %r12, r12(%rsp)
mov %rbp, rbp(%rsp)
assert_arity 1
assert_tag TAG_PROCEDURE, %rdi, not_a_procedure_string
unbox_pointer_internal %rdi, %rbx
mov execution_stack_top, %rax
mov %rsp, %r11
add $stack_frame_size, %r11
sub %r11, %rax
mov %eax, stack_depth(%rsp)
shr $POINTER_SIZE_SHIFT, %eax
add $CONTINUATION_SAVED_VALUES, %eax
box_int_internal %eax
call_scm make_vector, %rax, $VOID
unbox_pointer_internal
movw $TAG_CONTINUATION, header_object_type(%rax)
lea header_size(%rax), %r12
tag TAG_OBJECT, %rax
mov %rax, continuation(%rsp)
call_fn jit_maybe_add_to_constant_pool, %rax
parameter_value dynamic_extent_stack_symbol
call_scm reverse, %rax
mov %rax, dynamic_extent(%rsp)
.irp saved_value, dynamic_extent, rbx, r12, rbp
mov \saved_value(%rsp), %rax
mov %rax, (%r12)
add $POINTER_SIZE, %r12
.endr
mov execution_stack_top, %r11
mov stack_depth(%rsp), %eax
sub %rax, %r11
call_fn memcpy, %r12, %r11, %rax
perror
call_fn jit_call_with_current_continuation_escape_factory, continuation(%rsp)
tag TAG_PROCEDURE, %rax
mov %rax, %r11
call_scm *%rbx, %r11
return
values: # obj ...
assert_arity 1, jge
mov $1, %r10d
push %rbp
mov %rsp, %rbp
call_fn jit_rt_lambda_collect_varargs
pop %rbp
push %rdi
call_scm make_vector, $ONE_INT, %rsi
unbox_pointer_internal
movw $TAG_VALUES, header_object_type(%rax)
tag TAG_OBJECT, %rax
mov %rax, %rdx
pop %rax
ret
call_with_values: # producer, consumer
prologue vals
assert_arity 2
assert_tag TAG_PROCEDURE, %rdi, not_a_procedure_string
assert_tag TAG_PROCEDURE, %rsi, not_a_procedure_string
unbox_pointer_internal %rdi, %rbx
mov %rsi, %r12
xor %edx, %edx
call_scm *%rbx
mov %rax, %rbx
mov %rdx, vals(%rsp)
call_scm class_of, %rdx
cmp $TAG_VALUES, %eax
je 1f
mov $NIL, %rax
jmp 2f
1: call_scm record_ref, vals(%rsp), $ZERO_INT