59 lines
1.5 KiB
C
59 lines
1.5 KiB
C
#ifndef __LISP_OBJECT_H__
|
|
#define __LISP_OBJECT_H__
|
|
|
|
#include "enums.h"
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
struct Object {
|
|
enum Type type;
|
|
union {
|
|
// For PROCEDURE
|
|
struct {
|
|
char *name;
|
|
struct Object *(*func)(struct Object *args);
|
|
} procedure;
|
|
// For PAIR
|
|
struct {
|
|
struct Object *a, *b;
|
|
} pair;
|
|
// For BOOLEAN
|
|
bool boolean;
|
|
// For CHAR
|
|
char chr;
|
|
// For SYMBOL, STRING
|
|
char *s;
|
|
// For NUMBER
|
|
int64_t i;
|
|
};
|
|
};
|
|
|
|
struct Object *Object_new_procedure(
|
|
const char *name,
|
|
struct Object *(*func)(struct Object *args)
|
|
);
|
|
struct Object *Object_new_pair(struct Object *a, struct Object *b);
|
|
struct Object *Object_new_boolean(bool boolean);
|
|
struct Object *Object_new_char(char chr);
|
|
struct Object *Object_new_symbol(const char *s);
|
|
struct Object *Object_new_string(const char *s);
|
|
struct Object *Object_new_number(int64_t i);
|
|
|
|
struct Object *Object_build_list(int count, ...);
|
|
|
|
bool Object_is_null(struct Object *object);
|
|
bool Object_is_procedure(struct Object *object);
|
|
bool Object_is_pair(struct Object *object);
|
|
bool Object_is_boolean(struct Object *object);
|
|
bool Object_is_char(struct Object *object);
|
|
bool Object_is_symbol(struct Object *object);
|
|
bool Object_is_string(struct Object *object);
|
|
bool Object_is_number(struct Object *object);
|
|
|
|
bool Object_is_false(struct Object *object);
|
|
bool Object_is_true(struct Object *object);
|
|
|
|
void Object_print(struct Object *self, unsigned indent);
|
|
|
|
#endif
|