AST Macros: Just what will they be able to do?

BCS ao at pathlink.com
Thu Aug 16 11:24:33 PDT 2007


Reply to Robert,

> lets' say the
> coder has two checkboxes -- cb1 and cb2. They are D objects when the
> website is being created by the servlet, that render as <input
> type="checkbox"> or whatever. Now say the coder writes this:
> 
> cb1.onChange = {
> if(cb1.enabled)
> cb2.enabled = true;
> else
> cb2.enabled = false;
> }
> cb2.onChange = {
> if(cb2.enabled)
> doSomethingOnTheServer();
> }
> Using AST macros, would there be any way for the program to figure out
> at compile-time cb1s callback could be done entirely on the client
> side via JavaScript or something while cb2's would require some AJAX
> calls in some cases (which would then be generated automatically)? In
> particular, it would need to know that everything within the callback
> for cb1 refers to variables/state within a particular set those which
> are available on the client).

I once wrote a code generate that attempts to build a network interface proxy 
class (given a D interface, generate client/server code to allow a client 
to exercise an object on one computer from another computer) It' was a nasty 
pile before I more or less gave up on it. However with __traits, it might 
be buildable at compile time. To boot, you might also be able to build something 
analogous that would wright the AJAX code to let the client side run from 
JavaScript.

I'm thinking you would use it like this

interface I {/*stuff*}
class C : I {/*more stuff*/}

class MyPage : WebPage
{
	this()
	{
		
		InsertCode(AJAX!(I).ClientAJAX());	// put in needed javascript
		InsertCode(CustomCodeUsingAJAX);	// put in your  javascript
		//...
	}

	void BuildState() // called for each new page
	{
		auto o = AJAX!(I).Registered(new C());
		InsertCode(o.Binding); // insert code to get right object on server side
	}
}

Assuming lots of functionality in the WebPage class, the AJAX template would 
generate:
	client side AJAX (JavaScript) to call back to the server
	server side (D) to handle it
	code to keep track of object all around

It's a pipe dream for now, but not outside the range of the possible.





More information about the Digitalmars-d mailing list