Created
May 10, 2020 09:13
-
-
Save antoniogamiz/ec639c6db03d6335cbb8f6b6fc1913e9 to your computer and use it in GitHub Desktop.
Trying to understand how compilation works
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use nqp; | |
role GenericCache { | |
has $.precomp-repo; | |
method pod (Str :$name) { ... }; | |
method list-files (--> List ) { ... } | |
} | |
class Cache does GenericCache { | |
submethod BUILD(Str :$dir) { | |
$!precomp-repo = CompUnit::PrecompilationRepository::Default.new( | |
:store(CompUnit::PrecompilationStore::File.new(:prefix($dir.IO))), | |
); | |
} | |
method pod (Str :$pod-file-path ) { | |
my $handle = $!precomp-repo.try-load( | |
CompUnit::PrecompilationDependency::File.new( | |
:src($pod-file-path), | |
:id(CompUnit::PrecompilationId.new-from-string($pod-file-path)), | |
:spec(CompUnit::DependencySpecification.new(:short-name($pod-file-path))), | |
), | |
); | |
my $pod = nqp::atkey($handle.unit, '$=pod'); | |
} | |
method list-files () {return ();} | |
} | |
constant DIR="doc/"; | |
my $cache = Cache.new(:dir(DIR~".precomp")); | |
# first time I execute this, that file will be compiled | |
$cache.pod(:pod-file-path(DIR~"somepod.pod6")); | |
# Q1: what happens if I call it? It's compiled again? | |
say $cache.pod(:pod-file-path(DIR~"somepod.pod6")); | |
# Q2: The second time I run this script, if I call that method again, will it use the | |
# already compiled version? or will recompile de pod? | |
# Q3: If I run the script and after that modify somepod.pod6, will the changes be detected automatically | |
# by the CompUnit::PrecompilationDependency and recompiled? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin pod :kind("Type") :subkind("class") :category("basic") | |
=TITLE class Cool | |
=SUBTITLE Object that can be treated as both a string and number | |
class Cool is Any { } | |
=head1 Methods | |
=head2 routine abs | |
Defined as: | |
sub abs(Numeric() $x) | |
method abs() | |
=end pod | |
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6=begin pod :kind("Type") :subkind("class") :category("basic") | |
=TITLE class Cool | |
=SUBTITLE Object that can be treated as both a string and number | |
class Cool is Any { } | |
=head1 Methods | |
=head2 routine abs | |
Defined as: | |
sub abs(Numeric() $x) | |
method abs() | |
=end pod | |
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6 |
No, yes, yes. Same as I wrote in the comment where I posted the code. You can easily find out for yourself by just trying it. Run with RAKUDO_MODULE_DEBUG=1 to see what happens exactly.
Oh, RAKUDO_MODULE_DEBUG=1
is veeery useful :oo thanks!
The last question: there's a way to know what files are compiled in the .precomp dir? I mean, using only the CompUnit::PrecompilationRepository::Default
object?
No. But what would you use that for?
To tell you the truth I am not very sure, but JJ wants that feature. We will have to use a file to store the names then. Thanks a lot for your help! :D
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @niner ! I hope you're fine!
Could you please answers some questions about precompilation? (see comments
#Q?:
) I'm trying to revamp the cache using your previous feedback (perl6/Pod-To-Cached#16 (comment)) but I still have some doubts.