forked from ground/ground
Add any type for extlibs
This commit is contained in:
@@ -177,6 +177,7 @@ void groundCompileProgram(GroundProgram* program) {
|
|||||||
#ifdef GROUND_COMPILE_WITH_TRAM
|
#ifdef GROUND_COMPILE_WITH_TRAM
|
||||||
compileGroundProgram(program, "program.gexe");
|
compileGroundProgram(program, "program.gexe");
|
||||||
#else
|
#else
|
||||||
|
(void)program;
|
||||||
printf("This version of Ground has been compiled without Tram, so compilation is not supported.\n");
|
printf("This version of Ground has been compiled without Tram, so compilation is not supported.\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -211,6 +211,12 @@ GroundValueType stringToValueType(char* in) {
|
|||||||
if (strcmp(in, "function") == 0) {
|
if (strcmp(in, "function") == 0) {
|
||||||
return FUNCTION;
|
return FUNCTION;
|
||||||
}
|
}
|
||||||
|
if (strcmp(in, "struct") == 0) {
|
||||||
|
return STRUCTVAL;
|
||||||
|
}
|
||||||
|
if (strcmp(in, "any") == 0) {
|
||||||
|
return ANY;
|
||||||
|
}
|
||||||
return CUSTOM;
|
return CUSTOM;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -931,6 +937,10 @@ GroundValue interpretGroundInstruction(GroundInstruction inst, GroundScope* scop
|
|||||||
addVariable(scope->variables, in->args.args[1].value.refName, createStringGroundValue("struct"));
|
addVariable(scope->variables, in->args.args[1].value.refName, createStringGroundValue("struct"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case ANY: {
|
||||||
|
addVariable(scope->variables, in->args.args[1].value.refName, createStringGroundValue("any"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
case NONE: {
|
case NONE: {
|
||||||
addVariable(scope->variables, in->args.args[1].value.refName, createStringGroundValue("none"));
|
addVariable(scope->variables, in->args.args[1].value.refName, createStringGroundValue("none"));
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -128,6 +128,9 @@ static GroundArg parseArgument(const char* token) {
|
|||||||
else if (token[0] == '-') {
|
else if (token[0] == '-') {
|
||||||
// Could be type reference or negative number
|
// Could be type reference or negative number
|
||||||
if (strlen(token) > 1 && !isdigit(token[1])) {
|
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)
|
// Type reference (e.g., -int, -string)
|
||||||
return createRefGroundArg(TYPEREF, token + 1);
|
return createRefGroundArg(TYPEREF, token + 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -250,6 +250,10 @@ void printGroundValue(GroundValue* gv) {
|
|||||||
printf(" }>");
|
printf(" }>");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case ANY: {
|
||||||
|
printf("<any>");
|
||||||
|
break;
|
||||||
|
}
|
||||||
case ERROR: {
|
case ERROR: {
|
||||||
printf("<error type: %s, what: %s>", gv->data.errorVal.type, gv->data.errorVal.what);
|
printf("<error type: %s, what: %s>", gv->data.errorVal.type, gv->data.errorVal.what);
|
||||||
break;
|
break;
|
||||||
@@ -741,6 +745,7 @@ GroundError createGroundError(char* what, char* type, GroundInstruction* where,
|
|||||||
|
|
||||||
bool checkFnTypes(GroundValue* left, GroundFunctionArgs* right) {
|
bool checkFnTypes(GroundValue* left, GroundFunctionArgs* right) {
|
||||||
if (groundDisableTypeChecking) return true;
|
if (groundDisableTypeChecking) return true;
|
||||||
|
if (left->type == ANY || right->type == ANY) return true;
|
||||||
if (left->type != right->type) {
|
if (left->type != right->type) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ typedef enum GroundInstType {
|
|||||||
} GroundInstType;
|
} GroundInstType;
|
||||||
|
|
||||||
typedef enum GroundValueType {
|
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;
|
} GroundValueType;
|
||||||
|
|
||||||
typedef enum GroundArgType {
|
typedef enum GroundArgType {
|
||||||
|
|||||||
Reference in New Issue
Block a user