Skip to content

Commit

Permalink
caching now takes into account "last" variable. See the test to see w…
Browse files Browse the repository at this point in the history
…hich case this handles.
  • Loading branch information
davidedc committed Sep 20, 2016
1 parent 518bebf commit 1022a13
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions run-tests.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ test_low_level = ->
test_mroot()
test_dependencies()
test_assignments()
test_caching()

selftest = ->
test_low_level()
Expand Down
7 changes: 3 additions & 4 deletions runtime/freeze.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ freeze = ->
frozenPatterns = []
frozenHash = ""

#for i in [firstFreezableSymbol...symtab.length]
for i in [0...symtab.length]
#if symtab[i].printname == ""
# if isSymbolReclaimable == false
Expand All @@ -22,10 +21,10 @@ freeze = ->
# just clone them
frozenPatterns= userSimplificationsInListForm.slice(0)

return [frozenSymbols, frozenContents, frozenPatterns, binding[LAST], binding[LAST_LATEX_PRINT], zero, one, imaginaryunit, getStateHash()]
return [frozenSymbols, frozenContents, frozenPatterns, zero, one, imaginaryunit, getStateHash()]

unfreeze = (frozen) ->
[frozenSymbols, frozenContents, frozenPatterns, binding[LAST], binding[LAST_LATEX_PRINT], zero, one, imaginaryunit ] = frozen
[frozenSymbols, frozenContents, frozenPatterns, zero, one, imaginaryunit ] = frozen

#clear_symbols()

Expand All @@ -48,7 +47,7 @@ compareState = (previousHash) ->
getStateHash = ->
frozenHash = ""

for i in [firstFreezableSymbol...symtab.length]
for i in [NIL+1...symtab.length]
if symtab[i].printname == ""
if isSymbolReclaimable == false
break
Expand Down
2 changes: 1 addition & 1 deletion runtime/run.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ run = (stringToBeRun, generateLatex = false) ->

if ENABLE_CACHING
frozen = freeze()
toBeFrozen = [frozen[0], frozen[1], frozen[2], frozen[3], frozen[4], frozen[5], frozen[6], frozen[7], (new Date().getTime() - timeStart), stringToBeReturned]
toBeFrozen = [frozen[0], frozen[1], frozen[2], frozen[3], frozen[4], frozen[5], (new Date().getTime() - timeStart), stringToBeReturned]
if CACHE_DEBUGS then console.log "setting cache on key: " + cacheKey
cached_runs.set(cacheKey, toBeFrozen)

Expand Down
16 changes: 16 additions & 0 deletions tests/caching.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
test_caching = ->
run_test [

"2*x",
"2*x",

"d(last)",
"2",

"3*x",
"3*x",

"d(last)",
"3",

]

0 comments on commit 1022a13

Please sign in to comment.