Skip to content

Commit

Permalink
[dotnet/compiler] replace all var declarations with actual types
Browse files Browse the repository at this point in the history
  • Loading branch information
mberends committed Oct 27, 2010
1 parent fd17228 commit 11dbee6
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 13 deletions.
62 changes: 53 additions & 9 deletions dotnet/compiler/DNST2CSharp.pm
Expand Up @@ -103,7 +103,7 @@ our multi sub cs_for(DNST::TryCatch $tc) {
cs_for((@($tc))[0]);
$code := $code ~
" $try_result = $*LAST_TEMP;\n" ~
" } catch(" ~ $tc.exception_type ~ " " ~ $tc.exception_var ~ ")\{\n" ~
" } catch(" ~ $tc.exception_type ~ " " ~ $tc.exception_var ~ ")\{\n" ~
cs_for((@($tc))[1]) ~
" $try_result = $*LAST_TEMP;\n" ~
" }\n";
Expand All @@ -120,19 +120,63 @@ our multi sub cs_for(DNST::MethodCall $mc) {
@arg_names.push($*LAST_TEMP);
}

# What'we we calling it on?
# What're we calling it on?
my $invocant := $mc.on || @arg_names.shift;

# Code-gen the call.
$code := $code ~ ' ';
unless $mc.void {
$*LAST_TEMP := get_unique_id('result');
my $ret_type := $mc.type || 'var';
$*LAST_TEMP := get_unique_id('result');
my $method_name := "$invocant." ~ $mc.name;
# the next bit is very hacky, should be handled upstream in
# PAST2DNSTCompiler.pm
if $ret_type eq 'var' && $method_name eq 'Ops.unbox_str'
{
$ret_type := 'string';
}
if $ret_type eq 'var' && (
$method_name eq 'CaptureHelper.FormWith' ||
$method_name eq 'Ops.add_int' ||
$method_name eq 'Ops.box_str' ||
$method_name eq 'Ops.coerce_int_to_num' ||
$method_name eq 'Ops.coerce_int_to_str' ||
$method_name eq 'Ops.coerce_num_to_int' ||
$method_name eq 'Ops.coerce_num_to_str' ||
$method_name eq 'Ops.coerce_str_to_int' ||
$method_name eq 'Ops.coerce_str_to_num' ||
$method_name eq 'Ops.concat' ||
$method_name eq 'Ops.div_int' ||
$method_name eq 'Ops.equal_ints' ||
$method_name eq 'Ops.equal_nums' ||
$method_name eq 'Ops.equal_refs' ||
$method_name eq 'Ops.equal_strs' ||
$method_name eq 'Ops.get_how' ||
$method_name eq 'Ops.get_what' ||
$method_name eq 'Ops.instance_of' ||
$method_name eq 'Ops.leave_block' ||
$method_name eq 'Ops.lllist_bind_at_pos' ||
$method_name eq 'Ops.lllist_elems' ||
$method_name eq 'Ops.lllist_get_at_pos' ||
$method_name eq 'Ops.llmapping_bind_at_key' ||
$method_name eq 'Ops.llmapping_elems' ||
$method_name eq 'Ops.llmapping_get_at_key' ||
$method_name eq 'Ops.logical_not_int' ||
$method_name eq 'Ops.multi_dispatch_over_lexical_candidates' ||
$method_name eq 'Ops.mod_int' ||
$method_name eq 'Ops.mul_int' ||
$method_name eq 'Ops.sub_int' ||
$method_name eq 'Ops.throw_dynamic' ||
$method_name eq 'Ops.type_object_for' ||
$method_name eq 'StaticBlockInfo[1].StaticLexPad.SetByName' # WTF?
) {
$ret_type := 'RakudoObject';
}
$code := $code ~ "$ret_type $*LAST_TEMP = ";
if $ret_type eq 'var' { $code := $code ~ "// var from " ~ $invocant ~ "." ~ $mc.name ~ "\n"; }
}
$code := $code ~ "$invocant." ~ $mc.name ~
"(" ~ pir::join(', ', @arg_names) ~ ");\n";

return $code;
}

