add hex constants and data segments

This commit is contained in:
2021-11-12 22:08:53 +01:00
parent 51cf8a8d28
commit e4bf292e47
14 changed files with 355 additions and 84 deletions

View File

@@ -150,6 +150,46 @@ pub fn tc_script(script: &mut ast::Script, source: &str) -> Result<()> {
}
}
for data in &mut script.data {
tc_const(&mut data.offset, source)?;
if data.offset.type_ != Some(I32) {
result = type_mismatch(
Some(I32),
&data.offset.span,
data.offset.type_,
&data.offset.span,
source,
);
}
for values in &mut data.data {
match values {
ast::DataValues::Array { type_, values } => {
let needed_type = match type_ {
ast::DataType::I8 | ast::DataType::I16 | ast::DataType::I32 => {
ast::Type::I32
}
ast::DataType::I64 => ast::Type::I64,
ast::DataType::F32 => ast::Type::F32,
ast::DataType::F64 => ast::Type::F64,
};
for value in values {
tc_const(value, source)?;
if value.type_ != Some(needed_type) {
result = type_mismatch(
Some(needed_type),
&value.span,
value.type_,
&value.span,
source,
);
}
}
}
ast::DataValues::String(_) => (),
}
}
}
result
}