]> git.mdlowis.com Git - proto/cerise-c.git/commitdiff
added assert and error
authorMichael D. Lowis <mike@mdlowis.com>
Mon, 17 Jun 2024 02:41:39 +0000 (22:41 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Mon, 17 Jun 2024 02:41:39 +0000 (22:41 -0400)
runtime.h
runtime/Assert.c [new file with mode: 0644]
runtime/Error.c [new file with mode: 0644]

index 2a29bee2f5f58b0fbe23ec5a09e1d63eaf99cad7..92b118f8b4f8b4803a66dd32f36a27a6633c4fe8 100644 (file)
--- 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 (file)
index 0000000..fc6896b
--- /dev/null
@@ -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 (file)
index 0000000..bb99752
--- /dev/null
@@ -0,0 +1,6 @@
+#include "runtime.h"
+
+void Error(Value val) {
+    fprintf(stderr, "fatal error: %s\n", ValueAsString(val)->bytes);
+    exit(1);
+}