mirror of
https://github.com/edg-l/edlang.git
synced 2024-11-09 09:38:24 +00:00
Compare commits
2 commits
466b7687a7
...
8319844673
Author | SHA1 | Date | |
---|---|---|---|
Edgar | 8319844673 | ||
Edgar | f71abb0b26 |
|
@ -479,8 +479,6 @@ fn lower_assign(builder: &mut BodyBuilder, info: &ast::AssignStmt) -> Result<(),
|
|||
kind: ty,
|
||||
};
|
||||
|
||||
dbg!("here1");
|
||||
|
||||
for _ in 0..info.deref_times {
|
||||
match &ty.kind {
|
||||
TypeKind::Ptr(is_mut, inner) => {
|
||||
|
@ -500,12 +498,8 @@ fn lower_assign(builder: &mut BodyBuilder, info: &ast::AssignStmt) -> Result<(),
|
|||
place.projection.push(PlaceElem::Deref);
|
||||
}
|
||||
|
||||
dbg!("here2");
|
||||
|
||||
let (rvalue, _ty, _span) = lower_expr(builder, &info.value, Some(&ty))?;
|
||||
|
||||
dbg!("here3");
|
||||
|
||||
builder.statements.push(Statement {
|
||||
span: Some(info.name.first.span),
|
||||
kind: StatementKind::Assign(place, rvalue),
|
||||
|
@ -751,7 +745,7 @@ fn lower_binary_expr(
|
|||
) -> Result<(ir::RValue, TypeKind, Span), LoweringError> {
|
||||
trace!("lowering binary op: {:?}", op);
|
||||
|
||||
let (lhs, lhs_ty, _) = if type_hint.is_none() {
|
||||
let (lhs, lhs_ty, lhs_span) = if type_hint.is_none() {
|
||||
let ty = find_expr_type(builder, lhs)
|
||||
.unwrap_or_else(|| find_expr_type(builder, rhs).expect("cant find type"));
|
||||
lower_expr(
|
||||
|
@ -765,7 +759,7 @@ fn lower_binary_expr(
|
|||
} else {
|
||||
lower_expr(builder, lhs, type_hint)?
|
||||
};
|
||||
let (rhs, rhs_ty, _) = if type_hint.is_none() {
|
||||
let (rhs, rhs_ty, rhs_span) = if type_hint.is_none() {
|
||||
let ty = find_expr_type(builder, rhs).unwrap_or(lhs_ty.clone());
|
||||
lower_expr(
|
||||
builder,
|
||||
|
@ -779,6 +773,17 @@ fn lower_binary_expr(
|
|||
lower_expr(builder, rhs, type_hint)?
|
||||
};
|
||||
|
||||
if lhs_ty != rhs_ty {
|
||||
return Err(LoweringError::UnexpectedType {
|
||||
span: rhs_span,
|
||||
found: rhs_ty,
|
||||
expected: TypeInfo {
|
||||
span: Some(lhs_span),
|
||||
kind: lhs_ty,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
let lhs = match lhs {
|
||||
RValue::Use(op, _span) => op,
|
||||
lhs => {
|
||||
|
|
|
@ -348,34 +348,34 @@ pub(crate) Expression: ast::Expression = {
|
|||
}
|
||||
|
||||
pub BinaryFirstLvlOp: ast::BinaryOp = {
|
||||
<lo:@L> "==" <hi:@R> => ast::BinaryOp::Compare(ast::CmpOp::Eq, ast::Span::new(hi, lo)),
|
||||
<lo:@L> "!=" <hi:@R> => ast::BinaryOp::Compare(ast::CmpOp::NotEq, ast::Span::new(hi, lo)),
|
||||
<lo:@L> "<" <hi:@R> => ast::BinaryOp::Compare(ast::CmpOp::Lt, ast::Span::new(hi, lo)),
|
||||
<lo:@L> ">" <hi:@R> => ast::BinaryOp::Compare(ast::CmpOp::Gt, ast::Span::new(hi, lo)),
|
||||
<lo:@L> "<=" <hi:@R> => ast::BinaryOp::Compare(ast::CmpOp::LtEq, ast::Span::new(hi, lo)),
|
||||
<lo:@L> ">=" <hi:@R> => ast::BinaryOp::Compare(ast::CmpOp::GtEq, ast::Span::new(hi, lo)),
|
||||
<lo:@L> "&&" <hi:@R> => ast::BinaryOp::Logic(ast::LogicOp::And, ast::Span::new(hi, lo)),
|
||||
<lo:@L> "||" <hi:@R> => ast::BinaryOp::Logic(ast::LogicOp::Or, ast::Span::new(hi, lo)),
|
||||
<lo:@L> "==" <hi:@R> => ast::BinaryOp::Compare(ast::CmpOp::Eq, ast::Span::new(lo, hi)),
|
||||
<lo:@L> "!=" <hi:@R> => ast::BinaryOp::Compare(ast::CmpOp::NotEq, ast::Span::new(lo, hi)),
|
||||
<lo:@L> "<" <hi:@R> => ast::BinaryOp::Compare(ast::CmpOp::Lt, ast::Span::new(lo, hi)),
|
||||
<lo:@L> ">" <hi:@R> => ast::BinaryOp::Compare(ast::CmpOp::Gt, ast::Span::new(lo, hi)),
|
||||
<lo:@L> "<=" <hi:@R> => ast::BinaryOp::Compare(ast::CmpOp::LtEq, ast::Span::new(lo, hi)),
|
||||
<lo:@L> ">=" <hi:@R> => ast::BinaryOp::Compare(ast::CmpOp::GtEq, ast::Span::new(lo, hi)),
|
||||
<lo:@L> "&&" <hi:@R> => ast::BinaryOp::Logic(ast::LogicOp::And, ast::Span::new(lo, hi)),
|
||||
<lo:@L> "||" <hi:@R> => ast::BinaryOp::Logic(ast::LogicOp::Or, ast::Span::new(lo, hi)),
|
||||
}
|
||||
|
||||
pub BinarySecondLvlOp: ast::BinaryOp = {
|
||||
<lo:@L> "/" <hi:@R> => ast::BinaryOp::Arith(ast::ArithOp::Div, ast::Span::new(hi, lo)),
|
||||
<lo:@L> "*" <hi:@R> => ast::BinaryOp::Arith(ast::ArithOp::Mul, ast::Span::new(hi, lo)),
|
||||
<lo:@L> "%" <hi:@R> => ast::BinaryOp::Arith(ast::ArithOp::Mod, ast::Span::new(hi, lo)),
|
||||
<lo:@L> "/" <hi:@R> => ast::BinaryOp::Arith(ast::ArithOp::Div, ast::Span::new(lo, hi)),
|
||||
<lo:@L> "*" <hi:@R> => ast::BinaryOp::Arith(ast::ArithOp::Mul, ast::Span::new(lo, hi)),
|
||||
<lo:@L> "%" <hi:@R> => ast::BinaryOp::Arith(ast::ArithOp::Mod, ast::Span::new(lo, hi)),
|
||||
}
|
||||
|
||||
pub BinaryThirdLvlOp: ast::BinaryOp = {
|
||||
<lo:@L> "+" <hi:@R> => ast::BinaryOp::Arith(ast::ArithOp::Add, ast::Span::new(hi, lo)),
|
||||
<lo:@L> "-" <hi:@R> => ast::BinaryOp::Arith(ast::ArithOp::Sub, ast::Span::new(hi, lo)),
|
||||
<lo:@L> "&" <hi:@R> => ast::BinaryOp::Bitwise(ast::BitwiseOp::And, ast::Span::new(hi, lo)),
|
||||
<lo:@L> "|" <hi:@R> => ast::BinaryOp::Bitwise(ast::BitwiseOp::Or, ast::Span::new(hi, lo)),
|
||||
<lo:@L> "^" <hi:@R> => ast::BinaryOp::Bitwise(ast::BitwiseOp::Xor, ast::Span::new(hi, lo)),
|
||||
<lo:@L> "+" <hi:@R> => ast::BinaryOp::Arith(ast::ArithOp::Add, ast::Span::new(lo, hi)),
|
||||
<lo:@L> "-" <hi:@R> => ast::BinaryOp::Arith(ast::ArithOp::Sub, ast::Span::new(lo, hi)),
|
||||
<lo:@L> "&" <hi:@R> => ast::BinaryOp::Bitwise(ast::BitwiseOp::And, ast::Span::new(lo, hi)),
|
||||
<lo:@L> "|" <hi:@R> => ast::BinaryOp::Bitwise(ast::BitwiseOp::Or, ast::Span::new(lo, hi)),
|
||||
<lo:@L> "^" <hi:@R> => ast::BinaryOp::Bitwise(ast::BitwiseOp::Xor, ast::Span::new(lo, hi)),
|
||||
}
|
||||
|
||||
pub UnaryOp: ast::UnaryOp = {
|
||||
<lo:@L> "-" <hi:@R> => ast::UnaryOp::ArithNeg(ast::Span::new(hi, lo)),
|
||||
<lo:@L> "!" <hi:@R> => ast::UnaryOp::LogicalNot(ast::Span::new(hi, lo)),
|
||||
<lo:@L> "~" <hi:@R> => ast::UnaryOp::BitwiseNot(ast::Span::new(hi, lo)),
|
||||
<lo:@L> "-" <hi:@R> => ast::UnaryOp::ArithNeg(ast::Span::new(lo, hi)),
|
||||
<lo:@L> "!" <hi:@R> => ast::UnaryOp::LogicalNot(ast::Span::new(lo, hi)),
|
||||
<lo:@L> "~" <hi:@R> => ast::UnaryOp::BitwiseNot(ast::Span::new(lo, hi)),
|
||||
}
|
||||
|
||||
pub(crate) ValueExpr: ast::ValueExpr = {
|
||||
|
|
Loading…
Reference in a new issue