reimplementation (oupsi)

This commit is contained in:
Lobo 2026-01-10 10:03:31 -03:00
parent 0572264f76
commit 1aec6085d9
27 changed files with 1213 additions and 21 deletions

43
src/type.c Normal file
View file

@ -0,0 +1,43 @@
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <wolflisp.h>
// clang-format off
static const char *typenames[] = {
[TYPE_NIL] = "nil",
[TYPE_NUM] = "number",
[TYPE_SYM] = "symbol",
[TYPE_PRIM] = "primitive",
[TYPE_PAIR] = "pair",
[TYPE_CLOS] = "closure",
};
// clang-format on
I type(O obj) {
if (obj == NIL) {
return TYPE_NIL;
} else if (IMM(obj)) {
return TYPE_NUM;
} else {
switch (TAG_OF(obj)) {
case TAG_SYM:
return TYPE_SYM;
case TAG_PRIM:
return TYPE_PRIM;
case TAG_MAN: {
Gh *hdr = UNBOX(obj);
return hdr->type;
}
default:
fprintf(stderr, "unknown pointer tag %" PRIdPTR "\n", TAG_OF(obj));
abort();
}
}
}
const char *typename(I t) {
if (t >= TYPE__MAX)
return "??";
return typenames[t];
}