2024-12-06 14:59:59 +01:00
|
|
|
use std::env;
|
|
|
|
use std::fs;
|
2024-12-11 17:52:25 +01:00
|
|
|
use std::time::Instant;
|
2024-12-06 23:43:35 +01:00
|
|
|
|
2024-12-09 13:19:00 +01:00
|
|
|
mod pendragon;
|
|
|
|
use pendragon::*;
|
2024-12-08 15:45:49 +01:00
|
|
|
|
2024-12-11 17:52:25 +01:00
|
|
|
fn main() {
|
2024-12-07 10:43:48 +01:00
|
|
|
let arguments: Vec<String> = env::args().collect();
|
|
|
|
|
|
|
|
if arguments.len() < 2 {
|
2024-12-09 13:19:00 +01:00
|
|
|
eprintln!("Utilisation : pendragon <FILE>");
|
2024-12-07 10:43:48 +01:00
|
|
|
return
|
|
|
|
}
|
2024-12-10 13:24:36 +01:00
|
|
|
|
|
|
|
let debug_mode = arguments.contains(&"--debug".to_string());
|
2024-12-07 10:43:48 +01:00
|
|
|
|
|
|
|
let chemin_de_fichier = &arguments[1];
|
2024-12-10 13:24:36 +01:00
|
|
|
let mut pendragon = Pendragon::nouveau();
|
2024-12-07 10:43:48 +01:00
|
|
|
|
2024-12-11 17:52:25 +01:00
|
|
|
let lecture = fs::read_to_string(chemin_de_fichier);
|
|
|
|
|
|
|
|
if let Err(raison) = lecture {
|
|
|
|
eprintln!("Fichier illisible : {}", raison);
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
println!("# Compilation de '{}'.", chemin_de_fichier);
|
|
|
|
let debut = Instant::now();
|
|
|
|
if let Err(raison) = pendragon.compile(lecture.unwrap()) {
|
|
|
|
eprintln!("\n{}", raison);
|
|
|
|
eprintln!("\n# Échec de la compilation.");
|
|
|
|
return
|
|
|
|
}
|
|
|
|
println!("# Compilation Ok. ({:.2?})\n", debut.elapsed());
|
|
|
|
|
|
|
|
if debug_mode {
|
|
|
|
println!("{}\n", pendragon.programme);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
println!("# Exécution de '{}'.\n", chemin_de_fichier);
|
|
|
|
let debut = Instant::now();
|
|
|
|
if let Err(raison) = pendragon.programme.execute() {
|
|
|
|
eprintln!("\nErreur : {}", raison);
|
|
|
|
eprintln!("\n# Échec de l'exécution.");
|
|
|
|
return
|
2024-12-07 10:43:48 +01:00
|
|
|
}
|
2024-12-11 17:52:25 +01:00
|
|
|
|
|
|
|
println!("\n# Exécution Ok. ({:.2?})", debut.elapsed());
|
2024-12-06 23:43:35 +01:00
|
|
|
}
|