Is this what you want?

1
2
3
4
5
let CreateExpr (ci:ConstructorInfo) =
      let myVar = new Var("myVar", ci.ReflectedType)
      let construct = Expr.NewObject(ci, [ Expr.Value(1.0f) ])
      Expr.Let(myVar, Expr.Value(construct, ci.ReflectedType),
            Expr.PropGet(Expr.Var(myVar), ci.ReflectedType.GetProperties().[0]))
By on 2/16/2009 6:17 AM ()

Alright, i think i could live with that for now. But i'm still interested to grok the AddressOf operation and the purpose of the copyOfStruct@58 in my second code sample. Thanks!

By on 2/16/2009 2:20 PM ()

Yes exactly! albeit i'd like to have "construct" buildt with the default constructor instead. I'll try your code sample tonight and see if it works.
Thanks a lot.

Stringer

By on 2/16/2009 6:32 AM ()

Basically the expression i want to generate should be something like expr:

1
2
3
4
let Test2 () =
    let expr = <@@let x = new StructTest() in x.width@@>
    printf "%A" expr
do Test2 ()

Exectuting the code results in:

Let (x, Value (<null>),
Let (copyOfStruct@58, x,
PropGet (Some (AddressOf (copyOfStruct@58)), Single width, [])))

As I understand a defensive copy of the immutable value x is made with the introduction of this new Let expression. Plus, copyOfStruct@58 seems to be a mutable variable.

I've tried to mimic it using an intermediate Expr.Let and Expr.VarSet but again with no success (i get an

Microsoft.FSharp.Core.FailureException: unreachable):

1
2
3
4
5
Expr.Let(Var("myVar", ci.ReflectedType), Expr.Value(null, ci.ReflectedType),
    Expr.Let(Var("tmp", ci.ReflectedType, true), Expr.VarSet(Var("tmp", ci.ReflectedType, true), Expr.Var(Var("myVar", 

ci.ReflectedType))),
        Expr.AddressOf(Expr.Var(Var("tmp", ci.ReflectedType)))))

I read chapter 6.4.16.1 of the spec but it didn't help me that much.

Thanks.

Stringer

By on 2/16/2009 5:03 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper