示例#1
0
 public void AddArgument(ASTVariableNode v)
 {
     if (Arguments == null)
     {
         Arguments = new List <ASTVariableNode>();
     }
     v.Parent = this;
     Arguments.Insert(0, v);
 }
        private void VisitVariable(ASTVariableNode varNode)
        {
            var existsLocal = _currentSubroutine.FindLocal(varNode.Name);

            if (existsLocal == null)
            {
                _currentSubroutine.AddLocal(varNode.Name, new Variable());
            }
        }
示例#3
0
        /// <summary>
        /// Builds for loop statement
        /// </summary>
        /// <param name="forNode">For loop node</param>
        private void BuildForStatement(ASTForStatementNode forNode)
        {
            var condition = _emitter.DefineLabel();
            var exitFor   = _emitter.DefineLabel();

            ASTVariableNode counter = null;

            //init counter if needed
            if (forNode.Counter is ASTAssignStatementNode assignNode)
            {
                BuildStatement(assignNode);
                counter = (ASTVariableNode)assignNode.Left;
            }
            else
            {
                counter = (ASTVariableNode)forNode.Counter;
            }
            //check condition
            _emitter.MarkLabel(condition);
            BuildExpression(forNode.Condition);
            _emitter.JumpFalse(exitFor);
            //body
            _loopsEnds.Push(exitFor);
            if (forNode.Body != null)
            {
                BuildStatement(forNode.Body);
            }
            _loopsEnds.Pop();

            //load counter
            BuildExpression(counter);
            _emitter.ToDecimal();
            //build step
            if (forNode.Step != null)
            {
                BuildExpression(forNode.Step);
                if (_emitter.StackPeek() != typeof(decimal))
                {
                    _emitter.ToDecimal();
                }
            }
            else //default step
            {
                _emitter.PushLong(1);
                _emitter.ToDecimal();
            }
            //update counter
            _emitter.StaticCall(typeof(decimal), "Add", new Type[] { typeof(decimal), typeof(decimal) });
            _emitter.Box();
            Store(counter.Name);
            //jump to condition
            _emitter.Jump(condition);
            //exit
            _emitter.MarkLabel(exitFor);
        }
示例#4
0
 /// <summary>
 /// Loads variable value into stack
 /// </summary>
 /// <param name="varNode">Variable node</param>
 private void BuildVariable(ASTVariableNode varNode)
 {
     if (_context.IsLocal(varNode.Name))
     {
         _emitter.LoadLocal(_context.GetLocal(varNode.Name));
     }
     else
     {
         _emitter.LoadArg(_context.GetArgID(varNode.Name));
     }
 }
示例#5
0
        private void CheckVariable(ASTVariableNode varNode)
        {
            ISymbol definedVar = _currentSub.FindLocal(varNode.Name);

            if (definedVar == null)
            {
                _messages.Add(new MessageRecord(
                                  MsgCode.UndefinedVariable,
                                  varNode.SourcePath,
                                  varNode.StartLine,
                                  varNode.StartPos,
                                  varNode.Name
                                  ));
            }
        }