refactor(vm): use crate tracing

This commit is contained in:
Alain Zscheile 2022-09-23 21:03:41 +02:00
parent 51438c5568
commit a7c2068b01
4 changed files with 175 additions and 38 deletions

130
Cargo.lock generated
View file

@ -2,6 +2,15 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "ansi_term"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
dependencies = [
"winapi",
]
[[package]]
name = "atty"
version = "0.2.14"
@ -37,6 +46,12 @@ version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "3.2.22"
@ -89,6 +104,8 @@ dependencies = [
"fogtix-bytecode",
"once_cell",
"readfilez",
"tracing",
"tracing-subscriber",
]
[[package]]
@ -122,7 +139,7 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b1428b2b1abe959e6eedb0a17d0ab12f6ba20e1106cc29fc4874e3ba393c177"
dependencies = [
"cfg-if",
"cfg-if 0.1.10",
"int-enum-impl",
]
@ -132,19 +149,34 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2c3cecaad8ca1a5020843500c696de2b9a07b63b624ddeef91f85f9bafb3671"
dependencies = [
"cfg-if",
"cfg-if 0.1.10",
"proc-macro-crate",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.133"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0f80d65747a3e43d1596c7c5492d95d5edddaabd45a7fcdb02b95f644164966"
[[package]]
name = "log"
version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
dependencies = [
"cfg-if 1.0.0",
]
[[package]]
name = "memmap2"
version = "0.2.3"
@ -175,6 +207,12 @@ version = "6.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff"
[[package]]
name = "pin-project-lite"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
[[package]]
name = "ppv-lite86"
version = "0.2.16"
@ -272,12 +310,27 @@ version = "1.0.145"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b"
[[package]]
name = "sharded-slab"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31"
dependencies = [
"lazy_static",
]
[[package]]
name = "siphasher"
version = "0.3.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de"
[[package]]
name = "smallvec"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1"
[[package]]
name = "strsim"
version = "0.10.0"
@ -310,6 +363,15 @@ version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16"
[[package]]
name = "thread_local"
version = "1.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180"
dependencies = [
"once_cell",
]
[[package]]
name = "toml"
version = "0.5.9"
@ -319,12 +381,76 @@ dependencies = [
"serde",
]
[[package]]
name = "tracing"
version = "0.1.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307"
dependencies = [
"cfg-if 1.0.0",
"pin-project-lite",
"tracing-attributes",
"tracing-core",
]
[[package]]
name = "tracing-attributes"
version = "0.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11c75893af559bc8e10716548bdef5cb2b983f8e637db9d0e15126b61b484ee2"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tracing-core"
version = "0.1.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7"
dependencies = [
"once_cell",
"valuable",
]
[[package]]
name = "tracing-log"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922"
dependencies = [
"lazy_static",
"log",
"tracing-core",
]
[[package]]
name = "tracing-subscriber"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60db860322da191b40952ad9affe65ea23e7dd6a5c442c2c42865810c6ab8e6b"
dependencies = [
"ansi_term",
"sharded-slab",
"smallvec",
"thread_local",
"tracing-core",
"tracing-log",
]
[[package]]
name = "unicode-ident"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd"
[[package]]
name = "valuable"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "winapi"
version = "0.3.9"

View file

@ -8,6 +8,8 @@ publish = false
[dependencies]
clap = "3.2"
readfilez = "0.2"
tracing = "0.1"
tracing-subscriber = "0.3"
[dependencies.fogtix-bytecode]
path = "../fogtix-bytecode"

View file

@ -67,8 +67,8 @@ impl Process {
let previptr = self.instrp.1;
let nxti_arr = match self.instrp.0.h.get(previptr..) {
None => {
eprintln!(
"ERROR: reached EOF of module or jumped out of bounds -> {}",
tracing::error!(
"reached EOF of module or jumped out of bounds -> {}",
previptr
);
break;
@ -77,8 +77,8 @@ impl Process {
};
let (nxtiptr, nxti) = match Instr::parse(nxti_arr) {
Err(_) => {
eprintln!(
"ERROR: reached unparsable instruction {:?} @ {}",
tracing::error!(
"reached unparsable instruction {:?} @ {}",
&nxti_arr[..core::cmp::min(nxti_arr.len(), 20)],
self.instrp.1
);
@ -102,7 +102,7 @@ impl Process {
}
match self.stack.pop() {
None => {
eprintln!("ERROR: `call-r` invoked on empty stack @ {}", previptr);
tracing::error!("`call-r` invoked on empty stack @ {}", previptr);
break;
}
Some(StackEntValue::Pointer(wp)) => {
@ -112,9 +112,10 @@ impl Process {
self.stack.extend(args);
}
Some(x) => {
eprintln!(
"ERROR: `call-r` invoked on non-pointer {:?} @ {}",
x, previptr
tracing::error!(
"`call-r` invoked on non-pointer {:?} @ {}",
x,
previptr
);
break;
}
@ -122,9 +123,10 @@ impl Process {
if let Some(n2xti_arr) = self.instrp.0.h.get(self.instrp.1..) {
if let Ok((_, trgi)) = Instr::parse(n2xti_arr) {
if trgi != Instr::Label {
eprintln!(
"ERROR: `call-r` arrived at non-jump target {:?} @ {}",
trgi, previptr
tracing::error!(
"`call-r` arrived at non-jump target {:?} @ {}",
trgi,
previptr
);
break;
}
@ -145,9 +147,10 @@ impl Process {
self.instrp.1 = match x.try_into() {
Ok(y) => y,
Err(_) => {
eprintln!(
"ERROR: jump to out-of-bounds address @ {} -> {}",
previptr, x
tracing::error!(
"jump to out-of-bounds address @ {} -> {}",
previptr,
x
);
break;
}
@ -155,9 +158,10 @@ impl Process {
if let Some(n2xti_arr) = self.instrp.0.h.get(self.instrp.1..) {
if let Ok((_, trgi)) = Instr::parse(n2xti_arr) {
if trgi != Instr::Label {
eprintln!(
"ERROR: `call-l` arrived at non-jump target {:?} @ {}",
trgi, previptr
tracing::error!(
"`call-l` arrived at non-jump target {:?} @ {}",
trgi,
previptr
);
break;
}
@ -168,9 +172,10 @@ impl Process {
self.instrp.1 = match x.try_into() {
Ok(y) => y,
Err(_) => {
eprintln!(
"ERROR: jump to out-of-bounds address @ {} -> {}",
previptr, x
tracing::error!(
"jump to out-of-bounds address @ {} -> {}",
previptr,
x
);
break;
}
@ -178,9 +183,10 @@ impl Process {
if let Some(n2xti_arr) = self.instrp.0.h.get(self.instrp.1..) {
if let Ok((_, trgi)) = Instr::parse(n2xti_arr) {
if trgi != Instr::Label {
eprintln!(
"ERROR: jump arrived at non-jump target {:?} @ {}",
trgi, previptr
tracing::error!(
"jump arrived at non-jump target {:?} @ {}",
trgi,
previptr
);
break;
}
@ -190,7 +196,7 @@ impl Process {
Instr::Return => match self.callstack.pop() {
Some(x) => self.instrp = x,
None => {
eprintln!("ERROR: return called on empty callstack @ {}", previptr);
tracing::error!("return called on empty callstack @ {}", previptr);
break;
}
},
@ -207,7 +213,7 @@ impl Process {
});
}
Instr::Pop(_) if self.stack.is_empty() => {
eprintln!("ERROR: popped empty stack @ {}", previptr);
tracing::error!("popped empty stack @ {}", previptr);
break;
}
Instr::Pop(cnt) => {
@ -226,7 +232,7 @@ impl Process {
Instr::Dup => {
let x = match self.stack.last() {
None => {
eprintln!("ERROR: dup on empty stack @ {}", previptr);
tracing::error!("dup on empty stack @ {}", previptr);
break;
}
Some(x) => x.clone(),
@ -236,7 +242,7 @@ impl Process {
Instr::Swap => {
let ssl = self.stack.len();
if ssl < 2 {
eprintln!("ERROR: swap on empty stack @ {}", previptr);
tracing::error!("swap on empty stack @ {}", previptr);
break;
}
let x = &mut self.stack[ssl - 2..ssl];
@ -251,7 +257,7 @@ impl Process {
self.stack.push(StackEntValue::Atom(Atom(b, a)));
}
x => {
eprintln!("ERROR: BIF atom:build @ {} called with {:?}", previptr, x);
tracing::error!("BIF atom:build @ {} called with {:?}", previptr, x);
break;
}
}
@ -261,7 +267,7 @@ impl Process {
self.stack.push(StackEntValue::Int(b));
}
x => {
eprintln!("ERROR: BIF :atom:upper @ {} called with {:?}", previptr, x);
tracing::error!("BIF :atom:upper @ {} called with {:?}", previptr, x);
break;
}
},
@ -270,7 +276,7 @@ impl Process {
self.stack.push(StackEntValue::Int(a));
}
x => {
eprintln!("ERROR: BIF :atom:lower @ {} called with {:?}", previptr, x);
tracing::error!("BIF :atom:lower @ {} called with {:?}", previptr, x);
break;
}
},
@ -300,8 +306,8 @@ impl Process {
a
}
y => {
eprintln!(
"ERROR: BIF :math2:*({:?}) @ {} called with {:?}",
tracing::error!(
"BIF :math2:*({:?}) @ {} called with {:?}",
y,
previptr,
(
@ -314,7 +320,7 @@ impl Process {
})
}
x => {
eprintln!("ERROR: BIF :math2:* @ {} called with {:?}", previptr, x);
tracing::error!("BIF :math2:* @ {} called with {:?}", previptr, x);
break;
}
});
@ -336,6 +342,8 @@ fn main() {
)
.get_matches();
tracing_subscriber::fmt::init();
let main_mod_path = matches.get_one::<PathBuf>("main").unwrap();
let main_mod = Arc::new(Module {

View file

@ -18,9 +18,10 @@ pub static NOOP_MODULE: Lazy<Arc<Module>> = Lazy::new(|| {
struct NoopOrigin;
impl Origin for NoopOrigin {
fn call(&self, p: &Pointer, a: &Atom, _stack: &mut Vec<StackEntValue>) -> InstrPtr {
eprintln!(
"WARN: tried to invoke pointer {:?}({:?}) without valid context",
p, a
tracing::error!(
"tried to invoke pointer {:?}({:?}) without valid context",
p,
a
);
(Arc::clone(&NOOP_MODULE), 0)
}