Jump to content

Prog8 language and compiler topic


desertfish
 Share

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

Link to comment
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 😉

  • Like 1
  • Thanks 1
Link to comment
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.

Link to comment
Share on other sites

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

Posted (edited)
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
Link to comment
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.

Link to comment
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

Link to comment
Share on other sites

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) !

Link to comment
Share on other sites

I've just released a BETA version of the upcoming Prog8 6.5 , this version should be used if you're targeting the new "V39" of the commanderX16.   I'm using it to test my existing programs and write new code already for the upcoming cx16 release.

The final 6.5 release will appear shortly after "V39" is officially released and then I'll add the detailed change list as well.

Programs compiled with it may no longer work on the previous version of the emulator and roms, but I expect everyone that's writing new software to upgrade to "V39" real soon anyway

Link to comment
Share on other sites

  • 2 weeks later...
Posted (edited)

I've uploaded my first version of the Petaxian game now (very much inspired by C64 Galaga). It's no where near a complete game, but it's sort of playable.

As expected in this thread it's written in Prog8 which has certainly allowed me to make this a lot faster than trying to re-learn 6502 machine language (last used in 1987 when I upgraded from C64 to an Amiga 500). Though I'm a bit tempted to look closer at assembly to see if I can speed this up enough to get it to run smoothly on C64. It can be compiled and run on C64 as well but it slows down when there are a lot of moving "bits" on screen at once.

Edited by borgar
Link to comment
Share on other sites

Posted (edited)

By all means look at the generated assembly code: Some things that prog8 generates are *ahem* very inefficient when compared to had written asm.   I suggest finding a few very frequently called short routines in your code and only try tor replace those with %asm  {{..}}

I'm fairly certain you only have to do this on a few places to make it run fine on the C64 as well, it already ran pretty good as it is!

It can also help to split up long one-line expressions into several steps, sometimes even using temporary variables or one of the 'virtual registers' cx16.r0..r15 ,  this sometimes avoids prog8 generating slow stack-based evaluation code

Edited by desertfish
  • Like 1
Link to comment
Share on other sites

Thanks for the hints. I have already taken a peak at the asm output for what I think is the revelant sub and there might very well be a few things that might be possible to optimize.

But since there are no problems getting it to run on the cx16 I think I'll focus on getting a bit more of the main functionallity completed before I concentrate on C64 speed.

 

Link to comment
Share on other sites

I've uploaded a new version of Petaxian making it a bit more like a proper game. Now loop over 8 stages, 3 different enemy types (requiring different 1 to 3 hits to kill). And some simple sound effects. I basically just copied the X16 sound code from Tehtriz.

  • Like 1
Link to comment
Share on other sites

I've written a couple of assembly routines as a test and this seem to work fine. However, I was wondering how to use "temp" variables in the asmsub. I.e. I could not just add

  ubyte tmpvar

in the module file and then have the asmsub use this e.g. with

  sta testvar

I figured out that this is because the compiler removes the variable since it's unused in the actual prog8 code. Is there a way to indicate that a variable is in use in a asmsub?

BTW, I used P8ZP_SCRATCH_REG since I found that in the asmsub's in textelite.p8.

Link to comment
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.

 Share

×
×
  • Create New...

Important Information

Please review our Terms of Use