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..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 } @@ -221,3 +222,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; +} 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 {