fix parser
Algunas comprobaciones han fallado
CI (Gitea) / Test (beta) (push) Has been cancelled
CI (Gitea) / Test (nightly) (push) Has been cancelled
CI (Gitea) / Test (stable) (push) Has been cancelled
CI (Gitea) / Build Release (push) Has been cancelled
CI (Gitea) / Cross Compile (i686-unknown-linux-gnu) (push) Has been cancelled
CI (Gitea) / Cross Compile (x86_64-unknown-linux-gnu) (push) Has been cancelled
CI (Gitea) / Integration Tests (push) Has been cancelled

Signed-off-by: ale <ale@manalejandro.com>
Este commit está contenido en:
ale
2025-08-25 20:20:43 +02:00
padre 3a2a9edcbc
commit 2aa9b33418
Se han modificado 2 ficheros con 22 adiciones y 7 borrados

Ver fichero

@@ -131,8 +131,11 @@ impl CodeGenerator {
// Set up parameter tracking
self.current_function_params.clear();
self.local_variables.clear();
// Start local variables after parameters to avoid collision
self.stack_offset = -(function.parameters.len() as i32 * 8);
// Start local variables after all parameters to avoid collision
// Parameters use negative offsets -8, -16, -24, etc.
// Local variables should start after the last parameter
let param_space = (function.parameters.len() as i32) * 8;
self.stack_offset = -param_space - 8; // Start after all parameters
self.epilogue_emitted = false;
// Function prologue
@@ -175,10 +178,14 @@ impl CodeGenerator {
self.emit_line(" push rbp");
self.emit_line(" mov rbp, rsp");
// Reserve space for parameters + ensure 16-byte alignment
// Reserve space for parameters + local variables + ensure 16-byte alignment
let stack_space = parameters.len() * 8;
// Always reserve at least 8 bytes to maintain 16-byte alignment after rbp push
let min_space = if stack_space == 0 { 8 } else { stack_space };
// Reserve more space for local variables (128 bytes should be enough for most functions)
let min_space = if stack_space == 0 {
128
} else {
stack_space + 128
};
let aligned_space = min_space.div_ceil(16) * 16; // Round up to 16-byte boundary
self.emit_line(&format!(" sub rsp, {}", aligned_space));

Ver fichero

@@ -620,8 +620,16 @@ impl Parser {
self.consume(&TokenType::RightParen, "Expected ')' after parameters")?;
let body = if self.check(&TokenType::LeftBrace) {
self.advance()?; // Consume the LeftBrace
self.parse_block_statement()?
// Don't advance here, let parse_block_statement handle it
let mut statements = Vec::new();
self.consume(&TokenType::LeftBrace, "Expected '{' before function body")?;
while !self.check(&TokenType::RightBrace) && !self.is_at_end() {
statements.push(self.parse_statement()?);
}
self.consume(&TokenType::RightBrace, "Expected '}' after function body")?;
Statement::Block(statements)
} else {
self.consume(
&TokenType::Semicolon,