merge commit
This commit is contained in:
+14
-13
@@ -3,7 +3,7 @@ use std::{
|
||||
collections::HashSet,
|
||||
fs,
|
||||
hash::{DefaultHasher, Hash, Hasher},
|
||||
path::PathBuf,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use common::prelude::Instruction;
|
||||
@@ -19,27 +19,27 @@ pub mod model;
|
||||
pub mod parser;
|
||||
pub mod resolver;
|
||||
|
||||
pub fn assemble(src: &PathBuf) -> Vec<Instruction> {
|
||||
pub fn assemble(src: &Path) -> Vec<Instruction> {
|
||||
let mut modules = HashSet::<u64>::new();
|
||||
let mut program = Program::new();
|
||||
|
||||
let hash = quick_hash(src);
|
||||
modules.insert(hash);
|
||||
|
||||
match prepare_dependency(src.clone(), &mut modules, &mut program) {
|
||||
match prepare_dependency(src, &mut modules, &mut program) {
|
||||
Ok(_) => {}
|
||||
Err(err) => println!("BIG ERROR {:?}", err),
|
||||
Err(err) => println!("BIG ERROR {err:?}"),
|
||||
}
|
||||
|
||||
for node in program.nodes {
|
||||
println!("{:?}", node);
|
||||
println!("{node:?}");
|
||||
}
|
||||
|
||||
vec![]
|
||||
}
|
||||
|
||||
fn prepare_dependency(
|
||||
path: PathBuf,
|
||||
path: &Path,
|
||||
modules: &mut HashSet<u64>,
|
||||
program: &mut Program,
|
||||
) -> Result<(), AssembleError> {
|
||||
@@ -53,9 +53,9 @@ fn prepare_dependency(
|
||||
));
|
||||
}
|
||||
|
||||
let src = fs::read_to_string(&path)
|
||||
.map_err(|_| AssembleError::InvalidFile(path.clone()))?;
|
||||
let file_hash = quick_hash(&path);
|
||||
let src = fs::read_to_string(path)
|
||||
.map_err(|_| AssembleError::InvalidFile(path.to_path_buf()))?;
|
||||
let file_hash = quick_hash(path);
|
||||
|
||||
log(&format!("{:20} {:20}", "Tokenising", filename));
|
||||
let tokens = lexer::lexer(src, file_hash)?;
|
||||
@@ -84,14 +84,14 @@ fn prepare_dependency(
|
||||
|
||||
if !modules.contains(&quick_hash(&dep)) {
|
||||
modules.insert(quick_hash(&dep));
|
||||
prepare_dependency(dep, modules, program)?
|
||||
prepare_dependency(dep.as_path(), modules, program)?
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn build(src: Vec<Node>) -> Result<Vec<Instruction>, AssembleError> {
|
||||
fn _build(_src: Vec<Node>) -> Result<Vec<Instruction>, AssembleError> {
|
||||
Ok(vec![])
|
||||
}
|
||||
|
||||
@@ -125,14 +125,15 @@ impl fmt::Display for AssembleError {
|
||||
}
|
||||
}
|
||||
|
||||
fn quick_hash(value: &PathBuf) -> u64 {
|
||||
fn quick_hash(value: &Path) -> u64 {
|
||||
let mut hasher = DefaultHasher::new();
|
||||
value.canonicalize().unwrap().to_str().hash(&mut hasher);
|
||||
hasher.finish()
|
||||
}
|
||||
|
||||
// TODO: Use an actual logging or tracing library for pretty (scoped) output.
|
||||
fn log(message: &str) {
|
||||
println!("\x1b[32mINFO:\x1b[0m {}", message);
|
||||
println!("\x1b[32mINFO:\x1b[0m {message}");
|
||||
}
|
||||
|
||||
// create a macro that lexes and parses the input string into Nodes
|
||||
|
||||
Reference in New Issue
Block a user