1. my class Label {
  2. has Str $!name;
  3. has Str $!file;
  4. has Int $!line;
  5. has Str $!prematch;
  6. has Str $!postmatch;
  7. method new(:$name, :$line, :$prematch, :$postmatch) {
  8. # XXX Register in &?BLOCK.labels when we have &?BLOCK.
  9. my $obj := nqp::create(self);
  10. nqp::bindattr($obj, Label, '$!name', $name);
  11. nqp::bindattr($obj, Label, '$!file',
  12. nqp::p6box_s(nqp::ifnull(nqp::getlexdyn('$?FILES'), '<unknown>')));
  13. nqp::bindattr($obj, Label, '$!line', $line);
  14. nqp::bindattr($obj, Label, '$!prematch', nqp::p6box_s($prematch));
  15. nqp::bindattr($obj, Label, '$!postmatch', nqp::p6box_s($postmatch));
  16. $obj
  17. }
  18. method name() {
  19. $!name
  20. }
  21. method goto(*@) { X::NYI.new(:feature("{self.^name}.goto()")).throw }
  22. method leave(*@) { X::NYI.new(:feature("{self.^name}.leave()")).throw }
  23. multi method gist(Label:D:) {
  24. my ($red,$clear,$green,$yellow,$eject) = Rakudo::Internals.error-rcgye;
  25. "Label<$!name>(at $!file:$!line, '$green$!prematch$yellow$eject$red$!name$green$!postmatch$clear')"
  26. }
  27. method Int() { nqp::where(nqp::decont(self)) }
  28. method next() {
  29. my Mu $ex := nqp::newexception();
  30. nqp::setpayload($ex, nqp::decont(self));
  31. nqp::setextype($ex, nqp::const::CONTROL_NEXT + nqp::const::CONTROL_LABELED);
  32. nqp::throw($ex);
  33. }
  34. method redo() {
  35. my Mu $ex := nqp::newexception();
  36. nqp::setpayload($ex, nqp::decont(self));
  37. nqp::setextype($ex, nqp::const::CONTROL_REDO + nqp::const::CONTROL_LABELED);
  38. nqp::throw($ex);
  39. }
  40. method last() {
  41. my Mu $ex := nqp::newexception();
  42. nqp::setpayload($ex, nqp::decont(self));
  43. nqp::setextype($ex, nqp::const::CONTROL_LAST + nqp::const::CONTROL_LABELED);
  44. nqp::throw($ex);
  45. }
  46. }