- Notes.
- See An Introduction to Assembly Programming with RISC-V.
- ISA (Industry Standard Architecture) is the portion of the architecture which is visible to compiler writers. I.e., a contract.
- There are 33 general-purpose unprivileged registers:
zerot0~t6for temporary values, which are not to be persisted across calls.s0~s11for saved values.
a0~a7for arguments and return values.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::{ | |
| io::{Cursor, Seek, SeekFrom}, | |
| ops::RangeBounds, | |
| }; | |
| /// Tries to get a UTF-8 string from the given buffer at the provided range. | |
| fn str_from_utf8_range(buf: &[u8], range: impl RangeBounds<usize>) -> Option<&str> { | |
| buf.get((range.start_bound().cloned(), range.end_bound().cloned())) | |
| .map(|slice| std::str::from_utf8(slice).expect("valid utf8")) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::collections::BTreeMap; | |
| fn group<'a>(data: impl Iterator<Item = (&'a str, u32)>) -> BTreeMap<&'a str, u32> { | |
| data.fold(BTreeMap::new(), |mut map, (date, amount)| { | |
| *map.entry(date).or_default() += amount; | |
| map | |
| }) | |
| } | |
| #[test] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function query(label) { | |
| console.log(`(${label}) created 'lazy promise', but not started yet`); | |
| return { | |
| then(r) { | |
| console.log(`(${label}) started!`); | |
| // ... process query | |
| // "return" them: | |
| r([{ data: `result for ${label}` }]); | |
| }, | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| macro_rules! cat { | |
| ($($str:expr),*) => {{ | |
| const LEN: usize = $($str.len() + )* 0; | |
| to_str(&combine::<LEN>(&[$($str),*])) | |
| }}; | |
| } | |
| const fn combine<const LEN: usize>(list: &[&'static str]) -> [u8; LEN] { | |
| let mut bytes = [0; LEN]; | |
| let mut i = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::io; | |
| use std::time::Duration; | |
| use std::{ | |
| io::Write, | |
| net::{SocketAddr, ToSocketAddrs, UdpSocket}, | |
| str::FromStr, | |
| }; | |
| use stun_rs::{ | |
| MessageClass, MessageDecoderBuilder, MessageEncoderBuilder, StunMessageBuilder, | |
| attributes::stun::XorMappedAddress, methods::BINDING, |
OlderNewer