What to generate when using a base type that isn't an int

Oct 21, 2009 at 12:14 AM

We have an inhouse language that uses what we call grids to store integer values.
The idea is that math operations on grids act similarly to Lisp's map operator.

ie
var a = grid(1,2,3);
var b = grid(3)*a;
// b == (3,6,9)

Given this basic piece of DLR code:
    Ast.Action.Operator(
        Operators.Add,
        typeof(object),
        Ast.Constant(1),
        Ast.Constant(1)
    )
    
How would I write this so that the constant's use our integer grid type.

ie we want something like

    Ast.Action.Operator(
        Operators.Add,
        typeof(object),
        Ast.Constant(gird(1)),
        Ast.Constant(grid(1))
    )
    
Or would I just not use the Constant type at all and use the ActionBinder MakeRule<T> method to look for the cases where we have 2 grids of integers and apply to appropriate rule?

Coordinator
Dec 4, 2009 at 3:47 AM

Sorry for the delayed response.  It sounds like you’re using a pretty old version of the DLR.  ActionBinder.MakeRule<T> is gone and I believe so is Act.Action.Operator.  If everything is going to be dynamic I think you want something like:

var a = Experssion.Parameter(“a”, typeof(object));

var b = Experssion.Parameter(“b”, typeof(object));

Experssion.Block(

                new[] { a, b },

                Experssion.Assign(

                    a,

                    Experssion.New(typeof(Grid).GetConstructor(…), Experssion.Constant(1), Experssion.Constant(2), Experssion.Constant(3)

               ),

               Experssion.Assign(

                    b,

                    Experssion.Dynamic(

                           MyBinaryOperationBinder.Multiply,                            // this is a BinaryOperationBinder subclass – it should be cached and shared between all dynamic operations

                           Experssion.New(typeof(Grid).GetConstructor(…), Experssion.Constant(3)),

                           B

                    )

                )

)

If you’re doing type inference and this is all statically typed I think this becomes:

var a = Experssion.Parameter(“a”, typeof(grid));

var b = Experssion.Parameter(“b”, typeof(grid));

Experssion.Block(

                new[] { a, b },

                Experssion.Assign(

                    a,

                    Experssion.New(typeof(Grid).GetConstructor(…), Experssion.Constant(1), Experssion.Constant(2), Experssion.Constant(3)

               ),

               Experssion.Assign(

                    b,

                    Experssion.Multiply(

                           Experssion.New(typeof(Grid).GetConstructor(…), Experssion.Constant(3)),

                           B

                    )

                )

)

Hope that helps!

From: chollida1 [mailto:notifications@codeplex.com]
Sent: Tuesday, October 20, 2009 4:14 PM
To: Dino Viehland
Subject: What to generate when using a base type that isn't an int [dlr:72599]

From: chollida1

We have an inhouse language that uses what we call grids to store integer values.
The idea is that math operations on grids act similarly to Lisp's map operator.

ie
var a = grid(1,2,3);
var b = grid(3)*a;
// b == (3,6,9)

Given this basic piece of DLR code:
Ast.Action.Operator(
Operators.Add,
typeof(object),
Ast.Constant(1),
Ast.Constant(1)
)

How would I write this so that the constant's use our integer grid type.

ie we want something like

Ast.Action.Operator(
Operators.Add,
typeof(object),
Ast.Constant(gird(1)),
Ast.Constant(grid(1))
)

Or would I just not use the Constant type at all and use the ActionBinder MakeRule<T> method to look for the cases where we have 2 grids of integers and apply to appropriate rule?

Read the full discussion online.

To add a post to this discussion, reply to this email (dlr@discussions.codeplex.com)

To start a new discussion for this project, email dlr@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com