On-the-fly compilation and execution of C++ program

R

Raxit

Hi,


we are designing some stuff , that will generate c++ program(s)
What we want is we wanted to execute that generated code....

i.e.
1. Xml based language
2. C++ code generated from 1.[Its mapping between 1 & 2]
3. compilation
4. execution.

What we have got stucked at compilation, we want that our user should
not take care about compilation or c++ code generation etc...They just
write some xml "code" and it should execute !

[we are developing something like Event processor, reactor system etc]


-Raxit
 
K

Kai-Uwe Bux

Hi,


we are designing some stuff , that will generate c++ program(s)
What we want is we wanted to execute that generated code....

i.e.
1. Xml based language
2. C++ code generated from 1.[Its mapping between 1 & 2]
3. compilation
4. execution.

What we have got stucked at compilation, we want that our user should
not take care about compilation or c++ code generation etc...They just
write some xml "code" and it should execute !
[snip]

Well, what about using a compiler? If you don't want to write your own,
which would take a while, you could contact a compiler vendor for the
target platform and obtain a license to include a compiler into your
package and call it from a script or something. Other than that, you could
document the need for a C++ compiler and test for it during installation of
your program.


Best

Kai-Uwe Bux
 
G

gyakoo

we are designing some stuff , that will generate c++ program(s)
What we want is we wanted to execute that generated code....
i.e.
1. Xml based language
2. C++ code generated from 1.[Its mapping between 1 & 2]
3. compilation
4. execution.
What we have got stucked at compilation, we want that our user should
not take care about compilation or c++ code generation etc...They just
write some xml "code" and it should execute !

[snip]

Well, what about using a compiler? If you don't want to write your own,
which would take a while, you could contact a compiler vendor for the
target platform and obtain a license to include a compiler into your
package and call it from a script or something. Other than that, you could
document the need for a C++ compiler and test for it during installation of
your program.

Best

Kai-Uwe Bux

Well, I suppose that you have study .net alternative. If not, .net has
libraries to compile a code into common language code (something like
java bytecode, but in an exe or dll form), and to do a c++/c# parser
and compiler is pretty easy.
In a project I used c# as script language, which was compiled and
executed in runtime.

I hope that this help you.
 
J

James Kanze

(e-mail address removed) wrote:
we are designing some stuff , that will generate c++
program(s) What we want is we wanted to execute that
generated code....
i.e.
1. Xml based language
2. C++ code generated from 1.[Its mapping between 1 & 2]
3. compilation
4. execution.
What we have got stucked at compilation, we want that our
user should not take care about compilation or c++ code
generation etc...They just write some xml "code" and it
should execute !

Well, what about using a compiler? If you don't want to write
your own, which would take a while, you could contact a
compiler vendor for the target platform and obtain a license
to include a compiler into your package and call it from a
script or something. Other than that, you could document the
need for a C++ compiler and test for it during installation of
your program.

The real question is why they would insist on C++ for step 2.
It seems highly unlikely that machine generated code from user
written XML would require all of the power of C++. Unless they
really needed the speed of an optimized compilation, I'd
probably just "invent" some sort of internal language that was
1) easy to generate from XML, 2) easy to parse, and 3) easy to
interpret effectively. (Said language might not even support
text as a source format.)
 
R

Raxit

we are designing some stuff , that will generate c++
program(s) What we want is we wanted to execute that
generated code....
i.e.
1. Xml based language
2. C++ code generated from 1.[Its mapping between 1 & 2]
3. compilation
4. execution.
What we have got stucked at compilation, we want that our
user should not take care about compilation or c++ code
generation etc...They just write some xml "code" and it
should execute !
[snip]
Well, what about using a compiler? If you don't want to write
your own, which would take a while, you could contact a
compiler vendor for the target platform and obtain a license
to include a compiler into your package and call it from a
script or something. Other than that, you could document the
need for a C++ compiler and test for it during installation of
your program.

