lt-core/lt-stdlib/vec.lt
2024-06-11 15:17:58 +02:00

70 lines
1.2 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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'
};
};