add export block and ability to load multiple files
This commit is contained in:
parent
f06bf14b52
commit
8d19767c98
13 changed files with 439 additions and 245 deletions
47
lt-stdlib/color.lt
Normal file
47
lt-stdlib/color.lt
Normal file
|
@ -0,0 +1,47 @@
|
|||
export {
|
||||
let morph-rgb-to-hsv = λ{
|
||||
{
|
||||
red: ℝ_0,1 ~ ℤ_256 ~ machine.UInt64;
|
||||
green: ℝ_0,1 ~ ℤ_256 ~ machine.UInt64;
|
||||
blue: ℝ_0,1 ~ ℤ_256 ~ machine.UInt64;
|
||||
} : <Color sRGB>
|
||||
~ RGB
|
||||
~ <Vec3 ℝ_0,1 ~ ℤ_256 ~ machine.UInt64>;
|
||||
/*
|
||||
::> Color
|
||||
~ HSV
|
||||
~ {
|
||||
hue: Angle
|
||||
~ Degrees
|
||||
~ ℝ_0,360
|
||||
~ ℤ_360
|
||||
~ machine.UInt64 ;
|
||||
|
||||
saturation: ℝ_0,1 ~ ℤ_256 ~ machine.UInt64 ;
|
||||
value: ℝ_0,1 ~ ℤ_256 ~ machine.UInt64 ;
|
||||
}
|
||||
~ <Vec3 machine.UInt64>
|
||||
*/
|
||||
} ↦ {
|
||||
let channel_max = int-max (int-max red green) blue;
|
||||
let channel_min = int-min (int-min red green) blue;
|
||||
|
||||
/* value */
|
||||
channel_max;
|
||||
|
||||
/* saturation */
|
||||
i/ (i* 255 (i- channel_max channel_min)) channel_max;
|
||||
|
||||
/* hue */
|
||||
i% (i/ (i* 60
|
||||
if( int-eq channel_max red ) { i+ (i* 0 255) (i- green blue); }
|
||||
else {
|
||||
if( int-eq channel_max green ) { i+ (i* 2 255) (i- blue red); }
|
||||
else { i+ (i* 4 255) (i- red green); };
|
||||
}
|
||||
)
|
||||
(i- channel_max channel_min)
|
||||
)
|
||||
360;
|
||||
};
|
||||
}
|
28
lt-stdlib/euclidean.lt
Normal file
28
lt-stdlib/euclidean.lt
Normal file
|
@ -0,0 +1,28 @@
|
|||
|
||||
/* Integer Math
|
||||
*/
|
||||
|
||||
export {
|
||||
/* Euclidean Algorithm to calculate greatest common divisor
|
||||
*/
|
||||
let gcd = λ{
|
||||
a : ℤ ~ machine.Int64;
|
||||
b : ℤ ~ machine.Int64;
|
||||
} ↦ {
|
||||
while( b ) {
|
||||
let tmp = i% a b;
|
||||
! a b;
|
||||
! b tmp;
|
||||
}
|
||||
a;
|
||||
};
|
||||
|
||||
/* least common multiple
|
||||
*/
|
||||
let lcm = λ{
|
||||
a : ℤ ~ machine.Int64;
|
||||
b : ℤ ~ machine.Int64;
|
||||
} ↦ i* (int-abs a) (i/ (int-abs b) (gcd a b));
|
||||
|
||||
};
|
||||
|
18
lt-stdlib/int.lt
Normal file
18
lt-stdlib/int.lt
Normal file
|
@ -0,0 +1,18 @@
|
|||
|
||||
|
||||
/* Two's complement Signed Integers
|
||||
*/
|
||||
|
||||
export {
|
||||
let int-sign = λx:ℤ~machine.Int64 ↦ bit-and (bit-shr x 63) 1;
|
||||
let int-neg = λx:ℤ~machine.Int64 ↦ i+ (bit-neg x) 1;
|
||||
let int-abs = λx:ℤ~machine.Int64 ↦ if( int-sign x ) { int-neg x; } else { x; };
|
||||
let int-lt = λ{ a:ℤ~machine.Int64; b:ℤ~machine.Int64; } ↦ int-sign (i- a b);
|
||||
let int-gt = λ{ a:ℤ~machine.Int64; b:ℤ~machine.Int64; } ↦ int-sign (i- b a);
|
||||
let int-eq = λ{ a:ℤ~machine.Int64; b:ℤ~machine.Int64; } ↦ if (bit-xor a b) { 0; } else { 1; };
|
||||
let int-lte = λ{ a:ℤ~machine.Int64; b:ℤ~machine.Int64; } ↦ bit-or (int-lt a b) (int-eq a b);
|
||||
let int-gte = λ{ a:ℤ~machine.Int64; b:ℤ~machine.Int64; } ↦ bit-or (int-gt a b) (int-eq a b);
|
||||
let int-min = λ{ a:ℤ~machine.Int64; b:ℤ~machine.Int64; } ↦ if( int-lt a b ) { a; } else { b; };
|
||||
let int-max = λ{ a:ℤ~machine.Int64; b:ℤ~machine.Int64; } ↦ if( int-gt a b ) { a; } else { b; };
|
||||
};
|
||||
|
63
lt-stdlib/posint.lt
Normal file
63
lt-stdlib/posint.lt
Normal file
|
@ -0,0 +1,63 @@
|
|||
|
||||
|
||||
/* Positional Integer
|
||||
*/
|
||||
export {
|
||||
let fmt-uint-radix = λ{
|
||||
radix : ℕ ~ ℤ_2^64 ~ machine.UInt64;
|
||||
x : ℕ ~ ℤ_2^64 ~ machine.UInt64;
|
||||
} ↦ {
|
||||
if( x ) {
|
||||
while( x ) {
|
||||
let digit = (i% x radix);
|
||||
|
||||
if( int-lt digit 10 ) {
|
||||
i+ '0' digit;
|
||||
} else {
|
||||
i+ (i- 'a' 10) digit;
|
||||
};
|
||||
! x (i/ x radix);
|
||||
}
|
||||
} else {
|
||||
'0';
|
||||
};
|
||||
};
|
||||
|
||||
let uint-machine-to-posint =
|
||||
λ{
|
||||
radix: ℕ ~ ℤ_2^64 ~ machine.UInt64;
|
||||
value: ℕ ~ ℤ_2^64 ~ machine.UInt64;
|
||||
}
|
||||
/*
|
||||
::> ℕ
|
||||
~ <PosInt radix BigEndian>
|
||||
~ <Seq <Digit radix>
|
||||
~ ℤ_radix
|
||||
~ ℤ_2^64
|
||||
~ machine.UInt64>
|
||||
~ <LengthPrefixedArray machine.UInt64>
|
||||
*/
|
||||
↦ {
|
||||
let len = 0;
|
||||
while( value ) {
|
||||
/* push digit to sequence on stack */
|
||||
i% value radix;
|
||||
! value (i/ value radix);
|
||||
! len (i+ len 1);
|
||||
}
|
||||
/* push length of sequence to stack */
|
||||
len;
|
||||
};
|
||||
|
||||
let fmt-int-radix = λ{
|
||||
radix: ℕ ~ ℤ_2^64 ~ machine.UInt64;
|
||||
x : ℤ ~ machine.Int64;
|
||||
} ↦ {
|
||||
fmt-uint-radix radix (int-abs x);
|
||||
if( int-sign x ) { '-'; };
|
||||
};
|
||||
|
||||
let fmt-uint = λx:ℕ ↦ fmt-uint-radix 10 x;
|
||||
let fmt-int = λx:ℤ ↦ fmt-int-radix 10 x;
|
||||
}
|
||||
|
45
lt-stdlib/ratio.lt
Normal file
45
lt-stdlib/ratio.lt
Normal file
|
@ -0,0 +1,45 @@
|
|||
export {
|
||||
/* Implementation of Rational Numbers
|
||||
*/
|
||||
|
||||
let ratio-scale = λ{
|
||||
{p:ℕ; q:ℕ;} : ℚ ~ <Ratio ℕ~machine.UInt64> ;
|
||||
n : ℕ ~ machine.UInt64 ;
|
||||
} ↦ {
|
||||
i* q n;
|
||||
i* p n;
|
||||
};
|
||||
|
||||
let ratio-normalize = λ{
|
||||
p: ℤ~machine.Int64;
|
||||
q: ℤ~machine.Int64;
|
||||
} : ℚ ~ <Ratio ℤ~machine.Int64>
|
||||
↦ {
|
||||
let s = gcd p q;
|
||||
i/ q s;
|
||||
i/ p s;
|
||||
};
|
||||
|
||||
let ratio-add = λ{
|
||||
{ap:ℕ; aq:ℕ;}: ℚ ~ <Ratio ℕ ~ ℤ_2^64 ~ machine.UInt64> ;
|
||||
{bp:ℕ; bq:ℕ;}: ℚ ~ <Ratio ℕ ~ ℤ_2^64 ~ machine.UInt64> ;
|
||||
} ↦ {
|
||||
let l = lcm aq bq;
|
||||
let as = i/ l aq;
|
||||
let bs = i/ l bq;
|
||||
|
||||
i* aq as;
|
||||
i+ (i* ap as) (i* bp bs);
|
||||
};
|
||||
|
||||
let ratio-mul = λ{
|
||||
{ap:ℤ; aq:ℤ;}: ℚ ~ <Ratio ℤ ~ ℤ_2^64 ~ machine.Int64> ;
|
||||
{bp:ℤ; bq:ℤ;}: ℚ ~ <Ratio ℤ ~ ℤ_2^64 ~ machine.Int64> ;
|
||||
} ↦ ratio-normalize (i* ap bp) (i* aq bq);
|
||||
|
||||
|
||||
let fmt-ratio = λ{ p:ℤ; q:ℤ; }: ℚ~<Ratio ℤ> ↦ {
|
||||
fmt-int q;':';fmt-int p;
|
||||
};
|
||||
}
|
||||
|
12
lt-stdlib/stdio.lt
Normal file
12
lt-stdlib/stdio.lt
Normal file
|
@ -0,0 +1,12 @@
|
|||
export {
|
||||
/* output nullterminated string directly from datastack
|
||||
*/
|
||||
let print-nullterm =
|
||||
λ{} : < Seq Char~Ascii~machine.Word >
|
||||
~ < NullTerminatedArray machine.Word >
|
||||
↦ {
|
||||
while(dup) { emit; }
|
||||
drop;
|
||||
};
|
||||
}
|
||||
|
23
lt-stdlib/vec3i.lt
Normal file
23
lt-stdlib/vec3i.lt
Normal file
|
@ -0,0 +1,23 @@
|
|||
|
||||
export {
|
||||
/* Vec3i
|
||||
*/
|
||||
let vec3i-add = λ{
|
||||
{ ax:ℤ_2^64; ay:ℤ_2^64; az:ℤ_2^64; } : <Vec3 ℤ_2^64~machine.Int64>;
|
||||
{ bx:ℤ_2^64; by:ℤ_2^64; bz:ℤ_2^64; } : <Vec3 ℤ_2^64~machine.Int64>;
|
||||
} ↦ {
|
||||
i+ az bz;
|
||||
i+ ay by;
|
||||
i+ ax bx;
|
||||
};
|
||||
|
||||
let fmt-vec3i =
|
||||
λ{ x:ℤ_2^64; y:ℤ_2^64; z:ℤ_2^64; } : <Vec3 ℤ_2^64~machine.Int64>
|
||||
↦ {
|
||||
'}';
|
||||
fmt-int z; '='; 'z'; ' '; ';';
|
||||
fmt-int y; '='; 'y'; ' '; ';';
|
||||
fmt-int x; '='; 'x'; '{';
|
||||
};
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue