added exit function to astvm simulator

This commit is contained in:
Irmen de Jong 2020-03-13 02:44:01 +01:00
parent 64d682bfde
commit 0422ad080a
4 changed files with 12 additions and 6 deletions

View File

@ -1054,6 +1054,8 @@ internal class AstChecker(private val program: Program,
}
}
}
// TODO warn about unreachable code following a return statement???
}
private fun checkFunctionOrLabelExists(target: IdentifierReference, statement: Statement): Statement? {

View File

@ -588,6 +588,8 @@ internal class StatementOptimizer(private val program: Program) : IAstModifyingV
statements.removeAt(statements.lastIndex)
}
}
// TODO remove all statements following a 'return' statement ???
}
}

View File

@ -996,6 +996,11 @@ class AstVm(val program: Program, compilationTarget: String) {
else -> RuntimeValueNumeric(DataType.BYTE, 1)
}
}
"exit" -> {
val rv = args.single().numericValue()
dialog.canvas.printAsciiText("\n<program ended with exit($rv)>")
throw VmTerminationException("program ended with exit($rv)")
}
else -> TODO("astvm implement builtin function $name")
}
}

View File

@ -20,9 +20,9 @@ main {
sub sub2() {
c64scr.print("sp2:")
print_stackpointer()
exit(65)
sub3()
sub3()
return
sub3() ; TODO warning about unreachable code
sub3() ; TODO remove statements after a return
sub3()
sub3()
sub3()
@ -40,9 +40,6 @@ main {
}
sub print_stackpointer() {
%asm {{
tsx
}}
c64scr.print_ub(X) ; prints stack pointer
c64.CHROUT('\n')
}