|
|
|
@ -27,7 +27,7 @@ impl OpTrait for BufOps { |
|
|
|
|
|
|
|
|
|
let que = match value { |
|
|
|
|
BufValue::Zeros(len) => { |
|
|
|
|
let len = state.read(*len)? as usize; |
|
|
|
|
let len = state.read(len)? as usize; |
|
|
|
|
let mut que = VecDeque::with_capacity(len); |
|
|
|
|
que.resize(len, 0); |
|
|
|
|
que |
|
|
|
@ -35,7 +35,7 @@ impl OpTrait for BufOps { |
|
|
|
|
BufValue::Values(vals) => { |
|
|
|
|
let mut que = VecDeque::with_capacity(vals.len()); |
|
|
|
|
for val in vals { |
|
|
|
|
que.push_back(state.read(*val)?); |
|
|
|
|
que.push_back(state.read(val)?); |
|
|
|
|
} |
|
|
|
|
que |
|
|
|
|
} |
|
|
|
@ -50,13 +50,13 @@ impl OpTrait for BufOps { |
|
|
|
|
|
|
|
|
|
let data: &mut ExtData = state.ext_mut(); |
|
|
|
|
data.store.insert(id, que); |
|
|
|
|
state.write(*dst, id)?; |
|
|
|
|
state.write(dst, id)?; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BufOps::Push { obj, src } => { |
|
|
|
|
state.clear_status(); |
|
|
|
|
let val = state.read(*src)?; |
|
|
|
|
let handle = state.read_obj(*obj)?; |
|
|
|
|
let val = state.read(src)?; |
|
|
|
|
let handle = state.read_obj(obj)?; |
|
|
|
|
let stacks: &mut ExtData = state.ext_mut(); |
|
|
|
|
let stack = stacks.store.get_mut(&handle).ok_or_else(|| Fault::ObjectNotExist(handle))?; |
|
|
|
|
stack.push_back(val); |
|
|
|
@ -64,12 +64,12 @@ impl OpTrait for BufOps { |
|
|
|
|
|
|
|
|
|
BufOps::Pop { dst, obj } => { |
|
|
|
|
state.clear_status(); |
|
|
|
|
let handle = state.read_obj(*obj)?; |
|
|
|
|
let handle = state.read_obj(obj)?; |
|
|
|
|
let stacks: &mut ExtData = state.ext_mut(); |
|
|
|
|
let stack = stacks.store.get_mut(&handle).ok_or_else(|| Fault::ObjectNotExist(handle))?; |
|
|
|
|
if let Some(val) = stack.pop_back() { |
|
|
|
|
let empty = stack.is_empty(); |
|
|
|
|
state.write(*dst, val)?; |
|
|
|
|
state.write(dst, val)?; |
|
|
|
|
state.update_status(val); |
|
|
|
|
state.set_flag(Cond::Empty, empty); |
|
|
|
|
} else { |
|
|
|
@ -80,14 +80,14 @@ impl OpTrait for BufOps { |
|
|
|
|
|
|
|
|
|
BufOps::Read { dst, obj, idx } => { |
|
|
|
|
state.clear_status(); |
|
|
|
|
let handle = state.read_obj(*obj)?; |
|
|
|
|
let idx = state.read(*idx)?; |
|
|
|
|
let handle = state.read_obj(obj)?; |
|
|
|
|
let idx = state.read(idx)?; |
|
|
|
|
let stacks: &mut ExtData = state.ext_mut(); |
|
|
|
|
let stack = stacks.store.get(&handle).ok_or_else(|| Fault::ObjectNotExist(handle))?; |
|
|
|
|
if let Some(val) = stack.get(idx as usize) { |
|
|
|
|
let val = *val; |
|
|
|
|
state.update_status(val); |
|
|
|
|
state.write(*dst, val)?; |
|
|
|
|
state.write(dst, val)?; |
|
|
|
|
} else { |
|
|
|
|
state.set_flag(Cond::Overflow, true); |
|
|
|
|
} |
|
|
|
@ -95,19 +95,19 @@ impl OpTrait for BufOps { |
|
|
|
|
|
|
|
|
|
BufOps::GetLen { dst, obj } => { |
|
|
|
|
state.clear_status(); |
|
|
|
|
let handle = state.read_obj(*obj)?; |
|
|
|
|
let handle = state.read_obj(obj)?; |
|
|
|
|
let stacks: &mut ExtData = state.ext_mut(); |
|
|
|
|
let stack = stacks.store.get(&handle).ok_or_else(|| Fault::ObjectNotExist(handle))?; |
|
|
|
|
let val = stack.len() as Value; |
|
|
|
|
state.write(*dst, val)?; |
|
|
|
|
state.write(dst, val)?; |
|
|
|
|
state.update_status(val); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BufOps::Write { obj, idx, value } => { |
|
|
|
|
state.clear_status(); |
|
|
|
|
let handle = state.read_obj(*obj)?; |
|
|
|
|
let val = state.read(*value)?; |
|
|
|
|
let idx = state.read(*idx)? as usize; |
|
|
|
|
let handle = state.read_obj(obj)?; |
|
|
|
|
let val = state.read(value)?; |
|
|
|
|
let idx = state.read(idx)? as usize; |
|
|
|
|
let stacks: &mut ExtData = state.ext_mut(); |
|
|
|
|
let stack = stacks.store.get_mut(&handle).ok_or_else(|| Fault::ObjectNotExist(handle))?; |
|
|
|
|
if idx < stack.len() { |
|
|
|
@ -121,9 +121,9 @@ impl OpTrait for BufOps { |
|
|
|
|
|
|
|
|
|
BufOps::Insert { obj, idx, value } => { |
|
|
|
|
state.clear_status(); |
|
|
|
|
let handle = state.read_obj(*obj)?; |
|
|
|
|
let val = state.read(*value)?; |
|
|
|
|
let idx = state.read(*idx)? as usize; |
|
|
|
|
let handle = state.read_obj(obj)?; |
|
|
|
|
let val = state.read(value)?; |
|
|
|
|
let idx = state.read(idx)? as usize; |
|
|
|
|
let stacks: &mut ExtData = state.ext_mut(); |
|
|
|
|
let stack = stacks.store.get_mut(&handle).ok_or_else(|| Fault::ObjectNotExist(handle))?; |
|
|
|
|
if idx < stack.len() { |
|
|
|
@ -137,15 +137,15 @@ impl OpTrait for BufOps { |
|
|
|
|
|
|
|
|
|
BufOps::Remove { dst, obj, idx } => { |
|
|
|
|
state.clear_status(); |
|
|
|
|
let handle = state.read_obj(*obj)?; |
|
|
|
|
let idx = state.read(*idx)? as usize; |
|
|
|
|
let handle = state.read_obj(obj)?; |
|
|
|
|
let idx = state.read(idx)? as usize; |
|
|
|
|
let stacks: &mut ExtData = state.ext_mut(); |
|
|
|
|
let stack = stacks.store.get_mut(&handle).ok_or_else(|| Fault::ObjectNotExist(handle))?; |
|
|
|
|
if idx < stack.len() { |
|
|
|
|
let val = stack.remove(idx).unwrap(); |
|
|
|
|
let empty = stack.is_empty(); |
|
|
|
|
state.update_status(val); |
|
|
|
|
state.write(*dst, val)?; |
|
|
|
|
state.write(dst, val)?; |
|
|
|
|
state.set_flag(Cond::Empty, empty); |
|
|
|
|
} else { |
|
|
|
|
state.set_flag(Cond::Overflow, true); |
|
|
|
@ -153,15 +153,15 @@ impl OpTrait for BufOps { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BufOps::Resize { obj, len } => { |
|
|
|
|
let handle = state.read_obj(*obj)?; |
|
|
|
|
let len = state.read(*len)? as usize; |
|
|
|
|
let handle = state.read_obj(obj)?; |
|
|
|
|
let len = state.read(len)? as usize; |
|
|
|
|
let stacks: &mut ExtData = state.ext_mut(); |
|
|
|
|
let stack = stacks.store.get_mut(&handle).ok_or_else(|| Fault::ObjectNotExist(handle))?; |
|
|
|
|
stack.resize(len, 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BufOps::Reverse { obj } => { |
|
|
|
|
let handle = state.read_obj(*obj)?; |
|
|
|
|
let handle = state.read_obj(obj)?; |
|
|
|
|
let stacks: &mut ExtData = state.ext_mut(); |
|
|
|
|
let stack = stacks.store.get_mut(&handle).ok_or_else(|| Fault::ObjectNotExist(handle))?; |
|
|
|
|
let len = stack.len(); |
|
|
|
@ -177,8 +177,8 @@ impl OpTrait for BufOps { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BufOps::AppendBuf { obj, obj2 } => { |
|
|
|
|
let handle = state.read_obj(*obj)?; |
|
|
|
|
let handle2 = state.read_obj(*obj2)?; |
|
|
|
|
let handle = state.read_obj(obj)?; |
|
|
|
|
let handle2 = state.read_obj(obj2)?; |
|
|
|
|
let stacks: &mut ExtData = state.ext_mut(); |
|
|
|
|
let stack2 = stacks.store.get(&handle2).ok_or_else(|| Fault::ObjectNotExist(handle))?.clone(); |
|
|
|
|
let stack = stacks.store.get_mut(&handle).ok_or_else(|| Fault::ObjectNotExist(handle))?; |
|
|
|
@ -186,8 +186,8 @@ impl OpTrait for BufOps { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BufOps::PrependBuf { obj, obj2 } => { |
|
|
|
|
let handle = state.read_obj(*obj)?; |
|
|
|
|
let handle2 = state.read_obj(*obj2)?; |
|
|
|
|
let handle = state.read_obj(obj)?; |
|
|
|
|
let handle2 = state.read_obj(obj2)?; |
|
|
|
|
let stacks: &mut ExtData = state.ext_mut(); |
|
|
|
|
let stack2 = stacks.store.get(&handle2).ok_or_else(|| Fault::ObjectNotExist(handle))?.clone(); |
|
|
|
|
let stack = stacks.store.get_mut(&handle).ok_or_else(|| Fault::ObjectNotExist(handle))?; |
|
|
|
|