-
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.
vm: implement local slot storage for fast lookup
- Loading branch information
Showing
7 changed files
with
42 additions
and
19 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
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
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
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,25 @@ | ||
package gay.pizza.pork.vm | ||
|
||
class LocalSlots { | ||
private var slots = arrayOfNulls<Any>(4) | ||
|
||
fun load(index: UInt): Any { | ||
return slots[index.toInt()] | ||
?: throw VirtualMachineException("Attempted to access local $index that is not stored") | ||
} | ||
|
||
fun store(index: UInt, value: Any) { | ||
if (index >= slots.size.toUInt()) { | ||
resize(index + 4u) | ||
} | ||
slots[index.toInt()] = value | ||
} | ||
|
||
private fun resize(count: UInt) { | ||
val values = arrayOfNulls<Any>(count.toInt()) | ||
for ((i, value) in slots.withIndex()) { | ||
values[i] = value | ||
} | ||
slots = values | ||
} | ||
} |
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
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
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