]> git.lizzy.rs Git - nothing.git/blobdiff - src/ebisp/expr.c
(#594) assert -> trace_assert
[nothing.git] / src / ebisp / expr.c
index 9a7c029c03eb3bd3bf1804ffd3834675a2f9e417..16b4277df5bedae89185483cf97cc8fd13592f35 100644 (file)
@@ -1,4 +1,4 @@
-#include <assert.h>
+#include "system/stacktrace.h"
 #include <ctype.h>
 #include <stdarg.h>
 #include <stdio.h>
@@ -40,7 +40,7 @@ struct Expr void_expr(void)
 
 void print_atom_as_sexpr(FILE *stream, struct Atom *atom)
 {
-    assert(atom);
+    trace_assert(atom);
 
     switch (atom->type) {
     case ATOM_SYMBOL:
@@ -63,7 +63,7 @@ void print_atom_as_sexpr(FILE *stream, struct Atom *atom)
 
 void print_cons_as_sexpr(FILE *stream, struct Cons *head)
 {
-    assert(head);
+    trace_assert(head);
 
     struct Cons *cons = head;
 
@@ -266,8 +266,8 @@ void destroy_atom(struct Atom *atom)
 
 static int atom_as_sexpr(struct Atom *atom, char *output, size_t n)
 {
-    assert(atom);
-    assert(output);
+    trace_assert(atom);
+    trace_assert(output);
 
     switch (atom->type) {
     case ATOM_SYMBOL:
@@ -288,8 +288,8 @@ static int atom_as_sexpr(struct Atom *atom, char *output, size_t n)
 
 static int cons_as_sexpr(struct Cons *head, char *output, size_t n)
 {
-    assert(head);
-    assert(output);
+    trace_assert(head);
+    trace_assert(output);
 
     /* TODO(#378): cons_as_sexpr does not handle encoding errors of snprintf */
 
@@ -358,3 +358,26 @@ int expr_as_sexpr(struct Expr expr, char *output, size_t n)
 
     return 0;
 }
+
+const char *expr_type_as_string(enum ExprType expr_type)
+{
+    switch (expr_type) {
+    case EXPR_ATOM: return "EXPR_ATOM";
+    case EXPR_CONS: return "EXPR_CONS";
+    case EXPR_VOID: return "EXPR_VOID";
+    }
+
+    return "";
+}
+
+const char *atom_type_as_string(enum AtomType atom_type)
+{
+    switch (atom_type) {
+    case ATOM_SYMBOL: return "ATOM_SYMBOL";
+    case ATOM_NUMBER: return "ATOM_NUMBER";
+    case ATOM_STRING: return "ATOM_STRING";
+    case ATOM_NATIVE: return "ATOM_NATIVE";
+    }
+
+    return "";
+}