Example #1
0
        public object Execute(FunctionEnvironment functionEnvironment, VariableEnvironment variableEnvironment)
        {
            if (!functionEnvironment.IsFunctionDefined(Identifier))
            {
                throw new Exception("Calling undefined function: " + Identifier);
            }
            VariableEnvironment localVariables = new VariableEnvironment();

            localVariables.ParentEnvironment = variableEnvironment;//todo: switch

            FunctionDefinition functionDefinition = functionEnvironment.GetDefinedFunction(Identifier);

            for (int i = 0; i < Arguments.Count; i++)
            {
                object        obj           = Arguments[i].Execute(functionEnvironment, variableEnvironment);
                BogieLangType bogieLangType = BogieLangTypeHelpr.ObjectToType(obj);
                if (functionDefinition.Parameters[i].Item1 == bogieLangType)
                {
                    localVariables.DeclareVariable(functionDefinition.Parameters[i].Item2, functionDefinition.Parameters[i].Item1);
                    localVariables.DefineVariable(functionDefinition.Parameters[i].Item2, obj);
                }
            }

            return(functionDefinition.Execute(functionEnvironment, localVariables));
        }
Example #2
0
        public void Execute(FunctionEnvironment functionEnvironment, VariableEnvironment variableEnvironment)
        {
            object value = null;

            if (Expression != null)
            {
                value = Expression.Execute(functionEnvironment, variableEnvironment);
            }
            variableEnvironment.DeclareVariable(Identifier, (BogieLangType)BogieLangType);
            if (value != null)
            {
                variableEnvironment.DefineVariable(Identifier, value);
            }
        }