71 lines
1.2 KiB
Text
71 lines
1.2 KiB
Text
|
|
|||
|
type Vec = ΛT ↦ Struct {
|
|||
|
len : ℤ_2^64 ~ machine.UInt64 ~ machine.Word ;
|
|||
|
capacity : ℤ_2^64 ~ machine.UInt64 ~ machine.Word ;
|
|||
|
data : <RefMut T> ~ machine.Address ~ machine.UInt64 ~ machine.Word ;
|
|||
|
};
|
|||
|
|
|||
|
let yellow:Color~RGB~Vec3i = {
|
|||
|
0;
|
|||
|
220;
|
|||
|
220;
|
|||
|
};
|
|||
|
|
|||
|
let fn = λx:ℤ ↦ ℤ:{
|
|||
|
3;
|
|||
|
};
|
|||
|
|
|||
|
let swap = λ{x;y;}:{T;T;} ↦ ℤ:{x;y;}
|
|||
|
|
|||
|
let n : ℤ
|
|||
|
~ℤ_2^64
|
|||
|
~machine.UInt64
|
|||
|
~machine.Word
|
|||
|
=
|
|||
|
ℤ
|
|||
|
~<PosInt 16 BigEndian>
|
|||
|
~<Seq <Digit 16>
|
|||
|
~ Char >
|
|||
|
: CF03;
|
|||
|
|
|||
|
λ{} -> {x y} : <Vec2 ℤ>
|
|||
|
↦ {
|
|||
|
10;
|
|||
|
5;
|
|||
|
}
|
|||
|
|
|||
|
let Vec.new = ΛT ↦ λ{} ↦ self:<Vec T>{
|
|||
|
let sizeofT = 1;
|
|||
|
!self <Vec T>{
|
|||
|
|
|||
|
};
|
|||
|
|
|||
|
!self.len 0;
|
|||
|
!self.capacity 10;
|
|||
|
!self.data malloc (i* self.capacity sizeofT);
|
|||
|
};
|
|||
|
|
|||
|
let Vec.drop = ΛT ↦ λself:<Vec T> ↦ {
|
|||
|
mfree self.data;
|
|||
|
};
|
|||
|
|
|||
|
let vec-get =
|
|||
|
Λ T
|
|||
|
↦ λ vec: <Vec T>
|
|||
|
↦ λ idx: ℤ_2^64 ~ machine.UInt64 ~ machine.Word
|
|||
|
↦ T {
|
|||
|
if( int-lt idx vec.len ) {
|
|||
|
let j = 0;
|
|||
|
let sizeofT = 1; /* todo: <sizeof T> */
|
|||
|
|
|||
|
while( int-lt j sizeofT ) {
|
|||
|
@ (i+ vec.data
|
|||
|
(i+ (i* idx sizeofT) j));
|
|||
|
! j (i+ j 1);
|
|||
|
};
|
|||
|
} else {
|
|||
|
print-nullterm 'o''u''t'' ''o''f'' ''b''o''u''n''d''s''\n''\0'
|
|||
|
};
|
|||
|
};
|
|||
|
|