forked from n3tael/labast
initial commit
This commit is contained in:
@@ -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,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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
pub fn maxsize(memory: &mut Vec<u16>) {
|
||||
memory.push(65535);
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user