protected override List <AssemblyElement> VisitCompoundAssignment(CompoundAssignmentNode node)
        {
            List <AssemblyElement> instructions = new List <AssemblyElement>();

            instructions.AddRange(Visit(node.RightSideNode));
            instructions.AddRange(Visit(node.LeftSideNode));
            switch (node.Operator)
            {
            case CompoundAssignmentOperator.Add:
                instructions.Add(new AssignAdd());
                break;

            case CompoundAssignmentOperator.Sub:
                instructions.Add(new AssignSubtract());
                break;

            case CompoundAssignmentOperator.Mult:
                instructions.Add(new AssignMultiply());
                break;

            case CompoundAssignmentOperator.Div:
                instructions.Add(new AssignDivide());
                break;
            }
            return(instructions);
        }
        public override DynValue Visit(CompoundAssignmentNode compoundAssignmentNode)
        {
            DynValue val;

            if (CallStack.Count > 0)
            {
                var stackTop = CallStack.Peek();
                val = Visit(compoundAssignmentNode.Right);

                if (stackTop.ParameterScope.ContainsKey(compoundAssignmentNode.Variable.Name))
                {
                    stackTop.ParameterScope[compoundAssignmentNode.Variable.Name] = HandleCompoundOperation(
                        stackTop.ParameterScope[compoundAssignmentNode.Variable.Name],
                        val,
                        compoundAssignmentNode.Operation
                        );

                    return(DynValue.Zero);
                }
                else if (stackTop.LocalVariableScope.ContainsKey(compoundAssignmentNode.Variable.Name))
                {
                    stackTop.LocalVariableScope[compoundAssignmentNode.Variable.Name] = HandleCompoundOperation(
                        stackTop.LocalVariableScope[compoundAssignmentNode.Variable.Name],
                        val,
                        compoundAssignmentNode.Operation
                        );

                    return(DynValue.Zero);
                }
            }

            if (!Environment.Globals.ContainsKey(compoundAssignmentNode.Variable.Name))
            {
                throw new RuntimeException($"Variable '{compoundAssignmentNode.Variable.Name}' was not found in current scope.", null);
            }

            val = Visit(compoundAssignmentNode.Right);

            Environment.Globals[compoundAssignmentNode.Variable.Name] = HandleCompoundOperation(
                Environment.Globals[compoundAssignmentNode.Variable.Name],
                val,
                compoundAssignmentNode.Operation
                );

            return(DynValue.Zero);
        }
Exemplo n.º 3
0
 public abstract DynValue Visit(CompoundAssignmentNode compoundAssignmentNode);