Files
imp/lib/include/expr.h

57 lines
983 B
C

#ifndef EXPR_H
#define EXPR_H
#define MAX_SYMBOL_LEN 32U
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
struct am;
typedef struct {
char buf[MAX_SYMBOL_LEN];
size_t len;
} symbol_t;
typedef void (*prim_proc_t)(struct am *am);
typedef enum {
ATOM_TYPE_EMPTY_LIST,
ATOM_TYPE_INTEGER,
ATOM_TYPE_SYMBOL,
ATOM_TYPE_PRIM_PROC,
} atom_type_t;
typedef struct {
atom_type_t type;
union {
int64_t integer;
symbol_t symbol;
prim_proc_t prim_proc;
};
} atom_t;
struct expr;
typedef struct {
struct expr *car, *cdr;
} pair_t;
typedef struct expr {
bool is_atom;
union {
atom_t atom;
pair_t pair;
};
} expr_t;
expr_t *expr_integer(struct am *am, int64_t value);
expr_t *expr_symbol(struct am *am, const symbol_t *symbol);
expr_t *expr_str_symbol(struct am *am, const char *str);
expr_t *expr_empty_list(struct am *am);
expr_t *expr_pair(struct am *am, expr_t *car, expr_t *cdr);
expr_t *expr_prim_proc(struct am *am, prim_proc_t prim_proc);
#endif