Skip to content

Commit a438068

Browse files
committed
fix pc invalid jump
1 parent 33d5760 commit a438068

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

main.kar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
str f1 "Hello!"
22
call println
3-
jmp -1
3+
lit i8 -

src/main/kotlin/engine/Parser.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ fun parser(vm: Vm, file: List<String>): List<InstructData> {
173173
// throw e
174174
val x = e.message!!.split(" ")[3].substring(1, e.message!!.split(" ").size - 1).toRegisterType()
175175
if (x == null) {
176-
vm.errors.InvalidArgumentFormatException(badType = "BigLong", shouldBe = "Long")
176+
vm.errors.InvalidArgumentFormatException(badType = "Any", shouldBe = "Long")
177177
} else {
178-
vm.errors.InvalidArgumentFormatException(badType = "Long", shouldBe = "Long")
178+
vm.errors.InvalidArgumentFormatException(badType = "Long", shouldBe = "Register")
179179
}
180180
} catch (_: IllegalStateException) {
181181
vm.errors.InvalidArgumentFormatException(

src/main/kotlin/engine/execution/Execute.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ class Execute(val vm: Vm) {
3535
sleep(hertz)
3636

3737
vm.pc++
38+
39+
if (vm.pc - 1 < 0) {
40+
vm.errors.InvalidPcValueException((vm.pc - 1).toString())
41+
}
42+
3843
if (vm.pc - 1L == command.size.toLong()) {
3944
break
4045
}

src/main/kotlin/internals/Vm.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ class Pc(val vm: Vm) {
5757

5858

5959
operator fun getValue(thisRef: Any?, property: KProperty<*>): Long {
60-
61-
return RegisterType.I8.read(vm)
60+
val value = RegisterType.I8.read(vm)
61+
return value
6262
}
6363

6464
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: Long) = kotlin.run {

0 commit comments

Comments
 (0)