File tree Expand file tree Collapse file tree 1 file changed +13
-16
lines changed Expand file tree Collapse file tree 1 file changed +13
-16
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,17 @@ impl Expr {
25
25
)
26
26
} ;
27
27
}
28
+ macro_rules! call_func {
29
+ ( $func_obj: expr) => {
30
+ Some ( format!(
31
+ "{}{}\t mov r11, rax\n {}\t call r11\n {}" ,
32
+ pass_args!( ) ,
33
+ $func_obj. compile( ctx) ?,
34
+ stackframe!( "add" ) ,
35
+ stackframe!( "sub" ) ,
36
+ ) )
37
+ } ;
38
+ }
28
39
match expr. first ( ) ? {
29
40
Expr :: Atom ( Atom :: Symbol ( func_name) ) => {
30
41
macro_rules! multi_args {
@@ -91,24 +102,10 @@ impl Expr {
91
102
. push ( format ! ( "{name}:\n {receiver}\n {body}\t ret\n \n " ) ) ;
92
103
Some ( format ! ( "\t lea rax, [rel {name}]\n " ) )
93
104
}
94
- _ => Some ( format ! (
95
- "{}\t mov rax, [rel _ptr + {}]\n {}\t call rax\n {}" ,
96
- pass_args!( ) ,
97
- ctx. variables[ func_name] ,
98
- stackframe!( "add" ) ,
99
- stackframe!( "sub" ) ,
100
- ) ) ,
105
+ _ => call_func ! ( Expr :: Atom ( Atom :: Symbol ( func_name. to_owned( ) ) ) ) ,
101
106
}
102
107
}
103
- func_obj => {
104
- let code = func_obj. compile ( ctx) ?;
105
- Some ( format ! (
106
- "{}{code}{}\t call rax\n {}" ,
107
- pass_args!( ) ,
108
- stackframe!( "add" ) ,
109
- stackframe!( "sub" ) ,
110
- ) )
111
- }
108
+ func_obj => call_func ! ( func_obj) ,
112
109
}
113
110
}
114
111
Expr :: Atom ( atom) => atom. compile ( ctx) ,
You can’t perform that action at this time.
0 commit comments