emulator: imports work relatively to file being assembled (set cwd)
This commit is contained in:
@@ -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> {
|
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();
|
let mut dependencies = Vec::new();
|
||||||
for node in &nodes {
|
for node in &nodes {
|
||||||
if let Opcode::Include = node.opcode() {
|
if let Opcode::Include = node.opcode() {
|
||||||
@@ -81,7 +81,11 @@ pub fn resolve_dependencies(mut nodes: Vec<Node>) -> Result<Vec<Node>, AssembleE
|
|||||||
} else {
|
} else {
|
||||||
unreachable!()
|
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));
|
dependencies.push((name, hash));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ impl Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some(path) = FileDialog::new()
|
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", &["*"])
|
.add_filter("all", &["*"])
|
||||||
.set_directory(&work_dir)
|
.set_directory(&work_dir)
|
||||||
.save_file()
|
.save_file()
|
||||||
@@ -169,17 +169,22 @@ impl Editor {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if let Some(path) = FileDialog::new()
|
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", &["*"])
|
.add_filter("all", &["*"])
|
||||||
.set_directory(&work_dir)
|
.set_directory(&work_dir)
|
||||||
.pick_file()
|
.pick_file()
|
||||||
{
|
{
|
||||||
if let Ok(contents) = std::fs::read_to_string(&path) {
|
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.text.clone_from(&contents);
|
||||||
self.buffer = contents;
|
self.buffer = contents;
|
||||||
self.unsaved = false;
|
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.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
include print "../resources/dsa/print.dsa"
|
include print "print.dsa"
|
||||||
include fib "../resources/dsa/fib.dsa"
|
include fib "fib.dsa"
|
||||||
|
|
||||||
dw stack: 0x10000
|
dw stack: 0x10000
|
||||||
db string: "An idiot admires complexity, a genius admires simplicity,
|
db string: "An idiot admires complexity, a genius admires simplicity,
|
||||||
|
|||||||
Reference in New Issue
Block a user