diff --git a/cpp/src/ast.hpp b/cpp/src/ast.hpp index ed6477b..5fb8cb7 100644 --- a/cpp/src/ast.hpp +++ b/cpp/src/ast.hpp @@ -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(this->type)]); diff --git a/cpp/src/codegen.cpp b/cpp/src/codegen.cpp index b01b44a..f0b14d0 100644 --- a/cpp/src/codegen.cpp +++ b/cpp/src/codegen.cpp @@ -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" @@ -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."); diff --git a/cpp/src/parse.cpp b/cpp/src/parse.cpp index fc1d358..c94524a 100644 --- a/cpp/src/parse.cpp +++ b/cpp/src/parse.cpp @@ -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 params = {}; while(!this->match(lexer::token::type::close_paren)) { diff --git a/samples/scratchpad.psy b/samples/scratchpad.psy index 429013d..2f3ca02 100644 --- a/samples/scratchpad.psy +++ b/samples/scratchpad.psy @@ -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());