lisp: INT -> SMI

when we implement big integer support, we should use INT there
instead.  SMI signals intent much better.
This commit is contained in:
2026-03-05 19:41:16 +00:00
parent a50ca72b24
commit b93042fd27
6 changed files with 22 additions and 22 deletions

View File

@@ -26,7 +26,7 @@ typedef struct
/// Tagging system /// Tagging system
typedef enum Tag typedef enum Tag
{ {
TAG_INT = 0b00000001, // Atomic types TAG_SMI = 0b00000001, // Atomic types
TAG_SYM = 0b00000011, TAG_SYM = 0b00000011,
TAG_NIL = 0b00000000, // Container types (0 LSB) TAG_NIL = 0b00000000, // Container types (0 LSB)
TAG_CONS = 0b00000010, TAG_CONS = 0b00000010,
@@ -48,13 +48,13 @@ typedef enum Tag
#define INT_MIN (-(INT_MAX + 1)) #define INT_MIN (-(INT_MAX + 1))
tag_t get_tag(const lisp_t *); tag_t get_tag(const lisp_t *);
lisp_t *tag_int(const i64); lisp_t *tag_smi(const i64);
lisp_t *tag_sym(const char *); lisp_t *tag_sym(const char *);
lisp_t *tag_cons(const cons_t *); lisp_t *tag_cons(const cons_t *);
lisp_t *tag_vec(const vec_t *); lisp_t *tag_vec(const vec_t *);
lisp_t *tag_generic(void *, tag_t); lisp_t *tag_generic(void *, tag_t);
i64 as_int(lisp_t *); i64 as_smi(lisp_t *);
char *as_sym(lisp_t *); char *as_sym(lisp_t *);
cons_t *as_cons(lisp_t *); cons_t *as_cons(lisp_t *);
vec_t *as_vec(lisp_t *); vec_t *as_vec(lisp_t *);

View File

@@ -32,7 +32,7 @@ alloc_node_t *make_node(page_t *page, tag_t type)
size += sizeof(vec_t); size += sizeof(vec_t);
break; break;
case TAG_NIL: case TAG_NIL:
case TAG_INT: case TAG_SMI:
case TAG_SYM: case TAG_SYM:
default: default:
FAIL("Unreachable"); FAIL("Unreachable");
@@ -61,7 +61,7 @@ alloc_node_t *lisp_to_node(lisp_t *lisp)
raw_ptr = as_vec(lisp); raw_ptr = as_vec(lisp);
break; break;
case TAG_NIL: // These shouldn't be allocated case TAG_NIL: // These shouldn't be allocated
case TAG_INT: case TAG_SMI:
case TAG_SYM: case TAG_SYM:
default: default:
FAIL("Unreachable"); FAIL("Unreachable");
@@ -80,7 +80,7 @@ lisp_t *alloc_make(alloc_t *alloc, tag_t type)
case TAG_VEC: case TAG_VEC:
break; break;
case TAG_NIL: // These shouldn't be allocated case TAG_NIL: // These shouldn't be allocated
case TAG_INT: case TAG_SMI:
case TAG_SYM: case TAG_SYM:
default: default:
FAIL("Unreachable"); FAIL("Unreachable");
@@ -181,7 +181,7 @@ void alloc_free(alloc_t *alloc)
vec_free((vec_t *)node->data); vec_free((vec_t *)node->data);
break; break;
case TAG_NIL: case TAG_NIL:
case TAG_INT: case TAG_SMI:
case TAG_SYM: case TAG_SYM:
default: default:
FAIL("Unreachable"); FAIL("Unreachable");

View File

@@ -10,9 +10,9 @@
#include <alisp/lisp.h> #include <alisp/lisp.h>
lisp_t *tag_int(i64 i) lisp_t *tag_smi(i64 i)
{ {
return TAG(i, INT); return TAG(i, SMI);
} }
lisp_t *tag_sym(const char *str) lisp_t *tag_sym(const char *str)
@@ -36,8 +36,8 @@ lisp_t *tag_generic(void *ptr, tag_t type)
{ {
case TAG_NIL: case TAG_NIL:
return TAG(ptr, NIL); return TAG(ptr, NIL);
case TAG_INT: case TAG_SMI:
return tag_int((i64)ptr); return tag_smi((i64)ptr);
case TAG_SYM: case TAG_SYM:
return tag_sym(ptr); return tag_sym(ptr);
case TAG_CONS: case TAG_CONS:
@@ -56,9 +56,9 @@ tag_t get_tag(const lisp_t *lisp)
return GET_TAG(lisp); return GET_TAG(lisp);
} }
i64 as_int(lisp_t *obj) i64 as_smi(lisp_t *obj)
{ {
assert(IS_TAG(obj, INT)); assert(IS_TAG(obj, SMI));
u64 raw_obj = UNTAG(obj); u64 raw_obj = UNTAG(obj);
u64 msb = (NTH_BYTE(raw_obj, 6) & 0x80) >> 7; u64 msb = (NTH_BYTE(raw_obj, 6) & 0x80) >> 7;
msb = ((1LU << 8) - msb) << 56; msb = ((1LU << 8) - msb) << 56;
@@ -92,11 +92,11 @@ void lisp_print(FILE *fp, lisp_t *lisp)
case TAG_NIL: case TAG_NIL:
fprintf(fp, "NIL"); fprintf(fp, "NIL");
break; break;
case TAG_INT: case TAG_SMI:
#if VERBOSE_LOGS == 2 #if VERBOSE_LOGS == 2
fprintf(fp, "INT["); fprintf(fp, "INT[");
#endif #endif
fprintf(fp, "%ld", as_int(lisp)); fprintf(fp, "%ld", as_smi(lisp));
#if VERBOSE_LOGS == 2 #if VERBOSE_LOGS == 2
fprintf(fp, "]"); fprintf(fp, "]");
#endif #endif
@@ -186,7 +186,7 @@ u64 tag_sizeof(tag_t tag)
{ {
case TAG_NIL: case TAG_NIL:
return 0; return 0;
case TAG_INT: case TAG_SMI:
case TAG_SYM: case TAG_SYM:
return sizeof(lisp_t *); return sizeof(lisp_t *);
case TAG_CONS: case TAG_CONS:

View File

@@ -111,7 +111,7 @@ read_err_t read_negative(sys_t *sys, stream_t *stream, lisp_t **ret)
read_err_t err = read_int(sys, stream, ret); read_err_t err = read_int(sys, stream, ret);
if (err) if (err)
return err; return err;
i64 n = as_int(*ret); i64 n = as_smi(*ret);
n *= -1; n *= -1;
*ret = make_int(n); *ret = make_int(n);
return READ_ERR_OK; return READ_ERR_OK;

View File

@@ -46,7 +46,7 @@ void sys_free(sys_t *sys)
lisp_t *make_int(i64 i) lisp_t *make_int(i64 i)
{ {
return tag_int(i); return tag_smi(i);
} }
lisp_t *cons(sys_t *sys, lisp_t *car, lisp_t *cdr) lisp_t *cons(sys_t *sys, lisp_t *car, lisp_t *cdr)
@@ -102,7 +102,7 @@ void lisp_free(lisp_t *item)
break; break;
} }
case TAG_NIL: case TAG_NIL:
case TAG_INT: case TAG_SMI:
case TAG_SYM: case TAG_SYM:
case NUM_TAGS: case NUM_TAGS:
// shouldn't be dealt with (either constant or dealt with elsewhere) // shouldn't be dealt with (either constant or dealt with elsewhere)
@@ -134,7 +134,7 @@ void lisp_free_rec(lisp_t *item)
break; break;
} }
case TAG_NIL: case TAG_NIL:
case TAG_INT: case TAG_SMI:
case TAG_SYM: case TAG_SYM:
case NUM_TAGS: case NUM_TAGS:
// shouldn't be dealt with (either constant or dealt with elsewhere) // shouldn't be dealt with (either constant or dealt with elsewhere)

View File

@@ -23,7 +23,7 @@ void smi_test(void)
{ {
i64 in = ints[i]; i64 in = ints[i];
lisp_t *lisp = make_int(in); lisp_t *lisp = make_int(in);
i64 out = as_int(lisp); i64 out = as_smi(lisp);
TEST(in == out, "%ld == %ld", in, out); TEST(in == out, "%ld == %ld", in, out);
} }
@@ -47,7 +47,7 @@ void smi_oob_test(void)
{ {
i64 in = ints[i]; i64 in = ints[i];
lisp_t *lisp = make_int(in); lisp_t *lisp = make_int(in);
i64 out = as_int(lisp); i64 out = as_smi(lisp);
TEST(in != out, "%ld != %ld", in, out); TEST(in != out, "%ld != %ld", in, out);
} }