コード例 #1
0
ファイル: Execution.cs プロジェクト: GHLabs/SambaPOS-3
        /// <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>());
        }
コード例 #2
0
ファイル: TypeHelper.cs プロジェクト: GHLabs/SambaPOS-3
        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;
        }
コード例 #3
0
ファイル: Execution.cs プロジェクト: GHLabs/SambaPOS-3
        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);
            }
        }