Add --disassemble flag

Dumps disassembly of the given script to STDOUT and exits immediately.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2023-05-03 20:21:13 -07:00
parent 6c55eb2477
commit 2ebfb23b88

View File

@@ -16,6 +16,9 @@ use crate::vm::frame::{Frame, UserFrame};
struct Opt {
#[structopt(name = "PATH", parse(from_os_str))]
path: Option<PathBuf>,
#[structopt(long)]
disassemble: bool,
}
type Result<T = (), E = Box<dyn std::error::Error>> = std::result::Result<T, E>;
@@ -72,8 +75,11 @@ fn main() -> Result {
exec_body.push(Inst::Push(ObjPtr::new(Int::new(0))));
exec_body.push(Inst::Return);
//disassemble(&exec_body);
//return Ok(());
// Disassemble
if opt.disassemble {
disassemble(&exec_body);
return Ok(());
}
let locals: Vec<_> = scope.keys().copied().collect();
let main_fun: ObjPtr<_> = UserFun::new(None, vec![], locals, exec_body).into();