public Expr Function(FunctionExpr functionExpr)
 {
     return Context.GetFunction(functionExpr.FunctionName)
         .ConvertAs<ISupportDiff>().Return(
         x => x.Diff(this, functionExpr.Args),
         () => { throw new InvalidOperationException(); }); //TODO exception and message
 }
        private void InitializeFunctionCall(FunctionExpr expr)
        {
            // Keep track of total times this function was executed.
            // Keep tract of total times this function caused an error
            if (expr.ExecutionCount == long.MaxValue)
            {
                expr.ExecutionCount = 0;
            }
            else
            {
                expr.ExecutionCount++;
            }

            if (expr.ErrorCount == long.MaxValue)
            {
                expr.ErrorCount = 0;
            }

            expr.ContinueRunning = true;
            expr.ReturnValue     = null;
            expr.HasReturnValue  = false;

            PushParametersInScope(expr);
        }
 public object VisitFunction(FunctionExpr expr)
 {
     return(null);
 }
Beispiel #4
0
 public Value(FunctionExpr func)
 {
     _value = func;
     _type  = ValueType.Function;
 }
Beispiel #5
0
 Expr HandleFunction()
 {
     var funcLocation = _parser.PrevNonCommentLocation;
     string name = _parser.ReadIdentifier();
     AccessorLetExpr funcName = null;
     if( name != null )
     {
         funcName = new AccessorLetExpr( _parser.PrevNonCommentLocation, name );
         Expr eRegName = _scope.Declare( name, funcName );
         if( eRegName is SyntaxErrorExpr ) return eRegName;
     }
     IReadOnlyList<AccessorLetExpr> parameters, closures;
     Expr body = HandleFuncParametersAndBody( out parameters, out closures, false );
     var f = new FunctionExpr( funcLocation, parameters, body, closures, funcName );
     if( funcName == null ) return f;
     return new AssignExpr( funcLocation, funcName, f );
 }
        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);
            }
        }
 internal JSEvalFunction( FunctionExpr e, IReadOnlyList<Closure> closures )
 {
     if( e == null ) throw new ArgumentNullException();
     _expr = e;
     _closures = closures;
 }
Beispiel #8
0
        public override string Visit(FunctionExpr e)
        {
            var pStr = ST.Symbols.DictFuncsStr[e.TypeExpr] + ParenthesizedVisit(true, e.Argument);

            return(pStr);
        }
 /// <summary>
 /// Registers a custom function callback.
 /// </summary>
 /// <param name="pattern"></param>
 /// <param name="stmt">The function</param>
 public void Register(string pattern, FunctionExpr stmt)
 {
     _functions[pattern] = stmt;
     _lcaseToFormaNameMap[pattern.ToLower()] = pattern;
 }
Beispiel #10
0
 protected abstract object MatchFunctionExpr(FunctionExpr functionExpr);
Beispiel #11
0
 public virtual void Visit(FunctionExpr expr)
 {
 }
Beispiel #12
0
        protected override object MatchFunctionExpr(FunctionExpr expr)
        {
            FunctionExpr(expr, FunctionType.FUNCTION);

            return(null);
        }
Beispiel #13
0
 public Value(FunctionExpr func)
 {
     _value = func;
     _type = ValueType.Function;
 }
Beispiel #14
0
 public virtual T Visit(FunctionExpr e) => default(T);
 public Number Function(FunctionExpr functionExpr)
 {
     var func = Context.GetFunction(functionExpr.FunctionName);
     if(func != null) {
         return func.Evaluate(this, functionExpr.Args);
     }
     throw new NotImplementedException(); //TODO correct exception
 }