forked from ground/cground
Add int, char, and bool to compiler
This commit is contained in:
@@ -102,7 +102,7 @@ Commands:
|
|||||||
|
|
||||||
CGround now includes an experimental Ground -> x86_64 Linux ASM compiler. You can try it by adding the `-c` flag when running Ground. This will print the generated ASM to the console.
|
CGround now includes an experimental Ground -> x86_64 Linux ASM compiler. You can try it by adding the `-c` flag when running Ground. This will print the generated ASM to the console.
|
||||||
|
|
||||||
At present only the `int` data type is supported.
|
At present only the `int`, `char`, and `bool` data types are supported.
|
||||||
|
|
||||||
Supported instructions so far:
|
Supported instructions so far:
|
||||||
|
|
||||||
|
|||||||
@@ -114,10 +114,10 @@ GroundValueType getInstructionReturnType(GroundInstruction* gi, VariableTable* t
|
|||||||
}
|
}
|
||||||
case SET: {
|
case SET: {
|
||||||
if (gi->args.length == 2) {
|
if (gi->args.length == 2) {
|
||||||
if (gi->args.args[0].type == VALUE) {
|
if (gi->args.args[1].type == VALUE) {
|
||||||
return gi->args.args[0].value.value.type;
|
return gi->args.args[1].value.value.type;
|
||||||
} else if (gi->args.args[0].type == VALREF) {
|
} else if (gi->args.args[1].type == VALREF) {
|
||||||
VariableInfo* var = getVariable(table, gi->args.args[0].value.refName);
|
VariableInfo* var = getVariable(table, gi->args.args[1].value.refName);
|
||||||
if (var == NULL) {
|
if (var == NULL) {
|
||||||
return NONE;
|
return NONE;
|
||||||
}
|
}
|
||||||
@@ -177,6 +177,9 @@ GroundValueType getInstructionReturnType(GroundInstruction* gi, VariableTable* t
|
|||||||
return NONE;
|
return NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (rightType == INT && leftType == INT) {
|
||||||
|
return INT;
|
||||||
|
}
|
||||||
return NONE;
|
return NONE;
|
||||||
} else {
|
} else {
|
||||||
return NONE;
|
return NONE;
|
||||||
@@ -223,6 +226,9 @@ GroundValueType getInstructionReturnType(GroundInstruction* gi, VariableTable* t
|
|||||||
return NONE;
|
return NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (rightType == INT && leftType == INT) {
|
||||||
|
return INT;
|
||||||
|
}
|
||||||
return NONE;
|
return NONE;
|
||||||
} else {
|
} else {
|
||||||
return NONE;
|
return NONE;
|
||||||
@@ -269,6 +275,9 @@ GroundValueType getInstructionReturnType(GroundInstruction* gi, VariableTable* t
|
|||||||
return NONE;
|
return NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (rightType == INT && leftType == INT) {
|
||||||
|
return INT;
|
||||||
|
}
|
||||||
return NONE;
|
return NONE;
|
||||||
} else {
|
} else {
|
||||||
return NONE;
|
return NONE;
|
||||||
@@ -285,13 +294,29 @@ char* processValueString(GroundArg arg) {
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
if (arg.type == VALUE) {
|
if (arg.type == VALUE) {
|
||||||
if (arg.value.value.type != INT) {
|
switch (arg.value.value.type) {
|
||||||
printf("Only int is supported right now\n");
|
case INT: {
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
char* buf = malloc(sizeof(char) * 64);
|
char* buf = malloc(sizeof(char) * 64);
|
||||||
snprintf(buf, sizeof(char) * 260, "%" PRId64, arg.value.value.data.intVal);
|
snprintf(buf, sizeof(char) * 260, "%" PRId64, arg.value.value.data.intVal);
|
||||||
return buf;
|
return buf;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case BOOL: {
|
||||||
|
return arg.value.value.data.boolVal ? "1" : "0";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CHAR: {
|
||||||
|
char* buf = malloc(8);
|
||||||
|
snprintf(buf, 8, "%d", (int) arg.value.value.data.charVal);
|
||||||
|
return buf;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
printf("For now, only int, bool, and char are supported data types in the compiler.");
|
||||||
|
exit(1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user