6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Apr 26, 2024 10:42 pm

All times are UTC




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Thu Oct 12, 2017 11:15 pm 
Offline
User avatar

Joined: Thu Oct 12, 2017 10:51 pm
Posts: 87
...so at this point, anybody who also reads stardot is now rolling their eyes, because I've been boring people stiff about this there. But, hey, I feel I'm entitled to at least a few minutes smugness, and it may be of interest here.

I've just released Cowgol, a fully compiled, almost self-hosted strongly typed Ada-inspired modern programming language for the 6502.

http://cowlark.com/cowgol
https://github.com/davidgiven/cowgol

It's not quite self-hosting (yet) due to not quite having enough RAM but I'm sure could be made so. The generated code quality is pretty naff but it works. It's a multipass compiler with eight separate executables and it makes heavy use of disk storage, making it very very slow to compile --- eight minutes for a 'Hello world'! But it works. Mostly I cross compile from Linux.

It's targeting a BBC Micro with Tube, because that's the machine I'm used to and because it provides about 61kB of RAM plus disk operating system with file streams. It should be fairly easily portable to other platforms. I'm sure there's a C64 DOS which uses mapping tricks to get enough memory, somewhere? I've never worked with a C64; anyone who wants to help, please get in touch...

The language itself is rather boring but has a number of features I really like: multiple return parameters, nested subroutines, and strict typing. It turns out to be surprisingly comfortable to, e.g., write compilers in, which is a good thing, really. It forbids recursion to allow static placement of variables, and it walks the call graph to figure out which variables can safely share storage. This works really well, and even the biggest programs can, e.g., fit every pointer variable into less than half of zero page.

Here's some sample code:

https://github.com/davidgiven/cowgol/bl ... shower.cow

...I've been thinking about this since I was 8, so even in its incomplete, buggy state, I'm kinda pleased to actually achieve this!


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 13, 2017 4:43 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
Excellent! I like the idea of following the Algol heritage in that Wirthian direction - more types, more scope.


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 13, 2017 12:22 pm 
Offline

Joined: Sun Oct 01, 2017 1:54 pm
Posts: 20
That's a really nice piece of work! I personally think Ada is underrated and should be used more. I hope to get some time to play around with Cowgol in the near future. It looks pretty interesting.


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 15, 2017 9:04 am 
Offline
User avatar

Joined: Thu Oct 12, 2017 10:51 pm
Posts: 87
I've just committed the basic skeleton of Commodore 64 support --- the compiler won't run natively (the disk system's a bit weird and doesn't support seekable byte streams), but you can cross compile simple programs.

Any other 6502 based systems I should look at? Apple II DOS? I haven't found a programming manual yet...


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 15, 2017 9:32 am 
Offline

Joined: Sun Apr 10, 2011 8:29 am
Posts: 597
Location: Norway/Japan
I like the look of this language. Very interesting.
No recursion isn't much of a problem - I only use recursion for some particular parsers I write. That this removes the need for stack frames is a big help for e.g. the 6502.


Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 26, 2018 10:16 pm 
Offline
User avatar

Joined: Thu Oct 12, 2017 10:51 pm
Posts: 87
This isn't dead! I've just kicked 0.3 out the door. Lots of bug fixes and much faster code (compilation on the BBC Micro is literally twice as fast, although that's mostly due to disk buffering).

I need to seriously start thinking about 16-bit 6502 arithmetic and pointer accesses. It won't be pretty.


Top
 Profile  
Reply with quote  
PostPosted: Tue Feb 27, 2018 11:51 am 
Offline

Joined: Wed Mar 02, 2016 12:00 pm
Posts: 343
hjalfi wrote:
This isn't dead! I've just kicked 0.3 out the door. Lots of bug fixes and much faster code (compilation on the BBC Micro is literally twice as fast, although that's mostly due to disk buffering).

I need to seriously start thinking about 16-bit 6502 arithmetic and pointer accesses. It won't be pretty.


Any thoughts about 65C816 support?


Top
 Profile  
Reply with quote  
PostPosted: Tue Feb 27, 2018 4:40 pm 
Offline
User avatar

Joined: Thu Oct 12, 2017 10:51 pm
Posts: 87
It'd be totally possible. Right now the whole toolchain assumes 16 bit addresses, so dealing with multiple banks would be tricky, but assuming your program fit within a single bank then doing a code generator probably wouldn't be hard.

The 6502 is tough to generate code for because of the unorthogonal addressing modes and very limited register sets. Using 16-bit register mode would simplify things a lot (lda (ptr), y with unlimited offsets!). It'd also mean much more natural 16-bit arithmetic, which would be a big win.

But I'm not planning on doing this any time soon --- too much other stuff to work on (in rough order: improve 6502 code generation; throw away the parser and replace it with a smaller and less buggy table-based one; do Z80 port). OTOH the interfaces are reasonably stable, if hideously undocumented, so if anyone wants a look...

https://github.com/davidgiven/cowgol/tr ... /arch/6502

(Probably wouldn't recommend it. The 6502 code generator is awful. Hopefully once I've done the Z80 one I'll have had a chance to clean up the API a bit.)


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 13, 2018 8:39 am 
Offline
User avatar

Joined: Thu Oct 12, 2017 10:51 pm
Posts: 87
Cowgol's still going strong, BTW. The latest release is 0.6.1 and features substantially improved code generation for the 6502 plus a whole new Z80 code generator for CP/M and Fuzix (but nobody here will care about that, right?). It's also got some minor architectural improvements which let it make better use of memory; self-hosting may finally be possible on a system with enough RAM, and you should be able to compile useful (but small) programs in 48kB.


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 13, 2018 8:48 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
As Acorn's BBC Micro happily acts as a front-end to a Z80, which can run CP/M, and maybe one day Fuzix, yes - interested!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: