1. # enum Bool declared in BOOTSTRAP
  2. BEGIN {
  3. Bool.^add_method('Bool', my proto method Bool(|) {*});
  4. Bool.^add_method('gist', my proto method gist(|) {*});
  5. Bool.^add_method('Numeric', my proto method Numeric(|) {*});
  6. Bool.^add_method('Int', my proto method Int(|) {*});
  7. Bool.^add_method('ACCEPTS', my proto method ACCEPTS(|) {*});
  8. Bool.^add_method('pick', my proto method pick(|) {*});
  9. Bool.^add_method('roll', my proto method roll(|) {*});
  10. Bool.^add_method('perl', my proto method perl(|) {*});
  11. }
  12. BEGIN {
  13. Bool.^add_multi_method('Bool', my multi method Bool(Bool:D:) { self });
  14. Bool.^add_multi_method('gist', my multi method gist(Bool:D:) { self ?? 'True' !! 'False' });
  15. Bool.^add_multi_method('Str', my multi method Str(Bool:D:) { self ?? 'True' !! 'False' });
  16. Bool.^add_multi_method('Numeric', my multi method Numeric(Bool:D:) { self ?? 1 !! 0 });
  17. Bool.^add_multi_method('Int', my multi method Int(Bool:D:) { self ?? 1 !! 0 });
  18. Bool.^add_multi_method('Real', my multi method Real(Bool:D:) { self ?? 1 !! 0 });
  19. Bool.^add_multi_method('ACCEPTS', my multi method ACCEPTS(Bool:D: Mu \topic ) { self });
  20. Bool.^add_multi_method('perl', my multi method perl(Bool:D:) { self ?? 'Bool::True' !! 'Bool::False' });
  21. Bool.^add_multi_method('pick', my multi method pick(Bool:U:) { nqp::p6bool(nqp::isge_n(nqp::rand_n(2e0), 1e0)) });
  22. Bool.^add_multi_method('roll', my multi method roll(Bool:U:) { nqp::p6bool(nqp::isge_n(nqp::rand_n(2e0), 1e0)) });
  23. }
  24. BEGIN {
  25. Bool.^add_multi_method('Bool', my multi method Bool(Bool:U:) { Bool::False });
  26. Bool.^add_multi_method('ACCEPTS', my multi method ACCEPTS(Bool:U: \topic ) { nqp::istype(topic, Bool) });
  27. Bool.^add_multi_method('gist', my multi method gist(Bool:U:) { '(Bool)' });
  28. Bool.^add_multi_method('perl', my multi method perl(Bool:U:) { 'Bool' });
  29. Bool.^add_multi_method('pick', my multi method pick(Bool:U: $n) { self.^enum_value_list.pick($n) });
  30. Bool.^add_multi_method('roll', my multi method roll(Bool:U: $n) { self.^enum_value_list.roll($n) });
  31. Bool.^add_method('pred', my method pred() { Bool::False });
  32. Bool.^add_method('succ', my method succ() { Bool::True });
  33. Bool.^add_method('enums', my method enums() { self.^enum_values.Map });
  34. Bool.^compose;
  35. }
  36. multi sub prefix:<++>(Bool $a is rw) { $a = True; }
  37. multi sub prefix:<-->(Bool $a is rw) { $a = False; }
  38. multi sub postfix:<++>(Bool:U $a is rw --> False) { $a = True }
  39. multi sub postfix:<-->(Bool:U $a is rw) { $a = False; }
  40. multi sub postfix:<++>(Bool:D $a is rw) {
  41. if $a {
  42. True
  43. }
  44. else {
  45. $a = True;
  46. False
  47. }
  48. }
  49. multi sub postfix:<-->(Bool:D $a is rw) {
  50. if $a {
  51. $a = False;
  52. True
  53. }
  54. else {
  55. False
  56. }
  57. }
  58. proto sub prefix:<?>(Mu $) is pure {*}
  59. multi sub prefix:<?>(Bool:D \a) { a }
  60. multi sub prefix:<?>(Bool:U \a) { Bool::False }
  61. multi sub prefix:<?>(Mu \a) { a.Bool }
  62. proto sub prefix:<so>(Mu $) is pure {*}
  63. multi sub prefix:<so>(Bool:D \a) { a }
  64. multi sub prefix:<so>(Bool:U \a) { Bool::False }
  65. multi sub prefix:<so>(Mu \a) { a.Bool }
  66. proto sub prefix:<!>(Mu $) is pure {*}
  67. multi sub prefix:<!>(Bool \a) { nqp::p6bool(nqp::not_i(nqp::istrue(a))) }
  68. multi sub prefix:<!>(Mu \a) { nqp::p6bool(nqp::not_i(nqp::istrue(a))) }
  69. proto sub prefix:<not>(Mu $) is pure {*}
  70. multi sub prefix:<not>(Bool \a) { nqp::p6bool(nqp::not_i(nqp::istrue(a))) }
  71. multi sub prefix:<not>(Mu \a) { nqp::p6bool(nqp::not_i(nqp::istrue(a))) }
  72. proto sub prefix:<?^>(Mu $) is pure {*}
  73. multi sub prefix:<?^>(Mu \a) { not a }
  74. proto sub infix:<?&>(Mu $?, Mu $?) is pure {*}
  75. multi sub infix:<?&>(Mu $x = Bool::True) { $x.Bool }
  76. multi sub infix:<?&>(Mu \a, Mu \b) { a.Bool && b.Bool }
  77. proto sub infix:<?|>(Mu $?, Mu $?) is pure {*}
  78. multi sub infix:<?|>(Mu $x = Bool::False) { $x.Bool }
  79. multi sub infix:<?|>(Mu \a, Mu \b) { a.Bool || b.Bool }
  80. proto sub infix:<?^>(Mu $?, Mu $?) is pure {*}
  81. multi sub infix:<?^>(Mu $x = Bool::False) { $x.Bool }
  82. multi sub infix:<?^>(Mu \a, Mu \b) { nqp::p6bool(nqp::ifnull(nqp::xor(a.Bool,b.Bool), 0)) }
  83. # These operators are normally handled as macros in the compiler;
  84. # we define them here for use as arguments to functions.
  85. proto sub infix:<&&>(|) {*}
  86. multi sub infix:<&&>(Mu $x = Bool::True) { $x }
  87. multi sub infix:<&&>(Mu \a, &b) { a && b() }
  88. multi sub infix:<&&>(Mu \a, Mu \b) { a && b }
  89. proto sub infix:<||>(|) {*}
  90. multi sub infix:<||>(Mu $x = Bool::False) { $x }
  91. multi sub infix:<||>(Mu \a, &b) { a || b() }
  92. multi sub infix:<||>(Mu \a, Mu \b) { a || b }
  93. proto sub infix:<^^>(|) {*}
  94. multi sub infix:<^^>(Mu $x = Bool::False) { $x }
  95. multi sub infix:<^^>(Mu \a, &b) { a ^^ b() }
  96. multi sub infix:<^^>(Mu \a, Mu \b) { a ^^ b }
  97. multi sub infix:<^^>(+@a) {
  98. my Mu $a = shift @a;
  99. while @a {
  100. my Mu $b := shift @a;
  101. $b := $b() if $b ~~ Callable;
  102. next unless $b;
  103. return Nil if $a;
  104. $a := $b;
  105. }
  106. $a;
  107. }
  108. proto sub infix:<//>(|) {*}
  109. multi sub infix:<//>(Mu $x = Any) { $x }
  110. multi sub infix:<//>(Mu \a, &b) { a // b }
  111. multi sub infix:<//>(Mu \a, Mu \b) { a // b }
  112. proto sub infix:<and>(|) {*}
  113. multi sub infix:<and>(Mu $x = Bool::True) { $x }
  114. multi sub infix:<and>(Mu \a, &b) { a && b }
  115. multi sub infix:<and>(Mu \a, Mu \b) { a && b }
  116. proto sub infix:<or>(|) {*}
  117. multi sub infix:<or>(Mu $x = Bool::False) { $x }
  118. multi sub infix:<or>(Mu \a, &b) { a || b }
  119. multi sub infix:<or>(Mu \a, Mu \b) { a || b }
  120. proto sub infix:<xor>(|) {*}
  121. multi sub infix:<xor>(Mu $x = Bool::False) { $x }
  122. multi sub infix:<xor>(Mu \a, &b) { a ^^ b }
  123. multi sub infix:<xor>(Mu \a, Mu \b) { a ^^ b }
  124. multi sub infix:<xor>(|c) { &infix:<^^>(|c); }