From: Michael D. Lowis Date: Mon, 17 Jun 2024 02:41:39 +0000 (-0400) Subject: added assert and error X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=d3ab3ac44b8095878fcdb5c0a84e6cb80c74dd79;p=proto%2Fcerise-c.git added assert and error --- diff --git a/runtime.h b/runtime.h index 2a29bee..92b118f 100644 --- a/runtime.h +++ b/runtime.h @@ -199,20 +199,14 @@ Value ToString(Value val); /* Builtin Functions *************************************************/ -static void Error(Value val) { - fprintf(stderr, "fatal error: %s\n", ValueAsString(val)->bytes); - exit(1); -} -static void Assert(char* file, int lineno, Value val) { - if (IsFalse(val) || IsNil(val)) { - fprintf(stderr, "%s:%d:error: Assertion failed\n", file, lineno); - exit(1); - } -} +void Error(Value val); +void Assert(char* file, int lineno, Value val); + /* Binary Operators *************************************************/ + Value OpAdd(Value left, Value right); Value OpSub(Value left, Value right); Value OpMul(Value left, Value right); @@ -227,6 +221,7 @@ Value OpNeq(Value left, Value right); /* Arrays And Hashes *************************************************/ + void Array_Set(Value array, int index, Value value); Value Array_Get(Value array, int index); diff --git a/runtime/Assert.c b/runtime/Assert.c new file mode 100644 index 0000000..fc6896b --- /dev/null +++ b/runtime/Assert.c @@ -0,0 +1,8 @@ +#include "runtime.h" + +void Assert(char* file, int lineno, Value val) { + if (IsFalse(val) || IsNil(val)) { + fprintf(stderr, "%s:%d:error: Assertion failed\n", file, lineno); + exit(1); + } +} diff --git a/runtime/Error.c b/runtime/Error.c new file mode 100644 index 0000000..bb99752 --- /dev/null +++ b/runtime/Error.c @@ -0,0 +1,6 @@ +#include "runtime.h" + +void Error(Value val) { + fprintf(stderr, "fatal error: %s\n", ValueAsString(val)->bytes); + exit(1); +}