Skip to content

Commit

Permalink
chore: partially fix no-std use of the library
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Aug 17, 2024
1 parent f9f38bd commit c0901ca
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 31 deletions.
23 changes: 20 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,37 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo check --workspace --no-default-features
- run: cargo check --workspace --no-default-features --features alloc
features:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
feature: [ default, stl, std, alloc, ascii-armor, secp256k1, curve25519 ]
feature:
- ascii-armor
- secp256k1
- curve25519
- stl
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Feature ${{matrix.feature}}
run: cargo check --workspace --no-default-features --features=${{matrix.feature}}
run: cargo check --workspace --no-default-features --features=std,${{matrix.feature}}
- name: Feature ${{matrix.feature}}
run: cargo check --workspace --features=${{matrix.feature}}
features-nostd:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
feature:
- secp256k1
- curve25519
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Feature ${{matrix.feature}}
run: cargo check --workspace --no-default-features --features=alloc,${{matrix.feature}}
platforms:
runs-on: ${{ matrix.os }}
strategy:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ homepage = "https://aluvm.org"
keywords = ["virtual-machine", "emulator", "functional", "risc", "edge-computing"]
categories = ["no-std", "embedded", "compilers", "cryptography", "emulators"]
rust-version = "1.75.0" # Due to amplify
edition = "2018"
edition = "2021"
license = "Apache-2.0"
readme = "README.md"
exclude = [".github"]
Expand Down
36 changes: 14 additions & 22 deletions src/isa/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
use alloc::boxed::Box;
use alloc::collections::BTreeSet;
#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::string::String;
#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::vec::Vec;
use alloc::string::{String, ToString};
use core::cmp::Ordering;
use core::ops::{BitAnd, BitOr, BitXor, Neg, Rem, Shl, Shr};

Expand Down Expand Up @@ -148,7 +146,7 @@ where Extension: InstructionSet
Instr::Curve25519(instr) => instr.src_regs(),
Instr::ExtensionCodes(instr) => instr.src_regs(),
Instr::ReservedInstruction(instr) => instr.src_regs(),
Instr::Nop => bset![],
Instr::Nop => BTreeSet::new(),
}
}

Expand All @@ -168,7 +166,7 @@ where Extension: InstructionSet
Instr::Curve25519(instr) => instr.dst_regs(),
Instr::ExtensionCodes(instr) => instr.dst_regs(),
Instr::ReservedInstruction(instr) => instr.dst_regs(),
Instr::Nop => bset![],
Instr::Nop => BTreeSet::new(),
}
}

