Пример #1
0
    void Start()
    {
        laHizo = true;
        Flag.gameObject.SetActive(false);
        mision = Random.Range(0, a * b);
        este.SetActive(false);
        llol = new LArray(a * b);
        float timeNow = Time.realtimeSinceStartup;

        print(timeNow);
        for (float i = 0; i < a; i++)
        {
            for (float j = 0; j < b; j++)
            {
                posi = new Vector2(i, j);
                coordenadas.Add(count, posi);
                //llol.push(count);                         //Esto es para Listas con arreglos
                pack.InsertarMision(count);               //Esto es para listas enlazadas
                count++;
            }
        }
        float timeNow2 = Time.realtimeSinceStartup;

        print(timeNow2);
    }
Пример #2
0
        public void Can_Do_Array_Method_Calls()
        {
            var arrytext   = "var arr = ['a', 'b', 'c', 'd'];";
            var statements = new List <Tuple <string, Type, object, int, string> >()
            {
                new Tuple <string, Type, object, int, string>("result", typeof(int), 4, 4, arrytext + " var result = arr.length;"),
                new Tuple <string, Type, object, int, string>("result", typeof(string), "e", 5, arrytext + " arr.push('e'); var result = arr[4];"),
                new Tuple <string, Type, object, int, string>("result", typeof(string), "d", 3, arrytext + " var result = arr.pop();"),
                new Tuple <string, Type, object, int, string>("result", typeof(string), "a;b;c;d", 4, arrytext + " var result = arr.join(';');"),
                new Tuple <string, Type, object, int, string>("result", typeof(string), "d;c;b;a", 4, arrytext + " var result = arr.reverse().join(';');")
            };

            foreach (var stmt in statements)
            {
                var i = new Interpreter();
                Console.WriteLine(stmt.Item5);
                i.Execute(stmt.Item5);
                var result = i.Memory.Get <object>("result");

                LangTestsHelper.Compare(result, stmt.Item3);

                // Check length
                LArray arr = i.Memory.Get <LArray>("arr");
                Assert.AreEqual(stmt.Item4, arr.Value.Count);
            }
        }
Пример #3
0
        /// <summary>
        /// Evaluate
        /// </summary>
        /// <returns></returns>
        public override object DoEvaluate()
        {
            // Case 1: array type
            if (_arrayExpressions != null)
            {
                var items = new List <object>();

                foreach (var exp in _arrayExpressions)
                {
                    object result = exp == null ? null : exp.Evaluate();
                    items.Add(result);
                }
                var array = new LArray(items);
                return(array);
            }

            // Case 2: Map type
            var dictionary = new Dictionary <string, object>();

            foreach (var pair in _mapExpressions)
            {
                var    expression = pair.Item2;
                object result     = expression == null ? null : expression.Evaluate();
                dictionary[pair.Item1] = result;
            }
            var map = new LMap(dictionary);

            return(map);
        }
Пример #4
0
        private static object ConvertToHostLangArray(Type type, LArray array)
        {
            var   length   = array.Value.Count;
            var   fsarray  = array.Value;
            Array items    = null;
            var   hostType = typeof(int);

            if (type == typeof(string[]))
            {
                items    = new string[length];
                hostType = typeof(string);
            }
            else if (type == typeof(bool[]))
            {
                items    = new bool[length];
                hostType = typeof(bool);
            }
            else if (type == typeof(DateTime[]))
            {
                items    = new DateTime[length];
                hostType = typeof(DateTime);
            }
            else if (type == typeof(TimeSpan[]))
            {
                items    = new TimeSpan[length];
                hostType = typeof(TimeSpan);
            }
            else if (type == typeof(double[]))
            {
                items    = new double[length];
                hostType = typeof(double);
            }
            else if (type == typeof(float[]))
            {
                items    = new float[length];
                hostType = typeof(float);
            }
            else if (type == typeof(long[]))
            {
                items    = new long[length];
                hostType = typeof(long);
            }
            else if (type == typeof(int[]))
            {
                items    = new int[length];
                hostType = typeof(int);
            }

            for (var ndx = 0; ndx < fsarray.Count; ndx++)
            {
                var val     = fsarray[ndx] as LObject;
                var hostval = val.GetValue();

                // This converts double to long as fluentscript only supports double right now.
                var converted = ConvertToCorrectHostLangValue(hostType, hostval);
                items.SetValue(converted, ndx);
            }
            return(items);
        }
Пример #5
0
        /// <summary>
        /// Evaluate
        /// </summary>
        /// <returns></returns>
        public override object DoEvaluate(IAstVisitor visitor)
        {
            var    exePath     = "";
            var    workingDir  = "";
            var    failOnError = false;
            LArray args        = null;
            var    exitcode    = -1;

            /*
             * try
             * {
             *  this.ResolveParams();
             *  exePath = this.GetParamValueString(0, false, string.Empty);
             *  workingDir = this.GetParamValueString(1, true, string.Empty);
             *  args = this.GetParamValue(2, true, null) as LArray;
             *  failOnError = this.GetParamValueBool(3, true, false);
             *
             *  // Convert the items in the array to strings.
             *  // TODO: type-changes
             *  //var list = args.Raw;
             *  var list = new List<object>();
             *  var stringArgs = "";
             *  if (args != null && args.Value != null)
             *  {
             *      foreach (var item in args.Value)
             *      {
             *          var lobj = (LObject)item;
             *          stringArgs += Convert.ToString(lobj.GetValue()) + " ";
             *      }
             *  }
             *  var p = new System.Diagnostics.Process();
             *  p.StartInfo.FileName = exePath;
             *  p.StartInfo.Arguments = stringArgs;
             *  p.StartInfo.UseShellExecute = false;
             *  p.StartInfo.CreateNoWindow = true;
             *  p.StartInfo.WorkingDirectory = workingDir;
             *  p.Start();
             *  // TODO: Set up options on this plugin to configure wait time ( indefinite | milliseconds )
             *  p.WaitForExit();
             *  exitcode = p.ExitCode;
             * }
             * catch (Exception ex)
             * {
             *  exitcode = 1;
             *  if (failOnError)
             *  {
             *      var error = string.Format("An error occurred executing external application '{0}', in '{1}', with '{2}'.\r\n"
             + "message: {3}", exePath, workingDir, args, ex.Message);
             +      throw new LangFailException(error, this.Ref.ScriptName, this.Ref.Line);
             +  }
             + }
             */
            return(new LNumber(Convert.ToDouble(exitcode)));
        }
