mirror of
https://github.com/irmen/prog8.git
synced 2024-11-22 15:33:02 +00:00
warning about unreachable code after a return statement
added some dbus experiments for future compilation service
This commit is contained in:
parent
0422ad080a
commit
1382728bd2
@ -34,6 +34,7 @@ dependencies {
|
||||
implementation 'org.antlr:antlr4-runtime:4.8'
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-cli-jvm:0.1.0-dev-5'
|
||||
// implementation 'net.razorvine:ksim65:1.6'
|
||||
implementation("com.github.hypfvieh:dbus-java:3.2.0")
|
||||
implementation project(':parser')
|
||||
|
||||
testImplementation "org.jetbrains.kotlin:kotlin-test-junit5"
|
||||
|
BIN
compiler/lib/dbus-java-3.2.0.jar
Normal file
BIN
compiler/lib/dbus-java-3.2.0.jar
Normal file
Binary file not shown.
@ -1,6 +1,5 @@
|
||||
package prog8.ast.processing
|
||||
|
||||
import prog8.ast.IFunctionCall
|
||||
import prog8.ast.INameScope
|
||||
import prog8.ast.Module
|
||||
import prog8.ast.Program
|
||||
@ -1048,14 +1047,14 @@ internal class AstChecker(private val program: Program,
|
||||
|
||||
private fun visitStatements(statements: List<Statement>) {
|
||||
for((index, stmt) in statements.withIndex()) {
|
||||
if(stmt is FunctionCallStatement && stmt.target.nameInSource.last()=="exit") {
|
||||
if(index < statements.lastIndex) {
|
||||
printWarning("unreachable code", statements[index+1].position, "exit call above never returns")
|
||||
}
|
||||
}
|
||||
}
|
||||
if(stmt is FunctionCallStatement
|
||||
&& stmt.target.nameInSource.last()=="exit"
|
||||
&& index < statements.lastIndex)
|
||||
printWarning("unreachable code", statements[index+1].position, "exit call above never returns")
|
||||
|
||||
// TODO warn about unreachable code following a return statement???
|
||||
if(stmt is Return && index < statements.lastIndex)
|
||||
printWarning("unreachable code", statements[index+1].position, "return statement above")
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkFunctionOrLabelExists(target: IdentifierReference, statement: Statement): Statement? {
|
||||
|
@ -95,7 +95,6 @@ internal class StatementReorderer(private val program: Program): IAstModifyingVi
|
||||
module.statements.addAll(0, directives)
|
||||
|
||||
for(pos in addReturns) {
|
||||
println(pos)
|
||||
val returnStmt = Return(null, pos.first.position)
|
||||
returnStmt.linkParents(pos.first as Node)
|
||||
pos.first.statements.add(pos.second, returnStmt)
|
||||
|
@ -581,15 +581,16 @@ internal class StatementOptimizer(private val program: Program) : IAstModifyingV
|
||||
|
||||
|
||||
private fun visitStatements(statements: MutableList<Statement>) {
|
||||
// remove all statements following the call to exit()
|
||||
val exitCallIndex = statements.indexOfFirst { it is FunctionCallStatement && it.target.nameInSource.last()=="exit" }
|
||||
if(exitCallIndex>=0) {
|
||||
while(exitCallIndex < statements.lastIndex) {
|
||||
statements.removeAt(statements.lastIndex)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO remove all statements following a 'return' statement ???
|
||||
// TODO remove all unreachable code statements after call to exit() or a return
|
||||
// this is not yet correct because we still have nested subroutines
|
||||
// val exitCallIndex = statements.indexOfFirst { it is FunctionCallStatement && it.target.nameInSource.last()=="exit" }
|
||||
// if(exitCallIndex>=0) {
|
||||
// while(exitCallIndex < statements.lastIndex) {
|
||||
// val stmt = statements[exitCallIndex+1]
|
||||
// println("after exit() removing: $stmt")
|
||||
// statements.removeAt(exitCallIndex+1)
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
22
compiler/src/prog8/server/dbus/IrmenDbusTest.kt
Normal file
22
compiler/src/prog8/server/dbus/IrmenDbusTest.kt
Normal file
@ -0,0 +1,22 @@
|
||||
package prog8.server.dbus
|
||||
|
||||
import org.freedesktop.dbus.interfaces.DBusInterface
|
||||
|
||||
|
||||
interface IrmenDbusTest: DBusInterface
|
||||
{
|
||||
fun Status(address: String): Map<Int, String>
|
||||
}
|
||||
|
||||
|
||||
internal class TestService: IrmenDbusTest {
|
||||
override fun Status(address: String): Map<Int, String> {
|
||||
return mapOf(
|
||||
5 to "hello",
|
||||
42 to address
|
||||
)
|
||||
}
|
||||
|
||||
override fun isRemote() = true
|
||||
override fun getObjectPath() = "/razorvine/TestService"
|
||||
}
|
16
compiler/src/prog8/server/dbus/clientmain.kt
Normal file
16
compiler/src/prog8/server/dbus/clientmain.kt
Normal file
@ -0,0 +1,16 @@
|
||||
package prog8.server.dbus
|
||||
|
||||
import org.freedesktop.dbus.connections.impl.DBusConnection
|
||||
|
||||
|
||||
fun main() {
|
||||
DBusConnection.getConnection(DBusConnection.DBusBusType.SESSION).use {
|
||||
println(it.names.toList())
|
||||
println(it.uniqueName)
|
||||
println(it.address)
|
||||
println(it.machineId)
|
||||
val obj = it.getRemoteObject("local.net.razorvine.dbus.test", "/razorvine/TestService", IrmenDbusTest::class.java)
|
||||
println(obj.Status("irmen"))
|
||||
}
|
||||
}
|
||||
|
18
compiler/src/prog8/server/dbus/testdbus.kt
Normal file
18
compiler/src/prog8/server/dbus/testdbus.kt
Normal file
@ -0,0 +1,18 @@
|
||||
package prog8.server.dbus
|
||||
|
||||
import org.freedesktop.dbus.connections.impl.DBusConnection
|
||||
|
||||
|
||||
fun main() {
|
||||
DBusConnection.getConnection(DBusConnection.DBusBusType.SESSION).use {
|
||||
it.requestBusName("local.net.razorvine.dbus.test")
|
||||
println(it.names.toList())
|
||||
println(it.uniqueName)
|
||||
println(it.address)
|
||||
println(it.machineId)
|
||||
val service = TestService()
|
||||
it.exportObject(service.objectPath, service)
|
||||
|
||||
Thread.sleep(100000)
|
||||
}
|
||||
}
|
@ -20,9 +20,17 @@ main {
|
||||
sub sub2() {
|
||||
c64scr.print("sp2:")
|
||||
print_stackpointer()
|
||||
return
|
||||
exit(33)
|
||||
sub3() ; TODO warning about unreachable code
|
||||
sub3() ; TODO remove statements after a return
|
||||
c64scr.print("sp2:")
|
||||
c64scr.print("sp2:")
|
||||
sub3()
|
||||
|
||||
sub blerp() {
|
||||
;-- keep this!
|
||||
}
|
||||
|
||||
sub3()
|
||||
sub3()
|
||||
sub3()
|
||||
|
Loading…
Reference in New Issue
Block a user