Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Give P6Regex code objects in standalone mode.
This means that it now no longer depends on BlockMemo, and thus will
not use nqpattr either.
  • Loading branch information
jnthn committed Oct 21, 2012
1 parent c6cd504 commit 8bbf1cb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 16 deletions.
31 changes: 15 additions & 16 deletions src/QRegex/P6Regex/Actions.nqp
@@ -1,6 +1,14 @@
class QRegex::P6Regex::Actions is HLL::Actions {
method TOP($/) {
make self.qbuildsub($<nibbler>.ast, :anon(1), :addself(1));
make QAST::CompUnit.new(
:hll('P6Regex'),
:sc($*W.sc()),
:code_ref_blocks($*W.code_ref_blocks()),
:compilation_mode(0),
:pre_deserialize($*W.load_dependency_tasks()),
:post_deserialize($*W.fixup_tasks()),
self.qbuildsub($<nibbler>.ast, :anon(1), :addself(1))
);
}

method nibbler($/) { make $<termaltseq>.ast }
Expand Down Expand Up @@ -657,22 +665,14 @@ class QRegex::P6Regex::Actions is HLL::Actions {
}

# This is overridden by a compiler that wants to create code objects
# for regexes.
# for regexes. We just use the standard NQP one in standalone mode.
method create_regex_code_object($block) {
$*W.create_code($block, $block.name);
}

# Stores the captures info for a regex.
method store_regex_caps($code_obj, $block, %caps) {
my $hashpast := QAST::Op.new( :op<hash> );
for %caps {
if $_.key gt '' {
$hashpast.push(QAST::SVal.new( :value($_.key) ));
$hashpast.push(QAST::IVal.new( :value(
nqp::iscclass(pir::const::CCLASS_NUMERIC, $_.key, 0) + ($_.value > 1) * 2) ));
}
}
my $capblock := QAST::BlockMemo.new( :name($block.cuid ~ '_caps'), $hashpast );
$block.push(QAST::Stmt.new($capblock));
$code_obj.SET_CAPS(%caps);
}

# Override this to store the overall NFA for a regex. (Standalone mode doesn't need
Expand All @@ -682,11 +682,10 @@ class QRegex::P6Regex::Actions is HLL::Actions {

# Stores the NFA for a regex alternation.
method store_regex_alt_nfa($code_obj, $block, $key, @alternatives) {
my $nfaqast := QAST::Op.new( :op('list') );
my @saved;
for @alternatives {
$nfaqast.push($_.qast(:non_empty));
@saved.push($_.save(:non_empty));
}
my $nfablock := QAST::BlockMemo.new( :name($block.cuid ~ '_' ~ $key), $nfaqast);
$block.push(QAST::Stmt.new($nfablock));
$code_obj.SET_ALT_NFA($key, @saved);
}
}
36 changes: 36 additions & 0 deletions src/QRegex/P6Regex/Grammar.nqp
Expand Up @@ -3,6 +3,41 @@ use NQPHLL;
use QAST;
use PASTRegex;

class QRegex::P6Regex::World is HLL::World {
method create_code($past, $name) {
# Create a fresh stub code, and set its name.
my $dummy := pir::nqp_fresh_stub__PP(-> { nqp::die("Uncompiled code executed") });
pir::assign__vPS($dummy, $name);

# Tag it as a static code ref and add it to the root code refs set.
pir::setprop__vPsP($dummy, 'STATIC_CODE_REF', $dummy);
self.add_root_code_ref($dummy, $past);

# Create code object.
my $code_obj := nqp::create(NQPRegex);
nqp::bindattr($code_obj, NQPRegex, '$!do', $dummy);
my $slot := self.add_object($code_obj);

# Add fixup of the code object and the $!do attribute.
my $fixups := QAST::Stmt.new();
$fixups.push(QAST::Op.new(
:op('bindattr'),
QAST::WVal.new( :value($code_obj) ),
QAST::WVal.new( :value(NQPRegex) ),
QAST::SVal.new( :value('$!do') ),
QAST::BVal.new( :value($past) )
));
$fixups.push(QAST::Op.new(
:op('setcodeobj'),
QAST::BVal.new( :value($past) ),
QAST::WVal.new( :value($code_obj) )
));
self.add_fixup_task(:fixup_past($fixups));

$code_obj
}
}

grammar QRegex::P6Regex::Grammar is HLL::Grammar {

method obs ($old, $new, $when = ' in Perl 6') {
Expand All @@ -28,6 +63,7 @@ grammar QRegex::P6Regex::Grammar is HLL::Grammar {

token TOP {
:my %*RX;
:my $*W := QRegex::P6Regex::World.new(:handle(nqp::sha1(self.target)));
<nibbler>
[ $ || <.panic: 'Confused'> ]
}
Expand Down

0 comments on commit 8bbf1cb

Please sign in to comment.