Skip to content

Commit

Permalink
Merge pull request #118 from AluVM/develop
Browse files Browse the repository at this point in the history
Switch to Baid64 identifiers. Improvements to text armoring
  • Loading branch information
dr-orlovsky authored May 6, 2024
2 parents e654e88 + 25be42a commit 6b7b257
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 159 deletions.
162 changes: 73 additions & 89 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ required-features = ["stl"]

[dependencies]
amplify = { version = "4.6.0", default-features = false, features = ["apfloat", "derive", "hex"] }
ascii-armor = { version = "0.2.0", optional = true }
ascii-armor = { version = "0.6.0", optional = true }
baid64 = "0.1.0"
paste = "1"
strict_encoding = { version = "2.7.0-beta.3", default-features = false, features = ["float", "derive"] }
strict_types = { version = "2.7.0-beta.3", optional = true }
sha2 = "0.10.8"
blake3 = "1.5.1"
ripemd = "0.1.3"
baid58 = "0.4.4"
secp256k1 = { version = "0.28.2", optional = true, features = ["global-context"] }
curve25519-dalek = { version = "3.2", optional = true }
half = "~2.2.0" # Required to maintain MSRV
Expand All @@ -55,3 +55,7 @@ wasm-bindgen-test = "0.3"

[package.metadata.docs.rs]
features = ["all"]

