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