Extended Type Design.

janderson askme at me.com
Sat Mar 17 12:14:29 PDT 2007


Walter Bright wrote:
> eao197 wrote:
>> On Sat, 17 Mar 2007 01:41:54 +0300, Walter Bright 
>> <newshound at digitalmars.com> wrote:
>>
>>> eao197 wrote:
>>>> No, at first there must be 'D with macros' (like 'C with classes') 
>>>> and only then -- D++ :))
>>>
>>> D will get macros - but they won't be text processing macros, they'll 
>>> be abstract syntax tree (AST) processing macros.
>>
>> It is very interesting to hear that. Could you say more about the 
>> future macro system in D? Or it is a secret now?
> 
> It's pretty simple:
> 
>     macro foo(args)
>     {
>         ...syntax that gets inserted...
>     }
> 
> and the args and syntax is evaluated in the context of the invocation of 
> the macro, not the definition of the macro. You'll be able to do things 
> like:
> 
>     macro print(arg)
>     {
>         writefln(__FILE__, __LINE__, arg);
>     }
> 
> which get the file and line in the right context. There's no way to do 
> that right now.

On naming why not use mixin, since they are so similar?

mixin print(arg)
{

}

Then make them typesafe (using alias to get out of type-safty)?


What if you want the file in some other context?  It would be nice to 
have a complete solution to that, which allows some sort of stack 
traversal.  Although I'm not sure its possible, due to not wanting to 
keep this sort of information around at release time.

ie:

      macro print(arg)
      {
          writefln(__FILE__[stack_level], __LINE__[stack_level], arg);
      }

Or even better:

Stack[0].Line; //Current line
Stack[1].Line; //Line one level up
Stack[0].File;
Stack[0].Module;
Stack[0].Function;
Stack[0].NumbArgs; //Some form of reflection
Stack[0].Arg[N];   //Access to the value of the argument (ie Turple of 
values)
Stack[0].ArgIdentifier[N] //String name of the identifier
Stack[0].FuncType	 //The type of function we are in (is it a macro, a 
compile time function a member, a regular function)
ect...

      macro print(arg)
      {
	with(Stack[0])
	{
         	writefln(File, Line, arg);
	}
      }

I guess that would have problems for larger depths.  Perhaps it could be 
limited to two levels (current and parent) or only work for ones that 
can be evaluated at compile time (you would get a compile time error if 
the line number couldn't be evaluated.)  There could be a debug version 
that would work at run time.

-Joel



More information about the Digitalmars-d mailing list