public static CodeType GetCodeTypeFromContext(ParseInfo parseInfo, LambdaType type)
        {
            // Get the lambda type's parameters.
            var parameters = new CodeType[type.Parameters.Count];

            for (int i = 0; i < parameters.Length; i++)
            {
                parameters[i] = GetCodeTypeFromContext(parseInfo, type.Parameters[i]);

                // Constant types are not allowed.
                if (parameters[i] != null && parameters[i].IsConstant())
                {
                    parseInfo.Script.Diagnostics.Error("The constant type '" + parameters[i].GetName() + "' cannot be used in method types", type.Parameters[i].Range);
                }
            }

            // Get the return type.
            CodeType returnType   = null;
            bool     returnsValue = false;

            if (!type.ReturnType.IsVoid)
            {
                returnType   = GetCodeTypeFromContext(parseInfo, type.ReturnType);
                returnsValue = true;
            }

            return(new PortableLambdaType(LambdaKind.Portable, parameters, returnsValue, returnType, true));
        }
 protected Bot(Checker myColor, double? lambda = null, LambdaType? lambdaType = null)
 {
     Debug.Assert(myColor != Checker.Empty);
     MyColor = myColor;
     Lambda = lambda ?? 0.05;
     LambdaType = lambdaType ?? LambdaType.ProbabilityDistribution;
 }
Exemple #3
0
        public IWorkshopTree Parse(ActionSet actionSet)
        {
            // If the lambda type is constant, return the lambda itself.
            if (LambdaType.IsConstant())
            {
                return(new LambdaActionWorkshopInstance(actionSet, this));
            }

            // Otherwise, return an array containing data of the lambda.
            var lambdaMeta = new List <IWorkshopTree>();

            // The first element is the lambda's identifier.
            lambdaMeta.Add(new V_Number(Identifier));

            // The second element is the 'this' if applicable.
            lambdaMeta.Add(actionSet.This ?? new V_Null());

            // Every proceeding element is a captured local variable.
            foreach (var capture in CapturedVariables)
            {
                lambdaMeta.Add(actionSet.IndexAssigner[capture].GetVariable());
            }

            // Return the array.
            return(Element.CreateArray(lambdaMeta.ToArray()));
        }
Exemple #4
0
 public Lambda(Type propertyType, string peopertyName, LambdaType lambdaType, dynamic value)
 {
     PropertyType = propertyType;
     PropertyName = peopertyName;
     LambdaType   = lambdaType;
     Value        = value;
 }
Exemple #5
0
 protected Bot(Checker myColor, double?lambda = null, LambdaType?lambdaType = null)
 {
     Debug.Assert(myColor != Checker.Empty);
     MyColor    = myColor;
     Lambda     = lambda ?? 0.05;
     LambdaType = lambdaType ?? LambdaType.ProbabilityDistribution;
 }
Exemple #6
0
 public override void SurroundWith(Environment environment)
 {
     Env = environment;
     Body.SurroundWith(Env);
     Type = new LambdaType(MetaData, (
                               from i in ParameterList
                               select i.Type).ToList(), DeclaredType);
 }
 public void Finalize(PortableLambdaType expecting)
 {
     // Check if the current lambda implements the expected type.
     if (!LambdaType.Implements(expecting))
     {
         _parseInfo.Script.Diagnostics.Error("Expected lambda of type '" + expecting.GetName() + "'", _context.Arrow.Range);
     }
 }
Exemple #8
0
 public IWorkshopTree Parse(ActionSet actionSet, MethodCall methodCall)
 {
     if (LambdaType.IsConstant())
     {
         ILambdaInvocable lambda = (ILambdaInvocable)actionSet.CurrentObject;
         return(lambda.Invoke(actionSet, methodCall.ParameterValues));
     }
     return(actionSet.ToWorkshop.LambdaBuilder.Call(actionSet, methodCall, LambdaType.ReturnType));
 }
Exemple #9
0
 public bool Equals(LambdaExpression compareNode)
 {
     return
         (compareNode != null &&
          LambdaType?.Equals(compareNode.LambdaType) != false &&
          ReturnType?.Equals(compareNode.ReturnType) != false &&
          SemanticProperties?.Equals(compareNode.SemanticProperties) != false &&
          base.Equals(compareNode));
 }
        public IWorkshopTree Parse(ActionSet actionSet)
        {
            // If the lambda type is constant, return the lambda itself.
            if (LambdaType.IsConstant())
            {
                return(new LambdaActionWorkshopInstance(actionSet, this));
            }

            // Encode the lambda.
            return(Workshop.CaptureEncoder.Encode(actionSet, this));
        }
