|
|
|
@ -83,22 +83,20 @@ pub fn parse_data_disp(tok: Sexp, pcx: &ParserContext) -> Result<DataDisp, CrsnE |
|
|
|
|
return Ok(DataDisp::Discard); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// check if we have an alias defined
|
|
|
|
|
{ |
|
|
|
|
let pstate = pcx.state.borrow(); |
|
|
|
|
if let Some(val) = pstate.constants.get(&s) { |
|
|
|
|
return Ok(DataDisp::Immediate(*val)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if let Some(val) = pstate.reg_aliases.get(&s) { |
|
|
|
|
return Ok(DataDisp::Register(*val)); |
|
|
|
|
if s.starts_with('\'') && s.ends_with('\'') { |
|
|
|
|
if s.chars().count() == 3 { |
|
|
|
|
return Ok(DataDisp::Immediate(s.chars().nth(1).unwrap() as u64)); |
|
|
|
|
} else if s.chars().count() == 4 && s.chars().nth(1).unwrap() == '\\' { |
|
|
|
|
return Ok(DataDisp::Immediate(s.chars().nth(2).unwrap() as u64)); |
|
|
|
|
} else { |
|
|
|
|
return Err(CrsnError::Parse(format!("Invalid character literal synax {}", s).into(), pos)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if let Some(reference) = s.strip_prefix('@') { |
|
|
|
|
let pstate = pcx.state.borrow(); |
|
|
|
|
if let Some(val) = pstate.reg_aliases.get(reference) { |
|
|
|
|
Ok(DataDisp::ObjectPtr(*val)) |
|
|
|
|
if let Some(reg) = pstate.reg_aliases.get(reference) { |
|
|
|
|
Ok(DataDisp::ObjectPtr(*reg)) |
|
|
|
|
} else { |
|
|
|
|
let reg = reg::parse_reg(reference, &pos)?; |
|
|
|
|
|
|
|
|
@ -108,9 +106,18 @@ pub fn parse_data_disp(tok: Sexp, pcx: &ParserContext) -> Result<DataDisp, CrsnE |
|
|
|
|
Ok(DataDisp::ObjectPtr(reg)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else if s.starts_with(|c: char| c.is_ascii_digit()) { |
|
|
|
|
} else if s.starts_with(|c: char| c.is_ascii_digit() || c == '-') { |
|
|
|
|
Ok(DataDisp::Immediate(unsafe { std::mem::transmute(parse_i64(&s, &pos)?) })) |
|
|
|
|
} else { |
|
|
|
|
let pstate = pcx.state.borrow(); |
|
|
|
|
if let Some(val) = pstate.constants.get(&s) { |
|
|
|
|
return Ok(DataDisp::Immediate(*val)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if let Some(val) = pstate.reg_aliases.get(&s) { |
|
|
|
|
return Ok(DataDisp::Register(*val)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let reg = reg::parse_reg(&s, &pos)?; |
|
|
|
|
|
|
|
|
|
let pstate = pcx.state.borrow(); |
|
|
|
|