Esempio n. 1
0
 public static IExpression Tuple(params IExpression[] arguments)
 {
     if (arguments.Length == 0)
     {
         throw new System.Exception();
     }
     else if (arguments.Length == 1)
     {
         return(arguments.Single());
     }
     else
     {
         return(FunctionCall.Create(NameReference.Create(NameFactory.TupleFactoryReference(), NameFactory.CreateFunctionName), arguments));
     }
 }
Esempio n. 2
0
 public static TypeBuilder WithComparableCompare(this TypeBuilder builder, EntityModifier modifier = null)
 {
     return(builder.With(FunctionBuilder.Create(NameFactory.ComparableCompare,
                                                ExpressionReadMode.ReadRequired, NameFactory.OrderingNameReference(),
                                                Block.CreateStatement(
                                                    IfBranch.CreateIf(IsSame.Create(NameReference.CreateThised(), NameReference.Create("cmp")),
                                                                      new[] { Return.Create(NameFactory.OrderingEqualReference()) }),
                                                    // let obj = cmp cast? Self
                                                    VariableDeclaration.CreateStatement("obj", null, ExpressionFactory.CheckedSelfCast("cmp",
                                                                                                                                       NameFactory.ReferenceNameReference(builder.CreateTypeNameReference(TypeMutability.ReadOnly)))),
                                                    // return this.compare(obj.value)
                                                    Return.Create(FunctionCall.Create(NameReference.CreateThised(NameFactory.ComparableCompare),
                                                                                      NameReference.Create("obj")))))
                         .SetModifier(EntityModifier.Override | modifier)
                         .Parameters(FunctionParameter.Create("cmp",
                                                              NameFactory.ReferenceNameReference(NameFactory.IComparableNameReference(TypeMutability.ReadOnly))))));
 }
Esempio n. 3
0
File: New.cs Progetto: macias/Skila
        private New(string tempName, NameReference allocTypeName,
                    Memory allocMemory,
                    TypeMutability allocMutability,
                    FunctionCall init,
                    IEnumerable <IExpression> objectInitialization, NameReference outcome)
            : base(ExpressionReadMode.ReadRequired)
        {
            this.allocTypeName   = allocTypeName;
            this.allocMemory     = allocMemory;
            this.allocMutability = allocMutability;

            this.tempDeclaration      = VariableDeclaration.CreateStatement(tempName, null, createAlloc());
            this.InitConstructorCall  = init;
            this.objectInitialization = objectInitialization.StoreReadOnly();
            this.outcome = outcome;

            this.attachPostConstructor();
        }
Esempio n. 4
0
        public static IExpression CheckedSelfCast(string paramName, INameReference currentTypeName)
        {
            return(Block.CreateExpression(
                       // this is basically check for Self type
                       // assert this.getType()==other.GetType()
                       // please note
                       // assert other is CurrentType
                       // has different (and incorrect) meaning, because it does not really check both entities type
                       // consider this to be IFooChild of IFoo->IFooParent->IFooChild
                       // and current type would be IFooParent and the other would be of this type
                       AssertTrue(IsSame.Create(FunctionCall.Create(NameReference.CreateThised(NameFactory.GetTypeFunctionName)),
                                                FunctionCall.Create(NameReference.Create(paramName, NameFactory.GetTypeFunctionName)))),

                       // maybe in future it would be possible to dynamically cast to the actual type of other
                       // this would mean static dispatch to later calls
                       ExpressionFactory.GetOptionValue(ExpressionFactory.DownCast(NameReference.Create(paramName), currentTypeName))
                       ));
        }
Esempio n. 5
0
        internal void RouteSetup(int?minLimit, int?max1Limit)
        {
            if (this.prepared)
            {
                throw new Exception("Something wrong?");
            }

            this.prepared = true;

            this.expr.DetachFrom(this);
            if (max1Limit.HasValue)
            {
                this.expr = FunctionCall.Create(NameFactory.SpreadFunctionReference(), FunctionArgument.Create(this.expr),
                                                FunctionArgument.Create(NatLiteral.Create($"{minLimit}")),
                                                FunctionArgument.Create(NatLiteral.Create($"{max1Limit}")));
            }
            else
            {
                this.expr = FunctionCall.Create(NameFactory.SpreadFunctionReference(), FunctionArgument.Create(this.expr),
                                                FunctionArgument.Create(NatLiteral.Create($"{minLimit}")));
            }

            this.expr.AttachTo(this);
        }
Esempio n. 6
0
 public static Spawn Create(FunctionCall call)
 {
     return(new Spawn(call));
 }
Esempio n. 7
0
 public static IExpression Not(IExpression expr)
 {
     return(FunctionCall.Create(NameReference.Create(expr, NameFactory.NotOperator)));
 }
Esempio n. 8
0
 public static IExpression IsNotEqual(IExpression lhs, IExpression rhs)
 {
     return(FunctionCall.Create(NameReference.Create(lhs, NameFactory.NotEqualOperator), FunctionArgument.Create(rhs)));
 }
Esempio n. 9
0
 public static IExpression Divide(IExpression lhs, IExpression rhs)
 {
     return(FunctionCall.Create(NameReference.Create(lhs, NameFactory.DivideOperator), FunctionArgument.Create(rhs)));
 }
Esempio n. 10
0
 public static IExpression AddOverflow(IExpression lhs, IExpression rhs)
 {
     return(FunctionCall.Create(NameReference.Create(lhs, NameFactory.AddOverflowOperator), FunctionArgument.Create(rhs)));
 }
Esempio n. 11
0
 public static IExpression InitializeIndexable(string name, params IExpression[] arguments)
 {
     return(Block.CreateStatement(arguments.ZipWithIndex().Select(it =>
                                                                  Assignment.CreateStatement(FunctionCall.Indexer(NameReference.Create(name),
                                                                                                                  FunctionArgument.Create(NatLiteral.Create($"{it.Item2}"))),
                                                                                             it.Item1))));
 }
Esempio n. 12
0
 public static FunctionCall ThisInit(params FunctionArgument[] arguments)
 {
     return(FunctionCall.Constructor(NameReference.Create(NameFactory.ThisVariableName, NameFactory.InitConstructorName),
                                     arguments));
 }
Esempio n. 13
0
 public static FunctionCall BaseInit(params FunctionArgument[] arguments)
 {
     return(FunctionCall.Constructor(NameReference.CreateBaseInitReference(), arguments));
 }