C02 - An 8-bit optimized C syntax compiler for the 6502
Re: C02 - An 8-bit optimized C syntax compiler for the 6502
I just realized that the 65C02's PLX instruction gives me a way to easily allow an expression to be use as an array index on the left side of the assignment.
Re: C02 - An 8-bit optimized C syntax compiler for the 6502
I created a branch that targets the 65C02. but couldn't get the code to compile in dasm.
-
DerTrueForce
- Posts: 483
- Joined: 04 Jun 2016
- Location: Australia
Re: C02 - An 8-bit optimized C syntax compiler for the 6502
CurtisP wrote:
The intention of the language is that the fiddly parts will be written in assembler and called as functions. And the general program flow and overall logic written in C02.
CurtisP wrote:
The name was intended to be a pun of CO₂ (Carbon Dioxide), and I was also considering a variant for the 8080/Z80 called C80.
At the very least I should rename the compiler cc02, to match cc, gcc, tcc, etc...
At the very least I should rename the compiler cc02, to match cc, gcc, tcc, etc...
The CO₂ pun idea was actually fairly good, I think. I don't know about the whole cc thing, though.
Re: C02 - An 8-bit optimized C syntax compiler for the 6502
DerTrueForce wrote:
I still think I'd like to use C02 in my project, especially if it runs on the 'C02 as well.
-
White Flame
- Posts: 704
- Joined: 24 Jul 2012
Re: C02 - An 8-bit optimized C syntax compiler for the 6502
By the way, comparing to cc65 isn't going to be that meaningful. CC65's goal is to bring actual proper standard C to 6502 platforms, so it's going to be bigger and have greater mismatch with the CPU platform assumptions. If C02's goal is to have a 6502-friendly "C-like language", then yeah you're going to generate smaller more 6502-idiosyncratic instructions, but it's still a custom language to learn if you want to attract a userbase instead of just building your own tools.
Re: C02 - An 8-bit optimized C syntax compiler for the 6502
Sounds good to me though - a c-like language with a good fit to the machine.
(I'd call it CC02 though, to make search easier.)
(I'd call it CC02 though, to make search easier.)
Re: C02 - An 8-bit optimized C syntax compiler for the 6502
White Flame wrote:
CC65's goal is to bring actual proper standard C to 6502 platforms, so it's going to be bigger and have greater mismatch with the CPU platform assumptions.
-
DerTrueForce
- Posts: 483
- Joined: 04 Jun 2016
- Location: Australia
Re: C02 - An 8-bit optimized C syntax compiler for the 6502
CurtisP wrote:
DerTrueForce wrote:
I still think I'd like to use C02 in my project, especially if it runs on the 'C02 as well.
Basically, I'd want to use it on and for my own platform. This means I'd need to write my own libraries for it or adapt existing ones, but I think I can do that.
Re: C02 - An 8-bit optimized C syntax compiler for the 6502
I added a command line option -h to specify a header file to be inserted at the beginning of the code.
The purpose is to allow a single program to be easily compiled against different target machines.
I plan to add another option to specify the include file directory and restructure the sample/test code directories to better demostrate how this can be used.
The purpose is to allow a single program to be easily compiled against different target machines.
I plan to add another option to specify the include file directory and restructure the sample/test code directories to better demostrate how this can be used.
Re: C02 - An 8-bit optimized C syntax compiler for the 6502
White Flame wrote:
By the way, comparing to cc65 isn't going to be that meaningful. CC65's goal is to bring actual proper standard C to 6502 platforms, so it's going to be bigger and have greater mismatch with the CPU platform assumptions. If C02's goal is to have a 6502-friendly "C-like language", then yeah you're going to generate smaller more 6502-idiosyncratic instructions, but it's still a custom language to learn if you want to attract a userbase instead of just building your own tools.
Having more high-level language compilers for the 6502 is a win though. I didn't use cc65 because it's C, I used it because I found it quicker for testing ideas than assembler. I'd be prepared to learn a new syntax for that purpose (and I'm jealous because I wanted to write a high level language closely bound to the 6502).
Re: C02 - An 8-bit optimized C syntax compiler for the 6502
unclouded wrote:
White Flame wrote:
I'd be prepared to learn a new syntax for that purpose (and I'm jealous because I wanted to write a high level language closely bound to the 6502).
I'm still working out the details so any and all suggestions are appreciated.
Re: C02 - An 8-bit optimized C syntax compiler for the 6502
Another update to the code: up to three variables on the left side of the assignment, for function calls that return values in the X and/or Y registers as well as the Accumulator.
Re: C02 - An 8-bit optimized C syntax compiler for the 6502
Another update:
I deprecated the #define directive in favor of the const keyword, although the syntax differs from standard C.
I had previously implemented an #enum directive. This has been replaced by the num keyword with a syntax similar to standard C.
All constant references in C02 are prefixed with a # symbol.
I deprecated the #define directive in favor of the const keyword, although the syntax differs from standard C.
I had previously implemented an #enum directive. This has been replaced by the num keyword with a syntax similar to standard C.
All constant references in C02 are prefixed with a # symbol.
Re: C02 - An 8-bit optimized C syntax compiler for the 6502
Update: Added the struct keyword. C02 implements most of the functionality of structs in C.
Structs make the compiler a bit larger, but I feel they are too useful to leave out. For example, the variable and constant lookup tables are structured as arrjects (a separate array for each member). The struct lookup tables are implemented using structs and the as a result the code is much easier to read. I plan to go back and refactor the variable and constant tables to use structs as well.
C02 does not support arrays of structs, and the lack of native pointer support precludes a trivial implementation of linked lists. However, the block and pointer functions in the standard library were written to replicate both of these functionalities. The repository currently contains a test directory. I think I will add an examples directory as well.
Edit: I added @ as the size-of operator.
Structs make the compiler a bit larger, but I feel they are too useful to leave out. For example, the variable and constant lookup tables are structured as arrjects (a separate array for each member). The struct lookup tables are implemented using structs and the as a result the code is much easier to read. I plan to go back and refactor the variable and constant tables to use structs as well.
C02 does not support arrays of structs, and the lack of native pointer support precludes a trivial implementation of linked lists. However, the block and pointer functions in the standard library were written to replicate both of these functionalities. The repository currently contains a test directory. I think I will add an examples directory as well.
Edit: I added @ as the size-of operator.
Re: C02 - An 8-bit optimized C syntax compiler for the 6502
Bug Fix: Chained IF/ELSE statements weren't compiling correctly. Finally figured out how to make them work.