pcm4/stage2/include/lisp.h

48 lines
1.0 KiB
C
Raw Normal View History

2023-10-01 23:36:22 +00:00
#pragma once
#include <cstdint>
#define SYMBOL_TABLE_SIZE 2048
2023-10-02 01:00:25 +00:00
typedef unsigned int symbol_t;
2023-10-01 23:36:22 +00:00
#define TYPE_SYMBOL 1
#define TYPE_NUMBER 2
#define TYPE_STRING 3
#define TYPE_FLOAT 4
#define TYPE_LIST 5
#define symbolp(x) (x->type == TYPE_SYMBOL)
#define numberp(x) (x->type == TYPE_NUMBER)
#define stringp(x) (x->type == TYPE_STRING)
#define floatp(x) (x->type == TYPE_FLOAT)
#define listp(x) (x->type == TYPE_LIST)
typedef struct cell {
uint8_t type;
union {
struct {
cell *head;
cell *tail;
};
struct {
union {
symbol_t sym;
int num;
char *str;
float fnum;
};
};
};
2023-10-02 01:00:25 +00:00
};
symbol_t intern_symbol(const char *s);
symbol_t make_symbol(const char *s);
static auto NIL = make_symbol("nil");
2023-10-01 23:36:22 +00:00
2023-10-02 01:00:25 +00:00
cell head(cell x);
cell tail(cell x);