public override RuntimeValue Execute(ExecutionContext context)
        {
            RuntimeValue result = op switch
            {
                UnaryOperator.Plus => IntegerValue.Create(argument.Execute(context).AsInteger(argument)),
                UnaryOperator.Minus => IntegerValue.Create(-argument.Execute(context).AsInteger(argument)),
                UnaryOperator.Not => argument.Execute(context).AsBoolean(argument) ? BooleanValue.False : BooleanValue.True,
                _ => throw new NotImplementedException($"Unary operator {op} not implemented."),
            };

            return(result);
        }
        public override RuntimeValue Execute(ExecutionContext context)
        {
            var          rightValue = right.Execute(context);
            RuntimeValue value;

            if (op == AssignmentOperator.Equals)
            {
                value = rightValue;
            }
            else
            {
                var leftSymbol = context.CurrentScope.GetSymbol(this.identifier, identifierName);
                var leftInt    = leftSymbol.Value.AsInteger(this);
                var rightInt   = rightValue.AsInteger(this);
                var resultInt  = op switch
                {
                    AssignmentOperator.Add => leftInt + rightInt,
                    AssignmentOperator.Subtract => leftInt - rightInt,
                    AssignmentOperator.Multiply => leftInt * rightInt,
                    AssignmentOperator.Divide => leftInt / rightInt,
                    AssignmentOperator.Modulo => leftInt % rightInt,
                    _ => throw new NotImplementedException($"Assignment operator {op} not implemented in interpreter"),
                };
                value = IntegerValue.Create(resultInt);
            }
            context.CurrentScope.AddOrUpdateSymbol(this.Node, identifierName, value);
            return(value);
        }
Esempio n. 3
0
        public override RuntimeValue Execute(ExecutionContext context)
        {
            RuntimeValue result;

            if (op == BinaryOperator.And || op == BinaryOperator.Or)
            {
                // These operators are short-circuiting - don't evaluate right until we know the value of left:
                result = op switch
                {
                    BinaryOperator.And => left.Execute(context).AsBoolean(left) && right.Execute(context).AsBoolean(right) ? BooleanValue.True : BooleanValue.False,
                    BinaryOperator.Or => left.Execute(context).AsBoolean(left) || right.Execute(context).AsBoolean(right) ? BooleanValue.True : BooleanValue.False,
                    _ => throw new NotImplementedException($"Binary operator {op} not implemented in interpreter"),
                };
            }
            else if (op == BinaryOperator.Equal || op == BinaryOperator.NotEqual)
            {
                // These operate on any type:
                result = op switch
                {
                    BinaryOperator.Equal => left.Execute(context).IsEqualTo(right.Execute(context)) ? BooleanValue.True : BooleanValue.False,
                    BinaryOperator.NotEqual => left.Execute(context).IsEqualTo(right.Execute(context)) ? BooleanValue.False : BooleanValue.True,
                    _ => throw new NotImplementedException($"Binary operator {op} not implemented in interpreter")
                };
            }
            else
            {
                // These operate only on integers
                var leftValue  = left.Execute(context).AsInteger(left);
                var rightValue = right.Execute(context).AsInteger(right);

                result = op switch
                {
                    BinaryOperator.Add => IntegerValue.Create(leftValue + rightValue),
                    BinaryOperator.Subtract => IntegerValue.Create(leftValue - rightValue),
                    BinaryOperator.Multiply => IntegerValue.Create(leftValue * rightValue),
                    BinaryOperator.Divide => IntegerValue.Create(leftValue / rightValue),
                    BinaryOperator.Modulo => IntegerValue.Create(leftValue % rightValue),
                    BinaryOperator.Greater => leftValue > rightValue ? BooleanValue.True : BooleanValue.False,
                    BinaryOperator.GreaterOrEqual => leftValue >= rightValue ? BooleanValue.True : BooleanValue.False,
                    BinaryOperator.Less => leftValue < rightValue ? BooleanValue.True : BooleanValue.False,
                    BinaryOperator.LessOrEqual => leftValue <= rightValue ? BooleanValue.True : BooleanValue.False,
                    _ => throw new NotImplementedException($"Binary operator {op} not implemented in interpreter"),
                };
            }

            return(result);
        }
        public override RuntimeValue Execute(ExecutionContext context)
        {
            var valueResult = value.Execute(context);

            context.CurrentScope.AddSymbol(name, valueResult, isConstant: true);

            return(RuntimeValue.Void);
        }
Esempio n. 5
0
        public override RuntimeValue Execute(ExecutionContext context)
        {
            var valueResult = value?.Execute(context) ?? RuntimeValue.Null;

            context.CurrentScope.AddSymbol(name, valueResult);

            return(RuntimeValue.Void);
        }
Esempio n. 6
0
        public override RuntimeValue Execute(ExecutionContext context)
        {
            int?duringValue = during?.Execute(context).AsInteger(this);
            var result      = new ActionValue(new ImuseAction(name, duringValue, body));

            if (name != null)
            {
                context.CurrentScope.AddOrUpdateSymbol(this.Node, name, result);
            }
            return(result);
        }
        public override RuntimeValue Execute(ExecutionContext context)
        {
            int    soundId = id.Execute(context).AsInteger(id);
            string name    = this.name.Execute(context).AsString(this.name);

            context.Engine.RegisterSound(
                soundId,
                context.FileProvider.Load(name)
                );

            return(RuntimeValue.Void);
        }
        public override RuntimeValue Execute(ExecutionContext context)
        {
            if (context.EnqueuingCommands != null)
            {
                ErrorHelper.ThrowInvalidOperationError(Node, "Cannot enqueue while another queue is being built (no nested enqueue statements)");
            }

            var soundIdValue  = soundId.Execute(context).AsInteger(soundId);
            var markerIdValue = markerId.Execute(context).AsInteger(markerId);
            var commandList   = new EnqueueCommandList(soundIdValue, markerIdValue);

            // Start enqueueing state
            context.EnqueuingCommands = commandList;

            return(RuntimeValue.Void);
        }
 public override RuntimeValue Execute(ExecutionContext context)
 {
     expression.Execute(context);
     return(RuntimeValue.Void);
 }