From 034973a9e666e89f19d4d691d65e3f777d1518e3 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Tue, 20 Nov 2018 18:01:53 +0100 Subject: [PATCH] asm fixes --- compiler/compiler.iml | 6 ++-- compiler/examples/test.p8 | 33 ++++++++++--------- .../src/prog8/ast/AstIdentifiersChecker.kt | 10 +++++- compiler/src/prog8/compiler/Compiler.kt | 2 -- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/compiler/compiler.iml b/compiler/compiler.iml index f4ce5d996..35568f7d3 100644 --- a/compiler/compiler.iml +++ b/compiler/compiler.iml @@ -9,8 +9,8 @@ - - + + - + \ No newline at end of file diff --git a/compiler/examples/test.p8 b/compiler/examples/test.p8 index 5efa1fd20..cebdae339 100644 --- a/compiler/examples/test.p8 +++ b/compiler/examples/test.p8 @@ -1,4 +1,4 @@ - +%option enable_floats %import mathlib %import c64lib %import c64utils @@ -18,28 +18,29 @@ sub start() { ;v1=foo() - address =c64.MEMBOT(1, 40000.w) ; ok! - address =c64.MEMBOT(1, address) ; ok! - address =c64.MEMBOT(1, memaddr) ; ok!i + ;address =c64.MEMBOT(1, 40000.w) ; ok! + ;address =c64.MEMBOT(1, address) ; ok! + ;address =c64.MEMBOT(1, memaddr) ; ok!i ;address =c64.MEMBOT(1, wordarray[1]) ; @todo nice error about loading X register from stack - A, Y =c64.GETADR() ; ok! - Y, A =c64.GETADR() ; ok! - address = c64flt.GETADRAY() ; ok! - memaddr = c64flt.GETADRAY() ; ok! - wordarray[1] = c64flt.GETADRAY() ; ok! - v1, v2 =c64.GETADR() ; ok! - address =c64.IOBASE() ; ok! - A = c64.CHRIN() ; ok ! - X = c64.CHRIN() ; ok ! - v1 = c64.CHRIN() ; ok ! + ;A, Y =c64.GETADR() ; ok! + ;Y, A =c64.GETADR() ; ok! + ;address = c64flt.GETADRAY() ; ok! + ;memaddr = c64flt.GETADRAY() ; ok! + ;wordarray[1] = c64flt.GETADRAY() ; ok! + ;v1, v2 =c64.GETADR() ; ok! + ;address =c64.IOBASE() ; ok! + ;A = c64.CHRIN() ; ok ! + ;X = c64.CHRIN() ; ok ! + ;Y = c64.CHRIN() ; ok! + ;v1 = c64.CHRIN() ; ok ! return } -sub foo() -> byte { - return 1 ; @todo fix error: '1' as byte literal (not ubyte) +sub foo() -> float { + return 1 ; @todo fix error: '1' as byte or float literal (not ubyte) } diff --git a/compiler/src/prog8/ast/AstIdentifiersChecker.kt b/compiler/src/prog8/ast/AstIdentifiersChecker.kt index 15f406014..e41d7d082 100644 --- a/compiler/src/prog8/ast/AstIdentifiersChecker.kt +++ b/compiler/src/prog8/ast/AstIdentifiersChecker.kt @@ -6,7 +6,7 @@ import prog8.functions.BuiltinFunctions * Checks the validity of all identifiers (no conflicts) * Also builds a list of all (scoped) symbol definitions * Also makes sure that subroutine's parameters also become local variable decls in the subroutine's scope. - * Finally, it also makes sure the datatype of all Var decls is set correctly. + * Finally, it also makes sure the datatype of all Var decls and sub Return values is set correctly. */ fun Module.checkIdentifiers(): MutableMap { @@ -151,4 +151,12 @@ class AstIdentifiersChecker : IAstProcessor { printWarning("writing to the X register is dangerous, because it's used as an internal pointer", assignTarget.position) return super.process(assignTarget) } + + override fun process(returnStmt: Return): IStatement { + if(returnStmt.values.isNotEmpty()) { + println("CHECK $returnStmt") // TODO adjust return value literalvalue datatype to subroutine's definition + returnStmt.definingScope() + } + return super.process(returnStmt) + } } diff --git a/compiler/src/prog8/compiler/Compiler.kt b/compiler/src/prog8/compiler/Compiler.kt index ba6e64066..804df0eb6 100644 --- a/compiler/src/prog8/compiler/Compiler.kt +++ b/compiler/src/prog8/compiler/Compiler.kt @@ -794,8 +794,6 @@ private class StatementTranslator(private val prog: IntermediateProgram, private fun translateSubroutineCall(subroutine: Subroutine, arguments: List, callPosition: Position) { // evaluate the arguments and assign them into the subroutine's argument variables. - prog.line(callPosition) - if(subroutine.asmParameterRegisters.isNotEmpty()) { if(subroutine.parameters.size!=subroutine.asmParameterRegisters.size) throw CompilerException("no support for mix of register and non-register subroutine arguments")