Prog8 language and compiler topic

All aspects of programming on the Commander X16.
Post Reply
User avatar
desertfish
Posts: 1095
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

Prog8 language and compiler topic

Post by desertfish »

Prog8 is a free programming language that is written on a modern computer and is then cross-compiled into a machine code binary for 6502 8-bit machine targets such as the Commodore-64 and/or the Commander X16.

Prog8 documentation: https://prog8.readthedocs.io
Prog8 project and source code website: https://github.com/irmen/prog8

You can download the compiler from there as well, it is free and open-source (GPL license)

A whole bunch of example programs is included in the prog8 source repository: https://github.com/irmen/prog8/tree/master/examples

What does it do?
  • all advantages of a higher level language over having to write assembly code manually
  • programs run very fast because compilation to native machine code: often produces smaller and faster running programs than equivalent C code compiled with CC65 or even LLVM-MOS
  • modularity, symbol scoping, subroutines
  • various data types other than just bytes (16-bit words, floats, strings)
  • floating point math is supported if the target system provides floating point library routines (C64 and Cx16 both do)
  • strings can contain escaped characters but also many symbols directly if they have a petscii equivalent, such as "♠♥♣♦π▚●○╳". Characters like ^, _, , {, } and | are also accepted and converted to the closest petscii equivalents.
  • automatic static variable allocations, automatic string and array variables and string sharing
  • subroutines with input parameters and result values
  • high-level program optimizations
  • no need for forward declarations
  • small program boilerplate/compilersupport overhead
  • programs can be run multiple times without reloading because of automatic variable (re)initializations.
  • conditional branches
  • when statement to provide a concise jump table alternative to if/elseif chains
  • in expression for concise and efficient multi-value/containment check
  • many built-in functions such as sin, cos, rnd, abs, min, max, sqrt, msb, rol, ror, swap, sort and reverse
  • various powerful built-in libraries to do I/O, number conversions, graphics and more
  • convenience abstractions for low level aspects such as ZeroPage handling, program startup, explicit memory addresses
  • inline assembly allows you to have full control when every cycle or byte matters
  • supports the sixteen 'virtual' 16-bit registers R0 - R15 from the Commander X16, and provides them also on the C64.
  • encode strings and characters into petscii or screencodes or even other encodings, as desired (C64/Cx16)
Rapid edit-compile-run-debug cycle:
  • use a modern PC to do the work on, use nice editors and enjoy quick compilation times
  • can automatically run the program in the Vice emulator after succesful compilation
  • breakpoints, that let the Vice emulator drop into the monitor if execution hits them
  • source code labels automatically loaded in Vice emulator so it can show them in disassembly
Supports multiple target machines (c64, c128, pet, cx16, atari).
If you only use standard kernel and prog8 library routines, it is possible to compile the exact same program for both machines (just change the compiler target flag)!
Last edited by desertfish on Sat Jun 29, 2024 3:37 pm, edited 1 time in total.
Michael Steil
Posts: 94
Joined: Mon May 18, 2020 7:25 pm

Prog8 language and compiler topic

Post by Michael Steil »


I'd just post details and updates in this thread.

User avatar
desertfish
Posts: 1095
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

Prog8 language and compiler topic

Post by desertfish »


I just updated the post to mention the availability of the compiler now and where it can be found.

I'm excited to improve the Commander-X16 support even further in future releases!

One improvement I'm already thinking of, is perhaps making the set of 16-bit pseudo registers part of the language so you don't have to access them anymore as zeropage variables.

Bones
Posts: 3
Joined: Wed Jul 01, 2020 7:12 am

Prog8 language and compiler topic

Post by Bones »


Nice one.

What editor are you using for syntax highlighting in those screenshots ? 

 

Johan Kårlin
Posts: 292
Joined: Wed Jun 03, 2020 11:33 am
Location: Kalmar, Sweden

Prog8 language and compiler topic

Post by Johan Kårlin »

Incredible work you have done! You must have worked really hard to accomplish this. I am very happy to see that you have added support for the X16. It is a great gift to the community.
User avatar
desertfish
Posts: 1095
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

Prog8 language and compiler topic

Post by desertfish »


@Bones it's copied from the editor window from IntelliJ IDEA where I configured the major syntax highlighting rules for my language syntax. Which is incredibly easy to do in IDEA. To be honest, it was quite unexpected that pasting the source in here retained the coloring!  (it's not a screenshot- it's the actual source code pasted as text)

@Johan Kårlin Thank you so much for the kind words it means a lot to me. Yeah it has been a long time coming and there's still much work left to do on the code generation part  (projects are never "finished" are they? haha)  but I'm really happy today already with where the language and its compiler are.

User avatar
desertfish
Posts: 1095
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

Prog8 language and compiler topic

Post by desertfish »


Version 4.1 was just released with many improvements in the CommanderX16 support.   Most importantly is that floating point operations are now working.  (and a few example programs are now included that use this)

geek504
Posts: 95
Joined: Wed Aug 26, 2020 4:52 pm

Prog8 language and compiler topic

Post by geek504 »


Prog8 - that's a very interesting language you developed. What's the history of the language?

User avatar
desertfish
Posts: 1095
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

Prog8 language and compiler topic

Post by desertfish »


@geek504 Hi glad you asked, lets answer this here ?

I started working on it about three years ago. I wanted to learn how to create a programming language, a parser, and a compiler (I have written several interpreters over the years but never an actual compiler) . I started implementing it in Python but as the project grew larger, switched to Kotlin as an implementation language because it became too unwieldy to constantly refactor it  in Python even with IDE support.

Because I like retro computing and the Commodore-64 in particular, I thought it would be fun to try to target that platform to be able to write programs for it in a medium/high level language.  With the possibility to directly access the hardware and use inline assembler code when needed for the nitty gritty stuff.   Only recently I started adding CommanderX16 support into the compiler.

Prog8 the language itself is essentially a C like langue but with heavy Python influences because I really like Python.

It would be cool if people would use Prog8 for larger projects, but other than the few dozen example programs I've not actually written a large piece of software in Prog8 yet ?    Mostly because I'm still too busy tinkering with the compiler itself and fixing bugs, and now, CommanderX16 support for it.

SerErris
Posts: 172
Joined: Sat Aug 08, 2020 9:18 am

Prog8 language and compiler topic

Post by SerErris »



16 hours ago, desertfish said:




@geek504 Hi glad you asked, lets answer this here ?



I started working on it about three years ago. I wanted to learn how to create a programming language, a parser, and a compiler (I have written several interpreters over the years but never an actual compiler) . I started implementing it in Python but as the project grew larger, switched to Kotlin as an implementation language because it became too unwieldy to constantly refactor it  in Python even with IDE support.



Because I like retro computing and the Commodore-64 in particular, I thought it would be fun to try to target that platform to be able to write programs for it in a medium/high level language.  With the possibility to directly access the hardware and use inline assembler code when needed for the nitty gritty stuff.   Only recently I started adding CommanderX16 support into the compiler.



Prog8 the language itself is essentially a C like langue but with heavy Python influences because I really like Python.



It would be cool if people would use Prog8 for larger projects, but other than the few dozen example programs I've not actually written a large piece of software in Prog8 yet ?    Mostly because I'm still too busy tinkering with the compiler itself and fixing bugs, and now, CommanderX16 support for it.



So the result is similar to a compiled basic or a compiled c code? 



Do you use the 65c02 opcodes already? They could speed up certain things (e.g. bittests or bitsets etc).

Post Reply