basic renum function

This commit is contained in:
minjaesong
2020-06-01 04:55:49 +09:00
parent ad830866be
commit 1e0f122aff
2 changed files with 70 additions and 34 deletions

View File

@@ -192,8 +192,7 @@ class VM(
internal fun malloc(size: Int): Int {
val allocBlocks = ceil(size.toDouble() / MALLOC_UNIT).toInt()
val blockStart = findEmptySpace(allocBlocks)
if (blockStart == null) throw OutOfMemoryError()
val blockStart = findEmptySpace(allocBlocks) ?: throw OutOfMemoryError()
mallocSizes[blockStart] = allocBlocks
return blockStart * MALLOC_UNIT
@@ -201,8 +200,7 @@ class VM(
internal fun free(ptr: Int) {
val index = ptr / MALLOC_UNIT
val count = mallocSizes[index]
if (count == null) throw OutOfMemoryError()
val count = mallocSizes[index] ?: throw OutOfMemoryError()
mallocMap.set(index, index + count, false)
mallocSizes.remove(index)