-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c36e7e4
commit cc328ab
Showing
6 changed files
with
90 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,25 @@ | ||
lit f1 2 | ||
call alloc | ||
peek g1 | ||
lit g2 10 | ||
lit g3 1 | ||
|
||
store g2 g1 | ||
lit f1 4 | ||
call arrays.create | ||
|
||
add g1 g3 r1 | ||
pop g1 | ||
|
||
add g2 g3 g2 | ||
add g2 g3 g2 | ||
add g2 g3 g2 | ||
add g2 g3 g2 | ||
lit f1 4 | ||
call arrays.create | ||
|
||
peek f1 | ||
|
||
store g2 r1 | ||
|
||
lit f2 0 | ||
lit f3 111 | ||
call arrays.add | ||
|
||
load g1 r2 | ||
printr r2 | ||
|
||
|
||
add g1 g3 g1 | ||
|
||
load g1 r2 | ||
|
||
printr r2 | ||
lit f2 1 | ||
lit f3 222 | ||
call arrays.add | ||
|
||
mov g1 f1 | ||
printr f1 | ||
lit f2 4 | ||
lit f3 333 | ||
call arrays.add |
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 |
---|---|---|
@@ -1,12 +1,68 @@ | ||
package kilb | ||
|
||
import data.registers.RegisterType | ||
import data.registers.read | ||
import internals.Vm | ||
import os | ||
|
||
class Arrays(val vm: Vm) { | ||
val h = vm.heap!! | ||
fun size() { | ||
val meta = vm.registers.read(RegisterType.F1) | ||
val count = vm.heap!!.get(meta + 1) | ||
vm.stackOperations.internalStack.push(count) | ||
} | ||
|
||
fun create() { | ||
val size = RegisterType.F1.read(vm) | ||
val startAddr = h.alloc(size.toInt() + 1) | ||
h.set(startAddr, size) | ||
sreturn(vm, startAddr) | ||
} | ||
|
||
fun get() { | ||
val stAddr = RegisterType.F1.read(vm) | ||
val size = h.get(stAddr) | ||
val minAddr = stAddr + 1 | ||
println("-----------------------------------------------------------------------------") | ||
println("OS M = ${os.mainMemory.toList().subList(0, 30).joinToString()}") | ||
|
||
val index = RegisterType.F2.read(vm) | ||
val value = RegisterType.F3.read(vm) | ||
|
||
if (index >= size) { | ||
println("Index = $index, size - 2 = ${size - 2}") | ||
println("NOO!!!") | ||
return | ||
} | ||
h.set(minAddr + index, value) | ||
|
||
println("OS M = ${os.mainMemory.toList().subList(0, 30).joinToString()}") | ||
} | ||
|
||
fun add() { | ||
val stAddr = RegisterType.F1.read(vm) | ||
// F1 = addr | ||
// F2 = index | ||
// F3 = value | ||
val size = h.get(stAddr) | ||
val minAddr = stAddr + 1 | ||
|
||
val index = RegisterType.F2.read(vm) | ||
val value = RegisterType.F3.read(vm) | ||
|
||
if (index >= size) { | ||
println("Index = $index, size - 2 = ${size - 2}") | ||
println("ERRRORRR!!! FOR ADD RAY!") | ||
return | ||
} | ||
h.set(minAddr + index, value) | ||
} | ||
|
||
|
||
// fun createLinked(vm: Vm) { | ||
// | ||
// } | ||
|
||
|
||
} |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.