Compiler as dll

Daniel Keep daniel.keep.lists at gmail.com
Thu Jan 29 02:00:03 PST 2009



grauzone wrote:
> Daniel Keep wrote:
>> Personally, I think the best approach is to combine the two; write the
>> hot spots in C, D or some other fast language, and all the glue in a
>> dynamic language.  For all it's expressiveness, there are just some
>> things that are easier to do with a dynamic language like Python or Lua
>> than with D.
> 
> I agree, but it's hard to link all these languages together. They use
> different types, require bindings to import functions and classes, and
> all that. I heard writing Python modules in C is really hard.

Not in my experience.  Pyrex makes it embarrassingly easy.  I had a GUI
app written in Python; at one point, I decided to improve performance
and so I did a bit of profiling.  The big hot spot was in the rendering
code, so I re-wrote that part in C and used Pyrex to make the bridge.

Compiled to a native Python extension module, and replaced the old pure
Python version with it.  Restart app and boom, it runs faster without
having to touch a line of code anywhere else.

Also, don't forget that Python has ctypes, which lets it dynamically
bind to C libraries without having to actually write a wrapper.

Now, going the OTHER way is a nightmare. [1]

> Most debuggers seem to support a subset of C for evaluating expressions
> or even calling methods. For example, in gdb, you can write the command
> "print x->y->z".
> 
> I don't think there's any substantial difference between dynamic and
> static languages here. It's all a question of effort, and static
> languages are just a bit behind. For example, if you had a compiler as
> library (wow, that's actually the subject of this thread), it wouldn't
> be so hard anymore to implement a read-eval-print-loop for a static
> language. Actually, Scala is a statically typed language, that provides
> such an interactive interpreter.

Perhaps, but I'm yet to see any statically typed language that let me
replace objects or even whole functions while the program's running.

I'm not saying it can't be done, just that it's a lot harder for a
statically typed and compiled language than one with dynamic lookup.

  -- Daniel


[1] Actually, back when I was still playing around with Python bindings
for D, one thing I started hacking on was a module for runtime codegen.
 The idea was to fire up the Python interpreter, poke around inside a
Python module to find out what it might look like as a native function,
then generate a stub that went from native code to Python code and back
again.

... and then make it a DDL module so that you could treat Python
libraries as if they were native code.



More information about the Digitalmars-d mailing list