Skip to content

Commit

Permalink
assert()
Browse files Browse the repository at this point in the history
  • Loading branch information
momentarylapse committed Nov 28, 2024
1 parent f63f4c7 commit bea225e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/lib/kaba/dynamic/exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,5 +546,12 @@ void kaba_die(KabaException* e) {
just_die(e, trace);
}

void kaba_assert(bool b) {
if (!b) {
auto e = new KabaException("assert failed");
kaba_die(e);
}
}

}

5 changes: 3 additions & 2 deletions src/lib/kaba/dynamic/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class KabaException {
public:
string text;
KabaException(){}
KabaException(const string &message);
virtual ~KabaException(){}
explicit KabaException(const string &message);
virtual ~KabaException() = default;
void _cdecl __init__(const string &message);
virtual _cdecl void __delete__();
virtual _cdecl string message();
Expand All @@ -45,6 +45,7 @@ enum class ErrorID {

void _cdecl kaba_raise_exception(KabaException *kaba_exception);
void kaba_die(KabaException* e);
void kaba_assert(bool b);



Expand Down
2 changes: 2 additions & 0 deletions src/lib/kaba/lib/lib_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,8 @@ void SIAddPackageBase(Context *c) {
func_add_param("e", TypeExceptionXfer);
add_func("@die", TypeVoid, &kaba_die, Flags::Static | Flags::RaisesExceptions);
func_add_param("e", TypePointer);
add_func(Identifier::Assert, TypeVoid, &kaba_assert, Flags::Static | Flags::RaisesExceptions);
func_add_param("b", TypeBool);


// type casting
Expand Down
1 change: 1 addition & 0 deletions src/lib/kaba/syntax/Identifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ namespace Identifier {
const string Raise = "raise";
const string Try = "try";
const string Except = "except";
const string Assert = "assert";
const string If = "if";
const string Else = "else";
const string While = "while";
Expand Down
1 change: 1 addition & 0 deletions src/lib/kaba/syntax/Identifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ namespace Identifier {
extern const string Raise;
extern const string Try;
extern const string Except;
extern const string Assert;
extern const string If;
extern const string Else;
extern const string While;
Expand Down

0 comments on commit bea225e

Please sign in to comment.