== sign
This commit is contained in:
@@ -97,6 +97,37 @@ ResultType(SolsType, charptr) getNodeType(SolsNode* node, SolsScope* scope) {
|
||||
}
|
||||
return Success(SolsType, charptr, type.as.success);
|
||||
}
|
||||
case SNT_OP_EQUAL: {
|
||||
if (node->children.count < 2) {
|
||||
return Error(SolsType, charptr, "Not enough children to determine type");
|
||||
}
|
||||
|
||||
ResultType(SolsType, charptr) leftType = getNodeType(&node->children.at[0], scope);
|
||||
if (leftType.error) {
|
||||
return Error(SolsType, charptr, leftType.as.error);
|
||||
}
|
||||
ResultType(SolsType, charptr) rightType = getNodeType(&node->children.at[1], scope);
|
||||
if (rightType.error) {
|
||||
return Error(SolsType, charptr, rightType.as.error);
|
||||
}
|
||||
|
||||
if (leftType.as.success.type == STT_FUN || leftType.as.success.type == STT_TEMPLATE || leftType.as.success.type == STT_OBJECT) {
|
||||
return Error(SolsType, charptr, "Cannot compare with left type");
|
||||
}
|
||||
|
||||
if (rightType.as.success.type == STT_FUN || rightType.as.success.type == STT_TEMPLATE || rightType.as.success.type == STT_OBJECT) {
|
||||
return Error(SolsType, charptr, "Cannot compare with right type");
|
||||
}
|
||||
|
||||
if (leftType.as.success.type == rightType.as.success.type) {
|
||||
return Success(SolsType, charptr, {STT_BOOL});
|
||||
}
|
||||
if ((leftType.as.success.type == STT_INT && rightType.as.success.type == STT_DOUBLE) || (rightType.as.success.type == STT_INT && leftType.as.success.type == STT_DOUBLE)) {
|
||||
return Success(SolsType, charptr, {STT_BOOL});
|
||||
}
|
||||
|
||||
return Error(SolsType, charptr, "");
|
||||
}
|
||||
case SNT_LITERAL: {
|
||||
switch (node->as.literal.type) {
|
||||
case SLT_INT: {
|
||||
@@ -302,6 +333,36 @@ static inline ResultType(GroundProgram, charptr) generateDivNode(SolsNode* node,
|
||||
return Success(GroundProgram, charptr, gp);
|
||||
}
|
||||
|
||||
static inline ResultType(GroundProgram, charptr) generateEqualNode(SolsNode* node, SolsScope* scope) {
|
||||
if (node->children.count < 2) {
|
||||
return Error(GroundProgram, charptr, "equal requires arguments");
|
||||
}
|
||||
|
||||
// Use this function for type checking
|
||||
ResultType(SolsType, charptr) type = getNodeType(node, scope);
|
||||
if (type.error) {
|
||||
return Error(GroundProgram, charptr, type.as.error);
|
||||
}
|
||||
|
||||
GroundProgram gp = groundCreateProgram();
|
||||
GroundInstruction add = groundCreateInstruction(EQUAL);
|
||||
groundAddReferenceToInstruction(&add, node->children.at[0].accessArg);
|
||||
groundAddReferenceToInstruction(&add, node->children.at[1].accessArg);
|
||||
|
||||
char* tmpId = malloc(sizeof(char) * 64);
|
||||
if (tmpId == NULL) {
|
||||
return Error(GroundProgram, charptr, "Failed to allocate memory for temporary identifier in equal");
|
||||
}
|
||||
snprintf(tmpId, 64, "__SOLS_TMP_EQUAL_%zu", scope->tmpCounter++);
|
||||
|
||||
groundAddReferenceToInstruction(&add, groundCreateReference(DIRREF, tmpId));
|
||||
|
||||
node->accessArg = groundCreateReference(VALREF, tmpId);
|
||||
|
||||
groundAddInstructionToProgram(&gp, add);
|
||||
return Success(GroundProgram, charptr, gp);
|
||||
}
|
||||
|
||||
ResultType(GroundProgram, charptr) generateCode(SolsNode* node, SolsScope* scope) {
|
||||
|
||||
GroundProgram program = groundCreateProgram();
|
||||
@@ -326,6 +387,7 @@ ResultType(GroundProgram, charptr) generateCode(SolsNode* node, SolsScope* scope
|
||||
case SNT_OP_SUB: generate(Sub);
|
||||
case SNT_OP_MUL: generate(Mul);
|
||||
case SNT_OP_DIV: generate(Div);
|
||||
case SNT_OP_EQUAL: generate(Equal);
|
||||
}
|
||||
return Success(GroundProgram, charptr, program);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user