simple_reuse.carbon 809 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. //
  5. // AUTOUPDATE
  6. // RUN: %{explorer-run}
  7. // RUN: %{explorer-run-trace}
  8. // CHECK:STDOUT: result: 0
  9. package ExplorerTest api;
  10. __mixin Operations {
  11. fn Square[self: Self](x:i32) -> i32{
  12. return x * x;
  13. }
  14. }
  15. class Point {
  16. fn Origin() -> Point {
  17. return {.x = 0, .y = 0};
  18. }
  19. var x: i32;
  20. var y: i32;
  21. __mix Operations;
  22. }
  23. class Complex {
  24. fn Zero() -> Complex {
  25. return {.r = 0, .i = 0};
  26. }
  27. var r: i32;
  28. var i: i32;
  29. __mix Operations;
  30. }
  31. fn Main() -> i32 {
  32. var p: Point = Point.Origin();
  33. var c: Complex = Complex.Zero();
  34. p.x = 3;
  35. c.r = 4;
  36. return p.Square(p.x) - c.Square(c.r) + 7;
  37. }