haXe code meta-parsing

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

haXe code meta-parsing

Cauê W.
Hi all!

I've been working on a haXe-based object-oriented database management system, and I really need some ideas on an intelligent way of dealing with queries. The most intelligent way of handling them is what db4o calls "native queries". You really design a delegate function that never gets called, but is analyzed at runtime (it analyzes java / .net bytecodes!) and what they call a "SODA" query is created based on the function created. This SODA query is really a tree with constraints that is optimized to achieve good performance with querying on the database's file structure.


Well, the true benefit of this approach is that you can achieve compile-time check on your queries! So for example, instead of writing

query = Contraint( Employee, Constraint("sallary", Greater(500) ) );

you could write

query = function (emp : Employee):Bool
{
return emp.sallary > 500;
}

and it will translate into the above query.
I know this doesn't seem very easy to do, but maybe I am missing something, given the hidden wonders of our compiler! Is there any "not too hacky" way to achieve this kind of type-safety? The only way I can think of is really if there was any way to flag this anonymous function to carry along its haXe source code, or something like that. -- Like what haXe does when you're compiling to a flash debugger - but only with this specific function.

Would there be any good way to achieve this? By all means, what I really need is some way of sending out a emp.sallary as a FIELD (or reference), not as its value, so there is a way to recognize that emp.sallary is actually a field from the Employee class, and the field's name is "sallary". Can anyone point me out to the right direction?


Kind thanks!

Cauê W.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: haXe code meta-parsing

Cameron D
I'm new to haXe (started a couple days ago :-) but it sounds like the haxe.rtti.Infos package might provide what you need. My understanding is that any class (and subclass) that extends this class gets extra information about its fields, types, and a whole bunch of other stuff, stored as XML. The structure of this XML is a bit tricky to figure out, though.

Good luck,
Cameron

On Mon, Nov 9, 2009 at 6:42 PM, Cauê Waneck <[hidden email]> wrote:
Hi all!

I've been working on a haXe-based object-oriented database management system, and I really need some ideas on an intelligent way of dealing with queries. The most intelligent way of handling them is what db4o calls "native queries". You really design a delegate function that never gets called, but is analyzed at runtime (it analyzes java / .net bytecodes!) and what they call a "SODA" query is created based on the function created. This SODA query is really a tree with constraints that is optimized to achieve good performance with querying on the database's file structure.


Well, the true benefit of this approach is that you can achieve compile-time check on your queries! So for example, instead of writing

query = Contraint( Employee, Constraint("sallary", Greater(500) ) );

you could write

query = function (emp : Employee):Bool
{
return emp.sallary > 500;
}

and it will translate into the above query.
I know this doesn't seem very easy to do, but maybe I am missing something, given the hidden wonders of our compiler! Is there any "not too hacky" way to achieve this kind of type-safety? The only way I can think of is really if there was any way to flag this anonymous function to carry along its haXe source code, or something like that. -- Like what haXe does when you're compiling to a flash debugger - but only with this specific function.

Would there be any good way to achieve this? By all means, what I really need is some way of sending out a emp.sallary as a FIELD (or reference), not as its value, so there is a way to recognize that emp.sallary is actually a field from the Employee class, and the field's name is "sallary". Can anyone point me out to the right direction?


Kind thanks!

Cauê W.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: haXe code meta-parsing

Cauê W.
Hey, Cameron! Thanks for answering!

I've already got plans to use rtti.Infos to extract the class "schema"s whenever possible. It is really this kind of info that I would need, but I don't think it has a compiler switch that would display the haXe source code actually. It does have a switch to include comments, but this could do more harm than good in this case, I think.

I really don't think it is possible right now. Unfortunately. I needed to have some compile-time feature that would receive a Field not as its value, but as indeed a supposedly Field<T> type, just like we have with classes. So for example, I needed to be able to have a function with this kind of behaviour:

public static function querify<T>(field:Field<T>):{clazz:Class<T>, fieldName:String, fieldType:CType}
{
return {clazz: Type.getClassByField(field), fieldName: Type.getFieldName(field), fieldType: Type.getFieldType(field)}
}

So there could be compile-time type checking for the queries. At least some type checking!

Thanks!

2009/11/9 Cameron D <[hidden email]>
I'm new to haXe (started a couple days ago :-) but it sounds like the haxe.rtti.Infos package might provide what you need. My understanding is that any class (and subclass) that extends this class gets extra information about its fields, types, and a whole bunch of other stuff, stored as XML. The structure of this XML is a bit tricky to figure out, though.

Good luck,
Cameron

On Mon, Nov 9, 2009 at 6:42 PM, Cauê Waneck <[hidden email]> wrote:
Hi all!

I've been working on a haXe-based object-oriented database management system, and I really need some ideas on an intelligent way of dealing with queries. The most intelligent way of handling them is what db4o calls "native queries". You really design a delegate function that never gets called, but is analyzed at runtime (it analyzes java / .net bytecodes!) and what they call a "SODA" query is created based on the function created. This SODA query is really a tree with constraints that is optimized to achieve good performance with querying on the database's file structure.


Well, the true benefit of this approach is that you can achieve compile-time check on your queries! So for example, instead of writing

