Codegen unary expressions

This commit is contained in:
Sofia 2026-04-28 00:16:16 +03:00
parent 00689d3637
commit dd632b6bcc

View File

@ -448,11 +448,18 @@ namespace AST {
}
std::shared_ptr<types::Type> UnaryExpression::get_codegen_type(codegen::Scope& scope) {
return this->m_expr->get_codegen_type(scope);
auto unary = types::find_unop(scope.unops, this->m_expr->get_codegen_type(scope), this->m_unary);
return unary->res;
}
codegen::StackValue UnaryExpression::codegen(codegen::Builder&, codegen::Scope&, codegen::StackAllocator&) {
throw std::runtime_error("TODO");
codegen::StackValue UnaryExpression::codegen(codegen::Builder& builder, codegen::Scope& scope, codegen::StackAllocator& allocator) {
auto unary = types::find_unop(scope.unops, this->m_expr->get_codegen_type(scope), this->m_unary);
auto lvalue = scope.with_lvalue();
auto expr_ptr = this->m_expr->codegen(builder, lvalue, allocator);
return {
unary->codegen(builder, this->m_expr->get_codegen_type(scope), expr_ptr.value),
unary->res
};
}
void ReturnStatement::codegen(codegen::Builder& builder, codegen::Scope& scope, codegen::StackAllocator& allocator) {