Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first shot at "lazy" statement prefix

  • Loading branch information...
commit 18f9e4107347e765b11122cd4137858f3c95c5f2 1 parent f4e6701
@moritz moritz authored
View
4 src/Perl6/Actions.pm
@@ -901,6 +901,10 @@ class Perl6::Actions is HLL::Actions {
method statement_prefix:sym<PRE>($/) { make $*W.add_phaser($/, 'PRE', ($<blorst>.ast)<code_object>, ($<blorst>.ast)<past_block>); }
method statement_prefix:sym<POST>($/) { make $*W.add_phaser($/, 'POST', ($<blorst>.ast)<code_object>, ($<blorst>.ast)<past_block>); }
+ method statement_prefix:sym<lazy>($/) {
+ make $*W.create_lazy($/, $<blorst>.ast()<code_object>);
+ }
+
method statement_prefix:sym<DOC>($/) {
$*W.add_phaser($/, ~$<phase>, ($<blorst>.ast)<code_object>)
if %*COMPILING<%?OPTIONS><doc>;
View
1  src/Perl6/Grammar.pm
@@ -874,6 +874,7 @@ grammar Perl6::Grammar is HLL::Grammar {
token statement_prefix:sym<try> { <sym> <blorst> }
token statement_prefix:sym<gather>{ <sym> <blorst> }
token statement_prefix:sym<do> { <sym> <blorst> }
+ token statement_prefix:sym<lazy> { <sym> <blorst> }
token statement_prefix:sym<DOC> {
<sym> \s <.ws> $<phase>=['BEGIN' || 'CHECK' || 'INIT']
<blorst>
View
7 src/Perl6/World.pm
@@ -590,6 +590,13 @@ class Perl6::World is HLL::World {
self.finish_code_object($code, $code_past, $is_dispatcher, :yada($yada));
$code
}
+
+ method create_lazy($/, $code) {
+ my $type := self.find_symbol(['LazyScalar']);
+ my $container := $type.new($code);
+ self.add_object($container);
+ self.get_ref($container);
+ }
# Stubs a code object of the specified type.
method stub_code_object($type) {
View
18 src/core/LazyScalar.pm
@@ -0,0 +1,18 @@
+my class LazyScalar is Proxy {
+ method new($code) {
+ my int $reified = 0;
+ my Mu $payload;
+ self.Proxy::new(
+ FETCH => sub ($) {
+ unless $reified {
+ $payload := $code();
+ $reified = 1;
+ }
+ $payload;
+ },
+ STORE => sub ($, Mu \$new) {
+ $payload := $new;
+ }
+ )
+ }
+}
View
1  tools/build/Makefile.in
@@ -232,6 +232,7 @@ CORE_SOURCES = \
src/core/operators.pm \
src/core/metaops.pm \
src/core/terms.pm \
+ src/core/LazyScalar.pm \
src/core/NYI.pm \
src/core/you_are_here.pm \
Please sign in to comment.
Something went wrong with that request. Please try again.