From f4886770b667c1fd18c2178666602b4601692c6d Mon Sep 17 00:00:00 2001 From: Moritz Lenz Date: Tue, 4 Sep 2012 13:31:49 +0200 Subject: [PATCH] export trait for constants --- docs/ChangeLog | 1 + src/Perl6/Actions.pm | 9 +++++++-- src/core/traits.pm | 7 +++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/ChangeLog b/docs/ChangeLog index 24f4effff0f..ffca5b79aaa 100644 --- a/docs/ChangeLog +++ b/docs/ChangeLog @@ -5,6 +5,7 @@ New in 2012.09 + support for indirect type names in routine and type declarations + compiler now built with QAST-based NQP, which generates better code, thus making the compiler a little faster ++ support for "is export" traits on constants New in 2012.08 + tclc implemented diff --git a/src/Perl6/Actions.pm b/src/Perl6/Actions.pm index ed240ca01b3..8f474323e34 100644 --- a/src/Perl6/Actions.pm +++ b/src/Perl6/Actions.pm @@ -2697,6 +2697,11 @@ class Perl6::Actions is HLL::Actions { $*W.install_package($/, [$name], ($*SCOPE || 'our'), 'constant', $*PACKAGE, $*W.cur_lexpad(), $value); } + $*W.ex-handle($/, { + for $ -> $t { + ($t.ast)($value, :SYMBOL($name)); + } + }); # Evaluate to the constant. make QAST::WVal.new( :value($value) ); @@ -3146,8 +3151,8 @@ class Perl6::Actions is HLL::Actions { my %arg; %arg{~$} := @trait_arg ?? @trait_arg[0] !! $*W.find_symbol(['Bool', 'True']); - make -> $declarand { - $*W.apply_trait($/, '&trait_mod:', $declarand, |%arg); + make -> $declarand, *%additional { + $*W.apply_trait($/, '&trait_mod:', $declarand, |%arg, |%additional); }; } } diff --git a/src/core/traits.pm b/src/core/traits.pm index c0bc2dce2cd..8e71ba9eb0f 100644 --- a/src/core/traits.pm +++ b/src/core/traits.pm @@ -124,6 +124,13 @@ multi trait_mod:(Mu:U \type, :$export!) { 'DEFAULT'); EXPORT_SYMBOL($exp_name, @tags, type); } +# for constants +multi trait_mod:(Mu \sym, :$export!, :$SYMBOL!) { + my @tags = 'ALL', ($export ~~ Pair ?? $export.key !! + $export ~~ Positional ?? @($export)>>.key !! + 'DEFAULT'); + EXPORT_SYMBOL($SYMBOL, @tags, sym); +} multi trait_mod:(Mu:D $docee, :$docs!) { $docee does role {