The real question is why they would insist on C++ for step 2.
James, This is interesting point, we are at very early stage, and for
step 1 & 2, there is Boost library available (we know still it is not
very much straight forward job and it may require some dirty hacks, we
think it will be more easy.)
It seems highly unlikely that machine generated code from user
written XML would require all of the power of C++. Unless they
no, we may not require all the power of c++, you can say like XML is
like domain specific language that our developer want to execute, but C
++ code will be generated in middle, and finally bytecode/machinecode/
ELF32 etc...
really needed the speed of an optimized compilation, I'd
probably just "invent" some sort of internal language that was
1) easy to generate from XML, 2) easy to parse, and 3) easy to
interpret effectively. (Said language might not even support
text as a source format.)
We do think instead of generating new languages for optimized
compilation, its good idea not to re-invent wheel.(we may be wrong and
we are very early stage of poc, we may do something very much
diffenetly.)
--
James Kanze (GABI Software) email:[email protected]
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

-Raxit Sheth
 
K

kwikius

we are designing some stuff , that will generate c++
program(s) What we want is we wanted to execute that
generated code....
i.e.
1. Xml based language
2. C++ code generated from 1.[Its mapping between 1 & 2]
3. compilation
4. execution.
What we have got stucked at compilation, we want that our
user should not take care about compilation or c++ code
generation etc...They just write some xml "code" and it
should execute !

IMO I wouldnt worry about generating C++ code and use an intermediate
language :

JVM cross platform

http://en.wikipedia.org/wiki/Java_Virtual_Machine

For .Net (windows targets) use CLR :

http://en.wikipedia.org/wiki/Common_Language_Runtime

(See also LINQ which has AFAIK some nice XML facilities)
http://msdn.microsoft.com/en-gb/library/bb308960.aspx

Or LLVM cross platform

http://llvm.org/

regards
Andy Little
 
J

James Kanze

(e-mail address removed) wrote:
we are designing some stuff , that will generate c++
program(s) What we want is we wanted to execute that
generated code....
i.e.
1. Xml based language
2. C++ code generated from 1.[Its mapping between 1 & 2]
3. compilation
4. execution.
What we have got stucked at compilation, we want that our
user should not take care about compilation or c++ code
generation etc...They just write some xml "code" and it
should execute !
[snip]
Well, what about using a compiler? If you don't want to write
your own, which would take a while, you could contact a
compiler vendor for the target platform and obtain a license
to include a compiler into your package and call it from a
script or something. Other than that, you could document the
need for a C++ compiler and test for it during installation of
your program.
The real question is why they would insist on C++ for step 2.
James, This is interesting point, we are at very early stage,
and for step 1 & 2, there is Boost library available (we know
still it is not very much straight forward job and it may
require some dirty hacks, we think it will be more easy.)> It
seems highly unlikely that machine generated code from user
no, we may not require all the power of c++, you can say like
XML is like domain specific language that our developer want
to execute, but C ++ code will be generated in middle, and
finally bytecode/machinecode/ ELF32 etc...
We do think instead of generating new languages for optimized
compilation, its good idea not to re-invent wheel.(we may be
wrong and we are very early stage of poc, we may do something
very much diffenetly.)

If you need the optimization, generating C or C++, then using an
optimizing compiler, is certainly a good solution. If you don't
need that much optimization, however: my point is that it is
probably just as easy to generate a simple byte code as it is
C++, and to execute that immediately.
 
J

James Kanze

Or you could just generate javascript source code, as you can
get a javascript engine that is inexpensive (free, even) and
relatively small.

That's actually a very good suggestion. Javascript, perl,
python, and probably a couple of other languages have
interpreters which you can directly link into a C++ program.
Generating one of those languages is probably no more difficult
than generating C++, and you don't have to worry about the
interpreter. (Even Perl could be used here: readability isn't a
real consideration for machine generated code.)
 
S

shazled

