Пример #1
0
        public Void Visit_ReturnStmt(ReturnStmt stmt)
        {
            Object value = null;

            if (stmt.value != null)
            {
                value = Evaluate(stmt.value);
            }

            throw new Return(value);
        }
Пример #2
0
        public Void Visit_ReturnStmt(ReturnStmt stmt)
        {
            if (_currentFunctionType == FunctionType.None)
            {
                _errors.Add(new Error(stmt.keyword, ErrorType.InvalidReturnUsage, "Cannot return from top-level code."));
            }

            if (stmt.value != null)
            {
                if (_currentFunctionType == FunctionType.Initializer)
                {
                    _errors.Add(new Error(stmt.keyword, ErrorType.InvalidReturnUsage, "Can't use 'return' inside a constructor"));
                }

                Resolve(stmt.value);
            }
            return(null);
        }
Пример #3
0
        public object VisitReturnStmt(ReturnStmt stmt)
        {
            if (_currentFuncType == FunctionType.NONE)
            {
                Lox.Error(stmt.Keyword, "Cannot return from top-level code.");
            }

            if (stmt.Value != null)
            {
                if (_currentFuncType == FunctionType.INITIALIZER)
                {
                    Lox.Error(stmt.Keyword, "Cannot return a value from an initializer.");
                }

                Resolve(stmt.Value);
            }

            return(null);
        }
Пример #4
0
 public object VisitReturnStmt(ReturnStmt stmt)
 {
     throw new Return(stmt.Value != null
         ? Evaluate(stmt.Value)
         : null);
 }
Пример #5
0
 public string Visit_ReturnStmt(ReturnStmt stmt)
 {
     return(Parenthesize("Return", stmt.value));
 }