March 11, 2007
"Pragma" <ericanderton@yahoo.removeme.com> wrote in message news:essjou$cks$1@digitalmars.com...
> Craig Black wrote:
> > Since Walter is in the habit of adding super advanced features to D, I thought it possible that this one might eventually make it in.  As
always,
> > please let me know if I'm way off base.
> >
> > What if we could invoke the compiler from an application at run time and generate a function that would be instantiated on the heap?  The
function
> > would be defined by a text string and would be invoked via a function pointer or delegate.  This would allow a script-like capability with fully-optimized performance provided by the D compiler.  I think the D compiler would be ideal for this since it is so fast.  Since the method would be allocated on the heap dynamically, it could also be removed
when it
> > is done being used.
> >
> > Thoughts?
>
> Plenty.  I've tried my best to approach this kind of functionality for
some time in library space.  However I have my
> doubts as to having this included in D proper - since D is so minimal at
it's core, it becomes very much a library
> support problem.
>
> (I'll leave the DSP/DDL/Flectioned discussion for another thread).
>
> I can say from experience that doing this from within library space is
perfectly feasable, and yields some great
> results, at the cost of additional memory at runtime and a small (one-time
per module) delay for compilation and runtime
> binding.  I would have sooner considered drafting a runtime compiler if
DMD wasn't so fast.
>
> --
> - EricAnderton at yahoo

The run time library approach is feasible as you say, but not a efficient or elegant as using the heap.  However, this may be possible without modifications to the D compiler.  It would require compiling some code, then getting the result from a file, and loading it onto the heap.  Not a trivial task as there would be many details to work through.  But I am inclined to believe that it could be done.  On the other hand, if Walter wanted to help, we could probably get the compiler to emit the code directly to the heap, which would be even better.

A run time compiler would have many applications to be sure.  One is gaming, where a good chunk of the code is usually script.  Some game engines use .NET or Java instead of a scripting language for better performance.  A run time compiler would be even better.  Further, D is an ideal candidate for such a feature because of D's compilation speed and garbage collection.

-Craig


March 17, 2007
Russell Lewis wrote:
> Ok, ignore the bootstrap issues for a second, and consider: If the compiler were primarily implemented as a set of functions in the standard library, then we could view "static compilation" as CTFE of those functions...while "dynamic compilation" (a.k.a. runtime compiler) as ordinary, runtime execution.
> 
> Russ
> 


Even the .NET framework has something similar, though I don't know if you may call the compilers with a string containting the code you wish to execude.

For more details, search for CodeDOM at msdn
1 2
Next ›   Last »