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:
@@ -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,3 +1,3 @@
|
||||
pub fn maxsize(memory: &mut Vec<u16>) {
|
||||
memory.push(65535);
|
||||
memory.push(u16::MAX);
|
||||
}
|
||||
@@ -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,3 +1,3 @@
|
||||
pub fn print(arg: &String) {
|
||||
println!("{}", arg);
|
||||
print!("{}", arg);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
pub fn println(arg: &String) {
|
||||
println!("{}", arg);
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
Reference in New Issue
Block a user