diff --git a/compiler/src/prog8/compiler/astprocessing/VerifyFunctionArgTypes.kt b/compiler/src/prog8/compiler/astprocessing/VerifyFunctionArgTypes.kt index 011306334..2fa6a9f12 100644 --- a/compiler/src/prog8/compiler/astprocessing/VerifyFunctionArgTypes.kt +++ b/compiler/src/prog8/compiler/astprocessing/VerifyFunctionArgTypes.kt @@ -5,6 +5,7 @@ import prog8.ast.Program import prog8.ast.expressions.* import prog8.ast.statements.* import prog8.ast.walk.IAstVisitor +import prog8.code.core.ByteDatatypes import prog8.code.core.DataType import prog8.code.core.IErrorReporter import prog8.code.core.Position @@ -82,7 +83,9 @@ internal class VerifyFunctionArgTypes(val program: Program, val errors: IErrorRe if(mismatch>=0) { val actual = argtypes[mismatch] val expected = consideredParamTypes[mismatch] - return if(expected==DataType.BOOL && actual==DataType.UBYTE && call.args[mismatch].constValue(program)?.number in setOf(0.0, 1.0)) + return if(actual==DataType.BOOL && expected in ByteDatatypes) + null // a bool is just 1 or 0. + else if(expected==DataType.BOOL && actual==DataType.UBYTE && call.args[mismatch].constValue(program)?.number in setOf(0.0, 1.0)) null // specifying a 1 or 0 as a BOOL is okay else Pair("argument ${mismatch + 1} type mismatch, was: $actual expected: $expected", call.args[mismatch].position) diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 4f240ac97..98bdc1f56 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,7 +3,6 @@ TODO For next release ^^^^^^^^^^^^^^^^ -- fix error when passing boolean expression as ubyte param to a functioncall - fix expericodegen crashes from missing functions from virtual/prog8_lib.p8 ... diff --git a/examples/test.p8 b/examples/test.p8 index 12aabae94..226ccc08d 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,21 +1,24 @@ %import textio +%import string %zeropage basicsafe main { str name1 = "abc" str name2 = "irmen" - ubyte v1 - ubyte v2 - - sub func(ubyte value) { - value++ - } + ubyte[] arr1 = [11,22,33] + uword[] arr2 = [1111,2222,3333] sub start() { - func(v1==v2) - func(v1>v2) - func(name1 == name2) - func(name1 > name2) + ubyte @shared xx + ubyte value = 33 + uword value2 = 3333 + txt.print_ub(value in name1) + txt.print_ub('c' in name1) + txt.print_ub(name1 == name2) + txt.print_ub(name1 < name2) + txt.print_ub(value in arr1) + txt.print_ub(value2 in arr2) + } } diff --git a/virtualmachine/src/prog8/vm/SysCalls.kt b/virtualmachine/src/prog8/vm/SysCalls.kt index 34c5a88ec..03b85e09d 100644 --- a/virtualmachine/src/prog8/vm/SysCalls.kt +++ b/virtualmachine/src/prog8/vm/SysCalls.kt @@ -284,7 +284,12 @@ object SysCalls { val first = vm.memory.getString(firstAddr.toInt()) val second = vm.memory.getString(secondAddr.toInt()) val comparison = first.compareTo(second) - vm.registers.setSB(0, comparison.toByte()) + if(comparison==0) + vm.registers.setSB(0, 0) + else if(comparison<0) + vm.registers.setSB(0, -1) + else + vm.registers.setSB(0, 1) } Syscall.RNDFSEED -> { val seed1 = vm.registers.getUB(0)