mirror of
https://github.com/irmen/prog8.git
synced 2025-02-28 09:29:26 +00:00
inferred type for len() is now more precise
This commit is contained in:
parent
5766208207
commit
ebf1f12e97
@ -233,10 +233,25 @@ fun builtinFunctionReturnType(function: String, args: List<Expression>, program:
|
||||
}
|
||||
}
|
||||
"len" -> {
|
||||
// a length can be >255 so in that case, the result is an UWORD instead of an UBYTE
|
||||
// but to avoid a lot of code duplication we simply assume UWORD in all cases for now
|
||||
when(args.single().inferType(program).getOr(DataType.UNDEFINED)) {
|
||||
in ArrayDatatypes -> {
|
||||
val value = args.single() as? ArrayLiteralValue
|
||||
if(value!=null) {
|
||||
return if(value.value.size<256) InferredTypes.knownFor(DataType.UBYTE) else InferredTypes.knownFor(DataType.UWORD)
|
||||
} else {
|
||||
val targetVar = (args.single() as? IdentifierReference)?.targetVarDecl(program)
|
||||
if (targetVar?.isArray == true) {
|
||||
val length = targetVar.arraysize?.constIndex()
|
||||
if(length!=null)
|
||||
return if(length<256) InferredTypes.knownFor(DataType.UBYTE) else InferredTypes.knownFor(DataType.UWORD)
|
||||
}
|
||||
}
|
||||
return InferredTypes.knownFor(DataType.UWORD)
|
||||
}
|
||||
DataType.STR -> return InferredTypes.knownFor(DataType.UBYTE)
|
||||
else -> InferredTypes.unknown()
|
||||
}
|
||||
}
|
||||
else -> return InferredTypes.unknown()
|
||||
}
|
||||
}
|
||||
|
@ -441,6 +441,7 @@ String
|
||||
A string literal can occur with or without an encoding prefix (encoding followed by ':' followed by the string itself).
|
||||
When this is omitted, the string is stored in the machine's default character encoding (which is PETSCII on the CBM machines).
|
||||
You can choose to store the string in other encodings such as ``sc`` (screencodes) or ``iso`` (iso-8859-15).
|
||||
String length is limited to 255 characters.
|
||||
Here are several examples:
|
||||
|
||||
- ``"hello"`` a string translated into the default character encoding (PETSCII)
|
||||
|
@ -3,16 +3,11 @@ TODO
|
||||
|
||||
For next release
|
||||
^^^^^^^^^^^^^^^^
|
||||
- Fix compiler stack overflow crash:
|
||||
- BUGFIX RELEASE: Fix compiler stack overflow crash:
|
||||
sub sprite_y_for_row(ubyte row) -> word {
|
||||
return (8-row as byte)
|
||||
}
|
||||
- Fix: better error message for len() in:
|
||||
ubyte[64] chessboard
|
||||
sub init() {
|
||||
ubyte xx=len(board)
|
||||
sys.memset(chessboard, len(board), 0)
|
||||
}
|
||||
|
||||
- move vload() to cx16diskio module
|
||||
- nameInAssemblyCode() should search smarter
|
||||
- if char in "string" should fall back to string.find if string is longer than... 12?
|
||||
|
Loading…
x
Reference in New Issue
Block a user