1 ! Copyright (C) 2007 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: bootstrap.image.private kernel namespaces system
4 cpu.arm.assembler math layouts words compiler.units ;
7 ! We generate ARM3 code
23 : stack-frame 16 bootstrap-cells ;
25 : next-save stack-frame 2 bootstrap-cells - ;
26 : xt-save stack-frame 3 bootstrap-cells - ;
27 : array-save stack-frame 4 bootstrap-cells - ;
28 : scan-save stack-frame 5 bootstrap-cells - ;
31 temp-reg quot-reg quot-array@ <+> LDR ! load array
32 scan-reg temp-reg scan@ ADD ! initialize scan pointer
33 ] { } make jit-setup set
36 LR SP 4 <-> STR ! save return address
38 xt-reg SP xt-save <+> STR ! save XT
39 xt-reg stack-frame MOV
40 xt-reg SP next-save <+> STR ! save frame size
41 temp-reg SP array-save <+> STR ! save array
42 ] { } make jit-prolog set
45 temp-reg scan-reg 4 <!+> LDR ! load literal and advance
46 temp-reg ds-reg 4 <!+> STR ! push literal
47 ] { } make jit-push-literal set
50 temp-reg scan-reg 4 <!+> LDR ! load wrapper and advance
51 temp-reg dup wrapper@ <+> LDR ! load wrapped object
52 temp-reg ds-reg 4 <!+> STR ! push wrapped object
53 ] { } make jit-push-wrapper set
56 R1 SP 4 SUB ! pass stack pointer to primitive
57 ] { } make jit-word-primitive-jump set
60 R1 SP 4 SUB ! pass stack pointer to primitive
61 ] { } make jit-word-primitive-call set
64 word-reg scan-reg 4 <!+> LDR ! load word and advance
65 xt-reg word-reg word-xt@ <+> LDR ;
68 scan-reg SP scan-save <+> STR ! save scan pointer
69 LR PC MOV ! save return address
71 scan-reg SP scan-save <+> LDR ! restore scan pointer
77 [ load-word-xt jit-call ] { } make jit-word-call set
79 [ load-word-xt jit-jump ] { } make jit-word-jump set
82 xt-reg quot-reg quot-xt@ <+> LDR ;
85 temp-reg ds-reg 4 <-!> LDR ! pop boolean
86 temp-reg \ f tag-number CMP ! compare it with f
87 quot-reg scan-reg MOV ! point quot-reg at false branch
88 quot-reg dup 4 EQ ADD ! point quot-reg at true branch
89 quot-reg dup 4 <+> LDR ! load the branch
90 scan-reg dup 12 ADD ! advance scan pointer
96 ] { } make jit-if-jump set
100 ] { } make jit-if-call set
103 temp-reg ds-reg 4 <-!> LDR ! pop index
104 temp-reg dup 1 <LSR> MOV ! turn it into an array offset
105 scan-reg dup 4 <+> LDR ! load array
106 temp-reg dup scan-reg ADD ! compute quotation location
107 quot-reg temp-reg array-start <+> LDR ! load quotation
110 ] { } make jit-dispatch set
113 SP SP stack-frame ADD ! pop stack frame
114 LR SP 4 <-> LDR ! load return address
115 ] { } make jit-epilog set
117 [ LR BX ] { } make jit-return set
119 [ "bootstrap.arm" forget-vocab ] with-compilation-unit