initial commit

This commit is contained in:
2024-02-05 14:13:44 +02:00
parent a005400477
commit 317fa500b8
24 changed files with 78 additions and 7 deletions
+14
View File
@@ -0,0 +1,14 @@
use std::fs::File;
use std::io::Read;
use crate::RunError;
#[cfg(target_family = "unix")]
pub fn _unix_random(memory: &mut Vec<u16>) {
let mut rng = File::open("/dev/urandom").unwrap();
let mut buffer = [0u8; 1];
rng.read_exact(&mut buffer).unwrap();
let data = &memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
memory.push((buffer[0] as u16) % (*data - 1));
}
+1 -1
View File
@@ -1,7 +1,7 @@
use crate::{errors::RunError, stack::Stack};
pub fn args(memory: &mut Vec<u16>, origin_stack: &mut Option<&mut Stack>, data: &u16) {
let origin_memory = &mut origin_stack.as_mut().expect("msg").memory;
let origin_memory = &mut origin_stack.as_mut().expect(&format!("{}", RunError::RequestArgsInMainModule)).memory;
if *origin_memory == *memory {
eprintln!("{}", RunError::RequestArgsInMainModule);
+5
View File
@@ -1,4 +1,9 @@
pub fn dump(memory: &mut Vec<u16>) {
if memory.is_empty() {
println!("Stack is empty.");
return;
}
for (i, entry) in memory.iter().enumerate() {
println!("{0}: {1}", i, entry);
}
+1 -1
View File
@@ -6,7 +6,7 @@ pub fn jnz(memory: &mut Vec<u16>, labels: &mut [Option<i16>; 256], program_count
std::process::exit(2);
}
if memory.pop() != Some(0) {
if memory.last() != Some(&0) {
*program_counter = (labels[*data as usize].unwrap() - 1) as u16;
}
}
+1 -1
View File
@@ -6,7 +6,7 @@ pub fn jz(memory: &mut Vec<u16>, labels: &mut [Option<i16>; 256], program_counte
std::process::exit(2);
}
if memory.pop() == Some(0) {
if memory.last() == Some(&0) {
*program_counter = (labels[*data as usize].unwrap() - 1) as u16;
}
}
+3
View File
@@ -0,0 +1,3 @@
pub fn maxsize(memory: &mut Vec<u16>) {
memory.push(65535);
}
+4 -1
View File
@@ -19,4 +19,7 @@ pub mod exec;
pub mod args;
pub mod expr;
pub mod size;
pub mod exit;
pub mod exit;
pub mod maxsize;
#[cfg(target_family = "unix")]
pub mod _unix_random;