Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[dotnet] Enhance DNST::Local so it will be able to play the role of D…
…NST::Temp also.
  • Loading branch information
jnthn committed Dec 4, 2010
1 parent 512cfdb commit 903fb1c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
17 changes: 16 additions & 1 deletion dotnet/compiler/DNST.pm
Expand Up @@ -494,15 +494,30 @@ class DNST::JumpTable is DNST::Node {

class DNST::Local is DNST::Node {
has $!name;
has $!type;
has $!isdecl;

method name($set?) {
if pir::defined($set) { $!name := $set }
$!name
}

method new(:$name!) {
method type($set?) {
if $set { $!type := $set }
$!type
}

method isdecl($set?) {
if $set { $!isdecl := $set }
$!isdecl
}

method new(:$name!, :$type, :$isdecl, *@children) {
my $obj := self.CREATE;
$obj.name($name);
$obj.type($type);
$obj.isdecl($isdecl);
$obj.set_children(@children);
$obj;
}
}
Expand Down
15 changes: 14 additions & 1 deletion dotnet/compiler/DNST2CSharp.pm
Expand Up @@ -260,8 +260,21 @@ our multi sub cs_for(DNST::Literal $lit) {
}

our multi sub cs_for(DNST::Local $loc) {
my $code := '';
if $loc.isdecl {
unless +@($loc) == 1 {
pir::die('A DNST::Local with isdecl set must have exactly one child')
}
unless $loc.type {
pir::die('DNST::Local with isdecl requires type');
}
$code := cs_for((@($loc))[0]);
$code := $code ~ ' ' ~ $loc.type ~ ' ' ~ $loc.name ~ " = $*LAST_TEMP;\n";
} elsif +@($loc) != 0 {
pir::die('A DNST::Local without isdecl set must have no children')
}
$*LAST_TEMP := $loc.name;
return '';
return $code;
}

our multi sub cs_for(DNST::JumpTable $jt) {
Expand Down

0 comments on commit 903fb1c

Please sign in to comment.