forked from ground/cground
Fix type conversions
This commit is contained in:
@@ -75,7 +75,7 @@ build
|
||||
- [x] String operations
|
||||
- [x] Maths
|
||||
- [x] Comparisions
|
||||
- [ ] Type conversions
|
||||
- [x] Type conversions
|
||||
- [x] Functions
|
||||
- [x] Define functions
|
||||
- [x] Call functions
|
||||
@@ -83,7 +83,7 @@ build
|
||||
- [x] Arguments for functions
|
||||
- [x] Jumping within functions
|
||||
- [x] Custom data structures
|
||||
- [ ] Working with external libraries
|
||||
- [x] Working with external libraries
|
||||
|
||||
## Debugger
|
||||
|
||||
|
||||
@@ -1107,7 +1107,7 @@ GroundValue interpretGroundInstruction(GroundInstruction inst, GroundScope* scop
|
||||
if (in->args.args[1].type != DIRREF) {
|
||||
runtimeError(ARG_TYPE_MISMATCH, "Expecting a DirectRef for arg 2", in, currentInstruction);
|
||||
}
|
||||
addVariable(scope->variables, in->args.args[2].value.refName, createIntGroundValue(atoll(in->args.args[0].value.value.data.stringVal)));
|
||||
addVariable(scope->variables, in->args.args[1].value.refName, createIntGroundValue(atoll(in->args.args[0].value.value.data.stringVal)));
|
||||
break;
|
||||
}
|
||||
case STOD: {
|
||||
@@ -1123,7 +1123,7 @@ GroundValue interpretGroundInstruction(GroundInstruction inst, GroundScope* scop
|
||||
if (in->args.args[1].type != DIRREF) {
|
||||
runtimeError(ARG_TYPE_MISMATCH, "Expecting a DirectRef for arg 2", in, currentInstruction);
|
||||
}
|
||||
addVariable(scope->variables, in->args.args[1].value.refName, createIntGroundValue(atof(in->args.args[0].value.value.data.stringVal)));
|
||||
addVariable(scope->variables, in->args.args[1].value.refName, createDoubleGroundValue(atof(in->args.args[0].value.value.data.stringVal)));
|
||||
break;
|
||||
}
|
||||
case TOSTRING: {
|
||||
@@ -1140,57 +1140,53 @@ GroundValue interpretGroundInstruction(GroundInstruction inst, GroundScope* scop
|
||||
runtimeError(ARG_TYPE_MISMATCH, "Expecting a DirectRef for arg 2", in, currentInstruction);
|
||||
}
|
||||
GroundValue* value = &in->args.args[0].value.value;
|
||||
char buf[256];
|
||||
switch (value->type) {
|
||||
case INT: {
|
||||
char* buf = malloc(sizeof(char) * 256);
|
||||
snprintf(buf, sizeof(char) * 256, "%" PRId64, value->data.intVal);
|
||||
addVariable(scope->variables, in->args.args[1].value.refName, createStringGroundValue(buf));
|
||||
snprintf(buf, sizeof(buf) * 256, "%" PRId64, value->data.intVal);
|
||||
break;
|
||||
}
|
||||
case DOUBLE: {
|
||||
char* buf = malloc(sizeof(char) * 256);
|
||||
snprintf(buf, sizeof(char) * 256, "%f", value->data.doubleVal);
|
||||
addVariable(scope->variables, in->args.args[1].value.refName, createStringGroundValue(buf));
|
||||
snprintf(buf, sizeof(buf) * 256, "%f", value->data.doubleVal);
|
||||
break;
|
||||
}
|
||||
case STRING: {
|
||||
addVariable(scope->variables, in->args.args[1].value.refName, createStringGroundValue(value->data.stringVal));
|
||||
snprintf(buf, sizeof(buf), "%s", value->data.stringVal);
|
||||
break;
|
||||
}
|
||||
case CHAR: {
|
||||
char* buf = malloc(sizeof(char) * 2);
|
||||
buf[0] = value->data.charVal;
|
||||
buf[1] = '\0';
|
||||
addVariable(scope->variables, in->args.args[1].value.refName, createStringGroundValue(buf));
|
||||
break;
|
||||
}
|
||||
case BOOL: {
|
||||
if (value->data.boolVal) {
|
||||
addVariable(scope->variables, in->args.args[1].value.refName, createStringGroundValue("true"));
|
||||
snprintf(buf, sizeof(buf), "true");
|
||||
} else {
|
||||
addVariable(scope->variables, in->args.args[1].value.refName, createStringGroundValue("false"));
|
||||
snprintf(buf, sizeof(buf), "false");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case LIST: {
|
||||
addVariable(scope->variables, in->args.args[1].value.refName, createStringGroundValue("<list>"));
|
||||
snprintf(buf, sizeof(buf), "<list>");
|
||||
break;
|
||||
}
|
||||
case FUNCTION: {
|
||||
addVariable(scope->variables, in->args.args[1].value.refName, createStringGroundValue("<function>"));
|
||||
snprintf(buf, sizeof(buf), "<function>");
|
||||
break;
|
||||
}
|
||||
case CUSTOM: {
|
||||
addVariable(scope->variables, in->args.args[1].value.refName, createStringGroundValue("<custom>"));
|
||||
snprintf(buf, sizeof(buf), "<custom>");
|
||||
break;
|
||||
}
|
||||
case NONE:
|
||||
default: {
|
||||
addVariable(scope->variables, in->args.args[1].value.refName, createStringGroundValue("<default>"));
|
||||
snprintf(buf, sizeof(buf), "<default>");
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
addVariable(scope->variables, in->args.args[1].value.refName, createStringGroundValue(buf));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
tostring 32 &int
|
||||
tostring 32 &str
|
||||
stoi "12" &int
|
||||
stod "3.14" &dou
|
||||
|
||||
println $str
|
||||
println $int
|
||||
println $dou
|
||||
|
||||
Reference in New Issue
Block a user