Fix compile errors WIP.
This commit is contained in:
parent
50884e38fa
commit
11d368ab1a
@ -516,6 +516,42 @@ impl BinaryExpression {
|
||||
diagnostics_result!(diagnostics)
|
||||
}
|
||||
|
||||
pub fn lower_to_ir_operation(
|
||||
&self,
|
||||
builder: &mut IrBuilder,
|
||||
nodes_to_symbols: &NodesToSymbols,
|
||||
symbols_to_types: &SymbolsToTypes,
|
||||
nodes_to_types: &NodesToTypes,
|
||||
) -> IrOperation {
|
||||
let lhs = self.lhs.lower_to_ir_expression(
|
||||
builder,
|
||||
nodes_to_symbols,
|
||||
symbols_to_types,
|
||||
nodes_to_types,
|
||||
);
|
||||
let rhs = self.rhs.lower_to_ir_expression(
|
||||
builder,
|
||||
nodes_to_symbols,
|
||||
symbols_to_types,
|
||||
nodes_to_types,
|
||||
);
|
||||
|
||||
let ir_binary_operator = match &self.op {
|
||||
BinaryOperation::Multiply => IrBinaryOperator::Multiply,
|
||||
BinaryOperation::Divide => IrBinaryOperator::Divide,
|
||||
BinaryOperation::Modulo => IrBinaryOperator::Modulo,
|
||||
BinaryOperation::Add => IrBinaryOperator::Add,
|
||||
BinaryOperation::Subtract => IrBinaryOperator::Subtract,
|
||||
BinaryOperation::LeftShift => IrBinaryOperator::LeftShift,
|
||||
BinaryOperation::RightShift => IrBinaryOperator::RightShift,
|
||||
BinaryOperation::BitwiseAnd => IrBinaryOperator::BitwiseAnd,
|
||||
BinaryOperation::BitwiseXor => IrBinaryOperator::BitwiseXor,
|
||||
BinaryOperation::BitwiseOr => IrBinaryOperator::BitwiseOr,
|
||||
};
|
||||
IrOperation::Binary(IrBinaryOperation::new(lhs, rhs, ir_binary_operator))
|
||||
}
|
||||
|
||||
#[deprecated]
|
||||
pub fn to_ir_operation(
|
||||
&self,
|
||||
builder: &mut IrBuilder,
|
||||
@ -559,6 +595,7 @@ impl BinaryExpression {
|
||||
IrOperation::Binary(ir_binary_operation)
|
||||
}
|
||||
|
||||
#[deprecated]
|
||||
pub fn to_ir_expression(
|
||||
&self,
|
||||
builder: &mut IrBuilder,
|
||||
@ -578,4 +615,29 @@ impl BinaryExpression {
|
||||
.add_statement(IrStatement::Assign(ir_assign));
|
||||
IrExpression::Variable(as_rc)
|
||||
}
|
||||
|
||||
pub fn lower_to_ir_expression(
|
||||
&self,
|
||||
builder: &mut IrBuilder,
|
||||
nodes_to_symbols: &NodesToSymbols,
|
||||
symbols_to_types: &SymbolsToTypes,
|
||||
nodes_to_types: &NodesToTypes,
|
||||
) -> IrExpression {
|
||||
let ir_operation =
|
||||
self.lower_to_ir_operation(builder, nodes_to_symbols, symbols_to_types, nodes_to_types);
|
||||
|
||||
let type_info = nodes_to_types.get(&self.node_id).unwrap();
|
||||
|
||||
let t_var = Rc::new(RefCell::new(IrVariable::new_vr(
|
||||
builder.new_t_var().into(),
|
||||
builder.current_block().id(),
|
||||
type_info,
|
||||
)));
|
||||
|
||||
let ir_assign = IrAssign::new(t_var.clone(), ir_operation);
|
||||
builder
|
||||
.current_block_mut()
|
||||
.add_statement(IrStatement::Assign(ir_assign));
|
||||
IrExpression::Variable(t_var)
|
||||
}
|
||||
}
|
||||
|
||||
@ -379,7 +379,12 @@ impl Expression {
|
||||
nodes_to_types: &NodesToTypes,
|
||||
) -> IrOperation {
|
||||
match self {
|
||||
Expression::Binary(binary_expression) => {}
|
||||
Expression::Binary(binary_expression) => binary_expression.lower_to_ir_operation(
|
||||
builder,
|
||||
nodes_to_symbols,
|
||||
symbols_to_types,
|
||||
nodes_to_types,
|
||||
),
|
||||
Expression::Negative(negative_expression) => {
|
||||
IrOperation::Load(negative_expression.lower_to_ir_expression(
|
||||
builder,
|
||||
|
||||
@ -329,9 +329,12 @@ impl LetStatement {
|
||||
symbols_to_types: &SymbolsToTypes,
|
||||
nodes_to_types: &NodesToTypes,
|
||||
) {
|
||||
let init_operation = self
|
||||
.initializer
|
||||
.lower_to_ir_operation(builder, nodes_to_types);
|
||||
let init_operation = self.initializer.lower_to_ir_operation(
|
||||
builder,
|
||||
nodes_to_symbols,
|
||||
symbols_to_types,
|
||||
nodes_to_types,
|
||||
);
|
||||
|
||||
let destination_symbol = nodes_to_symbols.get(&self.node_id).unwrap();
|
||||
let destination_type_info = symbols_to_types.get(destination_symbol).unwrap();
|
||||
|
||||
@ -209,15 +209,40 @@ impl NegativeExpression {
|
||||
|
||||
IrExpression::Variable(destination)
|
||||
}
|
||||
IrExpression::Variable(ir_variable) => {}
|
||||
IrExpression::Int(i) => {}
|
||||
IrExpression::Double(d) => {}
|
||||
IrExpression::Variable(ir_variable) => {
|
||||
let destination = Rc::new(RefCell::new(IrVariable::new_vr(
|
||||
builder.new_t_var().into(),
|
||||
builder.current_block().id(),
|
||||
ir_variable.borrow().type_info(),
|
||||
)));
|
||||
|
||||
let rhs = match ir_variable.borrow().type_info() {
|
||||
TypeInfo::Integer => IrExpression::Int(-1),
|
||||
TypeInfo::Double => IrExpression::Double(-1.0),
|
||||
_ => panic!(),
|
||||
};
|
||||
|
||||
let operation = IrOperation::Binary(IrBinaryOperation::new(
|
||||
IrExpression::Variable(ir_variable),
|
||||
rhs,
|
||||
IrBinaryOperator::Multiply,
|
||||
));
|
||||
|
||||
let ir_assign = IrAssign::new(destination.clone(), operation);
|
||||
builder
|
||||
.current_block_mut()
|
||||
.add_statement(IrStatement::Assign(ir_assign));
|
||||
IrExpression::Variable(destination)
|
||||
}
|
||||
IrExpression::Int(i) => IrExpression::Int(i * -1),
|
||||
IrExpression::Double(d) => IrExpression::Double(d * -1.0),
|
||||
IrExpression::String(_) => {
|
||||
panic!();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[deprecated]
|
||||
pub fn to_ir(
|
||||
&self,
|
||||
builder: &mut IrBuilder,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user