-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactivation_stack.s
169 lines (128 loc) · 3.75 KB
/
activation_stack.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
.text
.globl _create_activation_stack
.globl _set_return_cursor
.globl _pop_activation_stack
.globl _get_activation_stack
.globl _start_variable_binding
.globl _end_variable_binding
.globl _bind_variable
.p2align 2
; activation record
; quad return cursor +0 (where to set the cursor after function call returns)
; quad scope stack +8 (stack of maps to accomplish lexical scoping)
; _pop_activation_stack is unsafe if the stack is empty but that should never happen
_create_activation_record:
stp fp, lr, [sp, -32]!
stp x19, x20, [sp, 16]
mov x0, 16
bl _malloc
str xzr, [x0] ; write 0 for return cursor
mov x19, x0 ; save entry
bl _s_create ; create scope stack
str x0, [x19, 8] ; store scope stack in entry
mov x20, x0 ; save scope stack
bl _m_create
mov x1, x0 ; set as parameter to push
mov x0, x20
bl _s_push ; push scope 0 map to scope stack
mov x0, x19 ; return entry
ldp x19, x20, [sp, 16]
ldp fp, lr, [sp], 32
ret
_create_activation_stack:
stp fp, lr, [sp, -16]!
bl _s_create
adrp x8, _activation_stack@page
add x8, x8, _activation_stack@pageoff
str x0, [x8] ; save return stack
bl _s_create
adrp x8, _variable_binding_stack@page
add x8, x8, _variable_binding_stack@pageoff
str x0, [x8] ; save variable binding stack
ldp fp, lr, [sp], 16
ret
; set the return cursor of the top activation record
; value in x0
_set_return_cursor:
stp fp, lr, [sp, -32]!
str x19, [sp, 16]
mov x19, x0 ; save cursor x19
adrp x8, _activation_stack@page
add x8, x8, _activation_stack@pageoff
ldr x0, [x8]
bl _s_top ; get top record
str x19, [x0] ; set cursor
ldr x19, [sp, 16]
ldp fp, lr, [sp], 32
ret
; returns return cursor of top record in x0
; deallocate activation record
; deallocate stack
_pop_activation_stack:
stp fp, lr, [sp, -32]!
str x19, [sp, 16]
adrp x8, _activation_stack@page
add x8, x8, _activation_stack@pageoff
ldr x0, [x8]
bl _s_pop ; pop activation record
mov x19, x0 ; save in x9
ldr x0, [x19, 8] ; load symbol stack
bl _s_destroy ; deallocate symbol stack
ldr x0, [x19] ; load cursor from activation record for return
ldr x19, [sp, 16]
ldp fp, lr, [sp], 32
ret
; return stack in x0
_get_activation_stack:
adrp x0, _activation_stack@page
add x0, x0, _activation_stack@pageoff
ldr x0, [x0]
ret
; create temporary activation record for variable binding
_start_variable_binding:
stp fp, lr, [sp, -16]!
bl _create_activation_record
mov x1, x0
adrp x8, _variable_binding_stack@page
add x8, x8, _variable_binding_stack@pageoff
ldr x0, [x8] ; variable binding stack
bl _s_push ; push activation record to variable binding stack
ldp fp, lr, [sp], 16
ret
; push temporary activation record to stack
_end_variable_binding:
stp fp, lr, [sp, -16]!
adrp x8, _variable_binding_stack@page
add x8, x8, _variable_binding_stack@pageoff
ldr x0, [x8] ; load activation record
bl _s_pop
mov x1, x0 ; move as arg1 for push to activation stack
adrp x8, _activation_stack@page
add x8, x8, _activation_stack@pageoff
ldr x0, [x8]
bl _s_push ; push to stack
ldp fp, lr, [sp], 16
ret
; key in x0
; entry in x1
_bind_variable:
stp fp, lr, [sp, -32]!
stp x19, x20, [sp, 16]
mov x19, x0
mov x20, x1
adrp x8, _variable_binding_stack@page
add x8, x8, _variable_binding_stack@pageoff
ldr x0, [x8]
bl _s_top ; get top record
ldr x0, [x0, 8] ; get AR's scope stack
bl _s_top ; get table
mov x1, x19
mov x2, x20
bl _m_insert
ldp x19, x20, [sp, 16]
ldp fp, lr, [sp], 32
ret
.data
.p2align 3
_activation_stack: .quad 0
_variable_binding_stack: .quad 0