another idea for compile time functions

Yauheni Akhotnikau eao197 at intervale.ru
Fri Feb 9 01:55:22 PST 2007


On Fri, 09 Feb 2007 12:00:01 +0300, Andrei Alexandrescu (See Website For  
Email) <SeeWebsiteForEmail at erdani.org> wrote:

> In a previous post I described the white hole and black hole classes.  
> Starting from an interface, build two degenerate implementations of it.  
> This is not possible with the naive approach of spawning execution of  
> separate programs.

Thanks.
Yes, it is not possible. But for this task it is necessary to run DSL code  
inside compiler. I don't like idea of interpretating D code with some  
limitation. But there can be (at least :) ) two alternatives:

1. Compile temporary D program as DLL and upload it into compiler. And  
provide some API to access to currently available compiler information  
(symbols, types, modules and so on). So, SomeDSLProcessor can use this API:

import std.compiler.internals;

char[] SomeDSLProcessor( char[] dsl )
{
   // parsing of dsl...
   // accessing compiler information via singleton object...
   auto symbol_info = DCompiler.getIntance().getSymbolInfo( ... );
   ...
}

2. Compiler plug-in system. Plug-in implement some special interface  
(interfaces):

// SomeDSLProcessor.d
import std.compiler.plugins;

class SomeDSLProcessor : ICompilerPlugIn
{
   // This method will be called for processing content of mixin expression.
   char[] invoke( ICompilerInformation compilerInfo, char[] dsl ) { ... }
   ...
}

// Some file which use SomeDSLProcessor plugin.
import plugin SomeDSLProcessor;

mixin( SomeDSLProcessor( `some DSL code` ) );


When compiler sees 'import plugin' clause it finds and uploads plugin DLL.  
When compiler sees name of plugin in mixin expression it instantiates  
object of class SomeDSLProcessor and calls its method invoke.

-- 
Regards,
Yauheni Akhotnikau



More information about the Digitalmars-d mailing list