2024-03-26 18:31:33 +00:00
|
|
|
#ifndef MK_VALUE_H
|
|
|
|
#define MK_VALUE_H
|
|
|
|
|
|
|
|
#include "commons.h"
|
2024-03-27 10:49:10 +00:00
|
|
|
#include "native.h"
|
2024-03-26 18:31:33 +00:00
|
|
|
|
|
|
|
#define TYPE_KIND(G) \
|
|
|
|
G(TY_INT), G(TY_FLOAT), G(TY_BOOL), \
|
2024-03-27 10:49:10 +00:00
|
|
|
G(TY_STRING), G(TY_SYMBOL), G(TY_REF), \
|
|
|
|
G(TY_NATIVE), G(TY_LAZY)
|
2024-03-26 18:31:33 +00:00
|
|
|
|
|
|
|
MK_ENUM_H(TypeKind, TYPE_KIND);
|
|
|
|
|
|
|
|
union value_data
|
|
|
|
{
|
|
|
|
int integer;
|
|
|
|
float real;
|
|
|
|
bool boolean;
|
|
|
|
char* str;
|
|
|
|
char* sym;
|
2024-03-27 10:49:10 +00:00
|
|
|
size_t ref;
|
|
|
|
struct native* native;
|
|
|
|
struct node* lazy;
|
2024-03-26 18:31:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct value
|
|
|
|
{
|
|
|
|
union value_data data;
|
|
|
|
TypeKind type;
|
|
|
|
int line;
|
|
|
|
};
|
|
|
|
|
|
|
|
void value_init_int(struct value* self, int value, int line);
|
|
|
|
void value_init_float(struct value* self, float value, int line);
|
|
|
|
void value_init_bool(struct value* self, bool value, int line);
|
|
|
|
void value_init_string(struct value* self, char const* value, int line);
|
|
|
|
void value_init_symbol(struct value* self, char const* value, int line);
|
2024-03-27 10:49:10 +00:00
|
|
|
void value_init_ref(struct value* self, size_t value, int line);
|
|
|
|
void value_init_native(struct value* self, struct native* value, int line);
|
|
|
|
void value_init_lazy(struct value* self, struct node* value, int line);
|
2024-03-29 04:46:35 +00:00
|
|
|
|
2024-03-26 18:31:33 +00:00
|
|
|
void value_free(struct value* self);
|
|
|
|
|
|
|
|
#endif
|