Skip to content

Commit

Permalink
Merge pull request #106 from AluVM/log
Browse files Browse the repository at this point in the history
Introduce log feature
  • Loading branch information
dr-orlovsky authored Feb 26, 2024
2 parents 1d24b92 + 09d5507 commit 61e8723
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ serde_crate = { package = "serde", version = "1", optional = true }

[features]
default = ["std"]
all = ["stl", "std", "secp256k1", "curve25519", "serde"]
all = ["stl", "std", "log", "secp256k1", "curve25519", "serde"]
stl = ["strict_types/base85", "std"]
std = ["amplify/std"]
log = ["std"]
alloc = ["amplify/alloc"]
curve25519 = ["curve25519-dalek"]
serde = ["serde_crate", "amplify/serde", "std"]
Expand Down
16 changes: 8 additions & 8 deletions src/library/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ impl Lib {
where
Isa: InstructionSet,
{
#[cfg(all(debug_assertions, feature = "std"))]
#[cfg(feature = "log")]
let (m, w, d, g, r, y, z) = (
"\x1B[0;35m",
"\x1B[1;1m",
Expand All @@ -325,7 +325,7 @@ impl Lib {

let instr = Isa::decode(&mut cursor).ok()?;

#[cfg(all(debug_assertions, feature = "std"))]
#[cfg(feature = "log")]
{
eprint!("{m}@{pos:06}:{z} {: <32}; ", instr.to_string());
for reg in instr.src_regs() {
Expand All @@ -336,7 +336,7 @@ impl Lib {

let next = instr.exec(registers, LibSite::with(pos, lib_hash), context);

#[cfg(all(debug_assertions, feature = "std"))]
#[cfg(feature = "log")]
{
eprint!("-> ");
for reg in instr.dst_regs() {
Expand All @@ -351,31 +351,31 @@ impl Lib {
st0 = registers.st0;

if !registers.acc_complexity(instr) {
#[cfg(all(debug_assertions, feature = "std"))]
#[cfg(feature = "log")]
eprintln!("complexity overflow");
return None;
}
match next {
ExecStep::Stop => {
#[cfg(all(debug_assertions, feature = "std"))]
#[cfg(feature = "log")]
{
let c = if registers.st0 { g } else { r };
eprintln!("execution stopped; {d}st0={z}{c}{}{z}", registers.st0);
}
return None;
}
ExecStep::Next => {
#[cfg(all(debug_assertions, feature = "std"))]
#[cfg(feature = "log")]
eprintln!();
continue;
}
ExecStep::Jump(pos) => {
#[cfg(all(debug_assertions, feature = "std"))]
#[cfg(feature = "log")]
eprintln!("{}", pos);
cursor.seek(pos).ok()?;
}
ExecStep::Call(site) => {
#[cfg(all(debug_assertions, feature = "std"))]
#[cfg(feature = "log")]
eprintln!("{}", site);
return Some(site);
}
Expand Down

0 comments on commit 61e8723

Please sign in to comment.