array literals

This commit is contained in:
2025-06-07 13:27:22 +02:00
parent c3badb609c
commit 252efd914e
7 changed files with 61 additions and 64 deletions

View File

@@ -58,6 +58,7 @@ macro_rules! emit {
}
static REGISTERS: [&str; 6] = ["rdi", "rsi", "rdx", "rcx", "r8", "r9"];
// TODO: currently they are all just 8 byte values
static TYPES: [&str; 6] = ["I64", "String", "Bool", "Ptr", "Char", "Array"];
pub struct CodegenX86_64 {
@@ -452,6 +453,18 @@ extern gettimeofday
emit!(&mut self.output, " call {}", callee);
}
Expr::ArrayLiteral(exprs) => {
emit!(&mut self.output, " call Array.new");
emit!(&mut self.output, " mov r12, rax");
for expr in exprs {
self.compile_expr(env, expr)?;
emit!(&mut self.output, " mov rsi, rax");
emit!(&mut self.output, " mov rdi, r12");
emit!(&mut self.output, " call Array.push");
}
emit!(&mut self.output, " mov rax, r12");
}
}
Ok(())
}