emulator: imports work relatively to file being assembled (set cwd)

This commit is contained in:
2025-06-19 16:35:00 +01:00
parent b5ce5e0011
commit 6f834025ed
3 changed files with 16 additions and 7 deletions
+6 -2
View File
@@ -66,7 +66,7 @@ fn generate_symbol_table(nodes: &[Node]) -> Result<HashMap<Symbol, u32>, Assembl
}
pub fn resolve_dependencies(mut nodes: Vec<Node>) -> Result<Vec<Node>, AssembleError> {
// first we get a list of imports
// First we get a list of imports.
let mut dependencies = Vec::new();
for node in &nodes {
if let Opcode::Include = node.opcode() {
@@ -81,7 +81,11 @@ pub fn resolve_dependencies(mut nodes: Vec<Node>) -> Result<Vec<Node>, AssembleE
} else {
unreachable!()
};
let hash = quick_hash(&PathBuf::from(path).canonicalize().unwrap());
let hash = quick_hash(
&PathBuf::from(path)
.canonicalize()
.expect("ERROR: Invalid import path."),
);
dependencies.push((name, hash));
}
+8 -3
View File
@@ -146,7 +146,7 @@ impl Editor {
}
if let Some(path) = FileDialog::new()
.add_filter("damn simple files", &["dsa", "dsb", "dsc", "dsd"])
.add_filter("Assembly Files or Binaries", &["dsa", "dsb"])
.add_filter("all", &["*"])
.set_directory(&work_dir)
.save_file()
@@ -169,17 +169,22 @@ impl Editor {
});
if let Some(path) = FileDialog::new()
.add_filter("damn simple files", &["dsa", "dsb", "dsc", "dsd"])
.add_filter("Assembly Files or Binaries", &["dsa", "dsb"])
.add_filter("all", &["*"])
.set_directory(&work_dir)
.pick_file()
{
if let Ok(contents) = std::fs::read_to_string(&path) {
self.path = Some(path);
self.path = Some(path.clone());
self.text.clone_from(&contents);
self.buffer = contents;
self.unsaved = false;
}
std::env::set_current_dir(
path.parent().expect("A file should be in a directory!"),
)
.expect("ERROR: Failed to set current working directory.");
}
}
+2 -2
View File
@@ -1,5 +1,5 @@
include print "../resources/dsa/print.dsa"
include fib "../resources/dsa/fib.dsa"
include print "print.dsa"
include fib "fib.dsa"
dw stack: 0x10000
db string: "An idiot admires complexity, a genius admires simplicity,