Skip to content

Commit

Permalink
Merge pull request #99 from AluVM/v0.11
Browse files Browse the repository at this point in the history
Release version 0.11 beta
  • Loading branch information
dr-orlovsky authored Dec 25, 2023
2 parents 98f48e9 + 57f36e5 commit a2157ca
Show file tree
Hide file tree
Showing 15 changed files with 2,635 additions and 340 deletions.
111 changes: 56 additions & 55 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "aluvm"
description = "Functional registry-based RISC virtual machine"
version = "0.11.0-beta.1"
version = "0.11.0-beta.2"
authors = ["Dr Maxim Orlovsky <[email protected]>"]
repository = "https://github.com/aluvm/rust-aluvm"
homepage = "https://aluvm.org"
Expand Down
27 changes: 26 additions & 1 deletion src/data/byte_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,32 @@ impl Display for ByteStr {
// 4)..].to_hex())
} else if let Ok(s) = String::from_utf8(vec) {
f.write_str("\"")?;
f.write_str(&s)?;
let mut ctl = false;
for c in s.chars() {
let v = c as u32;
if c.is_control() || v <= 0x21 || v >= 0x7F {
if !ctl {
f.write_str("\x1B[2;3m<\x1B[1m")?;
ctl = true;
}
if v <= 0xFF {
write!(f, "{v:02X}")?;
} else if v <= 0xFFFF {
write!(f, "{v:04X}")?;
} else {
write!(f, "{v:08X}")?;
}
} else {
if ctl {
f.write_str("\x1B[2m>\x1B[1;23m")?;
ctl = false;
}
f.write_char(c)?;
}
}
if ctl {
f.write_str("\x1B[2m>\x1B[1;23m")?;
}
f.write_str("\"")
} else {
f.write_str(&self.as_ref().to_hex())
Expand Down
31 changes: 31 additions & 0 deletions src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,34 @@ pub use byte_str::ByteStr;
pub use number::{
FloatLayout, IntLayout, Layout, LiteralParseError, MaybeNumber, Number, NumberLayout, Step,
};

/// Value which can be extracted from any register.
#[allow(clippy::large_enum_variant)]
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, From)]
pub enum RegValue {
/// Value extracted from numerical registers
#[from]
#[from(Number)]
Number(MaybeNumber),

/// Value extracted from string register
#[from]
#[from(ByteStr)]
String(Option<ByteStr>),
}

mod display {
use core::fmt::{self, Display, Formatter};

use super::*;

impl Display for RegValue {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
RegValue::Number(n) => Display::fmt(n, f),
RegValue::String(Some(s)) => Display::fmt(s, f),
RegValue::String(None) => f.write_str("~"),
}
}
}
}
Loading

0 comments on commit a2157ca

Please sign in to comment.