From 08b1edd7a742505aa8ccbe167ff6a90d41b4308b Mon Sep 17 00:00:00 2001 From: Maxwell Jeffress Date: Tue, 20 Jan 2026 20:17:26 +1100 Subject: [PATCH 1/5] Update include header --- include/groundvm.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/groundvm.h b/include/groundvm.h index 222d867..8c403d1 100644 --- a/include/groundvm.h +++ b/include/groundvm.h @@ -13,11 +13,11 @@ #include typedef enum GroundInstType { - IF, JUMP, END, INPUT, PRINT, PRINTLN, SET, GETTYPE, EXISTS, SETLIST, SETLISTAT, GETLISTAT, GETLISTSIZE, LISTAPPEND, GETSTRSIZE, GETSTRCHARAT, ADD, SUBTRACT, MULTIPLY, DIVIDE, EQUAL, INEQUAL, NOT, GREATER, LESSER, STOI, STOD, TOSTRING, FUN, RETURN, ENDFUN, PUSHARG, CALL, STRUCT, ENDSTRUCT, INIT, USE, EXTERN, CREATELABEL, PAUSE, DROP + IF, JUMP, END, INPUT, PRINT, PRINTLN, SET, GETTYPE, EXISTS, SETLIST, SETLISTAT, GETLISTAT, GETLISTSIZE, LISTAPPEND, GETSTRSIZE, GETSTRCHARAT, ADD, SUBTRACT, MULTIPLY, DIVIDE, EQUAL, INEQUAL, NOT, GREATER, LESSER, STOI, STOD, TOSTRING, FUN, RETURN, ENDFUN, PUSHARG, CALL, STRUCT, ENDSTRUCT, INIT, USE, EXTERN, CREATELABEL, PAUSE, DROP, ERRORCMD } GroundInstType; typedef enum GroundValueType { - INT, DOUBLE, STRING, CHAR, BOOL, LIST, FUNCTION, CUSTOM, NONE + INT, DOUBLE, STRING, CHAR, BOOL, LIST, FUNCTION, STRUCTVAL, CUSTOM, ERROR, NONE } GroundValueType; typedef enum GroundArgType { From 792aed13ae317e0c8afa05dfd4b64435639f1946 Mon Sep 17 00:00:00 2001 From: Maxwell Jeffress Date: Tue, 20 Jan 2026 21:17:08 +1100 Subject: [PATCH 2/5] Balright time to break master again --- include/groundext.h | 11 ---------- include/groundvm.h | 52 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/include/groundext.h b/include/groundext.h index 735b9b7..d3c76b5 100644 --- a/include/groundext.h +++ b/include/groundext.h @@ -14,17 +14,6 @@ extern "C" { struct GroundScope; typedef struct GroundScope GroundScope; -/* - * Stores data associated with an error thrown during Ground execution. - */ -typedef struct GroundError { - char* what; - char* type; - struct GroundInstruction* where; - size_t line; - bool hasLine; -} GroundError; - // Creates a GroundValue containing (in), with type ERROR. GroundValue createErrorGroundValue(GroundError in); diff --git a/include/groundvm.h b/include/groundvm.h index 8c403d1..58bb07a 100644 --- a/include/groundvm.h +++ b/include/groundvm.h @@ -11,6 +11,7 @@ #include #include #include +#include typedef enum GroundInstType { IF, JUMP, END, INPUT, PRINT, PRINTLN, SET, GETTYPE, EXISTS, SETLIST, SETLISTAT, GETLISTAT, GETLISTSIZE, LISTAPPEND, GETSTRSIZE, GETSTRCHARAT, ADD, SUBTRACT, MULTIPLY, DIVIDE, EQUAL, INEQUAL, NOT, GREATER, LESSER, STOI, STOD, TOSTRING, FUN, RETURN, ENDFUN, PUSHARG, CALL, STRUCT, ENDSTRUCT, INIT, USE, EXTERN, CREATELABEL, PAUSE, DROP, ERRORCMD @@ -41,6 +42,17 @@ typedef struct List { struct GroundValue* values; } List; +/* + * Stores data associated with an error thrown during Ground execution. + */ +typedef struct GroundError { + char* what; + char* type; + struct GroundInstruction* where; + size_t line; + bool hasLine; +} GroundError; + /* * Stores literal values created in a Ground program. */ @@ -53,8 +65,10 @@ typedef struct GroundValue { char charVal; bool boolVal; List listVal; + GroundError errorVal; struct GroundFunction* fnVal; - void* customVal; + struct GroundStruct* structVal; + struct GroundObject* customVal; } data; } GroundValue; @@ -115,6 +129,39 @@ typedef struct GroundFunction { size_t startLine; } GroundFunction; +/* + * Field for a GroundStruct + */ +typedef struct GroundStructField { + char id[64]; + GroundValue value; + UT_hash_handle hh; +} GroundStructField; + +/* + * Represents a Ground struct. + */ +typedef struct GroundStruct { + GroundStructField* fields; + size_t size; +} GroundStruct; + +/* + * Field for a GroundObject + */ +typedef struct GroundObjectField { + char id[64]; + GroundValue value; + UT_hash_handle hh; +} GroundObjectField; + +/* + * Represents an initialised Ground struct. + */ +typedef struct GroundObject { + GroundObjectField* fields; +} GroundObject; + #ifdef __cplusplus extern "C" { #endif @@ -133,6 +180,9 @@ GroundValue groundCreateValue(GroundValueType type, ...); GroundProgram groundParseFile(const char* code); +GroundStruct groundCreateStruct(); +void groundAddFieldToStruct(GroundStruct* gstruct, char* name, GroundValue field); + #ifdef __cplusplus } #endif From 46805970652163998811607b6cd288309fdce79e Mon Sep 17 00:00:00 2001 From: SpookyDervish Date: Tue, 20 Jan 2026 21:29:42 +1100 Subject: [PATCH 3/5] update to math library (v1.1.0) --- libs/math/math.c | 89 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 81 insertions(+), 8 deletions(-) diff --git a/libs/math/math.c b/libs/math/math.c index b48744c..36753b4 100644 --- a/libs/math/math.c +++ b/libs/math/math.c @@ -1,5 +1,10 @@ #include #include +#include +#include +#include +#include + GroundValue ground_sin(GroundScope* scope, List args) { return groundCreateValue( @@ -21,19 +26,15 @@ GroundValue ground_tan(GroundScope* scope, List args) { } GroundValue rad_to_deg(GroundScope* scope, List args) { - double radians = args.values[0].data.doubleVal; - return groundCreateValue( DOUBLE, - radians * (180.0 / M_PI) + args.values[0].data.doubleVal * (180.0 / M_PI) ); } GroundValue deg_to_rad(GroundScope* scope, List args) { - double deg = args.values[0].data.doubleVal; - return groundCreateValue( DOUBLE, - deg * (M_PI / 180.0) + args.values[0].data.doubleVal * (M_PI / 180.0) ); } @@ -62,16 +63,88 @@ GroundValue ground_sqrt(GroundScope* scope, List args) { ); } +GroundValue ground_abs(GroundScope* scope, List args) { + return groundCreateValue( + DOUBLE, + abs(args.values[0].data.doubleVal) + ); +} +GroundValue ground_min(GroundScope* scope, List args) { + double a = args.values[0].data.doubleVal; + double b = args.values[1].data.doubleVal; + + return groundCreateValue( + DOUBLE, + (a < b) ? a : b + ); +} +GroundValue ground_max(GroundScope* scope, List args) { + double a = args.values[0].data.doubleVal; + double b = args.values[1].data.doubleVal; + + return groundCreateValue( + DOUBLE, + (a > b) ? a : b + ); +} +GroundValue ground_clamp(GroundScope* scope, List args) { + double number = args.values[0].data.doubleVal; + double min = args.values[1].data.doubleVal; + double max = args.values[2].data.doubleVal; + + if (number < min) number = min; + if (number > max) number = max; + + return groundCreateValue( + DOUBLE, + number + ); +} + +GroundValue ground_random(GroundScope* scope, List args) { + int64_t min = args.values[0].data.intVal; + int64_t max = args.values[1].data.intVal; + + return groundCreateValue( + INT, + min + rand() % (max - min) + ); +} +GroundValue ground_random_double(GroundScope* scope, List args) { + double min = args.values[0].data.doubleVal; + double max = args.values[1].data.doubleVal; + + return groundCreateValue( + INT, + min + (double)rand() / RAND_MAX * (max - min) + ); +} +GroundValue ground_random_set_seed(GroundScope* scope, List args) { + srand(args.values[0].data.intVal); + return groundCreateValue( + INT, + 0 + ); +} + void ground_init(GroundScope* scope) { + srand(time(NULL)); groundAddNativeFunction(scope, "math_Sin", ground_sin, DOUBLE, 1, DOUBLE, "radians"); groundAddNativeFunction(scope, "math_Cos", ground_cos, DOUBLE, 1, DOUBLE, "radians"); groundAddNativeFunction(scope, "math_Tan", ground_tan, DOUBLE, 1, DOUBLE, "radians"); - groundAddNativeFunction(scope, "math_DegreesToRadians", deg_to_rad, DOUBLE, 1, DOUBLE, "degrees"); groundAddNativeFunction(scope, "math_RadiansToDegrees", rad_to_deg, DOUBLE, 1, DOUBLE, "radians"); groundAddNativeFunction(scope, "math_Modulos", ground_modulos, DOUBLE, 2, DOUBLE, "number1", DOUBLE, "number2"); groundAddNativeFunction(scope, "math_Pow", ground_pow, DOUBLE, 2, DOUBLE, "number1", DOUBLE, "number2"); - groundAddNativeFunction(scope, "math_Sqrt", ground_sqrt, DOUBLE, 1, DOUBLE, "number"); + + groundAddNativeFunction(scope, "math_Abs", ground_abs, DOUBLE, 1, DOUBLE, "number"); + groundAddNativeFunction(scope, "math_Min", ground_min, DOUBLE, 2, DOUBLE, "number1", DOUBLE, "number2"); + groundAddNativeFunction(scope, "math_Max", ground_max, DOUBLE, 2, DOUBLE, "number1", DOUBLE, "number2"); + groundAddNativeFunction(scope, "math_Clamp", ground_clamp, DOUBLE, 2, DOUBLE, "number", DOUBLE, "min", DOUBLE, "max"); + + groundAddNativeFunction(scope, "math_Random", ground_random, INT, 2, INT, "min", INT, "max"); + groundAddNativeFunction(scope, "math_RandomDouble", ground_random_double, DOUBLE, 2, DOUBLE, "min", DOUBLE, "max"); + groundAddNativeFunction(scope, "math_RandomSetSeed", ground_random_set_seed, INT, 1, INT, "seed"); } \ No newline at end of file From 0f155c80be618d9a70e14935eceef9e9c3e225c5 Mon Sep 17 00:00:00 2001 From: SpookyDervish Date: Wed, 21 Jan 2026 07:23:24 +1100 Subject: [PATCH 4/5] ground library version 1.1.5 --- libs/math/math.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/libs/math/math.c b/libs/math/math.c index 36753b4..6969778 100644 --- a/libs/math/math.c +++ b/libs/math/math.c @@ -4,6 +4,8 @@ #include #include #include +#include +#include GroundValue ground_sin(GroundScope* scope, List args) { @@ -101,6 +103,62 @@ GroundValue ground_clamp(GroundScope* scope, List args) { ); } +GroundValue ground_round(GroundScope* scope, List args) { + double x = args.values[0].data.doubleVal; + + if (x >= 0.0) + return groundCreateValue( + INT, + (long long)(x + 0.5) + ); + else + return groundCreateValue( + INT, + (long long)(x - 0.5) + ); +} +GroundValue ground_floor(GroundScope* scope, List args) { + double x = args.values[0].data.doubleVal; + + if (x >= (double)LLONG_MAX) return groundCreateValue(INT, LLONG_MAX); + if (x <= (double)LLONG_MIN) return groundCreateValue(INT, LLONG_MIN); + + long long i = (long long)x; // truncates toward zero + + if (x < 0 && x != (double)i) { + return groundCreateValue( + INT, + i-1 + ); + } + + return groundCreateValue( + INT, + i + ); +} +GroundValue ground_ceil(GroundScope* scope, List args) { + double x = args.values[0].data.doubleVal; + + if (x >= (double)LLONG_MAX) return groundCreateValue(INT, LLONG_MAX); + if (x <= (double)LLONG_MIN) return groundCreateValue(INT, LLONG_MIN); + + + long long i = (long long)x; // truncates toward zero + + if (x > 0 && x != (double)i) { + return groundCreateValue( + INT, + i+1 + ); + } + + return groundCreateValue( + INT, + i + ); +} + GroundValue ground_random(GroundScope* scope, List args) { int64_t min = args.values[0].data.intVal; int64_t max = args.values[1].data.intVal; @@ -115,7 +173,7 @@ GroundValue ground_random_double(GroundScope* scope, List args) { double max = args.values[1].data.doubleVal; return groundCreateValue( - INT, + DOUBLE, min + (double)rand() / RAND_MAX * (max - min) ); } @@ -128,7 +186,8 @@ GroundValue ground_random_set_seed(GroundScope* scope, List args) { } void ground_init(GroundScope* scope) { - srand(time(NULL)); + srand((unsigned)time(NULL) ^ (unsigned)clock()); + groundAddNativeFunction(scope, "math_Sin", ground_sin, DOUBLE, 1, DOUBLE, "radians"); groundAddNativeFunction(scope, "math_Cos", ground_cos, DOUBLE, 1, DOUBLE, "radians"); groundAddNativeFunction(scope, "math_Tan", ground_tan, DOUBLE, 1, DOUBLE, "radians"); @@ -144,6 +203,10 @@ void ground_init(GroundScope* scope) { groundAddNativeFunction(scope, "math_Max", ground_max, DOUBLE, 2, DOUBLE, "number1", DOUBLE, "number2"); groundAddNativeFunction(scope, "math_Clamp", ground_clamp, DOUBLE, 2, DOUBLE, "number", DOUBLE, "min", DOUBLE, "max"); + groundAddNativeFunction(scope, "math_Round", ground_round, INT, 1, DOUBLE, "number"); + groundAddNativeFunction(scope, "math_Floor", ground_floor, INT, 1, DOUBLE, "number"); + groundAddNativeFunction(scope, "math_Ceil", ground_ceil, INT, 1, DOUBLE, "number"); + groundAddNativeFunction(scope, "math_Random", ground_random, INT, 2, INT, "min", INT, "max"); groundAddNativeFunction(scope, "math_RandomDouble", ground_random_double, DOUBLE, 2, DOUBLE, "min", DOUBLE, "max"); groundAddNativeFunction(scope, "math_RandomSetSeed", ground_random_set_seed, INT, 1, INT, "seed"); From 32d6a029dde253ce22e85c4e88c6dc201ab06423 Mon Sep 17 00:00:00 2001 From: Maxwell Jeffress Date: Wed, 21 Jan 2026 11:55:34 +1100 Subject: [PATCH 5/5] trying to fix stuff --- src/interface.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/interface.c b/src/interface.c index 280c885..3fc61a6 100644 --- a/src/interface.c +++ b/src/interface.c @@ -68,11 +68,35 @@ GroundValue groundCreateValue(GroundValueType type, ...) { return createListGroundValue(va_arg(args, List)); break; } + case FUNCTION: { + return createFunctionGroundValue(va_arg(args, GroundFunction*)); + break; + } + case STRUCTVAL: { + GroundValue gv; + gv.type = STRUCTVAL; + gv.data.structVal = va_arg(args, GroundStruct*); + return gv; + break; + } + case NONE: { + return createNoneGroundValue(); + break; + } + case ERROR: + case CUSTOM: { + // FIXME + break; + } + /* default: { return createNoneGroundValue(); } + */ } + return createNoneGroundValue(); + va_end(args); }