we are designing some stuff , that will generate c++ program(s)
What we want is we wanted to execute that generated code....

i.e.
1. Xml based language
2. C++ code generated from 1.[Its mapping between 1 & 2]

For these first two steps something like Cog could be used:
http://nedbatchelder.com/code/cog/
(unfortunately the website is down at the moment). I have used this
with Cheetah:
http://www.cheetahtemplate.org/
to generate C++ code from XML descriptions. Cheetah could also be used
on its own to generate C++ from XML.

Saul
 
M

Matthias Buelow

What we have got stucked at compilation, we want that our user should
not take care about compilation or c++ code generation etc...They just
write some xml "code" and it should execute !

That thing has existed for over 50 years and is called "Lisp".
 
K

klmillr1

That's actually a very good suggestion. Javascript, perl,
python, and probably a couple of other languages have
interpreters which you can directly link into a C++ program.

Add Lua to that list. The Lua/C interface is modeled as a stack of
value-typed variables, and it's incredibly easy to integrate into C or
C++ projects.
 
J

James Kanze

That thing has existed for over 50 years and is called "Lisp".

Lisp can execute XML? (I'll bet it couldn't 50 years ago.)

Just about any interpreted language can, at least in principal,
take a string and execute it---I've even seen some Basic's which
can do it. Compiled languages, like C++, typically don't carry
the weight of a compiler around with them. About the only thing
special about Lisp (and its dialects, like Scheme) here is that
is remarkably easy to compile, so the extra weight is
considerably less (although the executable for scheme, on my
system, is still more than 3.5 MB). Historically, of course,
Lisp was the first interpreted language.
 
M

Matthias Buelow

James said:
Lisp can execute XML? (I'll bet it couldn't 50 years ago.)

:)

What I wanted to say is that the rôle that "executable XML" is supposed
to occupy is traditionally (and imho, much better) filled in by a Lisp
dialect of some sorts. They have a head-start of almost 50 years on XML
and Lisp S-expressions are (imho) more readable than XML.

The idea, of course, being that instead of somehow trying some awkward
construct to turn XML into C++ and feed that to an external compiler and
then load the generated object file (or somesuch), it might be more
productive to use S-expressions instead of XML, and embed a Lisp system
in the (C++) application.
 
J

James Kanze

What I wanted to say is that the rôle that "executable XML" is
supposed to occupy is traditionally (and imho, much better)
filled in by a Lisp dialect of some sorts. They have a
head-start of almost 50 years on XML and Lisp S-expressions
are (imho) more readable than XML.

Yes, but Lisp isn't "in", and XML is. So obviously, a new
project can't use Lisp, and must use XML.
The idea, of course, being that instead of somehow trying some
awkward construct to turn XML into C++ and feed that to an
external compiler and then load the generated object file (or
somesuch), it might be more productive to use S-expressions
instead of XML, and embed a Lisp system in the (C++)
application.

And XML probably maps easier into Lisp than into C++. (There is
a basic simimlarity of structure.) So you can still keep the
XML to show to the customer, and be in, and use a Lisp
interpreter to do the real work:). (Most of the time I've had
to generate code automatically, it's been mainly tables, and
nested structures do map fairly easily into C++, although if the
structures are dynamic, you end up needing a lot of pointers.)
 
M

Michael DOUBEZ

(e-mail address removed) a écrit :
Hi,


we are designing some stuff , that will generate c++ program(s)
What we want is we wanted to execute that generated code....

i.e.
1. Xml based language
2. C++ code generated from 1.[Its mapping between 1 & 2]
3. compilation
4. execution.

What we have got stucked at compilation, we want that our user should
not take care about compilation or c++ code generation etc...They just
write some xml "code" and it should execute !

[we are developing something like Event processor, reactor system etc]

Did you have a look at cpsh ? It is a c++ scripting language.
http://code.google.com/p/cpsh/

Still, I don't see the interest of generating c++ if all you want is to
interpret it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top