Skip to content

Commit

Permalink
fix for correct BUILD semantics of grammar
Browse files Browse the repository at this point in the history
This test uses a module that lists a bunch of internal methods.  This is
suboptimal, but for now just add the methods that are called when a proper
new/BUILDALL are done.  (The old code only worked because class Grammar
bypassed all that and went straight to nqp, which in turn made it impossible
to support user grammars with their own attributes.)

(Also, the module had the bug of passing the type object where the instantiated
object was needed.)

(Also suppress the redef warning caused by the module exporting the same name.)
  • Loading branch information
TimToady authored and zoffixznet committed May 20, 2017
1 parent 5c703c3 commit 1260b6c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions integration/advent2011-day07.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ grammar MyGrammar {
}
ok MyGrammar.parse("37 + 10 - 5 = 42"), "parsed";

my %timing = get-timing();
my %t = get-timing();

ok %timing<MyGrammar><num><calls>, "num calls recorded";
ok %timing<MyGrammar><num><time> ~~ Real:D, "time recorded";
ok %t<MyGrammar><num><calls>, "num calls recorded";
ok %t<MyGrammar><num><time> ~~ Real:D, "time recorded";
4 changes: 2 additions & 2 deletions packages/Advent/GrammarProfiler.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ my class ProfiledGrammarHOW is Metamodel::GrammarHOW {

method find_method($obj, $name) {
my $meth := callsame;
substr($name, 0, 1) eq '!' || $name eq any(<parse CREATE Bool defined MATCH perl BUILD DESTROY>) ??
substr($name, 0, 1) eq '!' || $name eq any(<parse CREATE Bool defined MATCH perl name BUILD TWEAK DESTROY new bless BUILDALL sink>) ??
$meth !!
-> $c, |args {
my $grammar = $obj.WHAT.perl;
%timing{$grammar} //= {}; # Vivify grammar hash
%timing{$grammar}{$meth.name} //= {}; # Vivify method hash
my %t := %timing{$grammar}{$meth.name};
my $start = now; # get start time
my $result := $meth($obj, |args); # Call original method
my $result := $meth($c, |args); # Call original method
%t<time> += now - $start; # accumulate execution time
%t<calls>++;
$result
Expand Down

0 comments on commit 1260b6c

Please sign in to comment.