Exemple #11
0
        private static void GenFunction(
            LLVMModuleRef module,
            LLVMBuilderRef builder,
            [NotNull] VariableDeclaration variable,
            [NotNull] LambdaType lambdaType)
        {
            var function = LLVMSharp.LLVM.AddFunction(module, variable.Name, GetLlvmType(lambdaType));

            LLVMSharp.LLVM.PositionBuilderAtEnd(builder, LLVMSharp.LLVM.AppendBasicBlock(function, "entry"));
            GenAstHolder.GenAst(module, builder, (LambdaExpression)variable.Expression);
            LLVMSharp.LLVM.VerifyFunction(function, LLVMVerifierFailureAction.LLVMPrintMessageAction);
        }
        public LambdaType GetLambda(int id)
        {
            LambdaType lambda;

            if (CollisionSystem.warmStarting && prevLambdas.TryGetValue(id, out var l))
            {
                lambda = l;
            }
            else
            {
                lambda = new LambdaType();
            }
            return(lambda);
        }
 public NeuralNetBot(Checker myColor, Network network, double? lambda=null, LambdaType? lambdaType=null)
     : base(myColor, lambda, lambdaType)
 {
     Network = network;
 }
Exemple #14
0
 public Scope ReturningScope() => LambdaType.GetObjectScope();
Exemple #15
0
 public Lambda(LambdaType func, string[] parms)
 {
     Delegate = func;
     Params = parms;
 }
Exemple #16
0
 /// <inheritdoc/>
 public ClientResponse <LambdaResponse> RetrieveLambdasByType(LambdaType type)
 {
     return(client.RetrieveLambdasByTypeAsync(type).GetAwaiter().GetResult());
 }
Exemple #17
0
        public override void SurroundWith(Environment environment)
        {
            base.SurroundWith(environment);
            if (DeclaredType is UnknownType unknownType)
            {
                unknownType.SurroundWith(Env);
                DeclaredType = unknownType.Resolve();
            }
            foreach (var variableDeclaration in ParameterList)
            {
                variableDeclaration.SurroundWith(Env);
            }
            EndLabel.SurroundWith(Env);
            var bodyEnv = new Environment(Env);

            Env.Declarations.Add(EndLabel);
            foreach (var variableDeclaration in ParameterList)
            {
                bodyEnv.Declarations.Add(variableDeclaration);
            }
            // https://github.com/Cm-lang/Cm-Document/issues/12
            if (null != DeclaredType)
            {
                Type = new LambdaType(MetaData, (
                                          from i in ParameterList
                                          select i.Type).ToList(), DeclaredType);
            }
            if (Recur)
            {
                // FEATURE #37
                var recur = new VariableDeclaration(MetaData, ReservedWords.Recur, this);
                // FEATURE #39
                recur.SurroundWith(Env);
                bodyEnv.Declarations.Add(recur);
            }
            Body.SurroundWith(bodyEnv);
//			while (null != Body.OptimizedStatementList)
//				Body = Body.OptimizedStatementList;
            while (null != Body.ConvertedStatementList)
            {
                Body = Body.ConvertedStatementList;
            }
            Body.Statements.Add(EndLabel);
            var retTypes = EndLabel.StatementsUsingThis.Select(i =>
            {
                i.ReturnLabel = EndLabel;
                return(i.Expression.GetExpressionType());
            }).ToList();

//			Body.Flatten();
            if (retTypes.Any(i => !Equals(i, DeclaredType ?? retTypes.First())))
            {
                Errors.Add(
                    $"{MetaData.GetErrorHeader()}ambiguous return types:\n" +
                    (DeclaredType != null ? $"<{DeclaredType}>" : "") +
                    $"[{string.Join(",", from i in retTypes select i.ToString())}]");
            }
            // FEATURE #12
            var retType = DeclaredType ?? (retTypes.Count != 0
                                              ? retTypes.First()
                                           // FEATURE #19
                                              : new PrimaryType(MetaData, PrimaryType.NullType));

            // FEATURE #46
            // FEATURE #47
            if (retTypes.Count > 1)
            {
                var varName = $"retClctor{(ulong) GetHashCode()}";
                Body.Statements.Insert(0, new VariableDeclaration(MetaData, varName, type: retType));
                var returnValueCollector = new VariableExpression(MetaData, varName);
                foreach (var endLabelStatement in EndLabel.StatementsUsingThis)
                {
                    endLabelStatement.Unify(returnValueCollector);
                }
                Body.Statements.Add(new ReturnStatement(MetaData, returnValueCollector)
                {
                    ReturnLabel = EndLabel
                });
            }
            Type = new LambdaType(MetaData, (
                                      from i in ParameterList
                                      select i.Type).ToList(), retType);
        }