Reputation: 225
I have an idea to create scripting language which will make people to program easier doing a lot of macros, functions, simpler function names everything more simpler for simple person to work with. That code (custom scripting language) then should be translated to simple C language things. Like so:
Scripting:
IO[9].high
@include "lib"
for (int i=0 to 55)
end
C:
IO |= (1<<9);
#include "lib.h"
int i = 0;
for (i=0; i<55; i++) {
}
Is it possible somehow efficiently write this macro/scripting language which would nicely output to c code?
Upvotes: 2
Views: 938
Reputation: 6797
Thanks to PyPy, it is possible to translate a subset of Python code into c.
For further details, see the following reference : http://doc.pypy.org/en/latest/translation.html
See also the following question, which is basically your question specifying Python as the scripting language : Use Cython as Python to C Converter
Upvotes: 3
Reputation: 8928
For example, Have you seen mib2c script from netsnmp?. It generates C source using script. You can refer to that for getting more ideas.
Upvotes: 1
Reputation: 157354
Absolutely; some languages which compile (or have compiled) into C include Eiffel, Haskell (GHC), Vala, and Squeak. The earlier versions of C++ were implemented as a C++-to-C translator (CFront).
The general concept is an intermediate language. C is mentioned as being used as an intermediate language; by making use of a C compiler you gain binary compatibility with many languages and libraries and avoid having to write your own compiler; Ritchie describes C as being used as a "portable assembly language".
However, as with C++ you might quickly find that targeting C becomes overly restrictive; GHC are moving towards a dedicated intermediate language called C--, and you might find that using the LLVM toolchain (essentially, targeting the LLVM intermediate representation) is a better approach for multi-platform compatibility.
Upvotes: 3