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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Raxit@MyKavita.com

    #1

    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





  • Kai-Uwe Bux

    #2
    Re: On-the-fly compilation and execution of C++ program

    Raxit@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

    Comment

    • gyakoo

      #3
      Re: On-the-fly compilation and execution of C++ program

      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.

      Comment

      • James Kanze

        #4
        Re: On-the-fly compilation and execution of C++ program

        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:james.kan ze@gmail.com
        Conseils en informatique orientée objet/
        Beratung in objektorientier ter Datenverarbeitu ng
        9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

        Comment

        • Raxit@MyKavita.com

          #5
          Re: On-the-fly compilation and execution of C++ program

          On Jun 1, 5:05 am, James Kanze <james.ka...@gm ail.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 objektorientier ter Datenverarbeitu ng
          9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
          -Raxit Sheth

          Comment

          • kwikius

            #6
            Re: On-the-fly compilation and execution of C++ program


            "Raxit@MyKavita .com" <raxitsheth2000 @gmail.comwrote in message
            news:20c12fdb-4cd8-44dc-a80d-357a21d69c10@p2 5g2000pri.googl egroups.com...
            On Jun 1, 5:05 am, James Kanze <james.ka...@gm ail.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



            For .Net (windows targets) use CLR :



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

            Or LLVM cross platform



            regards
            Andy Little





            Comment

            • James Kanze

              #7
              Re: On-the-fly compilation and execution of C++ program

              On Jun 1, 5:21 pm, "Ra...@MyKavita .com" <raxitsheth2... @gmail.com>
              wrote:
              On Jun 1, 5:05 am, James Kanze <james.ka...@gm ail.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:james.kan ze@gmail.com
              Conseils en informatique orientée objet/
              Beratung in objektorientier ter Datenverarbeitu ng
              9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

              Comment

              • Walter Bright

                #8
                Re: On-the-fly compilation and execution of C++ program

                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.



                Yes, I wrote it.

                -----------------
                Walter Bright
                Digital Mars
                http://www.digitalmars.com C, C++, D programming language compilers

                Comment

                • James Kanze

                  #9
                  Re: On-the-fly compilation and execution of C++ program

                  On Jun 2, 7:47 am, Walter Bright <wal...@digital mars-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.
                  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:james.kan ze@gmail.com
                  Conseils en informatique orientée objet/
                  Beratung in objektorientier ter Datenverarbeitu ng
                  9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

                  Comment

                  • shazled@gmail.com

                    #10
                    Re: On-the-fly compilation and execution of C++ program

                    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:

                    (unfortunately the website is down at the moment). I have used this
                    with Cheetah:

                    to generate C++ code from XML descriptions. Cheetah could also be used
                    on its own to generate C++ from XML.

                    Saul

                    Comment

                    • Matthias Buelow

                      #11
                      Re: On-the-fly compilation and execution of C++ program

                      Raxit@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".

                      Comment

                      • klmillr1@gmail.com

                        #12
                        Re: On-the-fly compilation and execution of C++ program

                        On Jun 2, 4:04 am, James Kanze <james.ka...@gm ail.comwrote:
                        On Jun 2, 7:47 am, Walter Bright <wal...@digital mars-nospamm.com>
                        wrote:
                        >>
                        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.

                        Comment

                        • James Kanze

                          #13
                          Re: On-the-fly compilation and execution of C++ program

                          On Jun 2, 4:28 pm, Matthias Buelow <m...@incubus.d ewrote:
                          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:james.kan ze@gmail.com
                          Conseils en informatique orientée objet/
                          Beratung in objektorientier ter Datenverarbeitu ng
                          9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

                          Comment

                          • Walter Bright

                            #14
                            Re: On-the-fly compilation and execution of C++ program

                            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.

                            Comment

                            • Matthias Buelow

                              #15
                              Re: On-the-fly compilation and execution of C++ program

                              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.

                              Comment

                              Working...