add perentheses around closed variable access (*closed_variables->a), etc, so that nothing can have higher precidence than the dereference (++ was incrementing the pointer instead of the value)
This commit is contained in:
@@ -294,20 +294,23 @@ CCodeTriple CGenerator::generate(NodeTree<ASTData>* from, NodeTree<ASTData>* 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.
|
//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 preName;
|
||||||
|
std::string postName;
|
||||||
//std::string preName = "/*ident*/";
|
//std::string preName = "/*ident*/";
|
||||||
// check for this being a closed over variable
|
// check for this being a closed over variable
|
||||||
// first, get declaring function, if it exists
|
// first, get declaring function, if it exists
|
||||||
if (enclosingFunction) {
|
if (enclosingFunction) {
|
||||||
if (enclosingFunction->getDataRef()->closedVariables.size()) {
|
if (enclosingFunction->getDataRef()->closedVariables.size()) {
|
||||||
std::cout << "WHOH IS A CLOSER" << std::endl;
|
std::cout << "WHOH IS A CLOSER" << std::endl;
|
||||||
if (enclosingFunction->getDataRef()->closedVariables.find(from) != enclosingFunction->getDataRef()->closedVariables.end())
|
if (enclosingFunction->getDataRef()->closedVariables.find(from) != enclosingFunction->getDataRef()->closedVariables.end()) {
|
||||||
preName += "/* SPECIAL CLOSED */ *closed_varibles->";
|
preName += "(*closed_varibles->";
|
||||||
|
postName += ")";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (enclosingObject && enclosingObject->getDataRef()->scope.find(data.symbol.getName()) != enclosingObject->getDataRef()->scope.end())
|
if (enclosingObject && enclosingObject->getDataRef()->scope.find(data.symbol.getName()) != enclosingObject->getDataRef()->scope.end())
|
||||||
preName += "this->";
|
preName += "this->";
|
||||||
// we're scope prefixing EVERYTHING
|
// 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:
|
case function:
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,3 +16,7 @@ closures now
|
|||||||
1337
|
1337
|
||||||
13371010
|
13371010
|
||||||
80
|
80
|
||||||
|
40
|
||||||
|
41
|
||||||
|
41
|
||||||
|
42
|
||||||
|
|||||||
@@ -34,6 +34,12 @@ fun main():int {
|
|||||||
var idx = 0
|
var idx = 0
|
||||||
runLambda(fun():int { return v.get(idx);})
|
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
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user