Skip to content

Commit

Permalink
Reduce more unnecessary evals.
Browse files Browse the repository at this point in the history
  • Loading branch information
corywalker committed Jul 13, 2017
1 parent 2b17881 commit e12e99c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
12 changes: 7 additions & 5 deletions expreduce/builtin_system.go
Expand Up @@ -238,18 +238,20 @@ func GetSystemDefinitions() (defs []Definition) {
// To make sure the result does not change
&StringTest{"6", "x=x*2"},
&StringTest{"36", "x=x*x"},

&StringTest{"a^2", "y=a*a"},
&StringTest{"a^4", "y=y*y"},
&StringTest{"2", "a=2"},
&StringTest{"16", "y"},
},
FurtherExamples: []TestInstruction{
&TestComment{"`Set` has the `HoldFirst` attribute, meaning `rhs` is evaluated before assignment:"},
&SameTest{"{HoldFirst, Protected, SequenceHold}", "Attributes[Set]"},
&TestComment{"`SetDelayed` has the `HoldAll` attribute, meaning `rhs` is not evaluated during assignment:"},
&SameTest{"{HoldAll, Protected, SequenceHold}", "Attributes[SetDelayed]"},
},
KnownFailures: []TestInstruction{
// Embarassing known failures until we fix the re-evaluation issue.
&StringTest{"a^4", "y=y*y"},
&StringTest{"a^2", "y=a*a"},
&StringTest{"2", "a=2"},
&StringTest{"16", "y"},
},
})
defs = append(defs, Definition{
Name: "SetDelayed",
Expand Down
24 changes: 11 additions & 13 deletions expreduce/ex_expression.go
Expand Up @@ -94,15 +94,20 @@ func (this *Expression) Eval(es *EvalState) Ex {
}
var currEx Ex = this.DeepCopy()
insideDefinition := false
//needsEval := currEx.NeedsEval()
//for currEx.NeedsEval() && currExHash != lastExHash {
for currExHash != lastExHash {
//fmt.Printf("%v, %v\n", currExHash, lastExHash)
lastExHash = currExHash
curr, isExpr := currEx.(*Expression)
// if isExpr && currExHash == curr.cachedHash {
// return this
// }

if isExpr && insideDefinition {
retVal, isReturn := tryReturnValue(curr)
if isReturn {
return retVal
}
}
if isExpr && currExHash == curr.cachedHash {
return curr
}

if *printevals {
fmt.Printf("Evaluating %v.\n", curr)
}
Expand All @@ -125,13 +130,6 @@ func (this *Expression) Eval(es *EvalState) Ex {
return toReturn
}

if insideDefinition {
retVal, isReturn := tryReturnValue(curr)
if isReturn {
return retVal
}
}

// Start by evaluating each argument
headSym, headIsSym := &Symbol{}, false
attrs := Attributes{}
Expand Down

0 comments on commit e12e99c

Please sign in to comment.