Merge pull request #7 from neuschaefer/fixes

Fixes for data directives
This commit is contained in:
Ry 2023-02-01 13:45:14 -08:00 committed by GitHub
commit ebdf8e3ac5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -605,25 +605,29 @@ fn parse_label(pair: pest::iterators::Pair<Rule>, next_pair: Option<pest::iterat
fn parse_data(pair: pest::iterators::Pair<Rule>) -> AstNode { fn parse_data(pair: pest::iterators::Pair<Rule>) -> AstNode {
//println!("{:#?}", pair); //println!("{:#?}", pair);
*CURRENT_SIZE.lock().unwrap() = Size::Word;
match pair.as_rule() { match pair.as_rule() {
Rule::data_byte => { Rule::data_byte => {
match parse_operand(pair.into_inner().next().unwrap(), false) { match parse_operand(pair.into_inner().next().unwrap(), false) {
AstNode::Immediate32(half) => AstNode::DataByte(half as u8), AstNode::Immediate32(half) => AstNode::DataByte(half as u8),
AstNode::LabelOperand {name, size, is_relative} => AstNode::LabelOperand {name, size, is_relative}, AstNode::LabelOperand {name, size: _, is_relative} =>
AstNode::LabelOperand {name, size: Size::Byte, is_relative},
_ => unreachable!(), _ => unreachable!(),
} }
}, },
Rule::data_half => { Rule::data_half => {
match parse_operand(pair.into_inner().next().unwrap(), false) { match parse_operand(pair.into_inner().next().unwrap(), false) {
AstNode::Immediate32(half) => AstNode::DataHalf(half as u16), AstNode::Immediate32(half) => AstNode::DataHalf(half as u16),
AstNode::LabelOperand {name, size, is_relative} => AstNode::LabelOperand {name, size, is_relative}, AstNode::LabelOperand {name, size: _, is_relative} =>
AstNode::LabelOperand {name, size: Size::Half, is_relative},
_ => unreachable!(), _ => unreachable!(),
} }
}, },
Rule::data_word => { Rule::data_word => {
match parse_operand(pair.into_inner().next().unwrap(), false) { match parse_operand(pair.into_inner().next().unwrap(), false) {
AstNode::Immediate32(word) => AstNode::DataWord(word), AstNode::Immediate32(word) => AstNode::DataWord(word),
AstNode::LabelOperand {name, size, is_relative} => AstNode::LabelOperand {name, size, is_relative}, AstNode::LabelOperand {name, size: _, is_relative} =>
AstNode::LabelOperand {name, size: Size::Word, is_relative},
_ => unreachable!(), _ => unreachable!(),
} }
}, },