This commit is contained in:
2026-04-11 16:06:40 +10:00
6 changed files with 28 additions and 2 deletions

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -250,6 +250,10 @@ void printGroundValue(GroundValue* gv) {
printf(" }>");
break;
}
case ANY: {
printf("<any>");
break;
}
case ERROR: {
printf("<error type: %s, what: %s>", 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;
}

View File

@@ -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 {