@@ -17,57 +17,34 @@ stack-call := λ ctx function-name function-args offset . (tail(
17
17
(local src-offset)
18
18
(local copy-offset)
19
19
(set src-offset (s2i 8)) # stack pointer is 64 bits
20
- (match (expr::get-expr e-args) (
21
- ()
22
- ( 1 (tail(
23
- (set copy-offset (add( (s2i '-1) copy-offset )))
24
- (set copy-bytes ( copy-bytes
25
- \t 'mov \s (i2s( src-offset )) \[ '%rbp \] , \s '%al \n
26
- \t 'mov \s '%al , \s (i2s( copy-offset )) \[ '%rbp \] \n
27
- ))
28
- (set src-offset (add( src-offset (s2i 1) )))
29
- )))
30
- ( 2 (tail(
31
- (set copy-offset (add( (s2i '-2) copy-offset )))
32
- (set copy-bytes ( copy-bytes
33
- \t 'mov \s (i2s( src-offset )) \[ '%rbp \] , \s '%ax \n
34
- \t 'mov \s '%ax , \s (i2s( copy-offset )) \[ '%rbp \] \n
35
- ))
36
- (set src-offset (add( src-offset (s2i 2) )))
37
- )))
38
- ( 4 (tail(
39
- (set copy-offset (add( (s2i '-4) copy-offset )))
40
- (set copy-bytes ( copy-bytes
41
- \t 'mov \s (i2s( src-offset )) \[ '%rbp \] , \s '%eax \n
42
- \t 'mov \s '%eax , \s (i2s( copy-offset )) \[ '%rbp \] \n
43
- ))
44
- (set src-offset (add( src-offset (s2i 4) )))
45
- )))
46
- ( copy-size (tail(
47
- (set copy-size (s2i copy-size))
48
- (set copy-offset (inv( copy-size )))
49
- (while copy-size (
50
- (set copy-bytes ( copy-bytes
51
- \t 'mov \s (i2s( src-offset )) \[ '%rbp \] , \s '%rax \n
52
- \t 'mov \s '%rax , \s (i2s( copy-offset )) \[ '%rbp \] \n
53
- ))
54
- (set copy-offset (add( (s2i '8) copy-offset )))
55
- (set src-offset (add( (s2i '8) src-offset )))
56
- (set copy-size (add( (s2i '-8) copy-size )))
57
- ))
58
- )))
20
+ (local copy-size)
21
+ (set copy-size (s2i (expr::get-expr e-args)))
22
+ (set copy-offset (inv( copy-size )))
23
+ (while copy-size (
24
+ (set copy-bytes ( copy-bytes
25
+ \t 'mov \s (i2s( src-offset )) \[ '%rbp \] , \s '%rax \n
26
+ \t 'mov \s '%rax , \s (i2s( copy-offset )) \[ '%rbp \] \n
27
+ ))
28
+ (set copy-offset (add( (s2i '8) copy-offset )))
29
+ (set src-offset (add( (s2i '8) src-offset )))
30
+ (set copy-size (add( (s2i '-8) copy-size )))
31
+ ))
32
+ (local args-size)
33
+ (set args-size (expr::get-expr e-args))
34
+ (if (eq( args-size 0 )) () (
35
+ (set args-size (max( '8 args-size )))
59
36
))
60
37
(set e-call (expr::set-prog( e-call (
61
38
(expr::get-frame e-args)
62
39
(expr::get-prog e-args)
63
40
(enter-function())
64
- (if (eq( (expr::get-expr e- args) 0 )) () (
65
- ( \t 'sub \s '$ (expr::get-expr e- args) , \s '%rsp \n )
41
+ (if (eq( args-size 0 )) () (
42
+ ( \t 'sub \s '$ args-size , \s '%rsp \n )
66
43
))
67
44
copy-bytes
68
45
(\t 'call \s (mangle-identifier( function-name (typecheck-lookup body) )) \n)
69
- (if (eq( (expr::get-expr e- args) 0 )) () (
70
- ( \t 'add \s '$ (expr::get-expr e- args) , \s '%rsp \n )
46
+ (if (eq( args-size 0 )) () (
47
+ ( \t 'add \s '$ args-size , \s '%rsp \n )
71
48
))
72
49
(\t 'mov \s '%rbp, \s '%rsp \n
73
50
\t 'pop \s '%rbp \n)
@@ -136,39 +113,32 @@ stack-call-push-arg := λ ctx e-arg offset args-size . (tail(
136
113
(assert-typeof( 'stack-call-push-arg::args-size args-size Atom ))
137
114
(local e1)
138
115
(local e2)
139
- (local e3)
140
116
(local et)
141
117
(set et (typecheck-lookup e-arg))
142
118
(local e-sz)
143
119
(set e-sz (typecheck-sizeof et))
120
+ (set e-sz (max( 8 e-sz )))
144
121
(set args-size (i2s(add( (s2i args-size) (s2i e-sz) ))) )
145
122
(local new-offset)
146
123
(set new-offset( (i2s(add( (s2i offset) (inv(s2i( e-sz ))) ))) ))
147
-
148
- (local frame)
124
+
149
125
(local unframe)
150
126
(if (eq( e-sz '0 )) () (
151
- (set frame ( \t 'sub \s '$ e-sz , \s '%rsp \n ))
152
- (set unframe ( \t 'add \s '$ e-sz , \s '%rsp \n ))
127
+ (set unframe ( \t 'add \s '$ (max( '8 e-sz )) , \s '%rsp \n ))
153
128
))
154
129
155
130
(set e1 (compile-expr-strict( ctx e-arg new-offset Used )))
156
131
(set e1 (expr::set-type( e1 (typecheck-lookup e-arg))))
157
- (set e2 (expr::new()))
158
- (set e2 (expr::set-expr( e2 new-offset )))
159
- (set e2 (expr::set-context( e2 ctx )))
160
- (set e2 (expr::set-offset( e2 new-offset )))
161
- (set e2 (expr::set-type( e2 (And( LocalVariable (Sized e-sz) )) )))
162
132
163
- (set e3 (fragment-apply(
164
- ctx 'mov (Cons( ( typecheck-lookup e-arg) (And( LocalVariable (Sized e-sz) )) ) )
165
- ((( ) e1) e2) e2
133
+ (set e2 (fragment-apply(
134
+ ctx 'push ( typecheck-lookup e-arg)
135
+ (() e1) e1
166
136
)))
167
137
168
- (set e3 (expr::set-frame( e3 ((expr::get-frame e3) frame ) )))
169
- (set e3 (expr::set-unframe( e3 ((expr::get-unframe e3) unframe) )))
170
- (set e3 (expr::set-expr( e3 args-size )))
171
- e3
138
+ (set e2 (expr::set-unframe( e2 ((expr::get-unframe e2) unframe ) )))
139
+ (set e2 (expr::set-expr( e2 args-size )))
140
+ (set e2 (expr::set-offset( e2 new-offset )))
141
+ e2
172
142
));
173
143
174
144
stack-destructure-args := λ ctx function-args offset arg-mode . (tail(
@@ -227,6 +197,7 @@ stack-define-destructure := λ ctx lhs offset . (match lhs (
227
197
(set ltype (typecheck-infer-type-compound ltype) )
228
198
(local size)
229
199
(set size (typecheck-sizeof ltype))
200
+ (set size (max( '8 size )))
230
201
(local new_offset)
231
202
(set new_offset (add( offset (inv(s2i size)) )) )
232
203
(local return)
@@ -242,6 +213,7 @@ stack-define-destructure := λ ctx lhs offset . (match lhs (
242
213
(set ltype (typecheck-infer-type-compound ltype) )
243
214
(local size)
244
215
(set size (typecheck-sizeof ltype))
216
+ (set size (max( '8 size )))
245
217
(local new_offset)
246
218
(set new_offset (add( offset (inv(s2i size)) )) )
247
219
(local more-e)
0 commit comments