Skip to content

Commit d140252

Browse files
committed
Add a $!shared to cursor, for parse-wide things.
We'll move $!orig and $!target in to here. This will mean they need not both be copied into every Cursor, meaning we'll save a word per Cursor, at the cost of a little extra indirection occasionally. Also this will be a good place to hang certain other things.
1 parent 9808c64 commit d140252

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/HLL/Grammar.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ An operator precedence parser.
801801
}
802802

803803
method LANG($lang, $regex, *@args) {
804-
my $lang_cursor := %*LANG{$lang}.'!cursor_init'(self.orig(), :p(self.pos()), :target(self.target()));
804+
my $lang_cursor := %*LANG{$lang}.'!cursor_init'(self.orig(), :p(self.pos()), :target(self.target()), :shared(self.'!shared'()));
805805
if self.HOW.traced(self) {
806806
$lang_cursor.HOW.trace-on($lang_cursor, self.HOW.trace_depth(self));
807807
}

src/QRegex/Cursor.nqp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
# Some things that all cursors involved in a given parse share.
2+
my class ParseShared {
3+
}
4+
15
role NQPCursorRole is export {
6+
has $!shared;
27
has $!orig;
38
has str $!target;
49
has int $!from;
@@ -65,8 +70,10 @@ role NQPCursorRole is export {
6570
$caps;
6671
}
6772

68-
method !cursor_init($orig, :$p = 0, :$c, :$target) {
73+
method !cursor_init($orig, :$p = 0, :$c, :$target, :$shared) {
6974
my $new := self.CREATE();
75+
$shared := nqp::create(ParseShared) unless $shared;
76+
nqp::bindattr($new, $?CLASS, '$!shared', $shared);
7077
nqp::bindattr($new, $?CLASS, '$!orig', $orig);
7178
nqp::bindattr_s($new, $?CLASS, '$!target', $target
7279
?? $target
@@ -190,6 +197,8 @@ role NQPCursorRole is export {
190197
nqp::findmethod($actions, $name)($actions, $match, $key)
191198
if !nqp::isnull($actions) && nqp::can($actions, $name);
192199
}
200+
201+
method !shared() { $!shared }
193202

194203
my @EMPTY := [];
195204
method !protoregex($name) {

0 commit comments

Comments
 (0)