pcm4/stage2/include/lisp.h

48 lines
1.0 KiB
C++

#pragma once
#include <cstdint>
#define SYMBOL_TABLE_SIZE 2048
typedef unsigned int symbol_t;
#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;
};
};
};
};
symbol_t intern_symbol(const char *s);
symbol_t make_symbol(const char *s);
static auto NIL = make_symbol("nil");
cell head(cell x);
cell tail(cell x);