Пример #1
0
        public static Result Run(UnsetExpression unset, Scope scope)
        {
            foreach (Expression expr in unset.Variables)
            {
                switch (expr)
                {
                case ArrayAccessExpression array_access_expression:
                    ArrayInterpreter.Resolve(array_access_expression, scope, (arr, key) =>
                    {
                        arr.Set(new ArrayItem(key, new NullExpression()));
                    });
                    break;

                case VariableExpression variable_expression:
                    IVariable variable = scope.Variables.EnsureExists(variable_expression.Name);
                    variable.Value = new NullExpression();
                    break;

                default:
                    Log.Error($"Cannot execute unset expression: Left Value is of unknown type {expr}");
                    break;
                }
            }

            return(Result.NULL);
        }
Пример #2
0
        public static Result Run(UnaryExpression expression, Scope scope)
        {
            Result value_result = Interpreters.Execute(expression.Value, scope);

            if (value_result.FastReturn)
            {
                return(value_result);
            }

            FinalExpression value = value_result.ResultValue;

            switch (expression.Operation)
            {
            case UnaryOp.CAST_STRING:
                return(new Result(new StringExpression(value.GetStringValue())));

            case UnaryOp.CAST_BOOL:
                return(new Result(new BoolExpression(value.GetBoolValue())));

            case UnaryOp.CAST_ARRAY:
                return(ArrayInterpreter.Run(new ArrayCreateExpression(ImmutableArray <ArrayItemExpression> .Empty), scope));

            case UnaryOp.CAST_OBJECT:
                return(new Result(value));

            case UnaryOp.LOGICAL_NEGATION:
                return(new Result(new BoolExpression(!value.GetBoolValue())));

            case UnaryOp.IS_EMPTY:
                return(new Result(new BoolExpression(string.IsNullOrEmpty(value.GetStringValue()))));

            case UnaryOp.AT_SIGN:
                return(new Result(value));

            default:
                Log.Error($"Unable to execute binary operation: {expression.Operation}");
                return(Result.NULL);
            }
        }
Пример #3
0
        public static Result Run(AssignExpression assign, Scope scope)
        {
            Result right_result = Interpreters.Execute(assign.Right, scope);

            if (right_result.FastReturn)
            {
                return(right_result);
            }

            switch (assign.Left)
            {
            case ArrayAccessExpression array_access_expression:
                ArrayInterpreter.Resolve(array_access_expression, scope, (arr, key) =>
                {
                    arr.Set(new ArrayItem(key, right_result.ResultValue));
                });
                break;

            case VariableExpression variable_expression:
                IVariable variable = scope.Variables.EnsureExists(variable_expression.Name);
                variable.Value = right_result.ResultValue;
                break;

            case StaticFieldAccessExpression static_field_access_expression:
                ClassInterpreter.Resolve(static_field_access_expression, scope, (var) =>
                {
                    var.Value = right_result.ResultValue;
                });
                break;

            default:
                Log.Error($"Cannot execute assign expression: Left Value is of unknown type {assign.Left}");
                break;
            }

            return(right_result);
        }
Пример #4
0
        public static Result Execute(Expression expression, Scope scope)
        {
            if (expression == null)
            {
                return(Result.NULL);
            }

            switch (expression)
            {
            case FinalExpression e:
                return(new Result(e));

            case DocExpression e:
                return(Result.NULL);

            case RequireFileExpression e:
                return(RequireFileInterpreter.Run(e, scope));

            case BlockExpression e:
                return(BlockInterpreter.Run(e, scope));

            case ConditionalBlockExpression e:
                return(ConditionalBlockInterpreter.Run(e, scope));

            case WhileExpression e:
                return(WhileInterpreter.Run(e, scope));

            case ForeachExpression e:
                return(ForeachInterpreter.Run(e, scope));

            case TryExpression e:
                return(TryInterpreter.Run(e, scope));

            case BreakExpression e:
                return(BreakInterpreter.Run(e, scope));

            case ContinueExpression e:
                return(ContinueInterpreter.Run(e, scope));

            case ReturnExpression e:
                return(ReturnInterpreter.Run(e, scope));

            case BinaryExpression e:
                return(BinaryInterpreter.Run(e, scope));

            case UnaryExpression e:
                return(UnaryInterpreter.Run(e, scope));

            case CallParameter e:
                return(CallParameterInterpreter.Run(e, scope));

            case FunctionCallExpression e:
                return(FunctionInterpreter.Run(e, scope));

            case FunctionDeclarationExpression e:
                return(FunctionInterpreter.Run(e, scope));

            case MethodCallExpression e:
                return(ClassInterpreter.Run(e, scope));

            case StaticMethodCallExpression e:
                return(ClassInterpreter.Run(e, scope));

            case ClassDeclarationExpression e:
                return(ClassInterpreter.Run(e, scope));

            case NewInstanceExpression e:
                return(ClassInterpreter.Run(e, scope));

            case StaticFieldAccessExpression e:
                return(ClassInterpreter.Run(e, scope));

            case ArrayCreateExpression e:
                return(ArrayInterpreter.Run(e, scope));

            case ArrayAccessExpression e:
                return(ArrayInterpreter.Run(e, scope));

            case VariableExpression e:
                return(VariableInterpreter.Run(e, scope));

            case PseudoConstExpression e:
                return(VariableInterpreter.Run(e, scope));

            case AssignExpression e:
                return(AssignInterpreter.Run(e, scope));

            case UnsetExpression e:
                return(AssignInterpreter.Run(e, scope));

            default:
                Log.Error($"Unable to execute expression: {expression}");
                return(Result.NULL);
            }
        }