add "_" pattern for explicitly specifying the "discard" destination (may be used for side effects)

floats
Ondřej Hruška 4 years ago
parent 8e7689df48
commit f493cc102a
Signed by untrusted user: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 9
      asm/src/data/mod.rs
  2. 2
      asm/src/error.rs
  3. 4
      asm/src/parse/parse_data.rs
  4. 1
      crsn/src/main.rs

@ -26,6 +26,8 @@ pub enum DataDisp {
Register(Register),
/// Pointer into memory, stored in a numbered register
RegisterPtr(Register),
/// Discard the written value
Discard,
}
impl Display for DataDisp {
@ -43,6 +45,9 @@ impl Display for DataDisp {
DataDisp::RegisterPtr(r) => {
write!(f, "@{}", r)
}
DataDisp::Discard => {
write!(f, "_")
}
}
}
}
@ -64,7 +69,7 @@ impl From<DstDisp> for DataDisp {
DstDisp::ImmediatePtr(x) => DataDisp::ImmediatePtr(x),
DstDisp::Register(x) => DataDisp::Register(x),
DstDisp::RegisterPtr(x) => DataDisp::RegisterPtr(x),
DstDisp::Discard => DataDisp::Immediate(0),
DstDisp::Discard => DataDisp::Discard,
}
}
}
@ -91,6 +96,7 @@ impl TryFrom<DataDisp> for SrcDisp {
DataDisp::ImmediatePtr(x) => Ok(SrcDisp::ImmediatePtr(x)),
DataDisp::Register(x) => Ok(SrcDisp::Register(x)),
DataDisp::RegisterPtr(x) => Ok(SrcDisp::RegisterPtr(x)),
DataDisp::Discard => Err(AsmError::DiscardAsValue),
}
}
}
@ -128,6 +134,7 @@ impl TryFrom<DataDisp> for DstDisp {
DataDisp::ImmediatePtr(x) => Ok(DstDisp::ImmediatePtr(x)),
DataDisp::Register(x) => Ok(DstDisp::Register(x)),
DataDisp::RegisterPtr(x) => Ok(DstDisp::RegisterPtr(x)),
DataDisp::Discard => Ok(DstDisp::Discard),
}
}
}

@ -33,6 +33,8 @@ pub enum AsmError {
UnevenOperandSize(Mask, Mask),
#[error("Value provided as output argument")]
ValueAsOutput,
#[error("Discard (_) provided as input argument")]
DiscardAsValue,
#[error("Conditional branch already defined for \"{0}\"")]
ConditionalAlreadyUsed(Cond),
#[error("Label \"{0:?}\" not defined")]

@ -26,6 +26,10 @@ pub fn parse_data_disp(tok: Option<Sexp>) -> Result<DataDisp, Error> {
Ok(DataDisp::Immediate(unsafe { std::mem::transmute(*val) }))
},
Sexp::Atom(Atom::S(s)) => {
if s == "_" {
return Ok(DataDisp::Discard);
}
if let Some(reference) = s.strip_prefix('@') {
if reference.starts_with(|c : char| c.is_ascii_digit()) {
let val : u64 = parse_u64(reference)?;

@ -43,6 +43,7 @@ fn main() {
let program = "
(
(main
(ld _ arg0)
(call fibo 5)
(ld r0 res0)
)

Loading…
Cancel
Save