mirror of
https://github.com/irmen/prog8.git
synced 2024-10-09 13:55:19 +00:00
fix multi-var decl
This commit is contained in:
parent
e076b3aedc
commit
d56565be25
@ -53,6 +53,7 @@ internal class AstIdentifiersChecker(private val errors: IErrorReporter,
|
|||||||
if(decl.name in BuiltinFunctions)
|
if(decl.name in BuiltinFunctions)
|
||||||
errors.err("builtin function cannot be redefined", decl.position)
|
errors.err("builtin function cannot be redefined", decl.position)
|
||||||
|
|
||||||
|
if(decl.names.size<2) {
|
||||||
val existingInSameScope = decl.definingScope.lookup(listOf(decl.name))
|
val existingInSameScope = decl.definingScope.lookup(listOf(decl.name))
|
||||||
if (existingInSameScope != null && existingInSameScope !== decl)
|
if (existingInSameScope != null && existingInSameScope !== decl)
|
||||||
nameError(decl.name, decl.position, existingInSameScope)
|
nameError(decl.name, decl.position, existingInSameScope)
|
||||||
@ -64,6 +65,7 @@ internal class AstIdentifiersChecker(private val errors: IErrorReporter,
|
|||||||
else
|
else
|
||||||
nameError(decl.name, decl.position, existingOuter)
|
nameError(decl.name, decl.position, existingOuter)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(decl.definingBlock.name==decl.name)
|
if(decl.definingBlock.name==decl.name)
|
||||||
nameError(decl.name, decl.position, decl.definingBlock)
|
nameError(decl.name, decl.position, decl.definingBlock)
|
||||||
|
@ -8,6 +8,7 @@ import io.kotest.matchers.types.instanceOf
|
|||||||
import prog8.ast.IFunctionCall
|
import prog8.ast.IFunctionCall
|
||||||
import prog8.ast.expressions.*
|
import prog8.ast.expressions.*
|
||||||
import prog8.ast.statements.Assignment
|
import prog8.ast.statements.Assignment
|
||||||
|
import prog8.ast.statements.ForLoop
|
||||||
import prog8.ast.statements.InlineAssembly
|
import prog8.ast.statements.InlineAssembly
|
||||||
import prog8.ast.statements.VarDecl
|
import prog8.ast.statements.VarDecl
|
||||||
import prog8.code.core.DataType
|
import prog8.code.core.DataType
|
||||||
@ -390,5 +391,54 @@ main {
|
|||||||
}"""
|
}"""
|
||||||
compileText(VMTarget(), optimize=false, src, writeAssembly=false) shouldNotBe null
|
compileText(VMTarget(), optimize=false, src, writeAssembly=false) shouldNotBe null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test("multi-var decls in scope with initializer") {
|
||||||
|
val src="""
|
||||||
|
main {
|
||||||
|
sub start() {
|
||||||
|
ubyte w
|
||||||
|
|
||||||
|
for w in 0 to 20 {
|
||||||
|
ubyte @zp x,y,z=13
|
||||||
|
ubyte q,r,s
|
||||||
|
x++
|
||||||
|
y++
|
||||||
|
z++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}"""
|
||||||
|
val result = compileText(VMTarget(), optimize = false, src, writeAssembly = false)!!
|
||||||
|
val st = result.compilerAst.entrypoint.statements
|
||||||
|
/*
|
||||||
|
sub start () {
|
||||||
|
ubyte s
|
||||||
|
s = 0
|
||||||
|
ubyte r
|
||||||
|
r = 0
|
||||||
|
ubyte q
|
||||||
|
q = 0
|
||||||
|
ubyte @zp z
|
||||||
|
ubyte @zp y
|
||||||
|
ubyte @zp x
|
||||||
|
ubyte w
|
||||||
|
for w in 0 to 20 step 1 {
|
||||||
|
z = 13
|
||||||
|
y = 13
|
||||||
|
x = 13
|
||||||
|
x++
|
||||||
|
y++
|
||||||
|
z++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
val vars = st.filterIsInstance<VarDecl>()
|
||||||
|
vars.size shouldBe 7
|
||||||
|
vars.all { it.names.size<=1 } shouldBe true
|
||||||
|
vars.map { it.name } shouldBe listOf("s","r","q","z","y","x","w")
|
||||||
|
val forloop = st.single { it is ForLoop } as ForLoop
|
||||||
|
forloop.body.statements[0] shouldBe instanceOf<Assignment>()
|
||||||
|
forloop.body.statements[1] shouldBe instanceOf<Assignment>()
|
||||||
|
forloop.body.statements[2] shouldBe instanceOf<Assignment>()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -660,7 +660,7 @@ private fun VardeclContext.toAst(type: VarDeclType, value: Expression?): VarDecl
|
|||||||
zp,
|
zp,
|
||||||
arrayindex()?.toAst(),
|
arrayindex()?.toAst(),
|
||||||
name,
|
name,
|
||||||
identifiers.map { it.NAME().text },
|
if(identifiers.size==1) emptyList() else identifiers.map { it.NAME().text },
|
||||||
value,
|
value,
|
||||||
ARRAYSIG() != null || arrayindex() != null,
|
ARRAYSIG() != null || arrayindex() != null,
|
||||||
options.SHARED().isNotEmpty(),
|
options.SHARED().isNotEmpty(),
|
||||||
|
Loading…
Reference in New Issue
Block a user