Expand All @@ -149,7 +193,7 @@ our multi sub cs_for(DNST::Call $mc) {
$code := $code ~ ' ';
unless $mc.void {
$*LAST_TEMP := get_unique_id('result');
$code := $code ~ "var $*LAST_TEMP = ";
$code := $code ~ "RakudoObject $*LAST_TEMP = ";
}
$code := $code ~ $mc.name ~
"(" ~ pir::join(', ', @arg_names) ~ ");\n";
Expand All @@ -168,7 +212,7 @@ our multi sub cs_for(DNST::New $new) {

# Code-gen the constructor call.
$*LAST_TEMP := get_unique_id('new');
$code := $code ~ " var $*LAST_TEMP = new " ~
$code := $code ~ " " ~ $new.type ~ " $*LAST_TEMP = new " ~
$new.type ~ "(" ~ pir::join(', ', @arg_names) ~ ");\n";

return $code;
Expand Down Expand Up @@ -213,7 +257,7 @@ our multi sub cs_for(DNST::Temp $tmp) {
unless +@($tmp) == 1 { pir::die('A DNST::Temp must have exactly one child') }
my $code := cs_for((@($tmp))[0]);
my $name := $tmp.name;
$code := $code ~ " var $name = $*LAST_TEMP;\n";
$code := $code ~ " " ~ $tmp.type ~ " $name = $*LAST_TEMP;\n";
$*LAST_TEMP := $name;
return $code;
}
Expand Down Expand Up @@ -257,7 +301,7 @@ our multi sub cs_for(DNST::ArrayLiteral $al) {

# Code-gen the array.
$*LAST_TEMP := get_unique_id('arr');
return $code ~ " var $*LAST_TEMP = new " ~ $al.type ~ '[] {' ~
return $code ~ " " ~ $al.type ~ "[] $*LAST_TEMP = new " ~ $al.type ~ '[] {' ~
pir::join(',', @item_names) ~ "};\n";
}

Expand All @@ -276,7 +320,7 @@ our multi sub cs_for(DNST::DictionaryLiteral $dl) {

# Code-gen the dictionary.
$*LAST_TEMP := get_unique_id('dic');
return $code ~ " var $*LAST_TEMP = new Dictionary<" ~
return $code ~ " Dictionary<" ~ $dl.key_type ~ ', ' ~ $dl.value_type ~ "> $*LAST_TEMP = new Dictionary<" ~
$dl.key_type ~ ', ' ~ $dl.value_type ~ '>() { ' ~
pir::join(',', @items) ~ " };\n";
}
Expand Down
12 changes: 8 additions & 4 deletions dotnet/compiler/PAST2DNSTCompiler.pm
Expand Up @@ -353,7 +353,8 @@ our multi sub dnst_for(PAST::Block $block) {

# Wrap in block prelude/postlude.
$result.push(DNST::Temp.new(
:name('C'), :type('var'),
:name('C'), :type('Context'),
# :name('C'), :type('var'),
DNST::New.new( :type('Context'), "StaticBlockInfo[$our_sbi]", "TC.CurrentContext", "Capture" )
));
$result.push(DNST::Bind.new( 'TC.CurrentContext', 'C' ));
Expand Down Expand Up @@ -479,13 +480,15 @@ our multi sub dnst_for(PAST::Op $op) {

# Invocant.
my $inv := DNST::Temp.new(
:name(get_unique_id('inv')), :type('var'),
:name(get_unique_id('inv')), :type('RakudoObject'),
# :name(get_unique_id('inv')), :type('var'),
dnst_for(@args.shift)
);

# Method lookup.
my $callee := DNST::Temp.new(
:name(get_unique_id('callee')), :type('var'),
:name(get_unique_id('callee')), :type('RakudoObject'),
# :name(get_unique_id('callee')), :type('var'),
DNST::MethodCall.new(
:on($inv.name), :name('STable.FindMethod'), :type('RakudoObject'),
'TC',
Expand Down Expand Up @@ -544,7 +547,8 @@ our multi sub dnst_for(PAST::Op $op) {
}
$callee := dnst_for(@args.shift);
}
$callee := DNST::Temp.new( :name(get_unique_id('callee')), :type('var'), $callee );
$callee := DNST::Temp.new( :name(get_unique_id('callee')), :type('RakudoObject'), $callee );
# $callee := DNST::Temp.new( :name(get_unique_id('callee')), :type('var'), $callee );

# How is capture formed?
my $capture := DNST::MethodCall.new(
Expand Down
1 change: 1 addition & 0 deletions dotnet/compiler/try.sh
Expand Up @@ -2,6 +2,7 @@
# this version of try for use with Mono 2.4 on Linux
cp ../runtime/bin/Debug/RakudoRuntime.dll .
make
rm ./RakudoOutput.exe 2> /dev/null
parrot compile.pir $1 > RakudoOutput.cs
gmcs -nowarn:162,168,219 RakudoOutput.cs /reference:RakudoRuntime.dll
echo ---
Expand Down

0 comments on commit 11dbee6

Please sign in to comment.