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
}
понедельник, 24 января 2011 г.
среда, 22 декабря 2010 г.
YAR: Added explicit type cast
a:integer;
d:double;
begin
...
d:=a; //Implicit
d:=double(a); //Explicit
But! I am still thinking about the syntax for declaring new implicit or explicit operators: Delphi or Free Pascal like. :)
d:double;
begin
...
d:=a; //Implicit
d:=double(a); //Explicit
But! I am still thinking about the syntax for declaring new implicit or explicit operators: Delphi or Free Pascal like. :)
YAR: Enhance syntax of [ ] array operator
Now support [.. , ..]
A sample
integerarrarr:Myrecord[6][3][5][3][3][6];
integerarrarr[1,1,2][1][1,2].c[1]:=abc().a;
A sample
integerarrarr:Myrecord[6][3][5][3][3][6];
integerarrarr[1,1,2][1][1,2].c[1]:=abc().a;
вторник, 7 декабря 2010 г.
YAR and static arrays
Working on support static arrays in YAR.
The shortest sample
program Helloworld;
integerarr:integer[6];
begin
integerarr[2]:=1;
end
=>
.assembly extern mscorlib { auto }
.assembly project {}
.field public static int32* integerarr
.method static public void main() cil managed
{
.entrypoint
ldc.i4 28
localloc
stsfld int32* integerarr
ldsfld int32* integerarr
ldc.i4 2
ldc.i4 4
mul
add
ldc.i4 1
stind.i4
ret
}
The shortest sample
program Helloworld;
integerarr:integer[6];
begin
integerarr[2]:=1;
end
=>
.assembly extern mscorlib { auto }
.assembly project {}
.field public static int32* integerarr
.method static public void main() cil managed
{
.entrypoint
ldc.i4 28
localloc
stsfld int32* integerarr
ldsfld int32* integerarr
ldc.i4 2
ldc.i4 4
mul
add
ldc.i4 1
stind.i4
ret
}
воскресенье, 5 декабря 2010 г.
YAR Update: Importing external function
Yar supports now for
import external functions
sample
program Helloworld;
function importedfunc(var a:integer):integer;external library=mydll name=importfunc;
GField:integer;
begin
GField:=1;
write importedfunc(GField);
end
=>
.assembly extern mscorlib { auto }
.assembly project {}
.field public static int32 GField
.method static public void main() cil managed
{
.entrypoint
ldc.i4 1
stsfld int32 GField
ldsflda int32 GField
call int32 importedfunc(int32& a)
call void [mscorlib]System.Console::Write(int32)
ret
}
.method public static pinvokeimpl("mydll.dll" as "importfunc" winapi)
int32 importedfunc(int32& a) cil managed preservesig
{}
import external functions
sample
program Helloworld;
function importedfunc(var a:integer):integer;external library=mydll name=importfunc;
GField:integer;
begin
GField:=1;
write importedfunc(GField);
end
=>
.assembly extern mscorlib { auto }
.assembly project {}
.field public static int32 GField
.method static public void main() cil managed
{
.entrypoint
ldc.i4 1
stsfld int32 GField
ldsflda int32 GField
call int32 importedfunc(int32& a)
call void [mscorlib]System.Console::Write(int32)
ret
}
.method public static pinvokeimpl("mydll.dll" as "importfunc" winapi)
int32 importedfunc(int32& a) cil managed preservesig
{}
пятница, 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
}
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
}
понедельник, 8 ноября 2010 г.
Added @ and ^ operators
I have just added.
begin
pinteger:=@mr.c;
a:=pinteger^;
mr.c:=@a^;
end
=>
.entrypoint
ldsflda valuetype Myrecord mr
ldflda int32 Myrecord::c
stsfld int32* pinteger
ldsfld int32* pinteger
ldobj int32
stsfld int32 a
ldsflda valuetype Myrecord mr
ldsflda int32 a
ldobj int32
stfld int32 Myrecord::c
ret
begin
pinteger:=@mr.c;
a:=pinteger^;
mr.c:=@a^;
end
=>
.entrypoint
ldsflda valuetype Myrecord mr
ldflda int32 Myrecord::c
stsfld int32* pinteger
ldsfld int32* pinteger
ldobj int32
stsfld int32 a
ldsflda valuetype Myrecord mr
ldsflda int32 a
ldobj int32
stfld int32 Myrecord::c
ret
Подписаться на:
Сообщения (Atom)