Beispiel #1
0
        public override Result Execute(IRuntime runtime)
        {
            if (this.MultByMinus1 == null)
            {
                return(runtime.EvaluateCodeBlock(this.ExpressionToPrefix));
            }
            else
            {
                var right = runtime.EvaluateCodeBlock(MultByMinus1);

                return(Expression.ArgumentCalcualte(this, new Result(new Number(-1)), right, OperatorType.Multiply, runtime));
            }
        }
Beispiel #2
0
        public override Result Execute(IRuntime runtime)
        {
            Result result = null;

            while (WhileCondition(runtime.EvaluateCodeBlock(LogicalExpression), runtime))
            {
                result = runtime.EvaluateCodeBlock(CodeBlock);
                if (runtime.ProcessingStopped())
                {
                    break;
                }
            }

            return(result);
        }
Beispiel #3
0
        public override Result Execute(IRuntime runtime)
        {
            var result = runtime.EvaluateCodeBlock(ReturnExpression);

            runtime.FunctionReturn(result);
            return(result);
        }
Beispiel #4
0
        public override Result Execute(IRuntime runtime)
        {
            var left = runtime.EvaluateCodeBlock(Arguments.Args[0]);

            if (Arguments.Args.Count > 1)
            {
                if (Arguments.Args[1] is Operator op)
                {
                    var right = runtime.EvaluateCodeBlock(Arguments.Args[2]);
                    return(Expression.ArgumentCalcualte(this, left, right, op.Kind, runtime));
                }
                else
                {
                    runtime.AddError(new RuntimeError("Operator not provided.", this));
                }
            }

            return(left);
        }
Beispiel #5
0
        public override Result Execute(IRuntime runtime)
        {
            var ifcheck = runtime.EvaluateCodeBlock(Condition);

            Result result = null;

            if (ifcheck?.HasResult() == true &&
                ifcheck.Get(runtime) is Number resultInt)
            {
                if (resultInt.Value != 0)
                {
                    result = runtime.EvaluateCodeBlock(BlockOfCode);
                }
            }
            else
            {
                runtime.AddError(new RuntimeError(
                                     $"Invalid data after evaulation of if check expression. Exptected {nameof(Number)}. "
                                     , this));
            }

            return(result);
        }
Beispiel #6
0
        public override Result Execute(IRuntime runtime)
        {
            var result = new LoplaList();
            var k      = 0;

            foreach (var baseMnemonic in Values)
            {
                var resultData = runtime.EvaluateCodeBlock(baseMnemonic).Get(runtime);
                result.Set(k, resultData);
                k++;
            }

            return(new Result(result));
        }
Beispiel #7
0
        public override Result Execute(IRuntime runtime)
        {
            var rightResult = runtime.EvaluateCodeBlock(RightSide);

            if (LeftSide is VariableName vn)
            {
                runtime.SetVariable(vn.Pointer.Name, rightResult.Get(runtime));
            }
            else if (LeftSide is ValueTable vt)
            {
                var leftSideIndexedType = runtime.GetReference(vt.TablePointer.Name);
                if (leftSideIndexedType != null)
                {
                    var value = leftSideIndexedType;
                    if (value is ILoplaIndexedValue)
                    {
                        var loplaList = value as ILoplaIndexedValue;
                        var idx       = runtime.EvaluateCodeBlock(vt.ElementPositionInTable).Get(runtime) as Number;
                        loplaList.Set(idx.ValueAsInt, rightResult.Get(runtime));
                        runtime.SetVariable(vt.TablePointer.Name, loplaList);
                    }
                    else
                    {
                        runtime.AddError(new RuntimeError($"Cannot handle {vt.TablePointer.Name} like an array.",
                                                          this));
                    }
                }
                else
                {
                    runtime.AddError(new RuntimeError($"Table {vt.TablePointer.Name} must be initialized before use.",
                                                      this));
                }
            }

            return(new Result());
        }
Beispiel #8
0
        public override Result Execute(IRuntime runtime)
        {
            var incomingParamters = Arguments.Args.ToList();
            var methodParamters   = new List <Result>();


            foreach (var argument in incomingParamters)
            {
                var result = runtime.EvaluateCodeBlock(argument);
                if (result.HasResult())
                {
                    methodParamters.Add(result);
                }
                else
                {
                    runtime.AddError(new RuntimeError($"Too much results or incorrect result {Pointer}", this));
                }
            }

            return(runtime.EvaluateMethodCall(Pointer, methodParamters));
        }
Beispiel #9
0
        public Result Evaluate(List <Mnemonic> mnemonics)
        {
            if (_requestForStop)
            {
                return(new Result());
            }
            Result result = null;

            //// call all lines in method or file
            foreach (var mExpression in mnemonics)
            {
                if (_requestForStop)
                {
                    break;
                }


                result = _runtime.EvaluateCodeBlock(mExpression);
            }

            return(result);
        }
Beispiel #10
0
        public override Result Execute(IRuntime runtime)
        {
            var value = runtime.GetReference(TablePointer.Name);

            if (value != null)
            {
                if (value is ILoplaIndexedValue tableInstance)
                {
                    if (runtime.EvaluateCodeBlock(ElementPositionInTable).Get(runtime) is Number idx)
                    {
                        var i = idx.ValueAsInt;
                        if (i >= 0 && i < tableInstance.Length())
                        {
                            return(new Result(tableInstance.Get(i)));
                        }
                        else
                        {
                            runtime.AddError(new RuntimeError($"Index {i} was out of bounds for {TablePointer.Name}", this));
                        }
                    }
                    else
                    {
                        runtime.AddError(new RuntimeError($"Index {TablePointer.Name} is not a number", this));
                    }
                }
                else
                {
                    runtime.AddError(new RuntimeError($"Value {TablePointer.Name} is not an array", this));
                }
            }
            else
            {
                runtime.AddError(new RuntimeError($"Value not defined {TablePointer.Name}", this));
            }
            return(new Result());
        }
Beispiel #11
0
 public override Result Execute(IRuntime runtime)
 {
     return(runtime.EvaluateCodeBlock(this.SubExpression));
 }
Beispiel #12
0
        public override Result Execute(IRuntime runtime)
        {
            var left = runtime.EvaluateCodeBlock(SubExpresion);

            return(left);
        }