diff --git a/compiler/src/prog8/compiler/astprocessing/AstExtensions.kt b/compiler/src/prog8/compiler/astprocessing/AstExtensions.kt index ccf03e53f..f0bd5a2e6 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstExtensions.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstExtensions.kt @@ -3,6 +3,7 @@ package prog8.compiler.astprocessing import prog8.ast.IStatementContainer import prog8.ast.Node import prog8.ast.Program +import prog8.ast.expressions.BinaryExpression import prog8.ast.expressions.CharLiteral import prog8.ast.expressions.IdentifierReference import prog8.ast.expressions.NumericLiteral @@ -82,6 +83,18 @@ internal fun Program.charLiteralsToUByteLiterals(target: ICompilationTarget, err } return noModifications } + + override fun after(decl: VarDecl, parent: Node): Iterable { + if(decl.datatype.isString) { + val initvalue = decl.value + if(initvalue!=null && initvalue is BinaryExpression) { + if(initvalue.left is CharLiteral || initvalue.right is CharLiteral) { + errors.err("using a char literal in a string initialization expression, should probably be a string literal with one character in it instead", initvalue.position) + } + } + } + return noModifications + } } walker.visit(this) diff --git a/compiler/test/ast/TestAstChecks.kt b/compiler/test/ast/TestAstChecks.kt index 94204b434..cca4bd3be 100644 --- a/compiler/test/ast/TestAstChecks.kt +++ b/compiler/test/ast/TestAstChecks.kt @@ -368,4 +368,19 @@ main { errors.warnings.size shouldBe 0 errors.errors[0] shouldContain "requires integer or boolean type" } + + test("missing address of in expression operand") { + val src=""" +main { + sub start() { + str name = "foo" + cx16.r0 = name+2 + } +}""" + val errors = ErrorReporterForTests() + compileText(C64Target(), false, src, writeAssembly = false, errors = errors) shouldBe null + errors.errors.size shouldBe 1 + errors.warnings.size shouldBe 0 + errors.errors[0] shouldContain "missing &" + } }) diff --git a/compilerAst/src/prog8/ast/expressions/AstExpressions.kt b/compilerAst/src/prog8/ast/expressions/AstExpressions.kt index 3d04c0905..e82101a29 100644 --- a/compilerAst/src/prog8/ast/expressions/AstExpressions.kt +++ b/compilerAst/src/prog8/ast/expressions/AstExpressions.kt @@ -253,7 +253,7 @@ class BinaryExpression( // if left or right is a numeric literal, and its value fits in the type of the other operand, use the other's operand type // EXCEPTION: if the numeric value is a word and the other operand is a byte type (to allow v * $0008 for example) - if (left is NumericLiteral) { + if (left is NumericLiteral && rightDt.isNumericOrBool) { if(!(leftDt.isWord && rightDt.isByte)) { val optimal = NumericLiteral.optimalNumeric(rightDt.base, null, left.number, left.position) if (optimal.type != leftDt.base && DataType.forDt(optimal.type) isAssignableTo rightDt) { @@ -261,7 +261,7 @@ class BinaryExpression( } } } - if (right is NumericLiteral) { + if (right is NumericLiteral && leftDt.isNumericOrBool) { if(!(rightDt.isWord && leftDt.isByte)) { val optimal = NumericLiteral.optimalNumeric(leftDt.base, null, right.number, right.position) if (optimal.type != rightDt.base && DataType.forDt(optimal.type) isAssignableTo leftDt) { diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 2ca281568..a22624754 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -22,6 +22,8 @@ Future Things and Ideas Make up our mind! Maybe all setup does need to be put into start() ? because the program cannot function correctly when the variables aren't initialized properly bss is not cleared etc. etc. Add a -library $xxxx command line option (and/or some directive) to preselect every setting that is required to make a library at $xxxx rather than a normal loadable and runnable program? Need to add some way to generate a stable jump table at a given address. + Need library to not call init_system AND init_system_phase2 not either. + Library must not include prog8_program_start stuff either. - Fix missing cases where regular & has to return the start of the split array in memory whatever byte comes first. Search TODO("address of split word array") - Add a syntax to access specific bits in a variable, to avoid manually shifts&ands, something like variable[4:8] ? (or something else this may be too similar to regular array indexing) - something to reduce the need to use fully qualified names all the time. 'with' ? Or 'using '? diff --git a/examples/test.p8 b/examples/test.p8 index db13a30a5..4dd639858 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,8 +1,7 @@ main { sub start() { - uword[] tasklist = [1111,2222,3333] - uword task_address = tasklist[0] - goto task_address - goto task_address+1 + ;str test = '?' * 10 + str name = "foo" + cx16.r0 = name+2 } }