Skip to content

Commit a182014

Browse files
Update gen.rs
1 parent bd96c5a commit a182014

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

src/gen.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ impl Expr {
2525
)
2626
};
2727
}
28+
macro_rules! call_func {
29+
($func_obj: expr) => {
30+
Some(format!(
31+
"{}{}\tmov r11, rax\n{}\tcall r11\n{}",
32+
pass_args!(),
33+
$func_obj.compile(ctx)?,
34+
stackframe!("add"),
35+
stackframe!("sub"),
36+
))
37+
};
38+
}
2839
match expr.first()? {
2940
Expr::Atom(Atom::Symbol(func_name)) => {
3041
macro_rules! multi_args {
@@ -91,24 +102,10 @@ impl Expr {
91102
.push(format!("{name}:\n{receiver}\n{body}\tret\n\n"));
92103
Some(format!("\tlea rax, [rel {name}]\n"))
93104
}
94-
_ => Some(format!(
95-
"{}\tmov rax, [rel _ptr + {}]\n{}\tcall 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()))),
101106
}
102107
}
103-
func_obj => {
104-
let code = func_obj.compile(ctx)?;
105-
Some(format!(
106-
"{}{code}{}\tcall rax\n{}",
107-
pass_args!(),
108-
stackframe!("add"),
109-
stackframe!("sub"),
110-
))
111-
}
108+
func_obj => call_func!(func_obj),
112109
}
113110
}
114111
Expr::Atom(atom) => atom.compile(ctx),

0 commit comments

Comments
 (0)