mirror of
https://github.com/irmen/prog8.git
synced 2025-01-26 19:30:59 +00:00
fix compiler crash when trying to concatenate string var and string literal.
This commit is contained in:
parent
5df623bd2e
commit
b21f7411dd
@ -862,6 +862,14 @@ internal class AstChecker(private val program: Program,
|
||||
errors.err("right operand is not numeric or str", expr.right.position)
|
||||
if(leftDt!=rightDt)
|
||||
errors.err("left and right operands aren't the same type", expr.left.position)
|
||||
|
||||
if(expr.operator !in comparisonOperators) {
|
||||
if (leftDt == DataType.STR && rightDt == DataType.STR || leftDt in ArrayDatatypes && rightDt in ArrayDatatypes) {
|
||||
// str+str and str*number have already been const evaluated before we get here.
|
||||
errors.err("no computational expressions with strings or arrays are possible", expr.position)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun visit(typecast: TypecastExpression) {
|
||||
|
@ -9,7 +9,7 @@ import prog8.ast.walk.IAstVisitor
|
||||
import java.util.*
|
||||
import kotlin.math.round
|
||||
|
||||
|
||||
// TODO capitalize for consistency
|
||||
val associativeOperators = setOf("+", "*", "&", "|", "^", "or", "and", "xor", "==", "!=")
|
||||
val comparisonOperators = setOf("==", "!=", "<", ">", "<=", ">=")
|
||||
val augmentAssignmentOperators = setOf("+", "-", "/", "*", "**", "&", "|", "^", "<<", ">>", "%", "and", "or", "xor")
|
||||
|
@ -313,10 +313,12 @@ platform (if defined). For the C-64, that is SCREEN CODES (also known as POKE co
|
||||
This @-prefix can also be used for character byte values.
|
||||
|
||||
|
||||
You can concatenate two string literals using '+' (not very useful though) or repeat
|
||||
a string literal a given number of times using '*'. You can also assign a new string
|
||||
value to another string. No bounds check is done so be sure the destination string is
|
||||
large enough to contain the new value (it is overwritten in memory)::
|
||||
You can concatenate two string literals using '+', which can be useful to
|
||||
split long strings over separate lines. But remember that the length
|
||||
of the total string still cannot exceed 255 characaters.
|
||||
A string literal can also be repeated a given number of times using '*'.
|
||||
And a new string value can be assigned to another string, but no bounds check is done
|
||||
so be sure the destination string is large enough to contain the new value (it is overwritten in memory)::
|
||||
|
||||
str string1 = "first part" + "second part"
|
||||
str string2 = "hello!" * 10
|
||||
@ -330,9 +332,6 @@ as newlines, quote characters themselves, and so on. The ones used most often ar
|
||||
``\\``, ``\"``, ``\n``, ``\r``. For a detailed description of all of them and what they mean,
|
||||
read the syntax reference on strings.
|
||||
|
||||
You can use the automatic string concatenation using ``+`` to split long strings over separate
|
||||
lines, but remember that the length of the total string still cannot exceed 255 characaters.
|
||||
|
||||
.. hint::
|
||||
Strings/arrays and uwords (=memory address) can often be interchanged.
|
||||
An array of strings is actually an array of uwords where every element is the memory
|
||||
|
@ -3,8 +3,6 @@ TODO
|
||||
|
||||
For next compiler release (7.6)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
fix compiler crash when trying to concatenate string var and string literal.
|
||||
|
||||
fix return value of diskio.load() (see commment) and possibly other routines?
|
||||
|
||||
optimization in call convention:
|
||||
|
@ -3,10 +3,10 @@
|
||||
|
||||
main {
|
||||
sub start() {
|
||||
ubyte @shared yy
|
||||
|
||||
if yy&64 {
|
||||
yy++
|
||||
}
|
||||
str derp = "derp" * 4
|
||||
derp = derp / "zzz"
|
||||
derp = derp - "zzz"
|
||||
derp = derp + "zzz"
|
||||
txt.print(&derp+2)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user