-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
evaluator: implement an elaborate system that should mean that recurs…
…ive functions don't require reaching far up the stack
- Loading branch information
Showing
3 changed files
with
36 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
evaluator/src/main/kotlin/gay/pizza/pork/evaluator/FastVariableCache.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package gay.pizza.pork.evaluator | ||
|
||
class FastVariableCache { | ||
private val cache = mutableMapOf<String, Any>() | ||
|
||
fun put(key: String, value: Any) { | ||
cache[key] = value | ||
} | ||
|
||
fun lookup(key: String): Any = cache[key] ?: NotFound | ||
fun has(key: String): Boolean = cache.containsKey(key) | ||
|
||
fun invalidate(key: String) { | ||
cache.remove(key) | ||
} | ||
|
||
object NotFound | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters