Skip to content

Commit

Permalink
Merge #226
Browse files Browse the repository at this point in the history
226: More standard command line r=jacob-hughes a=ltratt



Co-authored-by: Laurence Tratt <[email protected]>
  • Loading branch information
bors[bot] and ltratt authored Jan 31, 2023
2 parents d262fb5 + 06198c2 commit 7055b7c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .buildbot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ cargo +alloy test --release
cargo +alloy run -- --cp SOM/Smalltalk SOM/TestSuite/TestHarness.som
cargo +alloy run --release -- --cp SOM/Smalltalk SOM/TestSuite/TestHarness.som

cargo +alloy run --release -- --cp SOM/Smalltalk:lang_tests hello_world1

cd SOM
cargo +alloy run --release -- \
--cp Smalltalk:TestSuite:SomSom/src/compiler:SomSom/src/vm:SomSom/src/vmobjects:SomSom/src/interpreter:SomSom/src/primitives \
Expand Down
56 changes: 39 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ fn usage(prog: &str) -> ! {
.file_name()
.map(|x| x.to_str().unwrap_or("yksom"))
.unwrap_or("yksom");
writeln!(
&mut stderr(),
"Usage: {} [-h] --cp <path> <file.som> [-- <arg_1> [... <arg_n>]]",
leaf
)
.ok();
error(&format!(
"Usage: {leaf} [-h] --cp <path> <file.som> [-- <arg_1> [... <arg_n>]]"
));
}

fn error(msg: &str) -> ! {
stderr().write_all(msg.as_bytes()).ok();
process::exit(1)
}

Expand All @@ -56,18 +57,39 @@ fn main() {
usage(prog);
}

let src_path = &Path::new(&matches.free[0]).canonicalize().unwrap();
let mut cp = match src_path.parent() {
Some(p) => vec![p.to_owned()],
None => vec![],
let mut cp: Vec<_> = matches
.opt_str("cp")
.unwrap()
.split(":")
.map(|x| PathBuf::from_str(x).unwrap())
.collect();

let mut src_path = Path::new(&matches.free[0]).to_owned();
if !src_path.is_file() && src_path.extension().is_none() {
for d in &cp {
let mut p = PathBuf::new();
p.push(d);
p.push(&matches.free[0]);
p.set_extension("som");
if p.is_file() {
src_path = p;
}
}
if !src_path.is_file() {
error(&format!(
"{} does not exist or is not a file",
&matches.free[0]
));
}
}
let src_path = match src_path.canonicalize() {
Ok(s) => s,
Err(e) => error(&format!("Can't canonicalise {}: {}", &matches.free[0], e)),
};
cp.extend(
matches
.opt_str("cp")
.unwrap()
.split(":")
.map(|x| PathBuf::from_str(x).unwrap()),
);

if let Some(p) = src_path.parent() {
cp.insert(0, p.to_owned());
}

let mut vm = VM::new(cp);
let system = vm.get_global_or_nil("system");
Expand Down

0 comments on commit 7055b7c

Please sign in to comment.