Skip to content

Commit b24bb25

Browse files
committed
working str
1 parent b96057b commit b24bb25

File tree

9 files changed

+39
-29
lines changed

9 files changed

+39
-29
lines changed

src/main/kotlin/Main.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import data.io.FileDescriptors
32
import data.memory.InternalMemory
43
import data.registers.Registers
@@ -99,6 +98,11 @@ fun main(args: Array<String>) {
9998
exitProcess(1)
10099
}
101100
}
101+
102+
exitVM()
102103
}
103104

104105

106+
fun exitVM(): Nothing = exitProcess(0)
107+
108+

src/main/kotlin/data/registers/RegisterType.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import data.registers.RegisterDataType.*
88
* This enumeration allows for a unified way to refer to any register type, regardless of its specific category (General, System, or Return).
99
*/
1010
enum class RegisterType {
11-
G1, G2, G3, G4, G5, G6, G7, G8, F1, F2, F3, F4, F5, F6, F7, F8, IF1, IF2, IF3, IF4, IF5, IF6, IF7, IF8, R1, R2, R3, R4, R5, R6, R7, R8, S4, S1, S2, S3, I1, I2, I3, I4, I5, I6, I7,I8, X0, X1, X2, X3, X4, X5, X6, X7, X8,
11+
G1, G2, G3, G4, G5, G6, G7, G8, F1, F2, F3, F4, F5, F6, F7, F8, R1, R2, R3, R4, R5, R6, R7, R8, S4, S1, S2, S3, I1, I2, I3, I4, I5, I6, I7, I8, X0, X1, X2, X3, X4, X5, X6, X7, X8,
1212
}
1313

