Start work on dropping tmp vars after use

This commit is contained in:
2025-12-22 14:26:12 +11:00
parent 525b2bc733
commit 957e0fd95a
2 changed files with 26 additions and 0 deletions

View File

@@ -73,6 +73,7 @@ namespace Solstice {
case SolNodeType::Value: {
outputId = "tmp_" + std::to_string(tmpIdIterator++);
SolGroundCodeBlock codeBlock;
codeBlock.toBeDropped.push_back(outputId);
GroundInstruction gi = groundCreateInstruction(SET);
groundAddReferenceToInstruction(&gi, groundCreateReference(DIRREF, outputId.data()));
switch (data.type) {
@@ -119,6 +120,7 @@ namespace Solstice {
case SolNodeType::Add: {
SolGroundCodeBlock codeBlock;
outputId = "tmp_" + std::to_string(tmpIdIterator++);
codeBlock.toBeDropped.push_back(outputId);
GroundInstruction gi = groundCreateInstruction(ADD);
if (children.size() < 2) {
std::cout << "Need more stuff to add\n";
@@ -133,6 +135,7 @@ namespace Solstice {
case SolNodeType::Equal: {
SolGroundCodeBlock codeBlock;
outputId = "tmp_" + std::to_string(tmpIdIterator++);
codeBlock.toBeDropped.push_back(outputId);
GroundInstruction gi = groundCreateInstruction(EQUAL);
if (children.size() < 2) {
std::cout << "Need more stuff to equal\n";
@@ -147,6 +150,7 @@ namespace Solstice {
case SolNodeType::Inequal: {
SolGroundCodeBlock codeBlock;
outputId = "tmp_" + std::to_string(tmpIdIterator++);
codeBlock.toBeDropped.push_back(outputId);
GroundInstruction gi = groundCreateInstruction(INEQUAL);
if (children.size() < 2) {
std::cout << "Need more stuff to inequal\n";
@@ -161,6 +165,7 @@ namespace Solstice {
case SolNodeType::Greater: {
SolGroundCodeBlock codeBlock;
outputId = "tmp_" + std::to_string(tmpIdIterator++);
codeBlock.toBeDropped.push_back(outputId);
GroundInstruction gi = groundCreateInstruction(GREATER);
if (children.size() < 2) {
std::cout << "Need more stuff to greater\n";
@@ -175,6 +180,7 @@ namespace Solstice {
case SolNodeType::Lesser: {
SolGroundCodeBlock codeBlock;
outputId = "tmp_" + std::to_string(tmpIdIterator++);
codeBlock.toBeDropped.push_back(outputId);
GroundInstruction gi = groundCreateInstruction(LESSER);
if (children.size() < 2) {
std::cout << "Need more stuff to lesser\n";
@@ -192,9 +198,13 @@ namespace Solstice {
std::cout << "Need more stuff to inequal\n";
}
outputId = "tmp_" + std::to_string(tmpIdIterator++);
codeBlock.toBeDropped.push_back(outputId);
std::string trueLabelIdString = "internal_true" + std::to_string(labelIterator++);
codeBlock.toBeDropped.push_back(trueLabelIdString);
std::string falseLabelIdString = "internal_false" + std::to_string(labelIterator);
codeBlock.toBeDropped.push_back(falseLabelIdString);
std::string endLabelIdString = "internal_end" + std::to_string(labelIterator);
codeBlock.toBeDropped.push_back(endLabelIdString);
char* trueLabelId = (char*) malloc(sizeof(char) * (trueLabelIdString.size() + 1));
strcpy(trueLabelId, trueLabelIdString.data());
char* falseLabelId = (char*) malloc(sizeof(char) * (falseLabelIdString.size() + 1));
@@ -262,9 +272,13 @@ namespace Solstice {
std::cout << "Need more stuff to inequal\n";
}
outputId = "tmp_" + std::to_string(tmpIdIterator++);
codeBlock.toBeDropped.push_back(outputId);
std::string trueLabelIdString = "internal_true" + std::to_string(labelIterator++);
codeBlock.toBeDropped.push_back(trueLabelIdString);
std::string falseLabelIdString = "internal_false" + std::to_string(labelIterator);
codeBlock.toBeDropped.push_back(falseLabelIdString);
std::string endLabelIdString = "internal_end" + std::to_string(labelIterator);
codeBlock.toBeDropped.push_back(endLabelIdString);
char* trueLabelId = (char*) malloc(sizeof(char) * (trueLabelIdString.size() + 1));
strcpy(trueLabelId, trueLabelIdString.data());
char* falseLabelId = (char*) malloc(sizeof(char) * (falseLabelIdString.size() + 1));
@@ -342,6 +356,7 @@ namespace Solstice {
code.insert(code.end(), conditionCode.begin(), conditionCode.end());
outputId = "tmp_" + std::to_string(tmpIdIterator++);
SolGroundCodeBlock codeBlock;
codeBlock.toBeDropped.push_back(outputId);
GroundInstruction gi = groundCreateInstruction(NOT);
groundAddReferenceToInstruction(&gi, groundCreateReference(VALREF, children[0].outputId.data()));
groundAddReferenceToInstruction(&gi, groundCreateReference(DIRREF, outputId.data()));
@@ -384,6 +399,7 @@ namespace Solstice {
SolGroundCodeBlock checkBlock;
outputId = "tmp_" + std::to_string(tmpIdIterator++);
checkBlock.toBeDropped.push_back(outputId);
GroundInstruction gi = groundCreateInstruction(NOT);
groundAddReferenceToInstruction(&gi, groundCreateReference(VALREF, children[0].outputId.data()));
groundAddReferenceToInstruction(&gi, groundCreateReference(DIRREF, outputId.data()));
@@ -432,6 +448,7 @@ namespace Solstice {
}
GroundInstruction inputInstruction = groundCreateInstruction(INPUT);
outputId = "tmp_" + std::to_string(tmpIdIterator++);
inputCodeBlock.toBeDropped.push_back(outputId);
groundAddReferenceToInstruction(&inputInstruction, groundCreateReference(DIRREF, outputId.data()));
inputCodeBlock.code.push_back(inputInstruction);
code.push_back(inputCodeBlock);
@@ -854,6 +871,14 @@ namespace Solstice {
for (const auto& inst : code[i].code) {
groundAddInstructionToProgram(&gp, inst);
}
// Fix this later
/*
for (auto& tmpVar : code[i].toBeDropped) {
GroundInstruction gi = groundCreateInstruction(DROP);
groundAddReferenceToInstruction(&gi, groundCreateReference(DIRREF, tmpVar.data()));
groundAddInstructionToProgram(&gp, gi);
}
*/
}
return gp;
}

View File

@@ -28,6 +28,7 @@ namespace Solstice {
class SolGroundCodeBlock {
public:
std::vector<GroundInstruction> code;
std::vector<std::string> toBeDropped;
SolGroundCodeBlock() = default;
};