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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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