query = Contraint( Employee, Constraint("sallary", Greater(500) ) );

you could write

query = function (emp : Employee):Bool
{
return emp.sallary > 500;
}

and it will translate into the above query.
I know this doesn't seem very easy to do, but maybe I am missing something, given the hidden wonders of our compiler! Is there any "not too hacky" way to achieve this kind of type-safety? The only way I can think of is really if there was any way to flag this anonymous function to carry along its haXe source code, or something like that. -- Like what haXe does when you're compiling to a flash debugger - but only with this specific function.

Would there be any good way to achieve this? By all means, what I really need is some way of sending out a emp.sallary as a FIELD (or reference), not as its value, so there is a way to recognize that emp.sallary is actually a field from the Employee class, and the field's name is "sallary". Can anyone point me out to the right direction?


Kind thanks!

Cauê W.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: haXe code meta-parsing

Gustavs
In reply to this post by Cauê W.
A hack to get an expression's AST as a value perhaps. Such a feature would have interesting applications indeed, like allowing a soft implementation of yields while still having the full language.

For this though I don't think using enum expressions would be too bad, with a proper structure.


2009/11/10 Cauê Waneck <[hidden email]>
Hi all!

I've been working on a haXe-based object-oriented database management system, and I really need some ideas on an intelligent way of dealing with queries. The most intelligent way of handling them is what db4o calls "native queries". You really design a delegate function that never gets called, but is analyzed at runtime (it analyzes java / .net bytecodes!) and what they call a "SODA" query is created based on the function created. This SODA query is really a tree with constraints that is optimized to achieve good performance with querying on the database's file structure.


Well, the true benefit of this approach is that you can achieve compile-time check on your queries! So for example, instead of writing

query = Contraint( Employee, Constraint("sallary", Greater(500) ) );

you could write

query = function (emp : Employee):Bool
{
return emp.sallary > 500;
}

and it will translate into the above query.
I know this doesn't seem very easy to do, but maybe I am missing something, given the hidden wonders of our compiler! Is there any "not too hacky" way to achieve this kind of type-safety? The only way I can think of is really if there was any way to flag this anonymous function to carry along its haXe source code, or something like that. -- Like what haXe does when you're compiling to a flash debugger - but only with this specific function.

Would there be any good way to achieve this? By all means, what I really need is some way of sending out a emp.sallary as a FIELD (or reference), not as its value, so there is a way to recognize that emp.sallary is actually a field from the Employee class, and the field's name is "sallary". Can anyone point me out to the right direction?


Kind thanks!

Cauê W.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: haXe code meta-parsing

Nicolas Cannasse
Gustavs a écrit :
> A hack to get an expression's AST as a value perhaps. Such a feature
> would have interesting applications indeed, like allowing a soft
> implementation of yields while still having the full language.
>
> For this though I don't think using enum expressions would be too bad,
> with a proper structure.

Hi,

Yes, this is an interesting subject.

To Cauê : currently, there is no way to do what you want directly in
haXe, since as Gustavs suggests, this would need to add the ability to
express AST values.

Lisp has this feature. For example if you write `(+ a b) this is a value
for the expression "a + b". It's very easy in Lisp because the AST is as
much simple as an AST can be and because also Lisp is dynamically typed.

I wonder how it would be possible to encode a typed AST using enums, and
then which applications would be possible for it.

Or maybe we should just drop the types, and then we would have something
like hscript ? But then the only win of expressing the AST in haXe is
that you get the syntax checked at compile-time, whereas for hscript the
syntax is checked at runtime.

Cauê, you might want to use directly hscript right know, until maybe we
have something directly integrated in haXe for expressions-values.

Best,
Nicolas


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: haXe code meta-parsing

John A. De Goes

See Haskell's "Template Haskell" or Fantom's "compiler plug-ins". Or even C#'s LINQ.

Regards,

John

On Nov 22, 2009, at 7:08 AM, Nicolas Cannasse wrote:

> Gustavs a écrit :
>> A hack to get an expression's AST as a value perhaps. Such a feature would have interesting applications indeed, like allowing a soft implementation of yields while still having the full language.
>> For this though I don't think using enum expressions would be too bad, with a proper structure.
>
> Hi,
>
> Yes, this is an interesting subject.
>
> To Cauê : currently, there is no way to do what you want directly in haXe, since as Gustavs suggests, this would need to add the ability to express AST values.
>
> Lisp has this feature. For example if you write `(+ a b) this is a value for the expression "a + b". It's very easy in Lisp because the AST is as much simple as an AST can be and because also Lisp is dynamically typed.
>
> I wonder how it would be possible to encode a typed AST using enums, and then which applications would be possible for it.
>
> Or maybe we should just drop the types, and then we would have something like hscript ? But then the only win of expressing the AST in haXe is that you get the syntax checked at compile-time, whereas for hscript the syntax is checked at runtime.
>
> Cauê, you might want to use directly hscript right know, until maybe we have something directly integrated in haXe for expressions-values.
>
> Best,
> Nicolas
>
>
> --
> haXe - an open source web programming language
> http://haxe.org


--
haXe - an open source web programming language
http://haxe.org