From cc4242b1fe998c4e8cfda468453de042464ccfc7 Mon Sep 17 00:00:00 2001 From: Ry Date: Wed, 12 Oct 2022 13:32:14 -0700 Subject: [PATCH] Allow using constants in data.8 and data.16 --- src/main.rs | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5034838..55459a1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -598,26 +598,18 @@ fn parse_data(pair: pest::iterators::Pair) -> AstNode { //println!("{:#?}", pair); match pair.as_rule() { Rule::data_byte => { - let ast = parse_operand(pair.into_inner().next().unwrap(), false); - let byte = { - if let AstNode::Immediate32(word) = ast { - word as u8 - } else { - unreachable!() - } - }; - AstNode::DataByte(byte) + match parse_operand(pair.into_inner().next().unwrap(), false) { + AstNode::Immediate32(half) => AstNode::DataByte(half as u8), + AstNode::LabelOperand {name, size, is_relative} => AstNode::LabelOperand {name, size, is_relative}, + _ => unreachable!(), + } }, Rule::data_half => { - let ast = parse_operand(pair.into_inner().next().unwrap(), false); - let word = { - if let AstNode::Immediate32(word) = ast { - word as u16 - } else { - unreachable!() - } - }; - AstNode::DataHalf(word) + match parse_operand(pair.into_inner().next().unwrap(), false) { + AstNode::Immediate32(half) => AstNode::DataHalf(half as u16), + AstNode::LabelOperand {name, size, is_relative} => AstNode::LabelOperand {name, size, is_relative}, + _ => unreachable!(), + } }, Rule::data_word => { match parse_operand(pair.into_inner().next().unwrap(), false) {