Fix a compatability issue and a compilation error

This commit is contained in:
bʰedoh₂ swé 2024-06-19 23:45:59 +05:00
parent 751971576e
commit fb1207bae5
5 changed files with 20 additions and 9 deletions

View File

@ -1,6 +1,6 @@
use crate::{
instructions,
stack::{Instruction, Stack, StackVec},
stack::{Instruction, Stack},
};
fn find_labels(stack: &mut Stack) {
@ -28,18 +28,17 @@ fn find_labels(stack: &mut Stack) {
stack.program_counter = stack.labels[0].unwrap_or(0) as u16;
}
fn find_prefix_operators(instruction: &mut Instruction, memory: &mut StackVec) {
fn find_prefix_operators(instruction: &mut Instruction) {
match instruction.name.chars().nth(0) {
Some('|') => {
instruction.name = instruction.name.chars().skip(1).collect();
instruction.data = memory.pop();
instruction.ispiped = true;
}
Some('/') => {
instruction.name = instruction.name.chars().skip(1).collect();
memory.push(instruction.data);
instruction.data = 0;
instruction.isdrained = true;
}
_ => {}
}
@ -51,7 +50,16 @@ pub fn execute(stack: &mut Stack, mut origin_stack: Option<&mut Stack>, mod_name
while let Some(mut instruction) = stack.program.get_mut(stack.program_counter as usize) {
stack.program_counter += 1;
find_prefix_operators(&mut instruction, &mut stack.memory);
find_prefix_operators(&mut instruction);
if instruction.ispiped {
instruction.data = stack.memory.pop();
}
if instruction.isdrained {
stack.memory.push(instruction.data);
instruction.data = 0;
}
if instruction.name.chars().nth(0) == Some('#')
|| instruction.name.chars().nth(0) == Some('$')

View File

@ -11,11 +11,10 @@ extern fn stack_pop_callback() -> u16 {
}
#[no_mangle]
extern fn stack_push_callback(data: u16) -> i32 {
extern fn stack_push_callback(data: u16){
unsafe {
(*STACKPTR).memory.push(data)
};
return 0;
}
#[no_mangle]

View File

@ -22,5 +22,7 @@ pub fn insert(program: &mut Vec<Instruction>, arg: String, data: u16) {
name: arg.to_string(),
arg: "\n".to_string(),
data,
ispiped: false,
isdrained: false
});
}

View File

@ -48,7 +48,7 @@ pub fn parse(stack: &mut Stack, file_content: &str) {
}
if name != "" {
let inst = Instruction { name, arg, data };
let inst = Instruction { name, arg, data, ispiped: false, isdrained: false };
stack.program.push(inst);
}
}

View File

@ -7,6 +7,8 @@ pub struct Instruction {
pub name: String,
pub arg: String,
pub data: u16,
pub ispiped: bool,
pub isdrained: bool
}
pub struct Stack {