понедельник, 24 января 2011 г.

Mutable string and pinned managed objects

Added String type to YAR

sample

program myprogram;

procedure abc();
a:string;
i:integer;
begin
a:='abcdefghij';
for i:=0 to a.length()-1 do a[i]:='1';
write a;
end;

begin
abc();
end

=>

.assembly extern mscorlib { auto }
.assembly project {}
.method public static void main() cil managed
{
.entrypoint
call void abc()
ret
}
.method public static void abc() cil managed
{
.locals init(int32 _autoname0,string pinned a,int32 i)
ldstr "abcdefghij"
stloc a
ldc.i4 0
stloc i
ldloc a
callvirt instance int32 [mscorlib]System.String::get_Length()
ldc.i4 1
sub
stloc _autoname0
Label0:
ldloc i
ldloc _autoname0
cgt
brtrue Label1
ldloc a
conv.i
call int32 [mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::get_OffsetToStringData()
add
ldloc i
ldc.i4 2
mul
add
conv.i
ldc.i4 49
stobj char
ldloc i
ldc.i4 1
add
stloc i
br Label0
Label1:
ldloc a
call void [mscorlib]System.Console::Write(string)
ret
}

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