From e5776b16ddbeb4dddff747b4021b801e30e86699 Mon Sep 17 00:00:00 2001 From: Maxwell Jeffress Date: Sat, 11 Apr 2026 13:09:32 +1000 Subject: [PATCH 1/2] groundFindVariable function --- include/groundvm.h | 3 ++- src/interface.c | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/groundvm.h b/include/groundvm.h index ebe7c1e..505134e 100644 --- a/include/groundvm.h +++ b/include/groundvm.h @@ -20,7 +20,7 @@ typedef enum GroundInstType { } GroundInstType; typedef enum GroundValueType { - INT, DOUBLE, STRING, CHAR, BOOL, LIST, FUNCTION, STRUCTVAL, CUSTOM, ERROR, NONE + INT, DOUBLE, STRING, CHAR, BOOL, LIST, FUNCTION, STRUCTVAL, CUSTOM, ERROR, NONE, ANY } GroundValueType; typedef enum GroundArgType { @@ -209,6 +209,7 @@ GroundStruct groundCreateStruct(); void groundAddFieldToStruct(GroundStruct* gstruct, char* name, GroundValue field); GroundObjectField* groundFindField(GroundObject head, const char *id); +GroundVariable* groundFindVariable(GroundScope* gs, const char *id); // Run function returned by Ground code // Use argc to set count of args, accepts that amount of GroundValue's after diff --git a/src/interface.c b/src/interface.c index 2ff4d01..9c866fd 100644 --- a/src/interface.c +++ b/src/interface.c @@ -221,3 +221,9 @@ GroundObjectField* groundFindField(GroundObject head, const char *id) { HASH_FIND_STR(head.fields, id, s); return s; } + +GroundVariable* groundFindVariable(GroundScope* gs, const char *id) { + GroundVariable* var; + HASH_FIND_STR(*gs->variables, id, var); + return var; +} From cb6b6a564c4c586c7bdd40649b132f81ba709050 Mon Sep 17 00:00:00 2001 From: Maxwell Jeffress Date: Sat, 11 Apr 2026 13:19:04 +1000 Subject: [PATCH 2/2] Add any type for extlibs --- src/interface.c | 1 + src/interpreter.c | 10 ++++++++++ src/parser.c | 3 +++ src/types.c | 5 +++++ src/types.h | 2 +- 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/interface.c b/src/interface.c index 9c866fd..a6da43f 100644 --- a/src/interface.c +++ b/src/interface.c @@ -177,6 +177,7 @@ void groundCompileProgram(GroundProgram* program) { #ifdef GROUND_COMPILE_WITH_TRAM compileGroundProgram(program, "program.gexe"); #else + (void)program; printf("This version of Ground has been compiled without Tram, so compilation is not supported.\n"); #endif } diff --git a/src/interpreter.c b/src/interpreter.c index 7216d40..c40c420 100644 --- a/src/interpreter.c +++ b/src/interpreter.c @@ -211,6 +211,12 @@ GroundValueType stringToValueType(char* in) { if (strcmp(in, "function") == 0) { return FUNCTION; } + if (strcmp(in, "struct") == 0) { + return STRUCTVAL; + } + if (strcmp(in, "any") == 0) { + return ANY; + } return CUSTOM; } @@ -931,6 +937,10 @@ GroundValue interpretGroundInstruction(GroundInstruction inst, GroundScope* scop addVariable(scope->variables, in->args.args[1].value.refName, createStringGroundValue("struct")); break; } + case ANY: { + addVariable(scope->variables, in->args.args[1].value.refName, createStringGroundValue("any")); + break; + } case NONE: { addVariable(scope->variables, in->args.args[1].value.refName, createStringGroundValue("none")); break; diff --git a/src/parser.c b/src/parser.c index 276bac8..f8e1ce5 100644 --- a/src/parser.c +++ b/src/parser.c @@ -128,6 +128,9 @@ static GroundArg parseArgument(const char* token) { else if (token[0] == '-') { // Could be type reference or negative number if (strlen(token) > 1 && !isdigit(token[1])) { + if (strcmp(token, "-any") == 0) { + printf("Note: please avoid using \"any\" type outside of extlibs.\n"); + } // Type reference (e.g., -int, -string) return createRefGroundArg(TYPEREF, token + 1); } diff --git a/src/types.c b/src/types.c index 752f93f..25a03fc 100644 --- a/src/types.c +++ b/src/types.c @@ -250,6 +250,10 @@ void printGroundValue(GroundValue* gv) { printf(" }>"); break; } + case ANY: { + printf(""); + break; + } case ERROR: { printf("", gv->data.errorVal.type, gv->data.errorVal.what); break; @@ -741,6 +745,7 @@ GroundError createGroundError(char* what, char* type, GroundInstruction* where, bool checkFnTypes(GroundValue* left, GroundFunctionArgs* right) { if (groundDisableTypeChecking) return true; + if (left->type == ANY || right->type == ANY) return true; if (left->type != right->type) { return false; } diff --git a/src/types.h b/src/types.h index 152c86a..8c96cd4 100644 --- a/src/types.h +++ b/src/types.h @@ -33,7 +33,7 @@ typedef enum GroundInstType { } GroundInstType; typedef enum GroundValueType { - INT, DOUBLE, STRING, CHAR, BOOL, LIST, FUNCTION, STRUCTVAL, CUSTOM, ERROR, NONE + INT, DOUBLE, STRING, CHAR, BOOL, LIST, FUNCTION, STRUCTVAL, CUSTOM, ERROR, NONE, ANY } GroundValueType; typedef enum GroundArgType {