UNPKG

2.12 kBtext/coffeescriptView Raw
1
2cached_runs = new LRUCache(100, 60000 * 60 * 24 * 265)
3cached_findDependenciesInScript = new LRUCache(100, 60000 * 60 * 24 * 265)
4
5freeze = ->
6
7 frozenSymbols = []
8 frozenContents = []
9 frozenPatterns = []
10 frozenHash = ""
11
12 for i in [0...symtab.length]
13 #if symtab[i].printname == ""
14 # if isSymbolReclaimable[i] == false
15 # break
16 # else
17 # continue
18 if isSymbolReclaimable[i] == false
19 frozenSymbols.push symtab[i]
20 frozenContents.push binding[i]
21
22 # just clone them
23 frozenPatterns= userSimplificationsInListForm.slice(0)
24
25 return [frozenSymbols, frozenContents, frozenPatterns, zero, one, imaginaryunit, getStateHash()]
26
27unfreeze = (frozen) ->
28 [frozenSymbols, frozenContents, frozenPatterns, zero, one, imaginaryunit ] = frozen
29
30 #clear_symbols()
31
32 for i in [0...frozenSymbols.length]
33 symtab[i] = frozenSymbols[i]
34 binding[i] = frozenContents[i]
35
36 userSimplificationsInListForm = frozenPatterns.slice(0)
37
38
39compareState = (previousHash) ->
40
41 frozenHash = getStateHash()
42
43 if frozenHash == previousHash
44 return true
45 else
46 return false
47
48resetCache = ->
49 if cached_runs?
50 cached_runs.reset()
51 if DEBUG then console.log "resetting cached_runs"
52
53 if cached_findDependenciesInScript?
54 cached_findDependenciesInScript.reset()
55 if DEBUG then console.log "resetting cached_findDependenciesInScript"
56
57resetCacheHitMissCounts = ->
58 if cached_runs?
59 cached_runs.resetHitMissCount()
60
61 if cached_findDependenciesInScript?
62 cached_findDependenciesInScript.resetHitMissCount()
63
64totalAllCachesHits = ->
65 cached_runs.hitCount + cached_findDependenciesInScript.hitCount
66
67totalAllCachesMisses = ->
68 cached_runs.missCount + cached_findDependenciesInScript.missCount
69
70getStateHash = ->
71 frozenHash = ""
72
73 for i in [NIL+1...symtab.length]
74 if symtab[i].printname == ""
75 if isSymbolReclaimable[i] == false
76 break
77 else
78 continue
79
80 symtabi = print_list(symtab[i])
81 bindingi = print_list(binding[i])
82
83 frozenHash += " //" + symtabi + " : " + bindingi
84
85 for i in userSimplificationsInListForm
86 frozenHash += " pattern: " + i
87
88
89 if DEBUG then console.log "frozenHash: " + frozenHash
90 return frozenHash