Jump to content
desertfish

Prog8 language and compiler topic

Recommended Posts

Yeah I think it’s pretty much impossible to have the same full featured prog8 compiler optimizer and code generator natively. Then again there is a (limited) native C compiler that I also thought not being possible at all. 

I was using a macro assembler on the Commodore 64 back in the days

Share this post


Link to post
Share on other sites

@borgar i'm curious about your experiences with Prog8 so far. I'm not really aware of anyone else beside myself using it, so I wonder what you think of it and if you have any comments maybe?

Share this post


Link to post
Share on other sites

I quite like Prog8. It's almost exactly what I though it would be, I.e a low level language that produces fairly efficient code (at least compared with Basic) while abstracting away the most tedious parts of assembly.

I'm exactly the right age (50) for feeling nostalgic for the simplicity for the 80's computers (I used to own a C64 and later an Amiga 500).  On the other hand I work as a developer (well more as a dev manager now) and have no desire of writing anything in Commodore Basic again.

I don't have any serious feedback for the language so far. I've had experience with quite a lot of languages over the years so the syntax is comfortable. I actually like that the syntax is simple and limited. It matches well with the concept for X16. I.e. working within a simple and constrained platform where you have to get the most out of limited resources/capabilities

The only thing that I have missed so was a bit of doc for libraries (e.g. for txtio). Just a list of functions with signatures and simple description. But I just got these in the source so no worries. With a userbase of 1 I can see why this hasn't been a huge priority 😉

  • Thanks 1

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Posted (edited)

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.

Edited by borgar

Share this post


Link to post
Share on other sites

can you please attach the exact tmp.p8 file that fails to compile? I can't reproduce your problem...

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Edited by desertfish
  • Like 3

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Please review our Terms of Use