cleanup, auto deref Wd, Wr, RdObj

This commit is contained in:
2020-10-10 15:45:01 +02:00
parent 7a3cb539e1
commit 982ba27ed3
7 changed files with 119 additions and 101 deletions
+12
View File
@@ -17,6 +17,12 @@ impl Rd {
}
}
impl From<&Rd> for Rd {
fn from(a: &Rd) -> Self {
*a
}
}
impl Display for Rd {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0) // TODO mask, when implemented
@@ -43,6 +49,12 @@ impl RdObj {
}
}
impl From<&RdObj> for RdObj {
fn from(a: &RdObj) -> Self {
*a
}
}
impl Display for RdObj {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "@{}", self.0)
+6
View File
@@ -31,6 +31,12 @@ impl Wr {
}
}
impl From<&Wr> for Wr {
fn from(a: &Wr) -> Self {
*a
}
}
impl Display for Wr {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
+8 -8
View File
@@ -69,7 +69,7 @@ impl OpTrait for BuiltinOp {
Ok(pos) => {
let mut values = Vec::with_capacity(args.len());
for arg in args {
values.push(state.read(*arg)?);
values.push(state.read(arg)?);
}
let mut frame2 = StackFrame::new(pos, &values);
@@ -87,7 +87,7 @@ impl OpTrait for BuiltinOp {
Some(previous) => {
let mut values = Vec::with_capacity(retvals.len());
for arg in retvals {
values.push(state.read(*arg)?);
values.push(state.read(arg)?);
}
state.frame = previous;
state.frame.set_retvals(&values);
@@ -98,16 +98,16 @@ impl OpTrait for BuiltinOp {
}
}
BuiltinOp::Skip(val) => {
let steps = state.read(*val)?;
let steps = state.read(val)?;
res.advance = i64::from_ne_bytes(steps.to_ne_bytes());
let pc = state.get_pc();
program.validate_jump(pc, Addr((pc.0 as i64 + res.advance) as u64))?;
}
BuiltinOp::MoveValue { dst, src } => {
state.clear_status();
let val = state.read(*src)?;
let val = state.read(src)?;
state.update_status(val);
state.write(*dst, val)?;
state.write(dst, val)?;
}
BuiltinOp::SwapValues { a, b } => {
let aa = state.read(a)?;
@@ -117,14 +117,14 @@ impl OpTrait for BuiltinOp {
}
BuiltinOp::StoreFlags { dst } => {
let packed = state.frame.status.store();
state.write(*dst, packed)?;
state.write(dst, packed)?;
}
BuiltinOp::LoadFlags { src } => {
let x = state.read(*src)?;
let x = state.read(src)?;
state.frame.status.load(x);
}
BuiltinOp::Sleep { count: micros, unit_us } => {
std::thread::sleep(Duration::from_micros(state.read(*micros)? * unit_us.micros()))
std::thread::sleep(Duration::from_micros(state.read(micros)? * unit_us.micros()))
}
BuiltinOp::Delete(obj) => {
let x = state.read(Rd::new(RdData::Register(obj.reg())))?;
+2 -2
View File
@@ -88,8 +88,8 @@ impl RunState {
}
/// Read object handle value
pub fn read_obj(&mut self, rdo: RdObj) -> Result<Value, Fault> {
self.read(Rd::new(RdData::Register(rdo.reg())))
pub fn read_obj(&mut self, rdo: impl Into<RdObj>) -> Result<Value, Fault> {
self.read(Rd::new(RdData::Register(rdo.into().reg())))
}
/// Read a `Rd` value