Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
First pass at getting variable traits in place.
  • Loading branch information
jnthn committed Jul 25, 2013
1 parent b54c12b commit 4766065
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/Perl6/Actions.nqp
Expand Up @@ -2016,7 +2016,7 @@ class Perl6::Actions is HLL::Actions does STDActions {
if $desigilname eq '' {
$name := QAST::Node.unique('ANON_VAR_');
}
$*W.install_lexical_container($BLOCK, $name, %cont_info, $descriptor,
my $cont := $*W.install_lexical_container($BLOCK, $name, %cont_info, $descriptor,
:scope($*SCOPE), :package($*PACKAGE));

# Set scope and type on container, and if needed emit code to
Expand Down Expand Up @@ -2052,6 +2052,20 @@ class Perl6::Actions is HLL::Actions does STDActions {
scope => $*SCOPE,
);
}

# Apply any traits.
if $trait_list {
my $Variable := $*W.find_symbol(['Variable']);
my $varvar := nqp::create($Variable);
nqp::bindattr_s($varvar, $Variable, '$!name', $name);
nqp::bindattr_s($varvar, $Variable, '$!scope', $*SCOPE);
nqp::bindattr($varvar, $Variable, '$!var', $cont);
nqp::bindattr($varvar, $Variable, '$!block', $*DECLARAND);
for $trait_list {
my $applier := $_.ast;
if $applier { $applier($varvar); }
}
}
}
else {
$*W.throw($/, 'X::Comp::NYI',
Expand Down
5 changes: 4 additions & 1 deletion src/Perl6/World.nqp
Expand Up @@ -605,7 +605,7 @@ class Perl6::World is HLL::World {
QAST::Var.new( :scope('lexical'), :name($name) ),
QAST::SVal.new( :value('') ) ))
}
return 1;
return nqp::null();
}

# Build container.
Expand All @@ -622,6 +622,9 @@ class Perl6::World is HLL::World {
# Tweak var to have container.
$var.value($cont);
$var.decl($scope eq 'state' ?? 'statevar' !! 'contvar');

# Evaluate to the container.
$cont
}

# Creates a new container descriptor and adds it to the SC.
Expand Down
6 changes: 6 additions & 0 deletions src/core/Variable.pm
@@ -0,0 +1,6 @@
my class Variable {
has str $.name;
has str $.scope;
has $.var is rw;
has $.block;
}
1 change: 1 addition & 0 deletions tools/build/Makefile-JVM.in
Expand Up @@ -117,6 +117,7 @@ CORE_SOURCES = \
src/core/WhateverCode.pm \
src/core/Block.pm \
src/core/Attribute.pm \
src/core/Variable.pm \
src/core/Routine.pm \
src/core/Sub.pm \
src/core/Macro.pm \
Expand Down
1 change: 1 addition & 0 deletions tools/build/Makefile-Parrot.in
Expand Up @@ -162,6 +162,7 @@ CORE_SOURCES = \
src/core/WhateverCode.pm \
src/core/Block.pm \
src/core/Attribute.pm \
src/core/Variable.pm \
src/core/Routine.pm \
src/core/Sub.pm \
src/core/Macro.pm \
Expand Down

0 comments on commit 4766065

Please sign in to comment.