remove "immediate ptr" data type, move read, write funcs to RunState, add %objectPtr syntax

This commit is contained in:
2020-09-28 01:01:57 +02:00
parent d489b214e0
commit 8222efe6da
12 changed files with 328 additions and 271 deletions
+12 -14
View File
@@ -1,14 +1,12 @@
use std::collections::VecDeque;
use crsn::asm::data::literal::Value;
use crsn::asm::instr::op::{EvalRes, OpTrait};
use crsn::runtime::fault::Fault;
use crsn::runtime::run_thread::{RunState, ThreadInfo};
use crsn::runtime::run_thread::{state::RunState, ThreadInfo};
use crate::defs::StackOp;
use crsn::asm::instr::Cond;
struct Stacks {
stacks: Vec<VecDeque<Value>>,
@@ -27,34 +25,34 @@ impl OpTrait for StackOp {
let eres = EvalRes::default();
match self {
StackOp::Push { num, src } => {
state.frame.status.clear();
let stack_num = state.frame.read(*num)?;
let val = state.frame.read(*src)?;
state.clear_status();
let stack_num = state.read(*num)?;
let val = state.read(*src)?;
if stack_num > 8 {
state.frame.status.invalid = true;
state.set_flag(Cond::Invalid, true);
} else {
let obj: &mut Stacks = state.ext_mut();
obj.stacks[stack_num as usize].push_back(val);
}
}
StackOp::Pop { dst, num } => {
state.frame.status.clear();
let stack_num = state.frame.read(*num)?;
state.clear_status();
let stack_num = state.read(*num)?;
if stack_num > 8 {
state.frame.status.invalid = true;
state.set_flag(Cond::Invalid, true);
} else {
let obj: &mut Stacks = state.ext_mut();
let val = obj.stacks[stack_num as usize].pop_back();
if obj.stacks[stack_num as usize].is_empty() {
state.frame.status.zero = true;
state.set_flag(Cond::Zero, true);
}
let val = match val {
None => {
state.frame.status.overflow = true;
state.set_flag(Cond::Overflow, true);
0
}
Some(val) => {
@@ -62,7 +60,7 @@ impl OpTrait for StackOp {
}
};
state.frame.write(*dst, val)?;
state.write(*dst, val)?;
}
// TODO