mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
WIP: Implementing arrays into the script, read more
I had intended to solve the Advent of Code puzzles in Toy, but they don't work without arrays. I wasn't able to enable arrays in time, so I need to focus on doing things correctly. The most immediate tasks are marked with 'URGENT', and a lot of tests need writing.
This commit is contained in:
@@ -20,39 +20,45 @@ typedef enum Toy_ValueType {
|
||||
TOY_VALUE_OPAQUE,
|
||||
TOY_VALUE_TYPE,
|
||||
TOY_VALUE_ANY,
|
||||
|
||||
TOY_VALUE_REFERENCE, //not a value itself, but pointing to one
|
||||
TOY_VALUE_UNKNOWN, //The correct type is unknown, but will be determined later
|
||||
} Toy_ValueType;
|
||||
|
||||
//8 bytes in size
|
||||
typedef struct Toy_Value { //32 | 64 BITNESS
|
||||
typedef struct Toy_Value { //32 | 64 BITNESS
|
||||
union {
|
||||
bool boolean; //1 | 1
|
||||
int integer; //4 | 4
|
||||
float number; //4 | 4
|
||||
struct Toy_String* string; //4 | 8
|
||||
struct Toy_Array* array; //4 | 8
|
||||
struct Toy_Value* reference; //4 | 8
|
||||
bool boolean; //1 | 1
|
||||
int integer; //4 | 4
|
||||
float number; //4 | 4
|
||||
struct Toy_String* string; //4 | 8
|
||||
struct Toy_Array* array; //4 | 8
|
||||
//TODO: more types go here
|
||||
//TODO: consider 'stack' as a possible addition
|
||||
} as; //4 | 8
|
||||
|
||||
Toy_ValueType type; //4 | 4
|
||||
} Toy_Value; //8 | 16
|
||||
} as; //4 | 8
|
||||
|
||||
#define TOY_VALUE_IS_NULL(value) ((value).type == TOY_VALUE_NULL)
|
||||
#define TOY_VALUE_IS_BOOLEAN(value) ((value).type == TOY_VALUE_BOOLEAN)
|
||||
#define TOY_VALUE_IS_INTEGER(value) ((value).type == TOY_VALUE_INTEGER)
|
||||
#define TOY_VALUE_IS_FLOAT(value) ((value).type == TOY_VALUE_FLOAT)
|
||||
#define TOY_VALUE_IS_STRING(value) ((value).type == TOY_VALUE_STRING)
|
||||
#define TOY_VALUE_IS_ARRAY(value) ((value).type == TOY_VALUE_ARRAY)
|
||||
#define TOY_VALUE_IS_TABLE(value) ((value).type == TOY_VALUE_TABLE)
|
||||
#define TOY_VALUE_IS_FUNCTION(value) ((value).type == TOY_VALUE_FUNCTION)
|
||||
#define TOY_VALUE_IS_OPAQUE(value) ((value).type == TOY_VALUE_OPAQUE)
|
||||
Toy_ValueType type; //4 | 4
|
||||
} Toy_Value; //8 | 16
|
||||
|
||||
#define TOY_VALUE_AS_BOOLEAN(value) ((value).as.boolean)
|
||||
#define TOY_VALUE_AS_INTEGER(value) ((value).as.integer)
|
||||
#define TOY_VALUE_AS_FLOAT(value) ((value).as.number)
|
||||
#define TOY_VALUE_AS_STRING(value) ((value).as.string)
|
||||
#define TOY_VALUE_AS_ARRAY(value) ((value).as.array)
|
||||
#define TOY_VALUE_IS_NULL(value) (Toy_unwrapValue(value).type == TOY_VALUE_NULL)
|
||||
#define TOY_VALUE_IS_BOOLEAN(value) (Toy_unwrapValue(value).type == TOY_VALUE_BOOLEAN)
|
||||
#define TOY_VALUE_IS_INTEGER(value) (Toy_unwrapValue(value).type == TOY_VALUE_INTEGER)
|
||||
#define TOY_VALUE_IS_FLOAT(value) (Toy_unwrapValue(value).type == TOY_VALUE_FLOAT)
|
||||
#define TOY_VALUE_IS_STRING(value) (Toy_unwrapValue(value).type == TOY_VALUE_STRING)
|
||||
#define TOY_VALUE_IS_ARRAY(value) (Toy_unwrapValue(value).type == TOY_VALUE_ARRAY)
|
||||
#define TOY_VALUE_IS_TABLE(value) (Toy_unwrapValue(value).type == TOY_VALUE_TABLE)
|
||||
#define TOY_VALUE_IS_FUNCTION(value) (Toy_unwrapValue(value).type == TOY_VALUE_FUNCTION)
|
||||
#define TOY_VALUE_IS_OPAQUE(value) (Toy_unwrapValue(value).type == TOY_VALUE_OPAQUE)
|
||||
#define TOY_VALUE_IS_TYPE(value) (Toy_unwrapValue(value).type == TOY_VALUE_TYPE)
|
||||
#define TOY_VALUE_IS_REFERENCE(value) ((value).type == TOY_VALUE_REFERENCE)
|
||||
|
||||
#define TOY_VALUE_AS_BOOLEAN(value) (Toy_unwrapValue(value).as.boolean)
|
||||
#define TOY_VALUE_AS_INTEGER(value) (Toy_unwrapValue(value).as.integer)
|
||||
#define TOY_VALUE_AS_FLOAT(value) (Toy_unwrapValue(value).as.number)
|
||||
#define TOY_VALUE_AS_STRING(value) (Toy_unwrapValue(value).as.string)
|
||||
#define TOY_VALUE_AS_ARRAY(value) (Toy_unwrapValue(value).as.array)
|
||||
//TODO: more
|
||||
|
||||
#define TOY_VALUE_FROM_NULL() ((Toy_Value){{ .integer = 0 }, TOY_VALUE_NULL})
|
||||
@@ -63,7 +69,10 @@ typedef struct Toy_Value { //32 | 64 BITNESS
|
||||
#define TOY_VALUE_FROM_ARRAY(value) ((Toy_Value){{ .array = value }, TOY_VALUE_ARRAY})
|
||||
//TODO: more
|
||||
|
||||
#define TOY_REFERENCE_FROM_POINTER(ptr) ((Toy_Value){{ .reference = ptr }, TOY_VALUE_REFERENCE})
|
||||
|
||||
//utilities
|
||||
TOY_API Toy_Value Toy_unwrapValue(Toy_Value value);
|
||||
TOY_API unsigned int Toy_hashValue(Toy_Value value);
|
||||
|
||||
TOY_API Toy_Value Toy_copyValue(Toy_Value value);
|
||||
|
||||
Reference in New Issue
Block a user