EgonOlsen71 / basicv2

A Commodore (CBM) BASIC V2 interpreter/compiler written in Java
https://egonolsen71.github.io/basicv2/
The Unlicense
84 stars 15 forks source link

IndexOutOfBoundsException thrown in Integer Pass 1 #47

Closed viteisele closed 1 year ago

viteisele commented 1 year ago

There is a problem with Integer optimization and basicv2.jar with date 2022/07/17 and newer.

When compiling this code: 200 n%=9 210 dim d%(9) 220 for i=1 to 9: d%(i)=i: next 300 t1%=1 310 i1%=d%(t1%):d%(t1%)=d%(1):d%(1)=i1%: s2=10*i1% 320 rem further swaps 485 d%(1)=d%(t1%):d%(t1%)=i1% 490 t1%=t1%+2:if t1%<=n% goto 310

There is following error when compiling it with actual basicv2.jar: ... Total optimizations applied in this pass: 4 Integer pass 1... !!! Failed to apply integer optimizations: Index 17 out of bounds for length 17 java.lang.IndexOutOfBoundsException: Index 17 out of bounds for length 17 at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64) at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70) at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248) at java.base/java.util.Objects.checkIndex(Objects.java:372) at java.base/java.util.ArrayList.get(ArrayList.java:459) at com.sixtyfour.cbmnative.mos6502.IntOptimizer$33.modify(IntOptimizer.java:967) at com.sixtyfour.cbmnative.mos6502.IntPattern.modify(IntPattern.java:23) at com.sixtyfour.cbmnative.mos6502.IntOptimizer.applyIntOptimizations(IntOptimizer.java:1532) at com.sixtyfour.cbmnative.mos6502.Optimizer6502.applySpecialRules(Optimizer6502.java:267) at com.sixtyfour.cbmnative.mos6502.Optimizer6502.optimize(Optimizer6502.java:44) at com.sixtyfour.cbmnative.NativeCompiler.compile(NativeCompiler.java:190) at com.sixtyfour.cbmnative.shell.MoSpeedCL.main(MoSpeedCL.java:338) Total optimizations applied in this pass: 0 ...

EgonOlsen71 commented 1 year ago

Should be fixed now. Two different optimizations were fighting for dominance...

viteisele commented 1 year ago

The test programms are now compiled without error. Thank you :-)