Пример #6
0
        private void CheckArray(LArray larray, int newLength, object[] expectedItems)
        {
            var array = larray.Value;

            Assert.AreEqual(array.Count, newLength);
            var ndx = 0;

            foreach (var item in array)
            {
                var expected  = expectedItems[ndx];
                var actualVal = ((LObject)item).GetValue();
                Assert.AreEqual(expected, actualVal);
                ndx++;
            }
        }
Пример #7
0
        private void PushParametersInScope()
        {
            if (this.ArgumentValues == null || this.ArgumentValues.Count == 0)
            {
                return;
            }
            if (this.Meta.Arguments == null || this.Meta.Arguments.Count == 0)
            {
                return;
            }
            //if (this.ArgumentValues.Count > this.Meta.Arguments.Count)
            //    throw new ArgumentException("Invalid function call, more arguments passed than arguments in function: line " + Caller.Ref.Line + ", pos: " + Caller.Ref.CharPos);

            // Check if there is an parameter named "arguments"
            var hasParameterNamedArguments = false;

            if (this.Meta.Arguments != null && this.Meta.Arguments.Count > 0)
            {
                if (this.Meta.ArgumentsLookup.ContainsKey("arguments"))
                {
                    hasParameterNamedArguments = true;
                }
            }

            // Add function arguments to scope.
            for (int ndx = 0; ndx < this.Meta.Arguments.Count; ndx++)
            {
                var val = this.ArgumentValues[ndx] as LObject;
                if (val.Type.IsPrimitiveType())
                {
                    var copied = val.Clone();
                    this.ArgumentValues[ndx] = copied;
                }
                Ctx.Memory.SetValue(this.Meta.Arguments[ndx].Name, this.ArgumentValues[ndx]);
            }

            // Finally add the arguments.
            // NOTE: Any extra arguments will be part of the implicit "arguments" array.
            if (!hasParameterNamedArguments)
            {
                var argArray = new LArray(this.ArgumentValues);
                Ctx.Memory.SetValue("arguments", argArray);
            }
        }
Пример #8
0
        /// <summary>
        /// Evaluates an array type declaration.
        /// </summary>
        /// <returns></returns>
        public object VisitArray(ArrayExpr expr)
        {
            var arrayExprs = expr.Exprs;

            // Case 1: array type
            if (arrayExprs != null)
            {
                var items = new List <object>();

                foreach (var exp in arrayExprs)
                {
                    object result = exp == null ? null : exp.Evaluate(this);
                    items.Add(result);
                }
                var array = new LArray(items);
                return(array);
            }
            return(new LArray(new List <object>()));
        }
Пример #9
0
        private void PushParametersInScope(FunctionExpr expr)
        {
            // 1. Validate : any arguments.
            if (expr.ArgumentValues == null || expr.ArgumentValues.Count == 0)
            {
                return;
            }
            if (expr.Meta.Arguments == null || expr.Meta.Arguments.Count == 0)
            {
                return;
            }

            // 2. Check if there is an parameter named "arguments"
            var hasParameterNamedArguments = false;

            if (expr.Meta.Arguments != null && expr.Meta.Arguments.Count > 0)
            {
                if (expr.Meta.ArgumentsLookup.ContainsKey("arguments"))
                {
                    hasParameterNamedArguments = true;
                }
            }

            // 3. Get the symbolscope of the inside of the function and see if any statements.
            ISymbols symscope      = null;
            var      hasStatements = expr.Statements != null && expr.Statements.Count > 0;

            if (hasStatements)
            {
                symscope = expr.Statements[0].SymScope;
            }

            // 3. Add function arguments to scope
            for (var ndx = 0; ndx < expr.Meta.Arguments.Count; ndx++)
            {
                var val = expr.ArgumentValues[ndx] as LObject;
                var arg = expr.Meta.Arguments[ndx];

                // 4. Clone primitive datatypes.
                if (val.Type.IsPrimitiveType())
                {
                    var copied = val.Clone();
                    expr.ArgumentValues[ndx] = copied;
                }

                // 5. Now, set the memory value of the parameter.
                this.Ctx.Memory.SetValue(arg.Name, val);

                // 6. Finally, update the symbol type
                if (hasStatements)
                {
                    var sym = symscope.GetSymbol(arg.Name);
                    if (sym != null && val.Type.TypeVal == TypeConstants.Function &&
                        sym.Category != SymbolCategory.Func)
                    {
                        SymbolHelper.ResetSymbolAsFunction(symscope, arg.Name, val);
                    }
                }
            }

            // Finally add the arguments.
            // NOTE: Any extra arguments will be part of the implicit "arguments" array.
            if (!hasParameterNamedArguments)
            {
                var argArray = new LArray(expr.ArgumentValues);
                expr.Ctx.Memory.SetValue("arguments", argArray);
            }
        }