diff --git a/src/CGenerator.cpp b/src/CGenerator.cpp index bf4bf12..2dfb0bd 100644 --- a/src/CGenerator.cpp +++ b/src/CGenerator.cpp @@ -294,20 +294,23 @@ CCodeTriple CGenerator::generate(NodeTree* from, NodeTree* enc } //If we're in an object method, and our enclosing scope is that object, we're a member of the object and should use the this reference. std::string preName; + std::string postName; //std::string preName = "/*ident*/"; // check for this being a closed over variable // first, get declaring function, if it exists if (enclosingFunction) { if (enclosingFunction->getDataRef()->closedVariables.size()) { std::cout << "WHOH IS A CLOSER" << std::endl; - if (enclosingFunction->getDataRef()->closedVariables.find(from) != enclosingFunction->getDataRef()->closedVariables.end()) - preName += "/* SPECIAL CLOSED */ *closed_varibles->"; + if (enclosingFunction->getDataRef()->closedVariables.find(from) != enclosingFunction->getDataRef()->closedVariables.end()) { + preName += "(*closed_varibles->"; + postName += ")"; + } } } if (enclosingObject && enclosingObject->getDataRef()->scope.find(data.symbol.getName()) != enclosingObject->getDataRef()->scope.end()) preName += "this->"; // we're scope prefixing EVERYTHING - return preName + scopePrefix(from) + CifyName(data.symbol.getName()); //Cifying does nothing if not an operator overload + return preName + scopePrefix(from) + CifyName(data.symbol.getName()) + postName; //Cifying does nothing if not an operator overload } case function: { diff --git a/tests/test_lambda.expected_results b/tests/test_lambda.expected_results index 98281df..23e9cbb 100644 --- a/tests/test_lambda.expected_results +++ b/tests/test_lambda.expected_results @@ -16,3 +16,7 @@ closures now 1337 13371010 80 +40 +41 +41 +42 diff --git a/tests/test_lambda.krak b/tests/test_lambda.krak index 5abdfd5..879ae20 100644 --- a/tests/test_lambda.krak +++ b/tests/test_lambda.krak @@ -34,6 +34,12 @@ fun main():int { var idx = 0 runLambda(fun():int { return v.get(idx);}) + var outside = 40 + runLambda(fun():int { var toRet = outside; outside += 1; return toRet;}) + println(outside) + runLambda(fun():int { var toRet = outside; outside++; return toRet;}) + println(outside) + return 0 }