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