fixed certain type check error when passing boolean value to ubyte function parameter

fixed virtual machine string comparison syscall
This commit is contained in:
Irmen de Jong 2022-11-03 22:57:26 +01:00
parent 7303c00296
commit 0f1a4b9d8f
4 changed files with 23 additions and 13 deletions

View File

@ -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)

View File

@ -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
...

View File

@ -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)
}
}

View File

@ -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)