diff --git a/codeOptimizers/src/prog8/optimizer/ExpressionSimplifier.kt b/codeOptimizers/src/prog8/optimizer/ExpressionSimplifier.kt index 120572859..774a584c8 100644 --- a/codeOptimizers/src/prog8/optimizer/ExpressionSimplifier.kt +++ b/codeOptimizers/src/prog8/optimizer/ExpressionSimplifier.kt @@ -30,8 +30,9 @@ class ExpressionSimplifier(private val program: Program) : AstWalker() { val literal = typecast.expression as? NumericLiteral if (literal != null) { val newLiteral = literal.cast(typecast.type) - if (newLiteral.isValid && newLiteral.valueOrZero() !== literal) - mods += IAstModification.ReplaceNode(typecast.expression, newLiteral.valueOrZero(), typecast) + if (newLiteral.isValid && newLiteral.valueOrZero() !== literal) { + mods += IAstModification.ReplaceNode(typecast, newLiteral.valueOrZero(), parent) + } } // remove redundant nested typecasts diff --git a/compiler/res/prog8lib/cx16/psg.p8 b/compiler/res/prog8lib/cx16/psg.p8 index 8af0e598f..2ed115df1 100644 --- a/compiler/res/prog8lib/cx16/psg.p8 +++ b/compiler/res/prog8lib/cx16/psg.p8 @@ -90,6 +90,10 @@ psg { ; cx16.r1L = the voice number ; cx16.r2L = attack value + pushw(cx16.r0) + push(cx16.r1L) + push(cx16.r2L) + pushw(cx16.r9) ; calculate new volumes for cx16.r1L in 0 to 15 { when envelope_states[cx16.r1L] { @@ -138,6 +142,10 @@ psg { cx16.VERA_DATA0 = cx16.VERA_DATA1 & %11000000 | msb(envelope_volumes[cx16.r1L]) } cx16.pop_vera_context() + popw(cx16.r9) + pop(cx16.r2L) + pop(cx16.r1L) + popw(cx16.r0) } ubyte[16] envelope_states diff --git a/compiler/res/version.txt b/compiler/res/version.txt index cf022018d..47ea0f6ff 100644 --- a/compiler/res/version.txt +++ b/compiler/res/version.txt @@ -1 +1 @@ -8.3 +8.4-dev diff --git a/compilerAst/src/prog8/ast/AstToplevel.kt b/compilerAst/src/prog8/ast/AstToplevel.kt index 720a597b0..83eecb231 100644 --- a/compilerAst/src/prog8/ast/AstToplevel.kt +++ b/compilerAst/src/prog8/ast/AstToplevel.kt @@ -197,6 +197,14 @@ interface INameScope: IStatementContainer, INamedStatement { else statementScope = (statementScope as Node).definingScope } + + // still not found, maybe it is a symbol in another module + for(module in (this as Node).definingModule.program.modules) { + val stmt = module.searchSymbol(name) + if(stmt!=null) + return stmt + } + return null } diff --git a/compilerAst/src/prog8/ast/expressions/AstExpressions.kt b/compilerAst/src/prog8/ast/expressions/AstExpressions.kt index 971f692e4..b57f4009b 100644 --- a/compilerAst/src/prog8/ast/expressions/AstExpressions.kt +++ b/compilerAst/src/prog8/ast/expressions/AstExpressions.kt @@ -757,9 +757,11 @@ class ArrayLiteral(val type: InferredTypes.InferredType, // inferred because } } - // otherwise, select the "biggegst" datatype based on the elements in the array. + // otherwise, select the "biggest" datatype based on the elements in the array. + require(value.isNotEmpty()) { "can't determine type of empty array" } val datatypesInArray = value.map { it.inferType(program) } - require(datatypesInArray.isNotEmpty() && datatypesInArray.all { it.isKnown }) { "can't determine type of empty array" } + if(datatypesInArray.any{ it.isUnknown }) + return InferredTypes.InferredType.unknown() val dts = datatypesInArray.map { it.getOr(DataType.UNDEFINED) } return when { DataType.FLOAT in dts -> InferredTypes.InferredType.known(DataType.ARRAY_F) diff --git a/examples/test.p8 b/examples/test.p8 index df41c534e..434b531da 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,22 +1,17 @@ %import textio %zeropage basicsafe + main { sub start() { - ubyte value1 = %1110 - ubyte value2 = %1111 - - bool[2] @shared barr = [true, false] - -; if value1 and value2 ; TODO value1 isn't converted to bool in 6502 preprocess -; txt.print("ok") -; else -; txt.print("fail!") -; txt.nl() - - if value1 and value2!=255 ; TODO value1 isn't converted to bool in 6502 preprocess - txt.print("ok") - else - txt.print("fail!") + repeat { + uword keys = cx16.kbdbuf_peek2() + txt.print_uwhex(keys, true) + if msb(keys) { + c64.GETIN() + } + txt.nl() + } } } +