aggr64
auto aggr64 =
q{--- aggr64
// Test structs
struct Big {
i64 a;
i64 b;
}
struct Big2
{
u8 r;
u8 g;
u8 b;
u8 a;
u8 r2;
u8 g2;
u8 b2;
u8 a2;
}
struct Small {
i32 a;
i32 b;
}
struct Small3 {
i32 a;
i16 b;
i16 c;
}
struct Micro {
u8 a;
u8 b;
}
struct Mini {
Micro a;
Micro b;
}
struct Single_u8 { u8 a; }
struct Single_u16 { u16 a; }
struct Single_u32 { u32 a; }
struct Single_u64 { u64 a; }
// constructor is a function (expression) that returns struct type
// can compile it into create_aggregate instruction
// - default initialization of members
// + return result (by ptr)
Small returnSmallStruct() {
return Small(10, 42);
}
Single_u8 return_Single_u8_const () { return Single_u8 (42); }
Single_u16 return_Single_u16_const() { return Single_u16(42); }
Single_u32 return_Single_u32_const() { return Single_u32(42); }
Single_u64 return_Single_u64_const() { return Single_u64(42); }
Single_u8 return_Single_u8 (u8 val) { return Single_u8 (val); }
Single_u16 return_Single_u16(u16 val) { return Single_u16(val); }
Single_u32 return_Single_u32(u32 val) { return Single_u32(val); }
Single_u64 return_Single_u64(u64 val) { return Single_u64(val); }
// return aggregate by storing into hidden first parameter
Big returnBigStruct() {
return Big(10, 42);
}
Big returnBigStruct2() {
Big res = Big(10, 42);
return res;
}
Small buildSmallStruct(i32 a, i32 b) {
return Small(a, b);
}
Small3 buildSmall3Struct(i32 a, i16 b, i16 c) {
return Small3(a, b, c);
}
Mini buildMiniStruct(u8 a, u8 b, u8 c, u8 d) {
return Mini(Micro(a, b), Micro(c, d));
}
Big2 buildBig2Struct(u8 r, u8 g, u8 b, u8 a) {
return Big2(r, 42, b, 42, 42, g, 42, a);
}
Mini returnMiniStruct() {
return Mini(Micro(10, 42), Micro(120, 3));
}
// - pass as arg (fits in register)
Small passArgSmallStruct() {
return receiveArgSmallStruct(Small(10, 42));
}
Small passArgSmallStructVar(i32 x, i32 y) {
return receiveArgSmallStruct(Small(x+1, y+1));
}
// - pass as arg (fits in register, pushed)
Small passArgSmallStructPush() {
return receiveArgSmallStructPush(1,2,3,4,Small(10, 42));
}
// - pass as arg (by ptr)
Big passArgBigStruct() {
return receiveArgBigStruct(Big(10, 42));
}
// - pass as arg (by ptr, pushed)
Big passArgBigStructPush() {
return receiveArgBigStructPush(1,2,3,4,Big(10, 42));
}
// - receive parameter (fits in register)
Small receiveArgSmallStruct(Small arg) { return arg; }
Small receiveArgSmallStructPush(i32,i32,i32,i32,Small arg) { return arg; }
// - receive parameter (by ptr)
Big receiveArgBigStruct(Big arg) { return arg; }
Big receiveArgBigStructPush(i32,i32,i32,i32,Big arg) { return arg; }
// - pass member as arg (by ptr)
// - pass member as arg (fits in register)
// - receive result (fits in register)
// - receive result (by ptr)
// - return result (fits in register)
// - store in memory
// - load from memory
// - set member
// - get member
// - get member ptr
// - get ptr
};
tests aggregates
functionsvariables