diff --git a/src/codegen.cpp b/src/codegen.cpp index 5fe88c3..f90a63b 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -448,11 +448,18 @@ namespace AST { } std::shared_ptr 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) {