Filling various code holes. WIP.
This commit is contained in:
parent
9d3e906957
commit
34480a0870
@ -12,6 +12,7 @@ use crate::ir::ir_assign::IrAssign;
|
|||||||
use crate::ir::ir_set_field::IrSetField;
|
use crate::ir::ir_set_field::IrSetField;
|
||||||
use crate::ir::ir_statement::IrStatement;
|
use crate::ir::ir_statement::IrStatement;
|
||||||
use crate::source_range::SourceRange;
|
use crate::source_range::SourceRange;
|
||||||
|
use crate::symbol::Symbol;
|
||||||
use crate::symbol::class_symbol::ClassSymbol;
|
use crate::symbol::class_symbol::ClassSymbol;
|
||||||
use crate::symbol::expressible_symbol::ExpressibleSymbol;
|
use crate::symbol::expressible_symbol::ExpressibleSymbol;
|
||||||
use crate::symbol_table::SymbolTable;
|
use crate::symbol_table::SymbolTable;
|
||||||
@ -226,6 +227,7 @@ impl AssignStatement {
|
|||||||
(nodes_to_types, diagnostics)
|
(nodes_to_types, diagnostics)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[deprecated]
|
||||||
pub fn type_check(
|
pub fn type_check(
|
||||||
&mut self,
|
&mut self,
|
||||||
symbol_table: &SymbolTable,
|
symbol_table: &SymbolTable,
|
||||||
@ -358,6 +360,7 @@ impl AssignStatement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[deprecated]
|
||||||
pub fn to_ir(
|
pub fn to_ir(
|
||||||
&self,
|
&self,
|
||||||
builder: &mut IrBuilder,
|
builder: &mut IrBuilder,
|
||||||
@ -399,6 +402,60 @@ impl AssignStatement {
|
|||||||
|
|
||||||
builder.current_block_mut().add_statement(ir_statement);
|
builder.current_block_mut().add_statement(ir_statement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn lower_to_ir(
|
||||||
|
&self,
|
||||||
|
builder: &mut IrBuilder,
|
||||||
|
nodes_to_symbols: &NodesToSymbols,
|
||||||
|
symbols_to_types: &SymbolsToTypes,
|
||||||
|
nodes_to_types: &NodesToTypes,
|
||||||
|
) {
|
||||||
|
let destination_expressible_symbol = match self.destination.as_ref() {
|
||||||
|
Expression::Identifier(identifier) => nodes_to_symbols
|
||||||
|
.get(&identifier.scope_id())
|
||||||
|
.unwrap()
|
||||||
|
.unwrap_expressible_symbol(),
|
||||||
|
_ => unreachable!("Destination must be a mutable L value"),
|
||||||
|
};
|
||||||
|
|
||||||
|
let ir_statement = match destination_expressible_symbol {
|
||||||
|
ExpressibleSymbol::Field(field_symbol) => {
|
||||||
|
let field_type = symbols_to_types
|
||||||
|
.get(&Symbol::Field(field_symbol.clone()))
|
||||||
|
.unwrap();
|
||||||
|
let mut_field_pointer_variable =
|
||||||
|
get_or_init_mut_field_pointer_variable(builder, &field_symbol, field_type)
|
||||||
|
.clone();
|
||||||
|
|
||||||
|
let ir_set_field = IrSetField::new(
|
||||||
|
&mut_field_pointer_variable,
|
||||||
|
self.value.lower_to_ir_expression(
|
||||||
|
builder,
|
||||||
|
nodes_to_symbols,
|
||||||
|
symbols_to_types,
|
||||||
|
nodes_to_types,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
IrStatement::SetField(ir_set_field)
|
||||||
|
}
|
||||||
|
ExpressibleSymbol::Variable(variable_symbol) => {
|
||||||
|
let ir_variable = builder.local_variables().get(&variable_symbol).unwrap();
|
||||||
|
let ir_assign = IrAssign::new(
|
||||||
|
ir_variable.clone(),
|
||||||
|
self.value.lower_to_ir_operation(
|
||||||
|
builder,
|
||||||
|
nodes_to_symbols,
|
||||||
|
symbols_to_types,
|
||||||
|
nodes_to_types,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
IrStatement::Assign(ir_assign)
|
||||||
|
}
|
||||||
|
_ => unreachable!("Destination must be a mutable L value"),
|
||||||
|
};
|
||||||
|
|
||||||
|
builder.current_block_mut().add_statement(ir_statement);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@ -10,14 +10,13 @@ use crate::diagnostic_factories::{
|
|||||||
use crate::ir::ir_call::IrCall;
|
use crate::ir::ir_call::IrCall;
|
||||||
use crate::ir::ir_expression::IrExpression;
|
use crate::ir::ir_expression::IrExpression;
|
||||||
use crate::source_range::SourceRange;
|
use crate::source_range::SourceRange;
|
||||||
use crate::symbol::Symbol;
|
|
||||||
use crate::symbol::callable_symbol::CallableSymbol;
|
use crate::symbol::callable_symbol::CallableSymbol;
|
||||||
use crate::symbol::class_symbol::ClassSymbol;
|
use crate::symbol::class_symbol::ClassSymbol;
|
||||||
use crate::symbol::expressible_symbol::ExpressibleSymbol;
|
use crate::symbol::expressible_symbol::ExpressibleSymbol;
|
||||||
|
use crate::symbol::Symbol;
|
||||||
use crate::symbol_table::SymbolTable;
|
use crate::symbol_table::SymbolTable;
|
||||||
use crate::type_info::TypeInfo;
|
use crate::type_info::TypeInfo;
|
||||||
use crate::types_table::TypesTable;
|
use crate::types_table::TypesTable;
|
||||||
use std::thread::Builder;
|
|
||||||
|
|
||||||
pub struct Call {
|
pub struct Call {
|
||||||
node_id: NodeId,
|
node_id: NodeId,
|
||||||
|
|||||||
@ -17,9 +17,9 @@ use crate::error_codes::{FIELD_MULTIPLE_INIT, FIELD_UNINIT};
|
|||||||
use crate::ir::ir_class::{IrClass, IrField};
|
use crate::ir::ir_class::{IrClass, IrField};
|
||||||
use crate::ir::ir_function::IrFunction;
|
use crate::ir::ir_function::IrFunction;
|
||||||
use crate::source_range::SourceRange;
|
use crate::source_range::SourceRange;
|
||||||
|
use crate::symbol::Symbol;
|
||||||
use crate::symbol::class_symbol::ClassSymbol;
|
use crate::symbol::class_symbol::ClassSymbol;
|
||||||
use crate::symbol::constructor_symbol::ConstructorSymbol;
|
use crate::symbol::constructor_symbol::ConstructorSymbol;
|
||||||
use crate::symbol::Symbol;
|
|
||||||
use crate::symbol_table::SymbolTable;
|
use crate::symbol_table::SymbolTable;
|
||||||
use crate::type_info::TypeInfo;
|
use crate::type_info::TypeInfo;
|
||||||
use crate::types_table::TypesTable;
|
use crate::types_table::TypesTable;
|
||||||
|
|||||||
@ -425,7 +425,7 @@ impl Constructor {
|
|||||||
|
|
||||||
// PART 3. Constructor statements
|
// PART 3. Constructor statements
|
||||||
for statement in &self.statements {
|
for statement in &self.statements {
|
||||||
statement.lower(
|
statement.lower_to_ir(
|
||||||
&mut ir_builder,
|
&mut ir_builder,
|
||||||
nodes_to_symbols,
|
nodes_to_symbols,
|
||||||
symbols_to_types,
|
symbols_to_types,
|
||||||
|
|||||||
@ -140,4 +140,25 @@ impl ExpressionStatement {
|
|||||||
.add_statement(IrStatement::Return(IrReturn::new(ir_expression)));
|
.add_statement(IrStatement::Return(IrReturn::new(ir_expression)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn lower_to_ir(
|
||||||
|
&self,
|
||||||
|
builder: &mut IrBuilder,
|
||||||
|
nodes_to_symbols: &NodesToSymbols,
|
||||||
|
symbols_to_types: &SymbolsToTypes,
|
||||||
|
nodes_to_types: &NodesToTypes,
|
||||||
|
is_return_statement: bool,
|
||||||
|
) {
|
||||||
|
let ir_expression = self.expression.lower_to_ir_expression(
|
||||||
|
builder,
|
||||||
|
nodes_to_symbols,
|
||||||
|
symbols_to_types,
|
||||||
|
nodes_to_types,
|
||||||
|
);
|
||||||
|
if is_return_statement {
|
||||||
|
builder
|
||||||
|
.current_block_mut()
|
||||||
|
.add_statement(IrStatement::Return(IrReturn::new(Some(ir_expression))));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -492,7 +492,7 @@ impl Function {
|
|||||||
let should_return_value = !matches!(return_type_info, TypeInfo::Void);
|
let should_return_value = !matches!(return_type_info, TypeInfo::Void);
|
||||||
for (i, statement) in self.statements.iter().enumerate() {
|
for (i, statement) in self.statements.iter().enumerate() {
|
||||||
let is_last = i == self.statements.len() - 1;
|
let is_last = i == self.statements.len() - 1;
|
||||||
statement.lower(
|
statement.lower_to_ir(
|
||||||
&mut builder,
|
&mut builder,
|
||||||
nodes_to_symbols,
|
nodes_to_symbols,
|
||||||
symbols_to_types,
|
symbols_to_types,
|
||||||
|
|||||||
@ -199,7 +199,7 @@ impl Statement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lower(
|
pub fn lower_to_ir(
|
||||||
&self,
|
&self,
|
||||||
builder: &mut IrBuilder,
|
builder: &mut IrBuilder,
|
||||||
nodes_to_symbols: &NodesToSymbols,
|
nodes_to_symbols: &NodesToSymbols,
|
||||||
@ -211,8 +211,23 @@ impl Statement {
|
|||||||
Statement::Let(let_statement) => {
|
Statement::Let(let_statement) => {
|
||||||
let_statement.lower(builder, nodes_to_symbols, symbols_to_types, nodes_to_types);
|
let_statement.lower(builder, nodes_to_symbols, symbols_to_types, nodes_to_types);
|
||||||
}
|
}
|
||||||
Statement::Expression(expression_statement) => {}
|
Statement::Expression(expression_statement) => {
|
||||||
Statement::Assign(assign_statement) => {}
|
expression_statement.lower_to_ir(
|
||||||
|
builder,
|
||||||
|
nodes_to_symbols,
|
||||||
|
symbols_to_types,
|
||||||
|
nodes_to_types,
|
||||||
|
is_return_statement,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Statement::Assign(assign_statement) => {
|
||||||
|
assign_statement.lower_to_ir(
|
||||||
|
builder,
|
||||||
|
nodes_to_symbols,
|
||||||
|
symbols_to_types,
|
||||||
|
nodes_to_types,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user