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