Skip to content

Commit

Permalink
[cpp] various bugfixes and added __builtin_debugbreak
Browse files Browse the repository at this point in the history
  • Loading branch information
harrand committed Apr 30, 2024
1 parent 3881642 commit ca4cc59
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cpp/src/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ struct ast
type == lexer::token::type::bitwise_complement ||
type == lexer::token::type::logical_negation ||
type == lexer::token::type::ref ||
type == lexer::token::type::deref,
type == lexer::token::type::deref ||
type == lexer::token::type::defer,
"internal compiler error: parsed a unary_operator via lexer token type that doesn't represent a unary operator."
);
return std::format("unary-operator \"{}\"", lexer::token_type_names[static_cast<int>(this->type)]);
Expand Down
7 changes: 7 additions & 0 deletions cpp/src/codegen.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "codegen.hpp"
#include "diag.hpp"
#include "semantic.hpp"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/LLVMContext.h"

#include "llvm/ADT/APInt.h"
Expand Down Expand Up @@ -1364,6 +1365,12 @@ namespace codegen
type ty = this->state.try_get_type_from_payload(ptr_expr, this->tree, this->path);
ret = string_literal(*this, {.val = ty.name()});
}
if(call.function_name == "__builtin_debugbreak")
{
this->assert_that(call.params.empty(), "debugbreak takes no arguments.");
ret.llv = builder->CreateCall(llvm::Intrinsic::getDeclaration(program.get(), llvm::Intrinsic::trap));
ret.ty = type::from_primitive(primitive_type::u0);
}
if(call.function_name == "__builtin_sizeof")
{
this->assert_that(call.params.size() == 1, "__builtin_typename requires one argument.");
Expand Down
7 changes: 5 additions & 2 deletions cpp/src/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,11 @@ namespace parser
return std::nullopt;
}
std::string function_name = this->last_value();
this->must_match(lexer::token::type::colon);
this->must_match(lexer::token::type::open_paren);
if(!(this->match(lexer::token::type::colon) && this->match(lexer::token::type::open_paren)))
{
this->restore_index();
return std::nullopt;
}
std::vector<ast::variable_declaration> params = {};
while(!this->match(lexer::token::type::close_paren))
{
Expand Down
1 change: 1 addition & 0 deletions samples/scratchpad.psy
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ main : (argc : i64, argv : i8**) -> i64
defer default_free(shape_ptr);
= shape_ptr->base 'A';
= shape_ptr->height 19;
__builtin_debugbreak();

puts("the value is: ");
putchar(shape_ptr->get_half_perimeter());
Expand Down

0 comments on commit ca4cc59

Please sign in to comment.