fix argument evaluation
This commit is contained in:
@@ -533,19 +533,22 @@ Math.isqrt:
|
|||||||
paren,
|
paren,
|
||||||
args,
|
args,
|
||||||
} => {
|
} => {
|
||||||
// TODO: in function calls like a(1, b(2, 3)) the first argument will get overwritten when calling b
|
|
||||||
let callee = match *callee {
|
let callee = match *callee {
|
||||||
Expr::Variable(name) => name.lexeme,
|
Expr::Variable(name) => name.lexeme,
|
||||||
_ => return error!(&paren.loc, "tried to call a non-constant expression"),
|
_ => return error!(&paren.loc, "tried to call a non-constant expression"),
|
||||||
};
|
};
|
||||||
|
|
||||||
for (i, arg) in args.iter().enumerate() {
|
for arg in &args {
|
||||||
self.compile_expr(env, arg.clone())?;
|
self.compile_expr(env, arg.clone())?;
|
||||||
|
emit!(&mut self.output, " push rax");
|
||||||
|
}
|
||||||
|
|
||||||
|
for i in (0..args.len()).rev() {
|
||||||
let reg = match REGISTERS.get(i) {
|
let reg = match REGISTERS.get(i) {
|
||||||
Some(x) => x,
|
Some(x) => x,
|
||||||
None => return error!(&paren.loc, "only up to 6 args allowed"),
|
None => return error!(&paren.loc, "only up to 6 args allowed"),
|
||||||
};
|
};
|
||||||
emit!(&mut self.output, " mov {}, rax", reg,);
|
emit!(&mut self.output, " pop {}", reg);
|
||||||
}
|
}
|
||||||
|
|
||||||
emit!(&mut self.output, " call {}", callee);
|
emit!(&mut self.output, " call {}", callee);
|
||||||
|
|||||||
Reference in New Issue
Block a user