I would like to be able to use Nim to compile to C code that is suitable for a Z80 compiler such as z88dk or SDCC but am having difficulty in finding the correct command line switches etc.
The documentation lists the switches, but not the possible values. I have been able to find out some of the switch values by typing in gibberish and reading the error message hints, which narrows it down a little. That still doesn't tell me what the difference between "any" and "standalone" for "os" is, for example.
I have tried a combination of switches and values for a simple "hello world" text program, but the output seems overly large and complex.
Can anyone offer any advice?
This is for Nim 1.6.6 on Windows, in case that makes a difference.
Probably a good start would be nim c -d:release --os:standalone --exceptions:gotos --gc:arc
I wouldn't worry about the output size, any decent optimizing compiler should produce optimal code from Nim output.
I wouldn't worry about the output size, any decent optimizing compiler should produce optimal code from Nim output.
problem is that said thing doesn't really exist for those 8-bit micros.
For once when compilers started to get become acceptabably near handwritten C code those CPUs where already gone for most applications (especially those where using a high level programming language would be useful).
Besides that it's also plain harder to write a good compiler for those accumulator based architectures, with weird things such as registers made up from other registers and thus they can also not really benefit that much from existing compiler infrastructure, leaving us with completely independent compilers which then also lack in terms of standard compability.
Another thing to consider is that type sizes will be weird for lots of modern programs, even when not trying to make things fast (8 bit int, 16 or 24 bit pointers). While C can still account for a lot of this weirdness, Nim cannot. sizeof(int) == sizeof(pointer) will mean that if you aren't carefully using int8 everywhere your program will be even slower.
I'm no expert, but I would imagine that Nim is capable of producing code suitable for modern 8-bit compilers if it is able to do so for the Tiny C Compiler.
Following the C89 standard would be best for my use case, but most of C99 is usually supported too.
As I intend to create text adventures, 8-bit integers should be enough in most cases and using 16-bit integers shouldn't slow things down too much. As long as the programs run faster than they would in BASIC, most players would be happy.