Skip to content

Commit

Permalink
chore: introduce log feature
Browse files Browse the repository at this point in the history
Closes #101
  • Loading branch information
dr-orlovsky committed Feb 26, 2024
1 parent 1d24b92 commit 09d5507
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")]

Check warning on line 307 in src/library/lib.rs

View check run for this annotation

Codecov / codecov/patch

src/library/lib.rs#L307

Added line #L307 was not covered by tests
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")]

Check warning on line 339 in src/library/lib.rs

View check run for this annotation

Codecov / codecov/patch

src/library/lib.rs#L339

Added line #L339 was not covered by tests
{
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")]

Check warning on line 373 in src/library/lib.rs

View check run for this annotation

Codecov / codecov/patch

src/library/lib.rs#L373

Added line #L373 was not covered by tests
eprintln!("{}", pos);
cursor.seek(pos).ok()?;
}
ExecStep::Call(site) => {
#[cfg(all(debug_assertions, feature = "std"))]
#[cfg(feature = "log")]

Check warning on line 378 in src/library/lib.rs

View check run for this annotation

Codecov / codecov/patch

src/library/lib.rs#L378

Added line #L378 was not covered by tests
eprintln!("{}", site);
return Some(site);
}
Expand Down

0 comments on commit 09d5507

Please sign in to comment.