#ifndef TSL_VALUE_H #define TSL_VALUE_H #include "forward_decl.h" #include #include #include "string_view.h" #include "std_gc/list.h" typedef enum { TSL_TYPE_NULL, TSL_TYPE_NUMBER, TSL_TYPE_STRING, TSL_TYPE_STRING_REF, TSL_TYPE_BOOL, TSL_TYPE_LIST, TSL_TYPE_MAP, TSL_TYPE_FUNCTION, TSL_TYPE_USERDATA } TslType; /* TODO: Support BigInt */ typedef double TslNumber; typedef enum { TSL_FALSE, TSL_TRUE } TslBool; typedef struct { char *data; size_t size; } TslString; /* This is an index to the function */ typedef int TslFunction; typedef struct TslHashMap TslHashMap; struct TslValue { union { TslNumber number; TslString *string; /* TODO: Make this an int that refers to the index in the bytecode which contains the string view. Then the size of this union will be 8 bytes instead of 16 bytes on 64-bit systems. */ TslStringView string_ref; TslBool boolean; TslBool null; TslList *list; TslHashMap *map; TslFunction function; void *userdata; } data; uint8_t type; }; uint64_t tsl_value_hash(const TslValue *value); /* Returns 1 if equal, otherwise returns 0 */ int tsl_value_equals(const TslValue *lhs, const TslValue *rhs); /* This should be called before setting/modifying the data of the value */ void tsl_value_clear(TslValue *self); int tsl_value_add(const TslValue *lhs_value, const TslValue *rhs_value, TslValue *result); /* Returns NULL if index is out of bounds of the list */ TslValue* tsl_string_ref_get(const TslStringView *self, double index); #endif /* TSL_VALUE_H */