I want to look at alternatives to C for Z80 programming. Since there's probably nothing that directly compiles to Z80 asm I want to look at languages that compile to C. There are the fopllowing requirements:
- Compiles to C
- Free compiler
- Low memory usage (I have only 1KB of RAM)
Has anyone come across such a language?
The last requirement seems to be a rather hard one. Many languages that compile to C include relatively large overhead or do dynamic allocation of memory, etc. So far bitc
seems to be the closest match, but it's badly documented and a pain to build. It seems the authors just see it as a tool for development of Coyotos, their embedded OS, not as a generic programming language someone else might want to use.
So you add the overhead of a C compiler that needs to guess the optimal way to represent something in an alien language? If you don't want to program directly in C then I'd suggest focusing on other languages that do have Z80 output capability.
There are plenty of compiled languages that emit Z80 code - Ada, Fortran, ... and of course BASIC variants abound. And some interpreted BASICs (BBC BASIC for instance, used in the Amstrad NC100 among other things) are already ported to the Z80 and very nice.
CP/M ran on the Z80, so there are shiploads of old tools out there.
Rather than add another link in the chain, for litle benefit, find a toolchain that runs on the Z80, and operates on a PC (comand line) under Z80 emulation ? You will find forth, Pascal, Modula-2, BASIC's by the Dozen
I think Intel also had a PL/M for the 8080 ?
If you only have 1K ram, this cannot be a big project, so why the aversion to C ?
For small projects, it may be more productive to tolerate C, but have better access to DEBUG, than chosing a better language, with poorer debug access ?
eg Zilog's Z80Acclaim has a Free C, and it ALSO has good Debug support.
With 1KB of RAM, I can't see how you'd be doing anything at all useful in any language other than Z80 assembler. Wanting a pre-compiler to produce C then compile and link the C source output in 1KB - not a chance.
Or are you talking about rommable software with 1KB RAM?
Mark McDougall, Engineer
Virtual Logic Pty Ltd,
Many posts asked _why_ I want such a language that compiles to C.
- I've been programming for this system in C + asm for a while and want to try something new. I don't want Pascal or BASIC (I've seen a bit os Pascal a long time ago in school and I don't remember any advantages over C, I never want to go back to BASIC). I'm looking for a language that offers some new constructs over C. Object-orientation or a functional language might be interesting. Most languages that can be compiled directly to Z80 asm are quite old and not that interesting (Pascal, BASIC).
- I'm the maintainer of the Z80 port of sdcc, a free C compiler; I want to see how good sdcc is at compiling the output of another compiler. In the past compiling output from nesC helped find some obscure bugs.
Your question doesn't make sense unless you tell us more about your requirements for the programming language. Are you saying that you have a C compiler for the Z80, but don't like C, and you are happy with any other language than C?
Some examples are:
cfront (translates C++ to C) PtoC (translates Pascal to C) mercury (a logical/functional programming language with a C back-end)
With bitc the problem is not modifying the output to work on my system, it's more the rest of bitc:
-It's a functional language, thus different to what I'm used to. This is not a problem in itself, I've wanted to learn a functional language for some time, but it's probably difficult to start with bitc: No tutorials, just a little bit of sample code and an outdated specification, no other documentation.
-Bitc is a pain to build. I did it twice. I took days, since after each step I had to ask questions on the mailing list about the next problem that came up.
I started programming ColecoVision games as a hobby some years ago. Back then everyone used either asm or C with HITECH-C 3.09 in a CP/M emulator. I wrote a library and tools
for use with sdcc, so I could use a more modern C compiler. I started improving sdcc and became it's Z80 port maintainer. Sometimes when programming I found that object-orientation would be a natural way to express concepts, and wished I could use C++. And I want to try a language different from C, maybe something functional. And I'd like so see how sdcc handles C code generated by another compiler (some more oscure sdcc bugs have been found by compiling the poutput of nesC).
Fair enough - curiosity and interest are good reasons, at least if you don't have deadlines!
Pascal has some advantages, but they are more along the lines of things it does *not* support or allow. You have to use modules properly in Pascal, and can't make spaghetti with headers and macro definitions that change according to where the header is used. You can't randomly mix integers and enumerated types. You can't use functions or data without declarations. You can't mix up "=" and "==", or omit "break" statements in switches, or many of the other syntactically legal and semantically nonsense constructs that are allowed in C. There are a few other features such as nested functions that don't exist in C (although gcc allows nested functions as an extension), and simple set types.
However, if you are already competent at C programming (and I'm guessing that you are, as the maintainer of an sdcc port!), and already write well-structured and modular code, then their is little to gain.
I don't know about cfront (or if C++ appeals at all) - it's just an idea.
I expect mercury would quickly eat up your ram, and also produce code otherwise unsuitable for small systems (it probably expects 32-bit ints, for example). It's also a functional programming language, which you say you are not looking for at the moment. Again, it's just a random idea.
Have you looked much at the llvm project? I believe llvm can generate C code at the back end, which you could compile using sdcc. With a bit of glue, that would give you C, C++, Objective C, Ada and Fortran.