2021-07-13 07:47:31 +00:00
|
|
|
package prog8tests
|
|
|
|
|
2021-11-08 14:50:29 +00:00
|
|
|
import io.kotest.assertions.withClue
|
2021-11-07 23:16:58 +00:00
|
|
|
import io.kotest.core.spec.style.FunSpec
|
2021-11-08 14:50:29 +00:00
|
|
|
import io.kotest.matchers.shouldBe
|
2022-03-07 20:41:12 +00:00
|
|
|
import io.kotest.matchers.shouldNotBe
|
2021-11-08 14:50:29 +00:00
|
|
|
import io.kotest.matchers.string.shouldContain
|
2021-11-29 22:36:41 +00:00
|
|
|
import io.kotest.matchers.types.instanceOf
|
2022-02-10 23:21:40 +00:00
|
|
|
import prog8.ast.expressions.ArrayLiteral
|
2022-02-05 02:50:54 +00:00
|
|
|
import prog8.ast.expressions.IdentifierReference
|
2022-02-10 23:21:40 +00:00
|
|
|
import prog8.ast.expressions.NumericLiteral
|
2022-02-05 02:50:54 +00:00
|
|
|
import prog8.ast.expressions.RangeExpression
|
2021-07-13 07:47:31 +00:00
|
|
|
import prog8.ast.statements.ForLoop
|
|
|
|
import prog8.ast.statements.VarDecl
|
2022-03-10 21:38:16 +00:00
|
|
|
import prog8.code.core.DataType
|
|
|
|
import prog8.code.core.Encoding
|
|
|
|
import prog8.code.core.Position
|
2022-03-11 19:35:25 +00:00
|
|
|
import prog8.code.target.C64Target
|
|
|
|
import prog8.code.target.Cx16Target
|
2022-05-22 21:11:22 +00:00
|
|
|
import prog8tests.helpers.ErrorReporterForTests
|
2022-06-26 16:51:03 +00:00
|
|
|
import prog8tests.helpers.cartesianProduct
|
2022-07-01 22:21:18 +00:00
|
|
|
import prog8tests.helpers.compileText
|
2021-07-13 07:47:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ATTENTION: this is just kludge!
|
|
|
|
* They are not really unit tests, but rather tests of the whole process,
|
|
|
|
* from source file loading all the way through to running 64tass.
|
|
|
|
*/
|
2021-11-07 23:16:58 +00:00
|
|
|
class TestCompilerOnRanges: FunSpec({
|
2021-07-13 07:47:31 +00:00
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
test("testUByteArrayInitializerWithRange_char_to_char") {
|
2022-02-06 20:29:06 +00:00
|
|
|
val platform = Cx16Target()
|
2021-11-11 02:03:21 +00:00
|
|
|
val result = compileText(platform, false, """
|
2021-07-13 07:47:31 +00:00
|
|
|
main {
|
|
|
|
sub start() {
|
2022-02-11 20:56:33 +00:00
|
|
|
ubyte[] cs = sc:'a' to 'z' ; values are computed at compile time
|
2021-07-13 07:47:31 +00:00
|
|
|
cs[0] = 23 ; keep optimizer from removing it
|
|
|
|
}
|
|
|
|
}
|
2022-03-07 20:41:12 +00:00
|
|
|
""")!!
|
2021-07-13 07:47:31 +00:00
|
|
|
|
2023-02-09 00:46:23 +00:00
|
|
|
val program = result.compilerAst
|
2021-10-10 22:01:26 +00:00
|
|
|
val startSub = program.entrypoint
|
2021-07-13 07:47:31 +00:00
|
|
|
val decl = startSub
|
|
|
|
.statements.filterIsInstance<VarDecl>()[0]
|
2022-02-10 23:21:40 +00:00
|
|
|
val rhsValues = (decl.value as ArrayLiteral)
|
2021-07-13 07:47:31 +00:00
|
|
|
.value // Array<Expression>
|
2022-02-10 23:21:40 +00:00
|
|
|
.map { (it as NumericLiteral).number.toInt() }
|
2022-01-18 20:21:49 +00:00
|
|
|
val expectedStart = platform.encodeString("a", Encoding.SCREENCODES)[0].toInt()
|
|
|
|
val expectedEnd = platform.encodeString("z", Encoding.PETSCII)[0].toInt()
|
2021-07-13 07:47:31 +00:00
|
|
|
val expectedStr = "$expectedStart .. $expectedEnd"
|
|
|
|
|
|
|
|
val actualStr = "${rhsValues.first()} .. ${rhsValues.last()}"
|
2021-11-08 14:50:29 +00:00
|
|
|
withClue(".first .. .last") {
|
|
|
|
actualStr shouldBe expectedStr
|
|
|
|
}
|
|
|
|
withClue("rangeExpr.size()") {
|
|
|
|
(rhsValues.last() - rhsValues.first() + 1) shouldBe (expectedEnd - expectedStart + 1)
|
|
|
|
}
|
2021-07-13 07:47:31 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
test("testFloatArrayInitializerWithRange_char_to_char") {
|
2022-02-06 20:29:06 +00:00
|
|
|
val platform = C64Target()
|
2021-07-13 07:47:31 +00:00
|
|
|
val result = compileText(platform, optimize = false, """
|
2022-01-09 15:18:13 +00:00
|
|
|
%import floats
|
2021-07-13 07:47:31 +00:00
|
|
|
main {
|
|
|
|
sub start() {
|
2021-09-12 16:59:53 +00:00
|
|
|
float[] cs = 'a' to 'z' ; values are computed at compile time
|
2021-07-13 07:47:31 +00:00
|
|
|
cs[0] = 23 ; keep optimizer from removing it
|
|
|
|
}
|
|
|
|
}
|
2022-03-07 20:41:12 +00:00
|
|
|
""")!!
|
2021-07-13 07:47:31 +00:00
|
|
|
|
2023-02-09 00:46:23 +00:00
|
|
|
val program = result.compilerAst
|
2021-10-10 22:01:26 +00:00
|
|
|
val startSub = program.entrypoint
|
2021-07-13 07:47:31 +00:00
|
|
|
val decl = startSub
|
|
|
|
.statements.filterIsInstance<VarDecl>()[0]
|
2022-02-10 23:21:40 +00:00
|
|
|
val rhsValues = (decl.value as ArrayLiteral)
|
2021-07-13 07:47:31 +00:00
|
|
|
.value // Array<Expression>
|
2022-02-10 23:21:40 +00:00
|
|
|
.map { (it as NumericLiteral).number.toInt() }
|
2022-01-18 20:21:49 +00:00
|
|
|
val expectedStart = platform.encodeString("a", Encoding.PETSCII)[0].toInt()
|
|
|
|
val expectedEnd = platform.encodeString("z", Encoding.PETSCII)[0].toInt()
|
2021-07-13 07:47:31 +00:00
|
|
|
val expectedStr = "$expectedStart .. $expectedEnd"
|
|
|
|
|
|
|
|
val actualStr = "${rhsValues.first()} .. ${rhsValues.last()}"
|
2021-11-08 14:50:29 +00:00
|
|
|
withClue(".first .. .last") {
|
|
|
|
actualStr shouldBe expectedStr
|
|
|
|
}
|
|
|
|
withClue("rangeExpr.size()") {
|
|
|
|
rhsValues.size shouldBe (expectedEnd - expectedStart + 1)
|
|
|
|
}
|
2021-07-13 07:47:31 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
context("floatArrayInitializerWithRange") {
|
2022-06-26 16:51:03 +00:00
|
|
|
val combos = cartesianProduct(
|
2021-11-07 23:16:58 +00:00
|
|
|
listOf("", "42", "41"), // sizeInDecl
|
2022-01-09 15:18:13 +00:00
|
|
|
listOf("%import floats", ""), // optEnableFloats
|
2022-02-06 20:29:06 +00:00
|
|
|
listOf(Cx16Target(), C64Target()), // platform
|
2022-01-09 15:18:13 +00:00
|
|
|
listOf(false, true) // optimize
|
2021-11-07 23:16:58 +00:00
|
|
|
)
|
2021-07-13 07:47:31 +00:00
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
combos.forEach {
|
|
|
|
val (sizeInDecl, optEnableFloats, platform, optimize) = it
|
2021-07-13 07:47:31 +00:00
|
|
|
val displayName =
|
|
|
|
when (sizeInDecl) {
|
|
|
|
"" -> "no"
|
|
|
|
"42" -> "correct"
|
|
|
|
else -> "wrong"
|
|
|
|
} + " array size given" +
|
2021-11-07 23:16:58 +00:00
|
|
|
", " + (if (optEnableFloats == "") "without" else "with") + " %option enable_floats" +
|
|
|
|
", ${platform.name}, optimize: $optimize"
|
|
|
|
|
|
|
|
test(displayName) {
|
2021-07-13 07:47:31 +00:00
|
|
|
val result = compileText(platform, optimize, """
|
|
|
|
$optEnableFloats
|
|
|
|
main {
|
|
|
|
sub start() {
|
2021-11-07 23:16:58 +00:00
|
|
|
float[$sizeInDecl] cs = 1 to 42 ; values are computed at compile time
|
2021-07-13 07:47:31 +00:00
|
|
|
cs[0] = 23 ; keep optimizer from removing it
|
|
|
|
}
|
|
|
|
}
|
|
|
|
""")
|
2021-09-12 16:53:12 +00:00
|
|
|
if (optEnableFloats != "" && (sizeInDecl=="" || sizeInDecl=="42"))
|
2022-03-07 20:41:12 +00:00
|
|
|
result shouldNotBe null
|
2021-09-12 16:53:12 +00:00
|
|
|
else
|
2022-03-07 20:41:12 +00:00
|
|
|
result shouldBe null
|
2021-11-07 23:16:58 +00:00
|
|
|
|
2021-07-13 07:47:31 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-07 23:16:58 +00:00
|
|
|
}
|
2021-07-13 07:47:31 +00:00
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
test("testForLoopWithRange_char_to_char") {
|
2022-02-06 20:29:06 +00:00
|
|
|
val platform = Cx16Target()
|
2021-07-17 18:45:17 +00:00
|
|
|
val result = compileText(platform, optimize = true, """
|
2021-07-13 07:47:31 +00:00
|
|
|
main {
|
|
|
|
sub start() {
|
|
|
|
ubyte i
|
2022-02-11 20:56:33 +00:00
|
|
|
for i in sc:'a' to 'f' {
|
2021-07-13 07:47:31 +00:00
|
|
|
i += i ; keep optimizer from removing it
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-07 20:41:12 +00:00
|
|
|
""")!!
|
2021-07-13 07:47:31 +00:00
|
|
|
|
2023-02-09 00:46:23 +00:00
|
|
|
val program = result.compilerAst
|
2021-10-10 22:01:26 +00:00
|
|
|
val startSub = program.entrypoint
|
2021-07-13 07:47:31 +00:00
|
|
|
val iterable = startSub
|
|
|
|
.statements.filterIsInstance<ForLoop>()
|
|
|
|
.map { it.iterable }[0]
|
2022-01-07 20:02:37 +00:00
|
|
|
val rangeExpr = iterable as RangeExpression
|
2021-07-13 07:47:31 +00:00
|
|
|
|
2022-01-18 20:21:49 +00:00
|
|
|
val expectedStart = platform.encodeString("a", Encoding.SCREENCODES)[0].toInt()
|
|
|
|
val expectedEnd = platform.encodeString("f", Encoding.PETSCII)[0].toInt()
|
2021-07-13 07:47:31 +00:00
|
|
|
val expectedStr = "$expectedStart .. $expectedEnd"
|
|
|
|
|
2021-10-29 14:20:53 +00:00
|
|
|
val intProgression = rangeExpr.toConstantIntegerRange()
|
2021-07-13 07:47:31 +00:00
|
|
|
val actualStr = "${intProgression?.first} .. ${intProgression?.last}"
|
2021-11-08 14:50:29 +00:00
|
|
|
withClue(".first .. .last") {
|
|
|
|
actualStr shouldBe expectedStr
|
|
|
|
}
|
|
|
|
withClue("rangeExpr.size()") {
|
|
|
|
rangeExpr.size() shouldBe (expectedEnd - expectedStart + 1)
|
|
|
|
}
|
2021-07-13 07:47:31 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
test("testForLoopWithRange_bool_to_bool") {
|
2022-02-06 20:29:06 +00:00
|
|
|
val platform = Cx16Target()
|
2021-07-17 18:45:17 +00:00
|
|
|
val result = compileText(platform, optimize = true, """
|
2021-07-13 07:47:31 +00:00
|
|
|
main {
|
|
|
|
sub start() {
|
|
|
|
ubyte i
|
|
|
|
for i in false to true {
|
|
|
|
i += i ; keep optimizer from removing it
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-07 20:41:12 +00:00
|
|
|
""")!!
|
2021-07-13 07:47:31 +00:00
|
|
|
|
2023-02-09 00:46:23 +00:00
|
|
|
val program = result.compilerAst
|
2021-10-10 22:01:26 +00:00
|
|
|
val startSub = program.entrypoint
|
2021-07-13 07:47:31 +00:00
|
|
|
val rangeExpr = startSub
|
|
|
|
.statements.filterIsInstance<ForLoop>()
|
|
|
|
.map { it.iterable }
|
2022-01-07 20:02:37 +00:00
|
|
|
.filterIsInstance<RangeExpression>()[0]
|
2021-07-13 07:47:31 +00:00
|
|
|
|
2021-11-08 14:50:29 +00:00
|
|
|
rangeExpr.size() shouldBe 2
|
2021-10-29 14:20:53 +00:00
|
|
|
val intProgression = rangeExpr.toConstantIntegerRange()
|
2021-11-08 14:50:29 +00:00
|
|
|
intProgression?.first shouldBe 0
|
|
|
|
intProgression?.last shouldBe 1
|
2021-07-13 07:47:31 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
test("testForLoopWithRange_ubyte_to_ubyte") {
|
2022-02-06 20:29:06 +00:00
|
|
|
val platform = Cx16Target()
|
2021-07-17 18:45:17 +00:00
|
|
|
val result = compileText(platform, optimize = true, """
|
2021-07-13 07:47:31 +00:00
|
|
|
main {
|
|
|
|
sub start() {
|
|
|
|
ubyte i
|
|
|
|
for i in 1 to 9 {
|
|
|
|
i += i ; keep optimizer from removing it
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-07 20:41:12 +00:00
|
|
|
""")!!
|
2021-07-13 07:47:31 +00:00
|
|
|
|
2023-02-09 00:46:23 +00:00
|
|
|
val program = result.compilerAst
|
2021-10-10 22:01:26 +00:00
|
|
|
val startSub = program.entrypoint
|
2021-07-13 07:47:31 +00:00
|
|
|
val rangeExpr = startSub
|
|
|
|
.statements.filterIsInstance<ForLoop>()
|
|
|
|
.map { it.iterable }
|
2022-01-07 20:02:37 +00:00
|
|
|
.filterIsInstance<RangeExpression>()[0]
|
2021-07-13 07:47:31 +00:00
|
|
|
|
2021-11-08 14:50:29 +00:00
|
|
|
rangeExpr.size() shouldBe 9
|
2021-10-29 14:20:53 +00:00
|
|
|
val intProgression = rangeExpr.toConstantIntegerRange()
|
2021-11-08 14:50:29 +00:00
|
|
|
intProgression?.first shouldBe 1
|
|
|
|
intProgression?.last shouldBe 9
|
2021-07-13 07:47:31 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
test("testForLoopWithRange_str_downto_str") {
|
2021-10-21 23:25:26 +00:00
|
|
|
val errors = ErrorReporterForTests()
|
2022-03-11 19:35:25 +00:00
|
|
|
compileText(
|
|
|
|
Cx16Target(), true, """
|
2021-07-13 07:47:31 +00:00
|
|
|
main {
|
|
|
|
sub start() {
|
|
|
|
ubyte i
|
|
|
|
for i in "start" downto "end" {
|
|
|
|
i += i ; keep optimizer from removing it
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-07 20:41:12 +00:00
|
|
|
""", errors, false) shouldBe null
|
2021-11-08 14:50:29 +00:00
|
|
|
errors.errors.size shouldBe 2
|
2022-02-27 15:27:02 +00:00
|
|
|
errors.errors[0] shouldContain ".p8:5:30: range expression from value must be integer"
|
|
|
|
errors.errors[1] shouldContain ".p8:5:45: range expression to value must be integer"
|
2021-07-13 07:47:31 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
test("testForLoopWithIterable_str") {
|
2022-03-11 19:35:25 +00:00
|
|
|
val result = compileText(
|
|
|
|
Cx16Target(), false, """
|
2021-07-13 07:47:31 +00:00
|
|
|
main {
|
|
|
|
sub start() {
|
|
|
|
ubyte i
|
|
|
|
for i in "something" {
|
|
|
|
i += i ; keep optimizer from removing it
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-07 20:41:12 +00:00
|
|
|
""")!!
|
2021-07-13 07:47:31 +00:00
|
|
|
|
2023-02-09 00:46:23 +00:00
|
|
|
val program = result.compilerAst
|
2021-10-10 22:01:26 +00:00
|
|
|
val startSub = program.entrypoint
|
2021-07-13 07:47:31 +00:00
|
|
|
val iterable = startSub
|
|
|
|
.statements.filterIsInstance<ForLoop>()
|
|
|
|
.map { it.iterable }
|
|
|
|
.filterIsInstance<IdentifierReference>()[0]
|
|
|
|
|
2021-11-08 14:50:29 +00:00
|
|
|
iterable.inferType(program).getOr(DataType.UNDEFINED) shouldBe DataType.STR
|
2021-07-13 07:47:31 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
test("testRangeExprNumericSize") {
|
2022-01-07 20:02:37 +00:00
|
|
|
val expr = RangeExpression(
|
2022-02-10 23:21:40 +00:00
|
|
|
NumericLiteral.optimalInteger(10, Position.DUMMY),
|
|
|
|
NumericLiteral.optimalInteger(20, Position.DUMMY),
|
|
|
|
NumericLiteral.optimalInteger(2, Position.DUMMY),
|
2021-10-29 21:46:51 +00:00
|
|
|
Position.DUMMY)
|
2021-11-08 14:50:29 +00:00
|
|
|
expr.size() shouldBe 6
|
2023-08-11 00:14:54 +00:00
|
|
|
expr.toConstantIntegerRange() shouldBe (10..20 step 2)
|
|
|
|
|
|
|
|
val expr2 = RangeExpression(
|
|
|
|
NumericLiteral.optimalInteger(20, Position.DUMMY),
|
|
|
|
NumericLiteral.optimalInteger(10, Position.DUMMY),
|
|
|
|
NumericLiteral.optimalInteger(-3, Position.DUMMY),
|
|
|
|
Position.DUMMY)
|
|
|
|
expr2.size() shouldBe 4
|
|
|
|
expr2.toConstantIntegerRange() shouldBe (20 downTo 10 step 3)
|
2021-10-29 21:46:51 +00:00
|
|
|
}
|
2021-11-29 22:36:41 +00:00
|
|
|
|
|
|
|
test("range with negative step should be constvalue") {
|
2022-03-11 19:35:25 +00:00
|
|
|
val result = compileText(
|
|
|
|
C64Target(), false, """
|
2021-11-29 22:36:41 +00:00
|
|
|
main {
|
|
|
|
sub start() {
|
|
|
|
ubyte[] array = 100 to 50 step -2
|
|
|
|
ubyte xx
|
|
|
|
for xx in 100 to 50 step -2 {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-07 20:41:12 +00:00
|
|
|
""")!!
|
2023-02-09 00:46:23 +00:00
|
|
|
val statements = result.compilerAst.entrypoint.statements
|
2021-11-29 22:36:41 +00:00
|
|
|
val array = (statements[0] as VarDecl).value
|
2022-02-10 23:21:40 +00:00
|
|
|
array shouldBe instanceOf<ArrayLiteral>()
|
|
|
|
(array as ArrayLiteral).value.size shouldBe 26
|
2021-11-29 22:36:41 +00:00
|
|
|
val forloop = (statements.dropLast(1).last() as ForLoop)
|
2022-01-07 20:02:37 +00:00
|
|
|
forloop.iterable shouldBe instanceOf<RangeExpression>()
|
2022-02-10 23:21:40 +00:00
|
|
|
(forloop.iterable as RangeExpression).step shouldBe NumericLiteral(DataType.UBYTE, -2.0, Position.DUMMY)
|
2021-11-29 22:36:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test("range with start/end variables should be ok") {
|
2022-03-11 19:35:25 +00:00
|
|
|
val result = compileText(
|
|
|
|
C64Target(), false, """
|
2021-11-29 22:36:41 +00:00
|
|
|
main {
|
|
|
|
sub start() {
|
|
|
|
byte from = 100
|
|
|
|
byte end = 50
|
|
|
|
byte xx
|
|
|
|
for xx in from to end step -2 {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-07 20:41:12 +00:00
|
|
|
""")!!
|
2023-02-09 00:46:23 +00:00
|
|
|
val statements = result.compilerAst.entrypoint.statements
|
2021-11-29 22:36:41 +00:00
|
|
|
val forloop = (statements.dropLast(1).last() as ForLoop)
|
2022-01-07 20:02:37 +00:00
|
|
|
forloop.iterable shouldBe instanceOf<RangeExpression>()
|
2022-02-10 23:21:40 +00:00
|
|
|
(forloop.iterable as RangeExpression).step shouldBe NumericLiteral(DataType.UBYTE, -2.0, Position.DUMMY)
|
2021-11-29 22:36:41 +00:00
|
|
|
}
|
2021-12-28 16:21:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
test("for statement on all possible iterable expressions") {
|
2022-03-11 19:35:25 +00:00
|
|
|
compileText(
|
|
|
|
C64Target(), false, """
|
2021-12-28 16:21:41 +00:00
|
|
|
main {
|
|
|
|
sub start() {
|
|
|
|
ubyte xx
|
2021-12-29 15:21:37 +00:00
|
|
|
uword ww
|
2021-12-28 16:21:41 +00:00
|
|
|
str name = "irmen"
|
|
|
|
ubyte[] values = [1,2,3,4,5,6,7]
|
2021-12-29 15:21:37 +00:00
|
|
|
uword[] wvalues = [1000,2000,3000]
|
2021-12-28 16:21:41 +00:00
|
|
|
|
|
|
|
for xx in name {
|
|
|
|
xx++
|
|
|
|
}
|
|
|
|
|
|
|
|
for xx in values {
|
|
|
|
xx++
|
|
|
|
}
|
|
|
|
|
|
|
|
for xx in 10 to 20 step 3 {
|
|
|
|
xx++
|
|
|
|
}
|
|
|
|
|
|
|
|
for xx in "abcdef" {
|
|
|
|
xx++
|
|
|
|
}
|
|
|
|
|
|
|
|
for xx in [2,4,6,8] {
|
|
|
|
xx++
|
|
|
|
}
|
2021-12-29 15:21:37 +00:00
|
|
|
|
|
|
|
for ww in [9999,8888,7777] {
|
|
|
|
xx++
|
|
|
|
}
|
|
|
|
|
|
|
|
for ww in wvalues {
|
|
|
|
xx++
|
|
|
|
}
|
2021-12-28 16:21:41 +00:00
|
|
|
}
|
2022-03-07 20:41:12 +00:00
|
|
|
}""", writeAssembly = true) shouldNotBe null
|
2021-12-28 16:21:41 +00:00
|
|
|
}
|
|
|
|
|
2021-12-29 15:21:37 +00:00
|
|
|
test("if containment check on all possible iterable expressions") {
|
2022-03-11 19:35:25 +00:00
|
|
|
compileText(
|
|
|
|
C64Target(), false, """
|
2021-12-28 16:21:41 +00:00
|
|
|
main {
|
|
|
|
sub start() {
|
|
|
|
ubyte xx
|
2021-12-29 15:21:37 +00:00
|
|
|
uword ww
|
2021-12-28 16:21:41 +00:00
|
|
|
str name = "irmen"
|
|
|
|
ubyte[] values = [1,2,3,4,5,6,7]
|
2021-12-29 15:21:37 +00:00
|
|
|
uword[] wvalues = [1000,2000,3000]
|
|
|
|
|
|
|
|
if 'm' in name {
|
|
|
|
xx++
|
|
|
|
}
|
|
|
|
|
|
|
|
if 5 in values {
|
|
|
|
xx++
|
|
|
|
}
|
|
|
|
|
|
|
|
if 'b' in "abcdef" {
|
|
|
|
xx++
|
|
|
|
}
|
2021-12-28 16:21:41 +00:00
|
|
|
|
|
|
|
if xx in name {
|
|
|
|
xx++
|
|
|
|
}
|
|
|
|
|
|
|
|
if xx in values {
|
|
|
|
xx++
|
|
|
|
}
|
|
|
|
|
|
|
|
if xx in "abcdef" {
|
|
|
|
xx++
|
|
|
|
}
|
|
|
|
|
|
|
|
if xx in [2,4,6,8] {
|
|
|
|
xx++
|
|
|
|
}
|
2021-12-29 15:21:37 +00:00
|
|
|
|
|
|
|
if ww in [9999,8888,7777] {
|
|
|
|
xx++
|
|
|
|
}
|
|
|
|
|
|
|
|
if ww in wvalues {
|
|
|
|
xx++
|
|
|
|
}
|
|
|
|
}
|
2022-03-07 20:41:12 +00:00
|
|
|
}""", writeAssembly = true) shouldNotBe null
|
2021-12-29 15:21:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test("containment check in expressions") {
|
2022-03-11 19:35:25 +00:00
|
|
|
compileText(
|
|
|
|
C64Target(), false, """
|
2021-12-29 15:21:37 +00:00
|
|
|
main {
|
|
|
|
sub start() {
|
|
|
|
ubyte xx
|
|
|
|
uword ww
|
|
|
|
str name = "irmen"
|
|
|
|
ubyte[] values = [1,2,3,4,5,6,7]
|
|
|
|
uword[] wvalues = [1000,2000,3000]
|
|
|
|
|
|
|
|
xx = 'm' in name
|
|
|
|
xx = 5 in values
|
|
|
|
xx = 'b' in "abcdef"
|
|
|
|
xx = 8 in [2,4,6,8]
|
|
|
|
xx = xx in name
|
|
|
|
xx = xx in values
|
|
|
|
xx = xx in "abcdef"
|
|
|
|
xx = xx in [2,4,6,8]
|
|
|
|
xx = ww in [9000,8000,7000]
|
|
|
|
xx = ww in wvalues
|
2021-12-28 16:21:41 +00:00
|
|
|
}
|
2022-03-07 20:41:12 +00:00
|
|
|
}""", writeAssembly = true) shouldNotBe null
|
2021-12-28 16:21:41 +00:00
|
|
|
}
|
2021-11-07 23:16:58 +00:00
|
|
|
})
|