[patch.crates-io]
strict_encoding = { git = "https://github.com/strict-types/strict-encoding", branch = "develop" }
strict_types = { git = "https://github.com/strict-types/strict-types", branch = "develop" }
10 changes: 5 additions & 5 deletions src/isa/instr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,12 +429,12 @@ pub enum ArithmeticOp {
#[display("add.{0} {1}{2},{1}{3}")]
AddF(RoundingFlag, RegF, Reg32, Reg32),

/// Subtracts values from two integer arithmetic registers and puts result into the second
/// Subtracts the second register value from the first one and puts result into the second
/// register.
#[display("sub.{0} {1}{2},{1}{3}")]
SubA(IntFlags, RegA, Reg32, Reg32),

/// Subtracts values from two float arithmetic registers and puts result into the second
/// Subtracts the second register value from the first one and puts result into the second
/// register.
#[display("sub.{0} {1}{2},{1}{3}")]
SubF(RoundingFlag, RegF, Reg32, Reg32),
Expand All @@ -449,7 +449,7 @@ pub enum ArithmeticOp {
#[display("mul.{0} {1}{2},{1}{3}")]
MulF(RoundingFlag, RegF, Reg32, Reg32),

/// Divides values from two integer arithmetic registers and puts result into the second
/// Divides the first register value by the second one and puts result into the second
/// register.
///
/// Since the division operation may not result in overflow, the overflow flag is used to
Expand All @@ -462,14 +462,14 @@ pub enum ArithmeticOp {
#[display("div.{0} {1}{2},{1}{3}")]
DivA(IntFlags, RegA, Reg32, Reg32),

/// Divides values from two float arithmetic registers and puts result into the second
/// Divides the first register value by the second one and puts result into the second
/// register.
#[display("div.{0} {1}{2},{1}{3}")]
DivF(RoundingFlag, RegF, Reg32, Reg32),

/// Modulo division.
///
/// Puts a reminder of the division of source register on destination register into the
/// Puts a reminder of the division of the first register on the second register into the
/// second register.
#[display("rem {0}{1},{2}{3}")]
Rem(RegA, Reg32, RegA, Reg32),
Expand Down
63 changes: 24 additions & 39 deletions src/library/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use core::str::FromStr;

use amplify::confinement::SmallBlob;
use amplify::{confinement, ByteArray, Bytes32};
use baid58::{Baid58ParseError, Chunking, FromBaid58, ToBaid58, CHUNKING_32};
use baid64::{Baid64ParseError, DisplayBaid64, FromBaid64Str};
use sha2::{Digest, Sha256};
use strict_encoding::{StrictDeserialize, StrictSerialize};

Expand Down Expand Up @@ -65,31 +65,21 @@ pub struct LibId(
Bytes32,
);

impl ToBaid58<32> for LibId {
impl DisplayBaid64 for LibId {
const HRI: &'static str = "alu";
const CHUNKING: Option<Chunking> = CHUNKING_32;
fn to_baid58_payload(&self) -> [u8; 32] { self.to_byte_array() }
fn to_baid58_string(&self) -> String { self.to_string() }
const CHUNKING: bool = true;
const PREFIX: bool = true;
const EMBED_CHECKSUM: bool = false;
const MNEMONIC: bool = true;
fn to_baid64_payload(&self) -> [u8; 32] { self.to_byte_array() }
}
impl FromBaid58<32> for LibId {}

impl FromBaid64Str for LibId {}
impl FromStr for LibId {
type Err = Baid58ParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Self::from_baid58_str(s.trim_start_matches("urn:ubideco:"))
}
type Err = Baid64ParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> { Self::from_baid64_str(s) }
}
impl Display for LibId {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
if f.alternate() {
f.write_str("urn:ubideco:alu:")?;
}
if f.sign_minus() {
write!(f, "{:.2}", self.to_baid58())
} else {
write!(f, "{:#.2}", self.to_baid58())
}
}
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { self.fmt_baid64(f) }
}

impl LibId {
Expand Down Expand Up @@ -489,38 +479,33 @@ mod test {
let id = LibId::with("FLOAT", b"", b"", &none!());
assert_eq!(
format!("{id}"),
"Grjjwm-eTsibiEe-YYtjokmc-8j4Jn1KW-L2SX8Nug-G6T5kZ#pinball-eternal-colombo"
"alu:650XHPmh-WpXWR5R-Uz4B5jX-jeDqcyr-HXpdZxY-aX9gfO4#plasma-tunnel-mama"
);
assert_eq!(format!("{id:-}"), "Grjjwm-eTsibiEe-YYtjokmc-8j4Jn1KW-L2SX8Nug-G6T5kZ");
assert_eq!(
format!("{id:#}"),
"urn:ubideco:alu:Grjjwm-eTsibiEe-YYtjokmc-8j4Jn1KW-L2SX8Nug-G6T5kZ#\
pinball-eternal-colombo"
format!("{id:-}"),
"650XHPmh-WpXWR5R-Uz4B5jX-jeDqcyr-HXpdZxY-aX9gfO4#plasma-tunnel-mama"
);
assert_eq!(format!("{id:#}"), "alu:650XHPmh-WpXWR5R-Uz4B5jX-jeDqcyr-HXpdZxY-aX9gfO4");
assert_eq!(format!("{id:-#}"), "650XHPmh-WpXWR5R-Uz4B5jX-jeDqcyr-HXpdZxY-aX9gfO4");
}

#[test]
fn lib_id_from_str() {
let id = LibId::with("FLOAT", b"", b"", &none!());
assert_eq!(
Ok(id),
id,
LibId::from_str(
"urn:ubideco:alu:GrjjwmeTsibiEeYYtjokmc8j4Jn1KWL2SX8NugG6T5kZ#\
pinball-eternal-colombo"
"alu:650XHPmh-WpXWR5R-Uz4B5jX-jeDqcyr-HXpdZxY-aX9gfO4#plasma-tunnel-mama"
)
.unwrap()
);
assert_eq!(id, LibId::from_str("alu:650XHPmhWpXWR5RUz4B5jXjeDqcyrHXpdZxYaX9gfO4").unwrap());
assert_eq!(
Ok(id),
LibId::from_str("urn:ubideco:alu:GrjjwmeTsibiEeYYtjokmc8j4Jn1KWL2SX8NugG6T5kZ")
);
assert_eq!(
Ok(id),
LibId::from_str(
"alu:GrjjwmeTsibiEeYYtjokmc8j4Jn1KWL2SX8NugG6T5kZ#pinball-eternal-colombo"
)
id,
LibId::from_str("alu:650XHPmhWpXWR5RUz4B5jXjeDqcyrHXpdZxYaX9gfO4#plasma-tunnel-mama")
.unwrap()
);
assert_eq!(Ok(id), LibId::from_str("alu:GrjjwmeTsibiEeYYtjokmc8j4Jn1KWL2SX8NugG6T5kZ"));

assert_eq!(Ok(id), LibId::from_str("GrjjwmeTsibiEeYYtjokmc8j4Jn1KWL2SX8NugG6T5kZ"));
assert_eq!(id, LibId::from_str("650XHPmhWpXWR5RUz4B5jXjeDqcyrHXpdZxYaX9gfO4").unwrap());
}
}
2 changes: 1 addition & 1 deletion src/stl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use crate::LIB_NAME_ALUVM;

/// Strict type id for the library providing data types from this crate.
pub const LIB_ID_ALUVM: &str =
"urn:ubideco:stl:APYERRUMyWqLadwTv8tEFifHMPGpL3xGFSBxwaKYpmcV#square-mammal-uncle";
"stl:YnA1fyHl-46C2hsC-tZPxn60-w1jLk5Y-rDTjRmy-xo@5xjY#congo-archive-folio";

fn _aluvm_stl() -> Result<TypeLib, CompileError> {
LibBuilder::new(libname!(LIB_NAME_ALUVM), tiny_bset! {
Expand Down
26 changes: 13 additions & 13 deletions stl/[email protected]
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
-----BEGIN STRICT TYPE LIB-----
Id: urn:ubideco:stl:APYERRUMyWqLadwTv8tEFifHMPGpL3xGFSBxwaKYpmcV#square-mammal-uncle
Id: stl:YnA1fyHl-46C2hsC-tZPxn60-w1jLk5Y-rDTjRmy-xo@5xjY#congo-archive-folio
Name: AluVM
Dependency: EcCNgrgLaygt3tCZNu2ZVEzMzSAZYEUeTNAVi5E81YWi#aspirin-mango-average
Checksum-SHA256: d0b37000d730beef023af7883b4664c10ecce81ab144c4ac0cc4a85687b96fac
Dependencies: Std#ralph-blue-lucky
Check-SHA256: 33bd3f759d49fd0e46f3179acda055dcc81082b29db36d949482f9e168b6781c

1wm|eR!srQEFN!zncXl9K5w2;FV{y1jDTJCC^p$-mHEbO0#qjhQ*>kj15<Ql0RSh
2(Tr;j#yqcI82>cBr>9x-Cs#sheE97?nsOaXHkb)PY;b5{Lt$`p1^@?1b74+lZDj
=k00;ugEFN!zncXl9K5w2;FV{y1jDTJCC^p$-mHEbO0#qj_gwc#^4#qsMUl{*1zN
e>I^CwqAYJB+ZKALhJOg5MT00000000080000000006NpoRSWoHEe00{wQLP%5x#
+Iwz1XmoMZUe8>*JiqdOAW_7Xq?evcVyE5000000000$0000000003Ole{U1O#bw
VPydUTVY%eB()|DVs5)j?WBU==a=KzyTg3px>h43uaSoYV{c?-00;m8KmY&$0000
00RR600000000d-VbYTDp002M$0000000030{{R3000004Y-wV10n*|aTPJY^=0y
A22XT><RaQoljqI}$|D0ODWau{Om<3E}Vo78L0RRU806-uB225#UQ)Oob0RRaBr!
Z9lE%{u?@QI^EqCb}2Q7OO^w+`_q*ddTXmHSf)0000000000{{R30000002TW;VQ
)zT%1_A?YX<`AVFjWFA`CQ2GiK9iLKbGE6DZmrA4)G`0A&^0p`%?-7aBp(}00I
1wm|eR!srQEFN!zncXl9K5w2;FV{y1jDTJCC^p$-mHEbO0#qjhQ*>kj15<Ql0stq3(Tr;j#yqcI82>cB
r>9x-Cs#sheE97?nsOaXHkb)PY;b5{Lt$`pdPjz(4^OqB<q89*y8zxgORf>|1Bk8zGh-IHIi*o-3_)yg
XkkNPaC1&|Z3X}bNpoRNVQpmv0RRO80?I5NZ-bfLFbqC#o>4E?M+l67UG^w8*<_XZ#%uyqCnto_jB5_Y
Jg;9E|1`d*r&;qSS3+uh`0YNLave-Im;eX@$}AplgPGkh3_fq3Q7_j=2#kPT_9!;lWR>~GYywm#dPjz(
4^OqB<q89*y8zxgORf>|1Bk8zGh-IHIi*o-0RR91000002LJ#70000021#>aQ)Oob0RRaBlI1_jdG2&s
5l|&f*ZHF;qIbkhZU7>Kq8jXl$Dv2x0000000000KmY&$00000159aR1_T6Yb75rxvkfUR&BN*@p#4(i
bP}+pt<oOPGm6R3$XkS_lCK!E1Y>VxWdH~O06+i$000000096000000000DJVRT^t2mk;;0000000000
|Nj60000001Z-(ya{<!g7+WWC1?EKi+6QrwlvP$nl8x-M691f9z+~t)>6isfX<|ua1pxpD002NB00vBH
VpC;j1pxpF0jDrk0xkJm$nc4yMWR2J-cc#Q6SofWC)gp7L6!Sc3IG5A000000RI300000000&HIVpC~!
Wd;HRY-wTvr!Z9lE%{u?@QI^EqCb}2Q7OO^w+`_q*ddTXmHSf)18{G10006

-----END STRICT TYPE LIB-----

Binary file modified stl/[email protected]
Binary file not shown.
21 changes: 11 additions & 10 deletions stl/[email protected]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{-
Id: urn:ubideco:stl:APYERRUMyWqLadwTv8tEFifHMPGpL3xGFSBxwaKYpmcV#square-mammal-uncle
Id: stl:YnA1fyHl-46C2hsC-tZPxn60-w1jLk5Y-rDTjRmy-xo@5xjY#congo-archive-folio
Name: AluVM
Version: 0.1.0
Description: AluVM data type library
Expand All @@ -11,29 +11,30 @@
@context
typelib AluVM

import Std#EcCNgrgLaygt3tCZNu2ZVEzMzSAZYEUeTNAVi5E81YWi#aspirin-mango-average
use AlphaCaps#digital-mirage-dream
import Std#ralph-blue-lucky
use AlphaCaps#picnic-soprano-aurora
use AlphaCapsNum#aladdin-zebra-marble


@mnemonic(spirit-example-carrot)
data IsaName : [Std.AlphaCaps#digital-mirage-dream ^ 2..0x8]
@mnemonic(taboo-olympic-cloud)
data IsaName : Std.AlphaCaps, [Std.AlphaCapsNum ^ 1..0x7]

@mnemonic(blonde-format-kansas)
@mnemonic(freedom-ship-canal)
data IsaSeg : {IsaName ^ ..0x40}

@mnemonic(volcano-daniel-ticket)
@mnemonic(bernard-igor-version)
data Lib : isae IsaSeg
, code [Byte]
, data [Byte]
, libs LibSeg

@mnemonic(rebel-factor-rodeo)
@mnemonic(germany-culture-olivia)
data LibId : [Byte ^ 32]

@mnemonic(imitate-cargo-region)
@mnemonic(gilbert-tomato-caesar)
data LibSeg : {LibId ^ ..0xff}

@mnemonic(organic-escort-ceramic)
@mnemonic(chance-agent-ivory)
data LibSite : lib LibId, pos U16


0 comments on commit 6b7b257

Please sign in to comment.