public object visitReturnStmt(Stmt.Return returnStmt) { captureToken(returnStmt.keyword); if (current.type == FunctionType.TYPE_SCRIPT) { error("Cannot return from top-level code."); } if (returnStmt.value == null) { emitReturn(); } else { if (current.type == FunctionType.TYPE_INITIALIZER) { error("Cannot return a value from an initializer."); } compile(returnStmt.value); emitByte(OpCode.OP_RETURN); } return(null); }
public IEnumerable <string> VisitReturnStmt(Stmt.Return stmt) { yield return(stmt.Value.Match( some: value => $"return {value};", none: () => "return;" )); }
public override VoidObject VisitReturnStmt(Stmt.Return stmt) { bool sanityCheckFailed = false; if (stmt.Value != null) { if (!stmt.Value.TypeReference.IsResolved) { TypeValidationErrorCallback(new TypeValidationError( stmt.Keyword, $"Internal compiler error: return {stmt.Value} inference has not been attempted" )); sanityCheckFailed = true; } } else { // No return value - ensure that the return type of the current function is 'void'. } if (sanityCheckFailed) { return(VoidObject.Void); } // TODO: Validate that return type in stmt.TypeReference matches that of the associated function. return(VoidObject.Void); }
public bool VisitReturnStatement(Stmt.Return statement) { if (statement.Value == null) { if (CurrentFunction.ReturnType.Type == TypeEnum.VOID) { return(true); } return(false); } var sr = Examine(statement.Value); if (sr.ImplicitCastableTo(CurrentFunction.ReturnType)) { return(true); } if (sr != CurrentFunction.ReturnType) { Console.WriteLine("Mismatched return type"); return(false); } return(true); }
public LoxVoid VisitReturnStmt(Stmt.Return stmt) { object value = stmt.Value.HasValue ? Evalutate(stmt.Value.ValueOrFailure()) : null; throw new Return(value); }
public Unit VisitReturnStmt(Stmt.Return stmt) { if (stmt.Value != null) { Resolve(stmt.Value); } return(new Unit()); }
public object VisitReturnStmt(Stmt.Return stmt, object options) { if (stmt.value == null) { return("(return)"); } return(Parenthesize("return", stmt.value)); }
public string VisitReturnStmt(Stmt.Return stmt) { if (stmt.Value == null) { return("(return)"); } return(Parenthesize("return", stmt.Value)); }
public object VisitReturnStmt(Stmt.Return stmt) { object value = null; if (stmt.Value != null) { value = Evaluate(stmt.Value); } throw new Return(value); }
public object Visit(Stmt.Return stmt) { // Set to null if nothing returned object value = null; if (stmt.Value != null) { value = Evaluate(stmt.Value); } throw new ReturnException(value); }
public Unit VisitReturnStmt(Stmt.Return stmt) { if (CurrentFunction == FunctionType.NONE) { CSLox.Error(stmt.Keyword, "Can't return from top-level code"); } if (stmt.Value != null) { Resolve(stmt.Value); } return(new Unit()); }
public VoidObject VisitReturnStmt(Stmt.Return stmt) { if (currentFunction == FunctionType.NONE) { nameResolutionErrorHandler(new NameResolutionError("Cannot return from top-level code.", stmt.Keyword)); } if (stmt.Value != null) { Resolve(stmt.Value); } return(VoidObject.Void); }
public LoxVoid VisitReturnStmt(Stmt.Return stmt) { if (_currentFunction is FunctionType.None) { Lox.Error(stmt.Keyword, "Cannot return from top-level code."); } stmt.Value.MatchSome(expr => { if (_currentFunction == FunctionType.Initializer) { Lox.Error(stmt.Keyword, "Cannot return a value from an initializer"); } Resolve(expr); }); return(null); }
public Stmt VisitReturnStatement(Stmt.Return statement) { if (currentFunction.ReturnType.Type == TypeEnum.VOID) { LLVM.BuildRetVoid(_builder); } else { var type = Visit(statement.Value); var value = _valueStack.Pop(); var casted = CheckedCast(value, type, currentFunction.ReturnType); LLVM.BuildRet(_builder, casted); } return(null); }
public Unit VisitReturnStmt(Stmt.Return stmt) { if (CurrentFunction == FunctionType.NONE) { CSLox.Error(stmt.Keyword, "Can't return from top-level code"); } if (stmt.Value != null) { // Small hack to stop 'erberts return from a constructor. // Terminates current instancec if (CurrentFunction == FunctionType.INITIALISER) { CSLox.Error(stmt.Keyword, "Can't return a value from an initialiser."); } Resolve(stmt.Value); } return(new Unit()); }
public object VisitReturnStmt(Stmt.Return stmt) { if (_currentFunction == FunctionType.None) { Lox.Error(stmt.keyword, "Can't return from top-level code"); } if (_currentFunction == FunctionType.Initializer && stmt.value is not null) { Lox.Error(stmt.keyword, "Can't return a value from an initializer."); } if (stmt.value != null) { Resolve(stmt.value); } return(null); }
public object VisitReturnStmt(Stmt.Return stmt) { if (currentFunction == FunctionType.NONE) { this.compilerError?.AddError("Can't reach return. No function defined"); } if (stmt.expr != null) { if (currentFunction == FunctionType.INITIALIZER) { this.compilerError?.AddError("can't return from an initializer function"); } Resolve(stmt.expr); } return(new Stmt.DefaultStatement()); }
public object visitReturnStmt(Stmt.Return stmt) { if (currentFunction == FunctionType.TYPE_NONE) { Interpreter.error(stmt.keyword, "Cannot return from top-level code."); } if (stmt.value != null) { if (currentFunction == FunctionType.TYPE_INITIALIZER) { Interpreter.error(stmt.keyword, "Cannot return a value from an initializer."); } resolve(stmt.value); } return(null); }
/// <summary> /// Resolve a return statement /// </summary> /// <param name="stmt">The statement</param> /// <returns></returns> public object Visit(Stmt.Return stmt) { // Make sure we are in a function if (_current_function == FunctionType.NONE) { _error_handler.Error(stmt.Keyword, "Cannot return from top-level code."); } if (stmt.Value != null) { // Check this is not in a initializer if (_current_function == FunctionType.INITIALIZER) { _error_handler.Error(stmt.Keyword, "Cannot return from an initializer."); } Resolve(stmt.Value); } return(null); }
public object VisitReturnStmt(Stmt.Return stmt) { if (currentFunction == FunctionType.NONE) { throw new InterpretingException(stmt.Keyword, "Can't return from top-level code."); } if (stmt.Value != null) { if (currentFunction == FunctionType.INITIALIZER) { throw new InterpretingException(stmt.Keyword, "Can't return a value from an initializer."); } Resolve(stmt.Value); } return(null); }
public Stmt VisitReturnStmt(Stmt.Return stmt) { throw new NotImplementedException(); }
public static TrashObject ReturnStmt(this Interpreter interpreter, Stmt.Return stmt) { return(interpreter.Evaluate(stmt.Value)); }
public TrashObject VisitReturnStmt(Stmt.Return stmt) { return(this.ReturnStmt(stmt)); }
public object VisitReturnStmt(Stmt.Return stmt, object options = null) { return(null); }
public object VisitBreakStmt(Stmt.Break stmt) { Stmt.Return returnStatement = new Stmt.Return(null, null); return(VisitReturnStmt(returnStatement)); }