Expand Down Expand Up @@ -220,9 +218,9 @@ impl InstructionSet for ControlFlowOp {
#[inline]
fn isa_ids() -> IsaSeg { IsaSeg::default() }

fn src_regs(&self) -> BTreeSet<Reg> { bset![] }
fn src_regs(&self) -> BTreeSet<Reg> { BTreeSet::new() }

fn dst_regs(&self) -> BTreeSet<Reg> { bset![] }
fn dst_regs(&self) -> BTreeSet<Reg> { BTreeSet::new() }

#[inline]
fn complexity(&self) -> u64 { 2 }
Expand Down Expand Up @@ -270,11 +268,11 @@ impl InstructionSet for PutOp {
#[inline]
fn isa_ids() -> IsaSeg { IsaSeg::default() }

fn src_regs(&self) -> BTreeSet<Reg> { bset![] }
fn src_regs(&self) -> BTreeSet<Reg> { BTreeSet::new() }

fn dst_regs(&self) -> BTreeSet<Reg> {
match self {
PutOp::ClrA(_, _) | PutOp::ClrF(_, _) | PutOp::ClrR(_, _) => bset![],
PutOp::ClrA(_, _) | PutOp::ClrF(_, _) | PutOp::ClrR(_, _) => BTreeSet::new(),
PutOp::PutA(reg, reg32, _) => bset![Reg::A(*reg, *reg32)],
PutOp::PutF(reg, reg32, _) => bset![Reg::F(*reg, *reg32)],
PutOp::PutR(reg, reg32, _) => bset![Reg::R(*reg, *reg32)],
Expand Down Expand Up @@ -555,10 +553,8 @@ impl InstructionSet for CmpOp {
CmpOp::IfZR(reg, idx) | CmpOp::IfNR(reg, idx) => {
bset![Reg::R(*reg, *idx)]
}
CmpOp::St(_, _, _) => {
bset![]
}
CmpOp::StInv => bset![],
CmpOp::St(_, _, _) => BTreeSet::new(),
CmpOp::StInv => BTreeSet::new(),
}
}

Expand All @@ -567,7 +563,7 @@ impl InstructionSet for CmpOp {
CmpOp::St(_, reg, idx) => {
bset![Reg::A(*reg, (*idx).into())]
}
_ => bset![],
_ => BTreeSet::new(),
}
}

Expand Down Expand Up @@ -1084,9 +1080,7 @@ impl InstructionSet for BytesOp {

fn src_regs(&self) -> BTreeSet<Reg> {
match self {
BytesOp::Put(_reg, _, _) => {
bset![]
}
BytesOp::Put(_reg, _, _) => BTreeSet::new(),
BytesOp::Swp(reg1, reg2) | BytesOp::Find(reg1, reg2) => {
bset![Reg::S(*reg1), Reg::S(*reg2)]
}
Expand Down Expand Up @@ -1154,9 +1148,7 @@ impl InstructionSet for BytesOp {
BytesOp::Cnt(_src, _byte, cnt) => {
bset![Reg::new(RegA::A16, *cnt)]
}
BytesOp::Eq(_reg1, _reg2) => {
bset![]
}
BytesOp::Eq(_reg1, _reg2) => BTreeSet::new(),
BytesOp::Con(_reg1, _reg2, _no, offset, len) => {
bset![Reg::A(RegA::A16, *offset), Reg::A(RegA::A16, *len)]
}
Expand Down Expand Up @@ -1673,9 +1665,9 @@ impl InstructionSet for ReservedOp {
#[inline]
fn isa_ids() -> IsaSeg { IsaSeg::default() }

fn src_regs(&self) -> BTreeSet<Reg> { bset![] }
fn src_regs(&self) -> BTreeSet<Reg> { BTreeSet::new() }

fn dst_regs(&self) -> BTreeSet<Reg> { bset![] }
fn dst_regs(&self) -> BTreeSet<Reg> { BTreeSet::new() }

fn complexity(&self) -> u64 { u64::MAX }

Expand Down
7 changes: 6 additions & 1 deletion src/library/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ use amplify::confinement::SmallBlob;
use amplify::{confinement, ByteArray, Bytes32};
use baid64::{Baid64ParseError, DisplayBaid64, FromBaid64Str};
use sha2::{Digest, Sha256};
#[cfg(feature = "std")]
use strict_encoding::{StrictDeserialize, StrictSerialize};

#[cfg(feature = "ascii-armor")]
pub use self::_armor::LibArmorError;
use super::{Cursor, Read, WriteError};
use crate::data::ByteStr;
use crate::isa::{Bytecode, BytecodeError, ExecStep, Instr, InstructionSet};
#[cfg(feature = "std")]
use crate::isa::{Bytecode, Instr};
use crate::isa::{BytecodeError, ExecStep, InstructionSet};
use crate::library::segs::IsaSeg;
use crate::library::{CodeEofError, LibSeg, SegmentError};
use crate::reg::CoreRegs;
Expand Down Expand Up @@ -135,7 +138,9 @@ pub struct Lib {
pub libs: LibSeg,
}

#[cfg(feature = "std")]
impl StrictSerialize for Lib {}
#[cfg(feature = "std")]
impl StrictDeserialize for Lib {}

impl Display for Lib {
Expand Down
6 changes: 2 additions & 4 deletions src/library/segs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@
#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::borrow::ToOwned;
use alloc::collections::BTreeSet;
use alloc::collections::{btree_set, BTreeSet};
#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::string::String;
use alloc::string::{String, ToString};
#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::vec::Vec;
use core::fmt::{self, Debug, Display, Formatter};
use core::str::FromStr;
use std::collections::btree_set;
use std::convert::TryFrom;

use amplify::confinement;
use amplify::confinement::Confined;
Expand Down

0 comments on commit c0901ca

Please sign in to comment.