File tree Expand file tree Collapse file tree 4 files changed +39
-36
lines changed Expand file tree Collapse file tree 4 files changed +39
-36
lines changed Original file line number Diff line number Diff line change 1
- help printr
2
- str f1 "Hello, World!"
3
- call println
4
- xlit x1 0.2
5
- xlit x2 3.14
6
- xadd x1 x2
7
- cpy r5 f1
8
- call strings.cheekyfloat
1
+ lit g1 1
2
+ lit r4 0
3
+ lit f1 10
4
+ cpy f1 g4
5
+ lit g5 2
6
+ call arrays.create
7
+
8
+ lt r4 g4
9
+ peek f1
10
+ add g1 r4
11
+ mul r4 g5
12
+ cpy r4 f2
13
+ call arrays.append
14
+ jnz 8 i3
15
+
16
+ lit g1 3
17
+ load g1 g2
18
+ printr g2
Original file line number Diff line number Diff line change 1
1
package helpers
2
2
3
+ import MEMORY_LIMIT
4
+ import data.memory.MemoryAddress
3
5
import errors
4
6
import internalMemory
7
+ import kotlin.system.exitProcess
5
8
6
9
7
10
// should work with writeClosestString
8
11
fun findFreeMemory (size : Long ): Long {
9
- val possibleStarts = emptyMap<Long ?, Any ?>().toMutableMap()
12
+ var currentAddress = 0L
13
+ var freeCount = 0L
10
14
11
- internalMemory.memory.forEach {
12
- possibleStarts[it.key.address] = it.value.value
13
- }
14
- possibleStarts.filter { it.value == 0 }
15
-
16
- // Find a SPOT for a starting address for the string
17
- var spot: Long? = null
18
- for (i in possibleStarts.keys) {
19
- var count = 0L
20
- for (j in 0L .. size) {
21
- if (possibleStarts[i!! + j] == null ) {
22
- count++
15
+ while (currentAddress + size <= MEMORY_LIMIT ) {
16
+ if (internalMemory.memory[MemoryAddress (currentAddress)]?.value == null ) {
17
+ freeCount++
18
+ if (freeCount == size + 1L ) {
19
+ return currentAddress - size
23
20
}
21
+ } else {
22
+ freeCount = 0L
24
23
}
25
- if (count == size + 1L ) {
26
- spot = i
27
- break
28
- }
24
+ currentAddress++
29
25
}
30
26
31
- if (spot == null ) {
32
- errors.MemoryAllocationException (" Could not allocate memory" )
33
- }
34
- return spot!!
35
- }
27
+ errors.MemoryAllocationException (" Could not allocate memory" )
28
+ exitProcess(1 )
29
+ }
Original file line number Diff line number Diff line change 2
2
// f2 = value
3
3
lit s1 27
4
4
call arrays.size
5
- cpy f1 s1
6
- pop s2
7
- mov f2 s3
5
+ cpy f1 s2
6
+ pop s3
7
+ mov f2 s4
8
8
syscall
9
9
Original file line number Diff line number Diff line change 1
-
2
1
lit s1 28
3
- mov f1 s1
4
- mov f2 s2
2
+ mov f1 s2 // array location
3
+ mov f2 s3 // array index
5
4
syscall
6
5
push r2
You can’t perform that action at this time.
0 commit comments