Exemplo n.º 1
0
        IBoundExpr IUnboundExprVisitor<IBoundExpr>.Visit(RecordExpr expr)
        {
            //### bob: there's a bug here. this will convert the record into a
            // tuple where the fields are ordered by name, not by how the appear
            // in the source code. when the tuple is then compiled, the fields
            // will be evaluated in that order. this violates the left-to-right
            // evaluation a user would expect. for example:
            //
            //  Foo (->) Print "foo"
            //  Bar (->) Print "bar"
            //  Main (->)
            //      def a <- (y: Foo x: Bar)
            //  end
            //
            //  this will print "bar" then "foo".

            // bind the fields
            var fields = new Dictionary<string, IBoundExpr>();
            foreach (var field in expr.Fields)
            {
                fields.Add(field.Key, field.Value.Accept(this));
            }

            // determine the record type
            var fieldTypes = new Dictionary<string, IBoundDecl>();
            foreach (var field in fields)
            {
                fieldTypes.Add(field.Key, field.Value.Type);
            }

            var boundType = new BoundRecordType(fieldTypes);

            // discard the names and convert to just a struct
            // note that this assumes the fields will be correctly
            // iterated in sorted order
            return new BoundTupleExpr(fields.Values, boundType);
        }
 public virtual IUnboundExpr Transform(RecordExpr expr)
 {
     return(expr);
 }
Exemplo n.º 3
0
 IUnboundExpr IUnboundExprVisitor <IUnboundExpr> .Visit(RecordExpr expr)
 {
     throw new NotImplementedException();
 }