protected override sealed void Execute(SmallBasicEngine engine)
        {
            BaseValue second = engine.EvaluationStack.Pop();
            BaseValue first  = engine.EvaluationStack.Pop();

            engine.EvaluationStack.Push(this.Execute(first, second));
        }
Exemple #2
0
        protected override void Execute(SmallBasicEngine engine)
        {
            BaseValue value = engine.EvaluationStack.Pop();

            executeAux(new ArrayValue(engine.Memory), this.array, this.indicesCount);

            BaseValue executeAux(ArrayValue memory, string index, int remainingIndices)
            {
                if (remainingIndices == 0)
                {
                    memory.SetIndex(index, value);
                }
                else
                {
                    ArrayValue nextMemory =
                        memory.TryGetValue(index, out BaseValue elementValue) && elementValue is ArrayValue elementArrayValue
                        ? elementArrayValue
                        : new ArrayValue();

                    string nextIndex = engine.EvaluationStack.Pop().ToString();

                    memory.SetIndex(index, executeAux(nextMemory, nextIndex, remainingIndices - 1));
                }

                return(memory);
            }
        }
Exemple #3
0
        protected override void Execute(SmallBasicEngine engine)
        {
            BaseValue value = engine.EvaluationStack.Pop();

            executeAux(engine.Memory, this.array, this.indicesCount);

            BaseValue executeAux(Dictionary <string, BaseValue> memory, string index, int remainingIndices)
            {
                if (remainingIndices == 0)
                {
                    memory[index] = value;
                }
                else
                {
                    Dictionary <string, BaseValue> nextMemory =
                        memory.TryGetValue(index, out BaseValue elementValue) && elementValue is ArrayValue elementArrayValue
                        ? elementArrayValue.ToDictionary()
                        : new Dictionary <string, BaseValue>();

                    string nextIndex = engine.EvaluationStack.Pop().ToString();

                    memory[index] = executeAux(nextMemory, nextIndex, remainingIndices - 1);
                }

                return(new ArrayValue(memory));
            }
        }
        protected override BaseValue Execute(BaseValue first, BaseValue second)
        {
            if (first is NumberValue && second is NumberValue)
            {
                return(new NumberValue(first.ToNumber() + second.ToNumber()));
            }

            return(StringValue.Create(first.ToString() + second.ToString()));
        }
        protected override BaseValue Execute(BaseValue first, BaseValue second)
        {
            decimal divisor = second.ToNumber();

            if (divisor == 0)
            {
                divisor = 1;
            }

            return(new NumberValue(first.ToNumber() / divisor));
        }
Exemple #6
0
 public PushValueInstruction(BaseValue value, TextRange range)
     : base(range)
 {
     this.value = value;
 }
 protected abstract BaseValue Execute(BaseValue value);
        protected override sealed void Execute(SmallBasicEngine engine)
        {
            BaseValue value = engine.EvaluationStack.Pop();

            engine.EvaluationStack.Push(this.Execute(value));
        }
 protected abstract BaseValue Execute(BaseValue first, BaseValue second);
 protected override BaseValue Execute(BaseValue first, BaseValue second)
 => new BooleanValue(first.ToNumber() >= second.ToNumber());
 protected override BaseValue Execute(BaseValue first, BaseValue second)
 => new BooleanValue(first.ToString() != second.ToString());
 protected override BaseValue Execute(BaseValue value)
 => new NumberValue(-value.ToNumber());
 protected override BaseValue Execute(BaseValue first, BaseValue second) => new NumberValue(first.ToNumber() * second.ToNumber());