C02 - An 8-bit optimized C syntax compiler for the 6502

Programming the 6502 microprocessor and its relatives in assembly and other languages.
unclouded
Posts: 81
Joined: 24 Feb 2015

Re: C02 - An 8-bit optimized C syntax compiler for the 6502

Post by unclouded »

Just an idea: How about maintaining a short piece of sample code so we can see the current syntax? I like the way http://coffeescript.org/ explains the language by example.
CurtisP
Posts: 79
Joined: 10 Feb 2011

Re: C02 - An 8-bit optimized C syntax compiler for the 6502

Post by CurtisP »

unclouded wrote:
Just an idea: How about maintaining a short piece of sample code so we can see the current syntax? I like the way http://coffeescript.org/ explains the language by example.
A dense, but fairly exhaustive sample code section has been added to the README file, along with the new logo designed by Triangular
unclouded
Posts: 81
Joined: 24 Feb 2015

Re: C02 - An 8-bit optimized C syntax compiler for the 6502

Post by unclouded »

CurtisP wrote:
A dense, but fairly exhaustive sample code section has been added to the README file
Very nice! Is this one correct?

Code: Select all

do (c = getchr(); putchr(c); while (c<>13)
It looks to the untrained eye like there's an unmatched parenthesis following `do`

I see that:

Code: Select all

i:+
..is a condition for "i is positive". It might be friendlier to just recognise

Code: Select all

i>=0
as a degenerate comparison and emit the `BMI` pattern.
CurtisP
Posts: 79
Joined: 10 Feb 2011

Re: C02 - An 8-bit optimized C syntax compiler for the 6502

Post by CurtisP »

unclouded wrote:
Is this one correct?

Code: Select all

do (c = getchr(); putchr(c); while (c<>13)
It looks to the untrained eye like there's an unmatched parenthesis following `do`
This should have been

Code: Select all

do {c = getchr(); putchr(c);} while (c<>13)
I'll fix it.
unclouded wrote:
I see that:

Code: Select all

i:+
..is a condition for "i is positive". It might be friendlier to just recognise

Code: Select all

i>=0
as a degenerate comparison and emit the `BMI` pattern.
That won't work, because all variables, expressions, and comparisons are unsigned. So (128 > 1) is true even though (128:+) is not, and (128>0) should work the same way.
CurtisP
Posts: 79
Joined: 10 Feb 2011

Re: C02 - An 8-bit optimized C syntax compiler for the 6502

Post by CurtisP »

After a few months hiatus, I've started working on C02. I fixes a bug with break & continue in do/while loops, add a tag for strings to printf() in library stdiox.

I also added a new library memio, which mimics file i/o functions, but reads and writes directly to memory, for use with machines and emulators that do not have file system support, but do support loading and saving blocks of memory to and from a storage device. I did this to allow development of programs that would normally interact with files on these systems.
CurtisP
Posts: 79
Joined: 10 Feb 2011

Re: C02 - An 8-bit optimized C syntax compiler for the 6502

Post by CurtisP »

I fixed a bug in the parsing of escape sequences in strings (dumb mistake, but took me a while to find it).

But more importantly I made two changes to expression parsing and compilation: Expressions may be used as indexes in any subscripted array references within expressions, and function calls may appear in any term of an expression

My next step is to allow expressions as the second (and possibly third) arguments of function calls. I figure the less quirks in the language specification the better.

All changes have been pushed up to the github repository at https://github.com/RevCurtisP/C02
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Re: C02 - An 8-bit optimized C syntax compiler for the 6502

Post by BigEd »

Just to note, I stumbled on this old thread, and am pleased to see active development still going on in the repository. Nice!
Post Reply