Beispiel #1
0
 public string VisitReturnStmt(Stmt.Return stmt)
 {
     if (stmt.Value == null)
     {
         return("(return)");
     }
     return(Parenthesize("return", stmt.Value));
 }
Beispiel #2
0
        public object VisitReturnStmt(Stmt.Return stmt)
        {
            object value = null;

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

            throw new Return(value);
        }
Beispiel #3
0
        public object VisitReturnStmt(Stmt.Return stmt)
        {
            if (_currentFunction == FunctionType.NONE)
            {
                _logger.Error(stmt.Keyword, "Cannot return from top-level code.");
            }

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

            return(null);
        }