Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[dotnet] First cut at getting our subs working. A few fixes in code-g…
…en and PAST::Block.namespace handling along the way. Also our subs still need to be fully qualified with a namespace for now (since foo() is still assuming lexical always).
  • Loading branch information
jnthn committed Nov 19, 2010
1 parent 8c3ca76 commit 51fb629
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
24 changes: 21 additions & 3 deletions dotnet/compiler/Actions.pm
Expand Up @@ -389,6 +389,7 @@ sub package($/) {

# Prefix the class initialization with initial setup. Also install it
# in the symbol table right away, and also into $?CLASS.
my @empty;
$*PACKAGE-SETUP.unshift(PAST::Stmts.new(
PAST::Op.new( :pasttype('bind'),
PAST::Var.new( :name('type_obj'), :scope('register'), :isdecl(1) ),
Expand All @@ -399,7 +400,7 @@ sub package($/) {
)
),
PAST::Op.new( :pasttype('bind'),
PAST::Var.new( :name($name), :scope($*SCOPE eq 'my' ?? 'lexical' !! 'package') ),
PAST::Var.new( :name($name), :scope($*SCOPE eq 'my' ?? 'lexical' !! 'package'), :namespace(@empty) ),
PAST::Var.new( :name('type_obj'), :scope('register') )
),
PAST::Op.new( :pasttype('bind'),
Expand All @@ -423,7 +424,7 @@ sub package($/) {
PAST::Var.new( :name('type_obj'), :scope('register') )
),
PAST::Var.new( :name('type_obj'), :scope('register') ),
PAST::Var.new( :name(~$<package_def><parent>[0]), :scope('package') )
PAST::Var.new( :name(~$<package_def><parent>[0]), :namespace(@empty), :scope('package') )
));
}

Expand Down Expand Up @@ -550,9 +551,10 @@ method routine_def($/) {
if $<deflongname> {
my $name := ~$<sigil>[0] ~ $<deflongname>[0].ast;
$past.name($name);
if $*SCOPE eq '' || $*SCOPE eq 'my' {
if $*SCOPE eq '' || $*SCOPE eq 'my' || $*SCOPE eq 'our' {
if $*MULTINESS eq 'multi' {
# Does the current block have a candidate holder in place?
if $*SCOPE eq 'our' { pir::die('our-scoped multis not yet implemented') }
my $cholder;
my %sym := @BLOCK[0].symbol($name);
if %sym<cholder> {
Expand Down Expand Up @@ -602,6 +604,7 @@ method routine_def($/) {
# Create a candidate list holder for the dispatchees
# this proto will work over, and install them along
# with the proto.
if $*SCOPE eq 'our' { pir::die('our-scoped protos not yet implemented') }
my $cholder := PAST::Op.new( :pasttype('list') );
@BLOCK[0][0].push(PAST::Var.new( :name($name), :isdecl(1),
:viviself($past), :scope('lexical') ) );
Expand All @@ -616,6 +619,20 @@ method routine_def($/) {
@BLOCK[0][0].push(PAST::Var.new( :name($name), :isdecl(1),
:viviself($past), :scope('lexical') ) );
@BLOCK[0].symbol($name, :scope('lexical') );
if $*SCOPE eq 'our' {
# Need to install it at loadinit time but also re-bind
# it per invocation.
@BLOCK[0][0].push(PAST::Op.new(
:pasttype('bind'),
PAST::Var.new( :name($name), :scope('package') ),
PAST::Var.new( :name($name), :scope('lexical') )
));
@BLOCK[0].loadinit.push(PAST::Op.new(
:pasttype('bind'),
PAST::Var.new( :name($name), :scope('package') ),
PAST::Val.new( :value($past) )
));
}
}
$past := PAST::Var.new( :name($name) );
}
Expand Down Expand Up @@ -776,6 +793,7 @@ sub is_lexical($name) {
%setting_names<NQPList> := 1;
%setting_names<NQPArray> := 1;
%setting_names<NQPHash> := 1;
%setting_names<NQPStash> := 1;
%setting_names<Any> := 1;
if %setting_names{$name} {
return 1;
Expand Down
10 changes: 6 additions & 4 deletions dotnet/compiler/PAST2DNSTCompiler.pm
Expand Up @@ -276,11 +276,12 @@ our multi sub dnst_for(PAST::Block $block) {
my @*HANDLERS;

# Update namespace.
my @*CURRENT_NS;
my $prev_ns := @*CURRENT_NS;
if pir::isa($block.namespace(), 'ResizablePMCArray') {
@*CURRENT_NS := $block.namespace();
}
elsif ~$block.namespace() ne '' {
@*CURRENT_NS := pir::new('ResizablePMCArray');
@*CURRENT_NS.push(~$block.namespace());
}

Expand Down Expand Up @@ -464,8 +465,9 @@ our multi sub dnst_for(PAST::Block $block) {
));
}

# Clear up this PAST::Block from the blocks list.
# Clear up this PAST::Block from the blocks list and restore outer NS.
@*PAST_BLOCKS.shift;
@*CURRENT_NS := $prev_ns;

# For immediate evaluate to a call; for declaration, evaluate to the
# low level code object.
Expand Down Expand Up @@ -889,7 +891,7 @@ our multi sub dnst_for(PAST::Val $val) {
unless $val.value<SBI> {
pir::die("Can't use PAST::Val for a block reference for an as-yet uncompiled block");
}
return $val.value<SBI>;
return DNST::Literal.new( :value($val.value<SBI>) );
}

# Look up the type to box to.
Expand Down Expand Up @@ -981,7 +983,7 @@ our multi sub dnst_for(PAST::Var $var) {
# Get all parts of the name.
my @parts;
@parts.push('GLOBAL');
if $var.namespace {
if pir::isa($var.namespace, 'ResizablePMCArray') {
for $var.namespace { @parts.push($_); }
}
elsif +@*CURRENT_NS {
Expand Down

0 comments on commit 51fb629

Please sign in to comment.