Skip to content

Commit

Permalink
A little re-working on generic NFA storage.
Browse files Browse the repository at this point in the history
This means we can do them in a way that doesn't end up with different
NQP bootstrap layers ending up linked.
  • Loading branch information
jnthn committed Oct 26, 2012
1 parent 91543c1 commit 5e80295
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/QRegex/NFA.nqp
Expand Up @@ -19,11 +19,15 @@ class QRegex::NFA {
has int $!generic;

method new() {
my $new := self.bless(:states(nqp::list()), :edges(nqp::list()));
my $new := self.bless(:states(nqp::list()), :edges(0));
$new.addstate();
$new.addstate();
$new;
}

method from_saved($saved) {
self.bless(:states($saved), :edges(1));
}

method addstate() {
my int $id := +$!states;
Expand Down Expand Up @@ -482,3 +486,7 @@ class QRegex::NFA {
print("\n", $dumper.indent, ']');
}
}

INIT {
NQPRegex.SET_NFA_TYPE(QRegex::NFA);
}
10 changes: 7 additions & 3 deletions src/core/NQPRoutine.pm
Expand Up @@ -78,7 +78,7 @@ my knowhow NQPRegex {
%!alt_nfas{$name} := $nfa;
}
method SET_GENERIC_NFA($nfa) {
$!generic_nfa := $nfa;
$!generic_nfa := $nfa.save();
}
method ADD_NESTED_CODE($code) {
nqp::ifnull(@!nested_codes, @!nested_codes := nqp::list());
Expand Down Expand Up @@ -116,14 +116,18 @@ my knowhow NQPRegex {

$der
}
my $nfa_type;
method SET_NFA_TYPE($type) {
$nfa_type := $type;
}
method instantiate_generic($env) {
if nqp::isnull($!generic_nfa) || !nqp::can($!generic_nfa, 'instantiate_generic') {
if nqp::isnull($!generic_nfa) {
self
}
else {
my $ins := self.clone();
nqp::bindattr($ins, NQPRegex, '$!nfa',
$!generic_nfa.instantiate_generic($env).save());
$nfa_type.from_saved($!generic_nfa).instantiate_generic($env).save());
nqp::bindattr($ins, NQPRegex, '$!generic_nfa', nqp::null());
$ins
}
Expand Down

0 comments on commit 5e80295

Please sign in to comment.