469,604 Members | 2,381 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,604 developers. It's quick & easy.

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

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

Jun 27 '08 #1
16 3825
Ra***@MyKavita.com wrote:
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
Jun 27 '08 #2
On 31 mayo, 22:51, Kai-Uwe Bux <jkherci...@gmx.netwrote:
Ra...@MyKavita.com wrote:
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
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.
Jun 27 '08 #3
On May 31, 10:51 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
Ra...@MyKavita.com 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.
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.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
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
Jun 27 '08 #4
On Jun 1, 5:05 am, James Kanze <james.ka...@gmail.comwrote:
On May 31, 10:51 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
Ra...@MyKavita.com 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
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:james.ka...@gmail.com
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
Jun 27 '08 #5

"Ra***@MyKavita.com" <ra************@gmail.comwrote in message
news:20**********************************@p25g2000 pri.googlegroups.com...
On Jun 1, 5:05 am, James Kanze <james.ka...@gmail.comwrote:
On May 31, 10:51 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
Ra...@MyKavita.com 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 !
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

Jun 27 '08 #6
On Jun 1, 5:21 pm, "Ra...@MyKavita.com" <raxitsheth2...@gmail.com>
wrote:
On Jun 1, 5:05 am, James Kanze <james.ka...@gmail.comwrote:
On May 31, 10:51 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
Ra...@MyKavita.com 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
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.)
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.

--
James Kanze (GABI Software) email:ja*********@gmail.com
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
Jun 27 '08 #7
James Kanze wrote:
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.
Or you could just generate javascript source code, as you can get a
javascript engine that is inexpensive (free, even) and relatively small.

http://www.digitalmars.com/dscript/index.html

Yes, I wrote it.

-----------------
Walter Bright
Digital Mars
http://www.digitalmars.com C, C++, D programming language compilers
Jun 27 '08 #8
On Jun 2, 7:47 am, Walter Bright <wal...@digitalmars-nospamm.com>
wrote:
James Kanze wrote:
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.
Or you could just generate javascript source code, as you can
get a javascript engine that is inexpensive (free, even) and
relatively small.
http://www.digitalmars.com/dscript/index.html
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.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
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
Jun 27 '08 #9
On May 31, 9:34*pm, "Ra...@MyKavita.com" <raxitsheth2...@gmail.com>
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]
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
Jun 27 '08 #10
Ra***@MyKavita.com wrote:
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".
Jun 27 '08 #11
On Jun 2, 4:04 am, James Kanze <james.ka...@gmail.comwrote:
On Jun 2, 7:47 am, Walter Bright <wal...@digitalmars-nospamm.com>
wrote:
http://www.digitalmars.com/dscript/index.html

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.
Jun 27 '08 #12
On Jun 2, 4:28 pm, Matthias Buelow <m...@incubus.dewrote:
Ra...@MyKavita.com wrote:
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".
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.

--
James Kanze (GABI Software) email:ja*********@gmail.com
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
Jun 27 '08 #13
James Kanze wrote:
Lisp can execute XML? (I'll bet it couldn't 50 years ago.)
No, but it's been pointed out that the only fundamental difference
between Lisp and XML is that Lisp can be executed.
Jun 27 '08 #14
James Kanze wrote:
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.
Jun 27 '08 #15
Walter Bright wrote:
No, but it's been pointed out that the only fundamental difference
between Lisp and XML is that Lisp can be executed.
Or as John McCarthy says: "XML is isomorphic to the subset of Lisp data
where the first item in a list is required to be atomic."

(http://www-formal.stanford.edu/jmc/cbcl2/node4.html)
Jun 27 '08 #16
On Jun 3, 1:38 pm, Matthias Buelow <m...@incubus.dewrote:
James Kanze wrote:
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.
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.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
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
Jun 27 '08 #17

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Chris Krasnichuk | last post: by
20 posts views Thread by Chris Krasnichuk | last post: by
2 posts views Thread by Patricia | last post: by
reply views Thread by guiromero | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.