update v1.0.3

* fixed _unix_random bug
* add custom instruction "random"
* update to spec 1.12
* more cli options
This commit is contained in:
2024-02-06 19:59:43 +02:00
parent f2b551a586
commit 4fb06f8f34
13 changed files with 174 additions and 34 deletions
+2 -2
View File
@@ -6,9 +6,9 @@ use crate::RunError;
pub fn _unix_random(memory: &mut Vec<u16>) {
let mut rng = File::open("/dev/urandom").unwrap();
let mut buffer = [0u8; 1];
let mut buffer = [0u8; 2];
rng.read_exact(&mut buffer).unwrap();
let data = &memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
memory.push((buffer[0] as u16) % (*data - 1));
memory.push((u16::from_ne_bytes(buffer)) % (*data - 1));
}
+1 -1
View File
@@ -1,3 +1,3 @@
pub fn maxsize(memory: &mut Vec<u16>) {
memory.push(65535);
memory.push(u16::MAX);
}
+3 -1
View File
@@ -36,4 +36,6 @@ pub mod not;
pub mod kjnz;
pub mod kjz;
pub mod print;
pub mod insert;
pub mod println;
pub mod insert;
pub mod random;
+1 -1
View File
@@ -1,3 +1,3 @@
pub fn print(arg: &String) {
println!("{}", arg);
print!("{}", arg);
}
+3
View File
@@ -0,0 +1,3 @@
pub fn println(arg: &String) {
println!("{}", arg);
}
+7
View File
@@ -0,0 +1,7 @@
use fastrand;
use crate::RunError;
pub fn random(memory: &mut Vec<u16>) {
let data = &memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
memory.push(fastrand::u16(..) % (*data - 1));
}