Added simple assignment, read more

I was coding earlier this week, but my brain was so foggy I ended up not
knowing what I was doing. After a few days break, I've cleaned up the
mess, which took hours.

Changes:
* Variables can be assigned
* Added new value types as placeholders
* Added 'compare' and 'assign' to the AST
* Added duplicate opcode
* Added functions to copy and free values
* Max name length is 255 chars
* Compound assigns are squeezed into one word

To be completed:

* Tests for this commit's changes
* Compound assignments
* Variable access
This commit is contained in:
2024-10-25 22:48:24 +11:00
parent 5b17c5e1e9
commit 3148a56ce0
17 changed files with 653 additions and 182 deletions

View File

@@ -12,11 +12,12 @@ typedef enum Toy_ValueType {
TOY_VALUE_FLOAT,
TOY_VALUE_STRING,
TOY_VALUE_ARRAY,
TOY_VALUE_DICTIONARY,
TOY_VALUE_TABLE,
TOY_VALUE_FUNCTION,
TOY_VALUE_OPAQUE,
//TODO: type, any, consider 'stack' as a possible addition
TOY_VALUE_TYPE,
TOY_VALUE_ANY,
TOY_VALUE_UNKNOWN, //The correct value is unknown, but will be determined later
} Toy_ValueType;
//8 bytes in size
@@ -26,10 +27,8 @@ typedef struct Toy_Value { //32 | 64 BITNESS
int integer; //4 | 4
float number; //4 | 4
struct Toy_String* string; //4 | 8
//TODO: arrays
//TODO: dictonaries
//TODO: functions
//TODO: opaque
//TODO: more types go here
//TODO: consider 'stack' as a possible addition
} as; //4 | 8
Toy_ValueType type; //4 | 4
@@ -41,7 +40,7 @@ typedef struct Toy_Value { //32 | 64 BITNESS
#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_DICTIONARY(value) ((value).type == TOY_VALUE_DICTIONARY)
#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)
@@ -66,3 +65,5 @@ TOY_API bool Toy_private_isEqual(Toy_Value left, Toy_Value right);
unsigned int Toy_hashValue(Toy_Value value);
TOY_API Toy_Value Toy_copyValue(Toy_Value value);
TOY_API void Toy_freeValue(Toy_Value value);