simple_reuse.carbon 755 B

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