mirror of
https://github.com/irmen/prog8.git
synced 2024-09-10 09:54:32 +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.antlr:antlr4-runtime:4.8'
|
||||||
implementation 'org.jetbrains.kotlinx:kotlinx-cli-jvm:0.1.0-dev-5'
|
implementation 'org.jetbrains.kotlinx:kotlinx-cli-jvm:0.1.0-dev-5'
|
||||||
// implementation 'net.razorvine:ksim65:1.6'
|
// implementation 'net.razorvine:ksim65:1.6'
|
||||||
|
implementation("com.github.hypfvieh:dbus-java:3.2.0")
|
||||||
implementation project(':parser')
|
implementation project(':parser')
|
||||||
|
|
||||||
testImplementation "org.jetbrains.kotlin:kotlin-test-junit5"
|
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
|
package prog8.ast.processing
|
||||||
|
|
||||||
import prog8.ast.IFunctionCall
|
|
||||||
import prog8.ast.INameScope
|
import prog8.ast.INameScope
|
||||||
import prog8.ast.Module
|
import prog8.ast.Module
|
||||||
import prog8.ast.Program
|
import prog8.ast.Program
|
||||||
@ -1048,14 +1047,14 @@ internal class AstChecker(private val program: Program,
|
|||||||
|
|
||||||
private fun visitStatements(statements: List<Statement>) {
|
private fun visitStatements(statements: List<Statement>) {
|
||||||
for((index, stmt) in statements.withIndex()) {
|
for((index, stmt) in statements.withIndex()) {
|
||||||
if(stmt is FunctionCallStatement && stmt.target.nameInSource.last()=="exit") {
|
if(stmt is FunctionCallStatement
|
||||||
if(index < statements.lastIndex) {
|
&& stmt.target.nameInSource.last()=="exit"
|
||||||
|
&& index < statements.lastIndex)
|
||||||
printWarning("unreachable code", statements[index+1].position, "exit call above never returns")
|
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? {
|
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)
|
module.statements.addAll(0, directives)
|
||||||
|
|
||||||
for(pos in addReturns) {
|
for(pos in addReturns) {
|
||||||
println(pos)
|
|
||||||
val returnStmt = Return(null, pos.first.position)
|
val returnStmt = Return(null, pos.first.position)
|
||||||
returnStmt.linkParents(pos.first as Node)
|
returnStmt.linkParents(pos.first as Node)
|
||||||
pos.first.statements.add(pos.second, returnStmt)
|
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>) {
|
private fun visitStatements(statements: MutableList<Statement>) {
|
||||||
// remove all statements following the call to exit()
|
// TODO remove all unreachable code statements after call to exit() or a return
|
||||||
val exitCallIndex = statements.indexOfFirst { it is FunctionCallStatement && it.target.nameInSource.last()=="exit" }
|
// this is not yet correct because we still have nested subroutines
|
||||||
if(exitCallIndex>=0) {
|
// val exitCallIndex = statements.indexOfFirst { it is FunctionCallStatement && it.target.nameInSource.last()=="exit" }
|
||||||
while(exitCallIndex < statements.lastIndex) {
|
// if(exitCallIndex>=0) {
|
||||||
statements.removeAt(statements.lastIndex)
|
// while(exitCallIndex < statements.lastIndex) {
|
||||||
}
|
// val stmt = statements[exitCallIndex+1]
|
||||||
}
|
// println("after exit() removing: $stmt")
|
||||||
|
// statements.removeAt(exitCallIndex+1)
|
||||||
// TODO remove all statements following a 'return' statement ???
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
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() {
|
sub sub2() {
|
||||||
c64scr.print("sp2:")
|
c64scr.print("sp2:")
|
||||||
print_stackpointer()
|
print_stackpointer()
|
||||||
return
|
exit(33)
|
||||||
sub3() ; TODO warning about unreachable code
|
sub3() ; TODO warning about unreachable code
|
||||||
sub3() ; TODO remove statements after a return
|
sub3() ; TODO remove statements after a return
|
||||||
|
c64scr.print("sp2:")
|
||||||
|
c64scr.print("sp2:")
|
||||||
|
sub3()
|
||||||
|
|
||||||
|
sub blerp() {
|
||||||
|
;-- keep this!
|
||||||
|
}
|
||||||
|
|
||||||
sub3()
|
sub3()
|
||||||
sub3()
|
sub3()
|
||||||
sub3()
|
sub3()
|
||||||
|
Loading…
Reference in New Issue
Block a user