пятница, 3 декабря 2010 г.

YAR: records with methods

Syntax:

program Helloworld;

Myrecord=record
c:integer;
function abc(a:integer):integer;
begin
self.c:=a;
result:=self.c;
end;
end;

mr:Myrecord;

function Func(var a:Myrecord):integer;
begin
a.c:=4;
write mr.c;
a.abc(5);
write a.c;
result:=6;
end;

begin
Func(mr);
end

.NET BackEnd:

.assembly extern mscorlib { auto }
.assembly project {}
.class public sealed Myrecord extends [mscorlib]System.ValueType
{
.field public static int32 c
.method public instance int32 abc(int32 a) cil managed
{
ldarg.0
ldarg a
stfld int32 .this::c
ldarg.0
ldfld int32 .this::c
ret
}
}
.field public static valuetype Myrecord mr

.method static public void main() cil managed
{
.entrypoint
ldsflda valuetype Myrecord mr
call int32 Func( valuetype Myrecord& a)
pop
ret
}

.method static public int32 Func( valuetype Myrecord& a) cil managed
{
ldarg a
ldc.i4 4
stfld int32 Myrecord::c
ldsflda valuetype Myrecord mr
ldfld int32 Myrecord::c
call void [mscorlib]System.Console::Write(int32)
ldarg a
ldc.i4 5
call instance int32 Myrecord::abc(int32 a)
pop
ldarg a
ldfld int32 Myrecord::c
call void [mscorlib]System.Console::Write(int32)
ldc.i4 6
ret
}

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