1414
fun String.toRegisterDataType() = when (this.lowercase()) {
@@ -58,9 +58,6 @@ data class RegisterData(val name: RegisterType, var data: Long?, var dataType: R
5858
}
5959

6060

61-
62-
63-
6461
fun settype(newType: RegisterDataType) {
6562
dataType = when (newType) {
6663
RByte -> RByte

src/main/kotlin/engine/v2/TransMapIDs.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,8 @@ class TransMapIDs {
3131
F2 to '',
3232
F3 to '£',
3333
F4 to '¢',
34-
IF1 to '',
35-
IF2 to '§',
36-
IF3 to '',
37-
IF4 to ''
38-
)
34+
35+
)
3936

4037
val instructions = mapOf(
4138
"mov" to 'a',

src/main/kotlin/environment/ExecuteLib.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import environment.libEx.executeMar
66
import environment.libEx.findMarLib
77
import java.io.File
88

9-
9+
val snapShotManager = SnapShotManager()
1010
class ExecuteLib {
11-
val sm = SnapShotManager()
1211
var currentFunction = ""
1312
var enabledFunction = false
1413

src/main/kotlin/environment/libEx/SnapShotManager.kt

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import internalMemory
77
import registers
88

99
class SnapShotManager {
10+
11+
var safeMemory = mutableSetOf<LongRange>()
12+
1013
fun populateSnapShotRegister(snapShotRegisters: Map<RegisterType, Long?>) {
1114
for (i in snapShotRegisters) {
1215
registers.writeUnsafe(i.key, i.value)
@@ -15,16 +18,22 @@ class SnapShotManager {
1518

1619
fun snapShotRegisters(): Map<RegisterType, Long?> {
1720
val allRegisters = mutableMapOf<RegisterType, Long?>()
21+
allRegisters.forEach { if (!it.key.name.startsWith('I')) allRegisters.remove(it.key) }
1822
for (i in RegisterType.entries) {
1923
allRegisters[i] = registers.readUnsafe(i)
2024
}
2125
return allRegisters
2226
}
2327

24-
fun snapShotMemory(): Map<MemoryAddress, MemoryValue> = internalMemory.memory
25-
28+
fun snapShotMemory(): Map<MemoryAddress, MemoryValue> = internalMemory.memory.toMutableMap()
2629
fun populateSnapShotMemory(memory: Map<MemoryAddress, MemoryValue>) {
27-
internalMemory.memory = memory.toMutableMap()
30+
val internalMem = memory.toMutableMap()
31+
safeMemory.forEach {
32+
for (i in it) {
33+
internalMem[MemoryAddress(i)] = internalMemory.memory[MemoryAddress(i)] as MemoryValue
34+
}
35+
}
36+
internalMemory.memory = internalMem.toMutableMap()
2837
}
2938

3039

@@ -37,6 +46,12 @@ class SnapShotManager {
3746
fun populateSnapShot(data: SnapData) {
3847
populateSnapShotMemory(data.memory)
3948
populateSnapShotRegister(data.registers)
49+
safeMemory.clear()
50+
}
51+
52+
53+
fun memoryRequestBlock(intRange: LongRange) {
54+
safeMemory.add(intRange)
4055
}
4156

4257

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
package environment.libEx
22

33
import environment.ExecuteLib
4+
import environment.snapShotManager
45
import errors
56
import kilb.Klib
67
import vm
78

89
fun ExecuteLib.executeKt(name: String) {
910
val oldPc = vm.pc
10-
val snapshot = sm.fullSnapshot()
11+
val snapshot = snapShotManager.fullSnapshot()
1112
if (!Klib().match(name)) {
1213
errors.MissingLibraryException(name) // Kt should be the last resort
1314
}
1415
currentFunction = name
15-
sm.populateSnapShot(snapshot)
16+
snapShotManager.populateSnapShot(snapshot)
1617
vm.pc = oldPc
1718
}

src/main/kotlin/environment/libEx/executeMar.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ package environment.libEx
33
import engine.execution.Execute
44
import engine.parser
55
import environment.ExecuteLib
6+
import environment.snapShotManager
67
import vm
78
import java.io.File
89

910
fun ExecuteLib.executeMar(file: File) {
1011
val oldPc = vm.pc
11-
val snapshot = sm.fullSnapshot()
12+
val snapshot = snapShotManager.fullSnapshot()
1213
vm.pc - 2
1314
Execute().run(parser(file.readLines().subList(0, file.readLines().size)))
14-
sm.populateSnapShot(snapshot)
15+
snapShotManager.populateSnapShot(snapshot)
1516
vm.pc = oldPc
1617
}

src/main/kotlin/helpers/stringToSuperRegisterType.kt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,6 @@ fun String.toUnsafeRegisterType(): RegisterType? {
4747
"f7" -> RegisterType.F7
4848
"f8" -> RegisterType.F8
4949

50-
"if1" -> RegisterType.IF1
51-
"if2" -> RegisterType.IF2
52-
"if3" -> RegisterType.IF3
53-
"if4" -> RegisterType.IF4
54-
"if5" -> RegisterType.IF5
55-
"if6" -> RegisterType.IF6
56-
"if7" -> RegisterType.IF7
57-
"if8" -> RegisterType.IF8
5850

5951
"i1" -> RegisterType.I1
6052
"i2" -> RegisterType.I2

src/main/kotlin/kilb/Strings.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import data.memory.MemoryAddress
44
import data.registers.IntelRegisters
55
import data.registers.RegisterType
66
import data.registers.intelNames
7+
import environment.snapShotManager
78
import helpers.readRegisterString
89
import helpers.toLong
910
import helpers.writeClosestString
@@ -21,8 +22,9 @@ class Strings {
2122
// if (s1 == s2) registers.write(register = R4, value = 0)
2223
// else registers.write(register = R4, value = 1)
2324

24-
if (s1 == s2) vm.stackOperations.internalStack.push(true.toLong())
25-
else vm.stackOperations.internalStack.push(false.toLong())
25+
26+
if (s1 == s2) registers.write(intelNames[IntelRegisters.EF], true.toLong())
27+
else registers.write(intelNames[IntelRegisters.EF], false.toLong())
2628

2729
}
2830

@@ -31,6 +33,7 @@ class Strings {
3133
val s1: String = readRegisterString(register = RegisterType.F1)
3234
val s2: Comparable<String> = readRegisterString(register = RegisterType.F2)
3335
val location = writeClosestString(string = (s1 + s2))
36+
snapShotManager.memoryRequestBlock(location..location + (s1 + s2).length)
3437
// registers.write(R4, location)
3538
vm.stackOperations.internalStack.push(location)
3639

@@ -40,6 +43,7 @@ class Strings {
4043
registers.write(intelNames[IntelRegisters.ENSF], true.toLong())
4144
val string: String = readRegisterString(register = RegisterType.F1)
4245
val destinationAddress: Long = registers.read(register = RegisterType.F2)
46+
snapShotManager.memoryRequestBlock(destinationAddress..destinationAddress + string.length)
4347
writeStringSpecInMemory(string = string, destinationAddress = MemoryAddress(address = destinationAddress))
4448
}
4549

0 commit comments

Comments
 (0)