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)); } }
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)))))); }
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(); }
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)) )); }
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); }
public static Spawn Create(FunctionCall call) { return(new Spawn(call)); }
public static IExpression Not(IExpression expr) { return(FunctionCall.Create(NameReference.Create(expr, NameFactory.NotOperator))); }
public static IExpression IsNotEqual(IExpression lhs, IExpression rhs) { return(FunctionCall.Create(NameReference.Create(lhs, NameFactory.NotEqualOperator), FunctionArgument.Create(rhs))); }
public static IExpression Divide(IExpression lhs, IExpression rhs) { return(FunctionCall.Create(NameReference.Create(lhs, NameFactory.DivideOperator), FunctionArgument.Create(rhs))); }
public static IExpression AddOverflow(IExpression lhs, IExpression rhs) { return(FunctionCall.Create(NameReference.Create(lhs, NameFactory.AddOverflowOperator), FunctionArgument.Create(rhs))); }
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)))); }
public static FunctionCall ThisInit(params FunctionArgument[] arguments) { return(FunctionCall.Constructor(NameReference.Create(NameFactory.ThisVariableName, NameFactory.InitConstructorName), arguments)); }
public static FunctionCall BaseInit(params FunctionArgument[] arguments) { return(FunctionCall.Constructor(NameReference.CreateBaseInitReference(), arguments)); }