simple_reuse.carbon 758 B

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