вторник, 5 октября 2010 г.

Supporting dot operator for .NET backend

A sample

program Helloworld;

MyrecordStuff=record
a:integer;
b:integer;
c:boolean;
d:double;
f:double;
end;

Myrecord=record
a,b,c:integer;
private
d:integer;
f:integer;
public
pp:MyrecordStuff;
end;

function abc(var a:integer):integer;
begin
a:=1;
result:=5;
end;

function abc(var a:MyrecordStuff):integer;
begin
a.a:=7;
result:=5;
end;

a,b,c,d:Myrecord;
e:double;
f:integer;
begin
abc(a.a);
abc(a.pp.a);
e:=a.pp.d;
a.pp.a:=f;
a.pp.a:=a.pp.b;
write abc(a.pp);
write a.pp.a;
end

Generated MSIL code


.assembly extern mscorlib { auto }
.assembly project {}
.class public sealed MyrecordStuff extends [mscorlib]System.ValueType
{
.field public static int32 b
.field public static float64 f
.field public static int32 a
.field public static bool c
.field public static float64 d
}
.class public sealed Myrecord extends [mscorlib]System.ValueType
{
.field private static int32 f
.field private static int32 d
.field public static int32 b
.field public static int32 a
.field public static int32 c
.field public static valuetype MyrecordStuff pp
}
.field public static valuetype Myrecord b
.field public static float64 e
.field public static valuetype Myrecord a
.field public static int32 f
.field public static valuetype Myrecord c
.field public static valuetype Myrecord d

.method static public void main() cil managed
{
.entrypoint
ldsflda valuetype Myrecord a
ldflda int32 Myrecord::a
call int32 abc(int32& a)
pop
ldsflda valuetype Myrecord a
ldflda valuetype MyrecordStuff Myrecord::pp
ldflda int32 MyrecordStuff::a
call int32 abc(int32& a)
pop
ldsflda valuetype Myrecord a
ldflda valuetype MyrecordStuff Myrecord::pp
ldfld float64 MyrecordStuff::d
stsfld float64 e
ldsflda valuetype Myrecord a
ldflda valuetype MyrecordStuff Myrecord::pp
ldsfld int32 f
stfld int32 MyrecordStuff::a
ldsflda valuetype Myrecord a
ldflda valuetype MyrecordStuff Myrecord::pp
ldsflda valuetype Myrecord a
ldflda valuetype MyrecordStuff Myrecord::pp
ldfld int32 MyrecordStuff::b
stfld int32 MyrecordStuff::a
ldsflda valuetype Myrecord a
ldflda valuetype MyrecordStuff Myrecord::pp
call int32 abc( valuetype MyrecordStuff& a)
call void [mscorlib]System.Console::Write(int32)
ldsflda valuetype Myrecord a
ldflda valuetype MyrecordStuff Myrecord::pp
ldfld int32 MyrecordStuff::a
call void [mscorlib]System.Console::Write(int32)
ret
}

.method static public int32 abc(int32& a) cil managed
{
ldarg a
ldc.i4 1
stind.i4
ldc.i4 5
ret
}

.method static public int32 abc( valuetype MyrecordStuff& a) cil managed
{
ldarg a
ldc.i4 7
stfld int32 MyrecordStuff::a
ldc.i4 5
ret
}

Комментариев нет: