Prog8 language and compiler topic
Prog8 language and compiler topic
I have actually found something I'd consider a small bug in the compiler. You can't have a comment in the array initialization list as a separate line. So
ubyte[6] arr = [ 1,2,3,
; Comment here
5,6,7 ]
is illegal. I found this while trying add some comments in my data. It's not a big issue since this
ubyte[6] arr = [ 1,2,3, ; Comment here
5,6,7 ]
works fine.
- desertfish
- Posts: 1097
- Joined: Tue Aug 25, 2020 8:27 pm
- Location: Netherlands
Prog8 language and compiler topic
That first fragment compiles fine as well.... what error are you observing?
sub start() {
ubyte[6] array = [ 1,2,3,
; Comment here
4,5,6 ]
txt.print_ub(len(array))
}
correctly prints 6
Prog8 language and compiler topic
I get
Prog8 compiler v6.4 by Irmen de Jong (irmen@razorvine.net)
This software is licensed under the GNU GPL 3.0, see https://www.gnu.org/licenses/gpl.html
Compiler target: cx16. Parsing...
importing 'tmp'
tmp.p8:6:14: extraneous input '\r\n' expecting {'[', '+', '-', '~', 'not', '(', 'true', 'false', NAME, DEC_INTEGER, HEX_INTEGER, BIN_INTEGER, '&', '@', FLOAT_NUMBER, STRING, SINGLECHAR}
←[91mThere are 1 errors in 'tmp'.
←[0m
I'm compiling on Windows 10 with jdk-11.0.8.10.
- desertfish
- Posts: 1097
- Joined: Tue Aug 25, 2020 8:27 pm
- Location: Netherlands
Prog8 language and compiler topic
can you please attach the exact tmp.p8 file that fails to compile? I can't reproduce your problem...
-
- Posts: 137
- Joined: Tue Jun 30, 2020 3:47 pm
Prog8 language and compiler topic
4 hours ago, borgar said:
tmp.p8:6:14: extraneous input '\r\n'
4 hours ago, borgar said:
I'm compiling on Windows 10 with jdk-11.0.8.10.
Is it possible that this is an issue with Windows line endings?
- desertfish
- Posts: 1097
- Joined: Tue Aug 25, 2020 8:27 pm
- Location: Netherlands
Prog8 language and compiler topic
6 hours ago, Elektron72 said:
Windows line endings
Yup, this is the cause of the problem.
I'll try to fix it in the parser. EDIT: fixed , the source file loader now normalizes all line endings to just '\n' and I've simplified the parser grammar to just deal with Unix line endings.
- desertfish
- Posts: 1097
- Joined: Tue Aug 25, 2020 8:27 pm
- Location: Netherlands
Prog8 language and compiler topic
update regarding V39 of the emulator/roms:
I'm updating and fixing some things in Prog8 and its libraries, to accommodate the changes made in the emulator and rom V39 that will be out soon. Starting from the next version of Prog8 that will come out, 6.5, the compiler will produce programs meant to run on V39 of the commanderx16 emulator/rom (and hopefully on the actual hardware)
The compiler changes are sometimes incompatible with V38. Stick to prog8 6.4 if you absolutely have to create programs meant to run on V38. Programs compiled by the next prog8 version can sometimes still run on V38, but that is only if you're lucky.
I'm not adding backward compatibility to the compiler because I'm expecting everyone that compiles code for it, will hop to V39 anyway, as soon as it is released.
Prog8 language and compiler topic
I've found another compiler bug. I'm creating a data structure with an array of arrays (i.e array elements are memory locations). Here is a relevant code parts:
const REF_ACTIVE = 0
uword[] container = [ &item1, &item2 ]
uword myref = container[1]
ubyte tmp = myref[REF_ACTIVE]
Basically using arry index [0] doesn't work in this assignment (anything above 0 works fine).
Curiously it does compile if the same value is used in an if statement.
Compilable sample attached.
tmp.p8
- desertfish
- Posts: 1097
- Joined: Tue Aug 25, 2020 8:27 pm
- Location: Netherlands
Prog8 language and compiler topic
A assume you're getting the following error: (it would help if you paste the error itself as well , if you find any in the future! thanks in advance ? )
Exception in thread "main"
* internal error *
java.lang.IllegalArgumentException: Failed requirement.
at prog8.ast.statements.VarDecl.replaceChildNode(AstStatements.kt:235)
This one has already been fixed very recently in the master branch (that will become version 6.5) !