fix(vm): trivial errors found during initial testing

This commit is contained in:
Alain Zscheile 2022-09-23 21:49:12 +02:00
parent a7c2068b01
commit bc96f9f130

View file

@ -1,6 +1,5 @@
use fogtix_bytecode::{Atom, Parse, Pointer, Value as BcValue}; use fogtix_bytecode::{Atom, Parse, Pointer, Value as BcValue};
use std::marker::PhantomData; use std::marker::PhantomData;
use std::path::PathBuf;
use std::sync::Arc; use std::sync::Arc;
mod noop; mod noop;
@ -65,6 +64,7 @@ impl Process {
use fogtix_bytecode::consts::{AtomOp, MathBinOp}; use fogtix_bytecode::consts::{AtomOp, MathBinOp};
use fogtix_bytecode::Instr; use fogtix_bytecode::Instr;
let previptr = self.instrp.1; let previptr = self.instrp.1;
tracing::trace!("previptr = {}", previptr);
let nxti_arr = match self.instrp.0.h.get(previptr..) { let nxti_arr = match self.instrp.0.h.get(previptr..) {
None => { None => {
tracing::error!( tracing::error!(
@ -86,7 +86,7 @@ impl Process {
} }
Ok(x) => x, Ok(x) => x,
}; };
self.instrp.1 += nxtiptr.len() - nxti_arr.len(); self.instrp.1 += nxti_arr.len() - nxtiptr.len();
match nxti { match nxti {
Instr::Label => {} Instr::Label => {}
Instr::CallRemote(atom, arity) => { Instr::CallRemote(atom, arity) => {
@ -196,7 +196,7 @@ impl Process {
Instr::Return => match self.callstack.pop() { Instr::Return => match self.callstack.pop() {
Some(x) => self.instrp = x, Some(x) => self.instrp = x,
None => { None => {
tracing::error!("return called on empty callstack @ {}", previptr); //tracing::error!("return called on empty callstack @ {}", previptr);
break; break;
} }
}, },
@ -338,13 +338,14 @@ fn main() {
Arg::new("main") Arg::new("main")
.short('m') .short('m')
.help("the module whose entry point should be used") .help("the module whose entry point should be used")
.takes_value(true)
.required(true), .required(true),
) )
.get_matches(); .get_matches();
tracing_subscriber::fmt::init(); tracing_subscriber::fmt::init();
let main_mod_path = matches.get_one::<PathBuf>("main").unwrap(); let main_mod_path = matches.get_one::<String>("main").unwrap();
let main_mod = Arc::new(Module { let main_mod = Arc::new(Module {
h: readfilez::read_from_file(std::fs::File::open(&main_mod_path)) h: readfilez::read_from_file(std::fs::File::open(&main_mod_path))