io.carbon 879 B

123456789101112131415161718192021222324252627282930
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. // TODO: This library is not part of the design. Either write a matching
  5. // proposal or remove this.
  6. package Core library "io";
  7. import library "prelude";
  8. // TODO: Support printing other types.
  9. // TODO: Consider rewriting using native support once library support exists.
  10. fn Print(x: i32) = "print.int";
  11. fn PrintChar(x: char) -> i32 = "print.char";
  12. fn PrintStr(msg: str) {
  13. let size: i64 = msg.Size() as i64;
  14. var i: i64 = 0;
  15. while (i < size) {
  16. PrintChar(msg[i]);
  17. ++i;
  18. }
  19. }
  20. // TODO: Return an `Optional(char)` instead of `i32`.
  21. fn ReadChar() -> i32 = "read.char";
  22. // TODO: Change this to a global constant once they are fully supported.
  23. fn EOF() -> i32 { return -1; }