aboutsummaryrefslogtreecommitdiff
path: root/src/sexp.c
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-06-18 20:55:54 +0800
committerMistivia <i@mistivia.com>2025-06-18 20:55:54 +0800
commit0b335dc24e76cace44e748e62d5cbbc40c4355f5 (patch)
tree5fa2ef69b88908a8ddb6c78624919d967fcba875 /src/sexp.c
parent6f1cfbda4a519ad8a232d126539a2732ab43c671 (diff)
finish parser
Diffstat (limited to 'src/sexp.c')
-rw-r--r--src/sexp.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/sexp.c b/src/sexp.c
index b268414..5e80d07 100644
--- a/src/sexp.c
+++ b/src/sexp.c
@@ -1,8 +1,30 @@
#include "sexp.h"
#include "algds/vec.h"
+#include <inttypes.h>
+
+void SExpRef_show(SExpRef self, FILE* fp) { }
+
void SExp_show(SExp self, FILE* fp) {
- fprintf(fp, "{SEXP}");
+ if (self.type == kEmptySExp) fprintf(fp, "<EMPTY>");
+ else if (self.type == kIntegerSExp) fprintf(fp, "%"PRId64, self.integer);
+ else if (self.type == kRealSExp) fprintf(fp, "%lf", self.real);
+ else if (self.type == kBooleanSExp) {
+ if (self.boolean) fprintf(fp, "#t");
+ else fprintf(fp, "#f");
+ } else if (self.type == kNilSExp) fprintf(fp, "()");
+ else if (self.type == kCharSExp) fprintf(fp, "#\\%c", self.character);
+ else if (self.type == kStringSExp) fprintf(fp, "\"%s\"", self.str);
+ else if (self.type == kSymbolSExp) fprintf(fp, "'%s", self.str);
+ else if (self.type == kUserDataSExp) fprintf(fp, "<%p>", self.userdata);
+ else if (self.type == kFuncSExp) fprintf(fp, "<FUNCTION>");
+ else if (self.type == kPairSExp) {
+ fprintf(fp, "(<%d> . <%d>)", self.pair.car.idx, self.pair.cdr.idx);
+ }
+ else if (self.type == kEnvSExp) fprintf(fp, "<Env>");
+ else if (self.type == kBindingSExp) fprintf(fp, "<BINDING>");
+ else if (self.type == kMacroSExp) fprintf(fp, "<MACRO>");
}
VECTOR_IMPL(SExp);
+VECTOR_IMPL(SExpRef);