deimos-lang/dmc-lib/src/ast/expression_statement.rs
2026-02-28 08:22:57 -06:00

69 lines
2.0 KiB
Rust

use crate::ast::assemble_context::AssembleContext;
use crate::ast::expression::Expression;
use crate::ast::function::FunctionLoweringContext;
use crate::constants_table::ConstantsTable;
use crate::diagnostic::Diagnostic;
use crate::ir::ir_expression::IrExpression;
use crate::ir::ir_statement::IrStatement;
use crate::symbol_table::SymbolTable;
pub struct ExpressionStatement {
expression: Box<Expression>,
}
impl ExpressionStatement {
pub fn new(expression: Expression) -> Self {
Self {
expression: expression.into(),
}
}
pub fn expression(&self) -> &Expression {
&self.expression
}
pub fn gather_declared_names(&mut self, symbol_table: &mut SymbolTable) -> Vec<Diagnostic> {
self.expression.gather_declared_names(symbol_table)
}
pub fn check_name_usages(&mut self, symbol_table: &SymbolTable) -> Vec<Diagnostic> {
self.expression.check_name_usages(symbol_table)
}
pub fn type_check(&mut self, symbol_table: &SymbolTable) -> Vec<Diagnostic> {
self.expression.type_check(symbol_table)
}
pub fn lower_to_ir(&self, context: &mut FunctionLoweringContext) {
let ir_expression = self.expression.lower_to_ir(context);
match ir_expression {
IrExpression::Call(ir_call) => {
context.add_statement(IrStatement::Call(ir_call));
}
IrExpression::Constant(ir_constant) => {
unimplemented!()
}
IrExpression::IntegerLiteral(i) => {
unimplemented!()
}
IrExpression::Variable(ir_variable) => {
unimplemented!()
}
}
}
pub fn assemble(
&self,
context: &mut AssembleContext,
symbol_table: &SymbolTable,
constants_table: &mut ConstantsTable,
) {
match self.expression.as_ref() {
Expression::Call(call) => {
call.assemble(context, symbol_table, constants_table);
}
_ => unreachable!(),
}
}
}