Signed-off-by: ale <ale@manalejandro.com>
Este commit está contenido en:
ale
2025-08-21 16:59:27 +02:00
padre 771f2d64ae
commit 36718b59bf
Se han modificado 8 ficheros con 280 adiciones y 18 borrados

Ver fichero

@@ -26,7 +26,8 @@ impl CodeGenerator {
// Generate string literals section
if !self.string_literals.is_empty() {
self.emit_line(".section .rodata");
for (content, label) in &self.string_literals {
let string_literals = self.string_literals.clone(); // Clone to avoid borrow issues
for (content, label) in &string_literals {
self.emit_line(&format!("{}:", label));
self.emit_line(&format!(" .string \"{}\"", self.escape_string(content)));
}

Ver fichero

@@ -9,7 +9,7 @@ use crate::error::{AleccError, Result};
use std::path::{Path, PathBuf};
use std::process::Command;
use tokio::fs;
use tracing::{info, debug, warn, error};
use tracing::{info, debug, warn};
pub struct Compiler {
args: Args,
@@ -44,9 +44,10 @@ impl Compiler {
self.target.as_str());
let mut object_files = Vec::new();
let input_files = self.args.input_files.clone(); // Clone to avoid borrow issues
// Process each input file
for input_file in &self.args.input_files {
for input_file in &input_files {
debug!("Processing file: {}", input_file.display());
let extension = input_file.extension()
@@ -95,7 +96,7 @@ impl Compiler {
info!("Compiling source file: {}", input_file.display());
// Read source file
let source = fs::read_to_string(input_file).await.map_err(|e| {
let source = fs::read_to_string(input_file).await.map_err(|_e| {
AleccError::FileNotFound {
path: input_file.to_string_lossy().to_string(),
}
@@ -177,21 +178,36 @@ impl Compiler {
if trimmed.starts_with("#include") {
// Handle #include (simplified)
let include_file = self.extract_include_file(trimmed)?;
let include_path = self.resolve_include_path(&include_file)?;
if include_path.exists() {
let include_content = fs::read_to_string(&include_path).await.map_err(|e| {
AleccError::IoError(e)
})?;
let included = self.preprocess(&include_content, &include_path).await?;
preprocessed.push_str(&included);
preprocessed.push('\n');
match self.extract_include_file(trimmed) {
Ok(include_file) => {
match self.resolve_include_path(&include_file) {
Ok(include_path) => {
if include_path.exists() {
match fs::read_to_string(&include_path).await {
Ok(include_content) => {
// Simple include without recursive preprocessing to avoid recursion issues
preprocessed.push_str(&include_content);
preprocessed.push('\n');
}
Err(_) => {
// Skip file if can't read
}
}
}
}
Err(_) => {
// Skip include if can't resolve path
}
}
}
Err(_) => {
// Skip malformed include
}
}
} else if trimmed.starts_with("#define") {
// Handle #define (simplified)
let parts: Vec<&str> = trimmed[7..].split_whitespace().collect();
if parts.len() >= 1 {
if !parts.is_empty() {
let key = parts[0].to_string();
let value = if parts.len() > 1 {
parts[1..].join(" ")

Ver fichero

@@ -2,7 +2,6 @@ use crate::targets::Target;
use crate::error::{AleccError, Result};
use std::path::{Path, PathBuf};
use std::process::Command;
use tokio::fs;
pub struct Linker {
target: Target,

Ver fichero

@@ -1,4 +1,4 @@
use clap::{Parser, Subcommand};
use clap::Parser;
use anyhow::Result;
use tracing::{info, error};

Ver fichero

@@ -1,5 +1,5 @@
use crate::parser::Program;
use crate::error::{AleccError, Result};
use crate::error::Result;
pub struct Optimizer {
level: OptimizationLevel,