On 28/12/2011, at 9:09 PM, john skaller wrote: > Latest commit implements operator *. as shown: > > px *. a > > is just a short hand for > > (*px).a
The following now works: ////////////////////// // test if pointer to struct + field name works struct X { a: int; }; var x: X = X(1); println$ "x.a = " + x.a.str; var px = &x; println$ "px*.a = " + px*.a.str; println$ "(*px).a = " + (*px).a.str; println$ "*(px.a) = " + (*(px.a)).str; println$ "*(px.a) = " + px.a*.str; x.a = 2; println$ "px*.a = " + px*.a.str; println$ "(*px).a = " + (*px).a.str; println$ "*(px.a) = " + (*(px.a)).str; println$ "*(px.a) = " + px.a*.str; px . a <- 3; println$ "px*.a = " + px*.a.str; println$ "(*px).a = " + (*px).a.str; println$ "*(px.a) = " + (*(px.a)).str; println$ "*(px.a) = " + px.a*.str; struct Y { b: X; }; var y = Y(X(1)); println$ "y.b.a = " + y.b.a.str; y.b.a = 5; println$ "y.b.a = " + y.b.a.str; ///////////// Now, the important thing here is the fact that y.b.a = 5 works. The aim is to keep that working as restrictions on address-of operator & are re-introduced. The basic idea here is that there are only two uses of addressing: 1. You can address a whole variable (var). 2. You can address the result of a C function returning an lvalue Felix functions can't return lvalues, they return pointers instead. This isn't tenable for C functions because the compiler cannot optimise sequences like *(&x) if the (&x) part is hidden inside a C function. Support for lvalue returning C functions is problematic (not sure if it even works anymore :) Currently Felix compiler contains a hack to work around previous problems. The standard addression combinator is EXPR_deref (v) where v is a variable name. This can't be used on expressions like x.a, it only works on a whole variable, and that's the way it should be. To make x.a = 1 work, since that actually means &(x.a) <- 1 I introduced a general EXPR_address (e) term and gave up on checking if the expression was actually addressable. The C++ compiler will reject some cases where 'e' isn't an lvalue, however it will let pass addressing of lvalue expressions which are not allowed in Felix, eg addressing a val. The idea is to revert, and get rid of general address taking. This means that x.a = 1 has to be handled differently: either we sugar that as (&x).a <- 1 in the parser, or we translate &(x.a) <- 1 into that form during, say, desugaring. Care must be taken with the "other" meaning of operator dot, namely reverse application (not to mention the other one, composition of functions :) Anyhow, we're getting there. Consideration of how to handle C style array iterators and arrays is required too. We need to make using arrays safer, whilst still allowing interfacing to C. IN GENERAL: having written some tools and library code in Felix now, I am even more inclined to throw out unsafe practices and favour enforced checking of stuff like null pointer deref and array bounds. Even in C it is hard to avoid null pointer and array bounds violations, in Felix it is easier to avoid them but much harder to debug those cases where we didn't manage it. Throwing away some performance for safety seems warranted especially if, in extreme desperation the client can work around it, or, as for say array library, there are safe and unsafe variants. Ideally the checks would be removed using proofs they're not needed, but in general this is beyond the scope of the current Felix developer team (namely me :) -- john skaller skal...@users.sourceforge.net ------------------------------------------------------------------------------ Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex infrastructure or vast IT resources to deliver seamless, secure access to virtual desktops. With this all-in-one solution, easily deploy virtual desktops for less than the cost of PCs and save 60% on VDI infrastructure costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language