Programming languages than can be compiled to C

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

formatting link
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.

Philipp

Reply to
Philipp Klaus Krause
Loading thread data ...

Which are quite rare.

Have you considered FORTH?

Reply to
toby

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.

Take a look, for just one example, at

Reply to
larwe

If you understand C programming, why not modify the C output from bitc or any other compiler.

If don't understand C programming, learn.

donald

Reply to
donald

Which Z80 only has 1K ram ?

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.

-jg

Reply to
Jim Granville

The 28 year old Sinclair ZX80 perhaps? ;-)

formatting link

Joop

Reply to
Joop

nclair_ZX80

The ZX81 was considerably more popular, if you have a spare ZX80 I want to buy it :) Also there are many hobbyist SBCs and I think a couple of other home computers with a Z80 CPU and 1K RAM (as 2 x

2114).

There are various Z80 micros with 1K RAM on-chip too, the Z80S188 coming immediately to mind.

Reply to
larwe

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?

Regards,

--
Mark McDougall, Engineer
Virtual Logic Pty Ltd, 
21-25 King St, Rockdale, 2216
Ph: +612-9599-3255 Fax: +612-9599-3266
Reply to
Mark McDougall

The first processor for which I wrote embedded C had 128 bytes of RAM, and the application worked just peachy. 1kB would have left me awash in spare memory.

I would put a 1kB processor into the "definitely use C" category, rather than the "definitely avoid C" category.

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

Do you need to implement control loops in software?
"Applied Control Theory for Embedded Systems" gives you just what it says.
See details at http://www.wescottdesign.com/actfes/actfes.html
Reply to
Tim Wescott

Was the code in ROM with 128 bytes of RAM? I'm assuming the OP is talking about a total ROM+ROM of 1KB. Hence my last (as yet unanswered) question.

Regards,

--
Mark McDougall, Engineer
Virtual Logic Pty Ltd, 
21-25 King St, Rockdale, 2216
Ph: +612-9599-3255 Fax: +612-9599-3266
Reply to
Mark McDougall

that should be ROM+RAM...

--
Mark McDougall, Engineer
Virtual Logic Pty Ltd, 
21-25 King St, Rockdale, 2216
Ph: +612-9599-3255 Fax: +612-9599-3266
Reply to
Mark McDougall

I have 32KB of ROM (and there's an 8KB BIOS, which I don't use except for it's font).

Philipp

Reply to
Philipp Klaus Krause

ColecoVision.

Philipp

Reply to
Philipp Klaus Krause

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.

Philipp

Reply to
Philipp Klaus Krause

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)

Reply to
David Brown

donald schrieb:

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.

Philipp

Reply to
Philipp Klaus Krause

Now you've got me interested... ;)

Regards,

-- Mark McDougall, Engineer Virtual Logic Pty Ltd,

21-25 King St, Rockdale, 2216 Ph: +612-9599-3255 Fax: +612-9599-3266
Reply to
Mark McDougall

David Brown schrieb:

I like C, but want to try another language.

- AFAIR remember from school Pascal is C-like and doesn't offer any advantages over C.

- cfront is acient. Will it compile on modern systems?

- mercury looks nice, I already found it some time ago, but back then it would need more than 1KB of RAM.

Philipp

Reply to
Philipp Klaus Krause

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

formatting link
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).

Philipp

Reply to
Philipp Klaus Krause

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.

Reply to
David Brown

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.