2024-03-31 21:10:56 +00:00
|
|
|
#ifndef SK_VALUE_H
|
|
|
|
#define SK_VALUE_H
|
|
|
|
|
|
|
|
#include "commons.h"
|
|
|
|
#include "node.h"
|
2024-04-02 20:44:34 +00:00
|
|
|
#include "fun.h"
|
2024-03-31 21:10:56 +00:00
|
|
|
|
|
|
|
#define TYPE_KIND(G) \
|
2024-04-01 19:42:36 +00:00
|
|
|
G(TYPE_INT), G(TYPE_BOOL), G(TYPE_FLOAT), \
|
2024-04-06 18:44:58 +00:00
|
|
|
G(TYPE_STRING), G(TYPE_FUN), G(TYPE_REF), \
|
|
|
|
G(TYPE_NATIVE_FUN)
|
2024-03-31 21:10:56 +00:00
|
|
|
|
|
|
|
SK_ENUM_H(TypeKind, TYPE_KIND);
|
|
|
|
|
|
|
|
union val
|
|
|
|
{
|
|
|
|
int integer;
|
2024-04-01 19:08:42 +00:00
|
|
|
double real;
|
2024-04-01 12:00:06 +00:00
|
|
|
bool boolean;
|
2024-04-01 19:42:36 +00:00
|
|
|
char* str;
|
2024-04-02 20:44:34 +00:00
|
|
|
struct fun* fun;
|
2024-04-06 18:44:58 +00:00
|
|
|
struct nfun* nfun;
|
2024-04-03 04:28:03 +00:00
|
|
|
size_t ref;
|
2024-03-31 21:10:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct value
|
|
|
|
{
|
|
|
|
TypeKind type;
|
|
|
|
union val val;
|
2024-04-01 05:20:42 +00:00
|
|
|
int line;
|
2024-03-31 21:10:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void value_init(struct value* self,
|
|
|
|
TypeKind type,
|
2024-04-01 05:20:42 +00:00
|
|
|
union val val,
|
|
|
|
int line);
|
2024-03-31 21:10:56 +00:00
|
|
|
|
|
|
|
void value_free(struct value* self);
|
|
|
|
|
2024-04-02 20:44:34 +00:00
|
|
|
struct value* value_new_clone(struct value* self);
|
|
|
|
|
2024-04-01 05:20:42 +00:00
|
|
|
bool value_equals(struct value* self, struct value* rhs);
|
|
|
|
|
2024-03-31 21:10:56 +00:00
|
|
|
void value_str(struct value* self, struct str* dest);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|