diff --git a/cpp/src/codegen.cpp b/cpp/src/codegen.cpp index 56a0c71..a84f0f4 100644 --- a/cpp/src/codegen.cpp +++ b/cpp/src/codegen.cpp @@ -3,6 +3,7 @@ #include "builtin.hpp" #include "llvm/BinaryFormat/Dwarf.h" #include "llvm/IR/DIBuilder.h" +#include "llvm/IR/InlineAsm.h" #include "llvm/IR/Intrinsics.h" #include "llvm/IR/LLVMContext.h" @@ -1814,8 +1815,15 @@ namespace code } break; case builtin::debugbreak: - ret.llv = builder->CreateCall(llvm::Intrinsic::getDeclaration(program.get(), llvm::Intrinsic::trap)); + { + // trap doesn't seem to be continuable so this is not a good fit. + //ret.llv = builder->CreateCall(llvm::Intrinsic::getDeclaration(program.get(), llvm::Intrinsic::trap)); + // inline-asm int3 is a winner if it can be done: + llvm::InlineAsm* int3 = llvm::InlineAsm::get(llvm::FunctionType::get(llvm::Type::getVoidTy(*ctx), false), "int3", "~{dirflag},~{fpsr},~{flags}", true, false, llvm::InlineAsm::AsmDialect::AD_ATT); + llvm::CallInst* int3call = builder->CreateCall(int3, {}); + int3call->addAttributeAtIndex(llvm::AttributeList::FunctionIndex, llvm::Attribute::NoUnwind); ret.ty = func.return_ty; + } break; default: d.ctx.error(error_code::nyi, "missing codegen for builtin \"{}\"", call.function_name); diff --git a/cpp/src/parse.cpp b/cpp/src/parse.cpp index 84b0e8c..d93f0b1 100644 --- a/cpp/src/parse.cpp +++ b/cpp/src/parse.cpp @@ -1644,6 +1644,7 @@ namespace parse shift(); while(this->reduce()){} } + while(this->reduce()){} // next level and go again (until when???) std::size_t error_count = 0; diff --git a/samples/scratchpad.psy b/samples/scratchpad.psy index 7ef03d0..9d1604a 100644 --- a/samples/scratchpad.psy +++ b/samples/scratchpad.psy @@ -1,6 +1,7 @@ main :: () -> i64 { puts("hello world! ;)"); + assert(false, "woopsie!"); greeting : string; defer greeting.cleanup(); diff --git a/stdlib/stdlib.psy b/stdlib/stdlib.psy index 2ee808d..c105e9d 100644 --- a/stdlib/stdlib.psy +++ b/stdlib/stdlib.psy @@ -40,8 +40,18 @@ string :: struct strcpy(this.str, literal); } - //print :: () -> u0 - //{ - // puts(this.str); - //} + print :: () -> u0 + { + puts(this.str); + } +} + +assert :: (expr : bool, msg : i8& const) -> u0 +{ + if (expr != true) + { + puts(msg); + __builtin_debugbreak(); + } } +// \ No newline at end of file