diff --git a/lib-ltcore/src/runtime.rs b/lib-ltcore/src/runtime.rs index 048e462..1f64d90 100644 --- a/lib-ltcore/src/runtime.rs +++ b/lib-ltcore/src/runtime.rs @@ -13,8 +13,8 @@ pub fn init_runtime(linker: &mut Linker) -> Arc> { symbols.write().unwrap().declare_proc_parse( "dup", vec!["T"], - vec!["T~machine.Word"], - vec!["T~machine.Word", "T~machine.Word"], + vec!["machine.Word"], + vec!["machine.Word", "machine.Word"], ); /* drop topmost element @@ -30,7 +30,7 @@ pub fn init_runtime(linker: &mut Linker) -> Arc> { symbols.write().unwrap().declare_proc_parse( "emit", vec![], - vec!["Char~Unicode~ℤ_2^32~ℤ_2^64~machine.UInt64~machine.Word"], + vec!["Char~Unicode~ℤ_2^32~machine.Int64~machine.Word"], vec![], ); symbols.write().unwrap().declare_proc_parse( @@ -53,49 +53,54 @@ pub fn init_runtime(linker: &mut Linker) -> Arc> { symbols.write().unwrap().declare_proc_parse( "i+", vec![], - vec![ - "ℤ_2^64~machine.UInt64~machine.Word", - "ℤ_2^64~machine.UInt64~machine.Word", - ], - vec!["ℤ_2^64~machine.UInt64~machine.Word"], + vec!["machine.Int64","machine.Int64"], + vec!["machine.Int64"], + ); + symbols.write().unwrap().declare_proc_parse( + "u+", + vec![], + vec!["machine.UInt64","machine.UInt64"], + vec!["machine.UInt64"], ); symbols.write().unwrap().declare_proc_parse( "i-", vec![], - vec![ - "ℤ_2^64~machine.UInt64~machine.Word", - "ℤ_2^64~machine.UInt64~machine.Word", - ], - vec!["ℤ_2^64~machine::UInt64~machine.Word"], + vec!["machine.Int64","machine.Int64"], + vec!["machine.Int64"], + ); + symbols.write().unwrap().declare_proc_parse( + "u-", + vec![], + vec!["machine.UInt64","machine.UInt64"], + vec!["machine.UInt64"], ); symbols.write().unwrap().declare_proc_parse( "i*", vec![], vec![ - "ℤ_2^64~machine.UInt64~machine.Word", - "ℤ_2^64~machine.UInt64~machine.Word", + "machine.Int64~machine.Word", + "machine.Int64~machine.Word", ], - vec!["ℤ_2^64~machine.UInt64~machine.Word"], + vec!["machine.Int64~machine.Word"], ); symbols.write().unwrap().declare_proc_parse( "i/", vec![], vec![ - "ℤ_2^64~machine.UInt64~machine.Word", - "ℤ_2^64~machine.UInt64~machine.Word", + "machine.Int64~machine.Word", + "machine.Int64~machine.Word", ], - vec!["ℤ_2^64~machine.UInt64~machine.Word"], + vec!["machine.Int64~machine.Word"], ); symbols.write().unwrap().declare_proc_parse( "i%", vec![], vec![ - "ℤ_2^64~machine.UInt64~machine.Word", - "ℤ_2^64~machine.UInt64~machine.Word", + "machine.Int64~machine.Word", + "machine.Int64~machine.Word", ], - vec!["ℤ_2^64~machine.UInt64~machine.Word"], + vec!["machine.Int64~machine.Word"], ); - symbols.write().unwrap().declare_proc_parse( "f+", vec![], @@ -146,6 +151,9 @@ pub fn init_runtime(linker: &mut Linker) -> Arc> { vec!["ℝ~machine.f64~machine.Word"], ); + linker.add_procedure("u+", tisc::Assembler::new().inst(tisc::VM_Instruction::IntAdd).build()); + linker.add_procedure("u-", tisc::Assembler::new().inst(tisc::VM_Instruction::IntSub).build()); + linker.add_procedure("i+", tisc::Assembler::new().inst(tisc::VM_Instruction::IntAdd).build()); linker.add_procedure("i-", tisc::Assembler::new().inst(tisc::VM_Instruction::IntSub).build()); linker.add_procedure("i*", tisc::Assembler::new().inst(tisc::VM_Instruction::IntMul).build()); @@ -162,24 +170,24 @@ pub fn init_runtime(linker: &mut Linker) -> Arc> { symbols.write().unwrap().declare_proc_parse( "bit-neg", - vec![], vec!["machine.Word", "machine.Word"], vec!["machine.Word"], + vec![], vec!["machine.Word"], vec!["machine.Word"], ); symbols.write().unwrap().declare_proc_parse( "bit-and", vec![], vec!["machine.Word", "machine.Word"], vec!["machine.Word"], - ); + ); symbols.write().unwrap().declare_proc_parse( "bit-or", vec![], vec!["machine.Word", "machine.Word"], vec!["machine.Word"], - ); + ); symbols.write().unwrap().declare_proc_parse( "bit-xor", vec![], vec!["machine.Word", "machine.Word"], vec!["machine.Word"], ); - symbols.write().unwrap().declare_proc_parse( + symbols.write().unwrap().declare_proc_parse( "bit-shl", vec![], vec!["machine.Word", "machine.Word"], vec!["machine.Word"], - ); + ); symbols.write().unwrap().declare_proc_parse( "bit-shr", vec![], vec!["machine.Word", "machine.Word"], vec!["machine.Word"], @@ -217,12 +225,11 @@ pub fn init_runtime(linker: &mut Linker) -> Arc> { linker.add_procedure("!", tisc::Assembler::new().inst(tisc::VM_Instruction::Store).build()); - + let section_id = linker.add_static("data-frame-ptr", vec![0x1000]); symbols.write().unwrap().declare_static_parse( "data-frame-ptr", ">~machine.Address~machine.Word", ); - linker.add_static("data-frame-ptr", vec![0x1000]); symbols.write().unwrap().declare_proc_parse( "data-frame-set", diff --git a/lib-ltcore/src/symbols.rs b/lib-ltcore/src/symbols.rs index 2ced667..50b275e 100644 --- a/lib-ltcore/src/symbols.rs +++ b/lib-ltcore/src/symbols.rs @@ -324,7 +324,6 @@ impl Scope { } pub fn declare_static(&mut self, name: String, typ: laddertypes::TypeTerm, export: bool) { - eprintln!("add {} export {}", name, export); self.symbols.insert( name, SymbolDef::StaticRef { diff --git a/lib-ltcore/src/typing.rs b/lib-ltcore/src/typing.rs index 2a7b24a..83064db 100644 --- a/lib-ltcore/src/typing.rs +++ b/lib-ltcore/src/typing.rs @@ -163,7 +163,7 @@ impl LTExpr { ); // todo examine stack .. - + return if errors.len() == 0 { result_type = sugared_result_type.desugar(&mut *super_scope.write().unwrap()); @@ -355,7 +355,7 @@ impl Statement { Statement::Expr(expr) => { let t = expr.infer_type(scope)?; - let symb = expr.export_symbols(); + // let symb = expr.export_symbols(); // eprintln!("expr statement: import symbols from expr {:?}", symb); // scope.write().unwrap().import( symb ); @@ -384,4 +384,3 @@ impl Statement { } } } - diff --git a/lt-stdlib/angle.lt b/lt-stdlib/angle.lt index c29dbe0..e1eea22 100644 --- a/lt-stdlib/angle.lt +++ b/lt-stdlib/angle.lt @@ -1,4 +1,5 @@ export { +/* let angle-normalize = λ a : Angle ~ Degree @@ -16,4 +17,5 @@ export { ~ ℝ ~ machine.Float64 ↦ f/ a 360 ; +*/ } diff --git a/lt-stdlib/bool.lt b/lt-stdlib/bool.lt new file mode 100644 index 0000000..ebb18e4 --- /dev/null +++ b/lt-stdlib/bool.lt @@ -0,0 +1,31 @@ +/* + * + */ +export { + let bool-norm = + λ { x: Bool ~ machine.Word; } + ↦ if(x) { + (1 des machine.Word) as Bool; + } else { + (0 des machine.Word) as Bool; + }; + + let bool-neg = + λ { x: Bool ~ machine.Word; } + ↦ (bit-and (bit-neg (bool-norm x)) 1) as Bool; + + let bool-or = + λ { a: Bool ~ machine.Word; + b: Bool ~ machine.Word; } + ↦ (bit-or a b) as Bool ~ machine.Word; + + let bool-and = + λ{ a: Bool ~ machine.Word; + b: Bool ~ machine.Word; } + ↦ (bit-and (bool-norm a) (bool-norm b)) as Bool ~ machine.Word; + + let bool-xor = + λ{ a: Bool ~ machine.Word; + b: Bool ~ machine.Word; } + ↦ (bit-xor (bool-norm a) (bool-norm b)) as Bool ~ machine.Word; +} diff --git a/lt-stdlib/color.lt b/lt-stdlib/color.lt deleted file mode 100644 index 906ecca..0000000 --- a/lt-stdlib/color.lt +++ /dev/null @@ -1,63 +0,0 @@ -export { - /* todo: allow machine.UInt8 in the VM - */ - let morph-rgb-to-hsv = λ{ - { - red: ℝ_[0,1] ~ ℤ_256 ~ machine.UInt64; - green: ℝ_[0,1] ~ ℤ_256 ~ machine.UInt64; - blue: ℝ_[0,1] ~ ℤ_256 ~ machine.UInt64; - } : - ~ RGB - ~ ; - } - /* - -> - ~ HSV - ~ { - hue: Angle ~ Degrees ~ ℝ_0,360 ~ ℤ_360 ~ machine.UInt64 ; - sat: ℝ_[0,1] ~ ℤ_256 ~ machine.UInt64; - val: ℝ_[0,1] ~ ℤ_256 ~ machine.UInt64; - } - ~ - */ - ↦ { - let channel_max = int-max (int-max red green) blue; - let channel_min = int-min (int-min red green) blue; - let channel_delta = i- channel_max channel_min; - - /* value */ - channel_max; - - /* saturation */ - i/ (i* 255 channel_delta) 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); }; - } - ) - channel_delta - ) - 360; - }; - -/* - let get-srgb-luminance = - -> ℝ_[0,1] ~ machine.Float64 - λ{r:ℝ,g:ℝ,b:ℝ} : ~ RGB ~ - ↦ - { - machine.Float64.mul red 0.22248840; - machine.Float64.mul green 0.71690369; - machine.Float64.mul blue 0.06060791; - machine.Float64.add; - machine.Float64.add; - -// add (add (mul r 0.2) (mul g 0.7)) (mul b 0.6) - }; -*/ -} - diff --git a/lt-stdlib/complex.lt b/lt-stdlib/complex.lt deleted file mode 100644 index 4caba45..0000000 --- a/lt-stdlib/complex.lt +++ /dev/null @@ -1,10 +0,0 @@ -export { - let complex-magnitude = λ{ - { re: ℝ, im: ℝ } - : ℂ - ~ Cartesian - ~ - } -> ℝ ↦ { - - } -} diff --git a/lt-stdlib/euclidean.lt b/lt-stdlib/euclidean.lt index 21962cf..01d3425 100644 --- a/lt-stdlib/euclidean.lt +++ b/lt-stdlib/euclidean.lt @@ -3,25 +3,27 @@ */ export { + import "int.lt"; + /* Euclidean Algorithm to calculate greatest common divisor */ let gcd = λ{ - a : ℤ ~ machine.Int64; - b : ℤ ~ machine.Int64; + a : machine.Int64 ~ machine.Word; + b : machine.Int64 ~ machine.Word; } ↦ { - while( b ) { + while( int-gt b 0 ) { let tmp = i% a b; ! a b; ! b tmp; - } + }; a; }; /* least common multiple */ let lcm = λ{ - a : ℤ ~ machine.Int64; - b : ℤ ~ machine.Int64; + a : machine.Int64 ~ machine.Word; + b : machine.Int64 ~ machine.Word; } ↦ i* (int-abs a) (i/ (int-abs b) (gcd a b)); }; diff --git a/lt-stdlib/float.lt b/lt-stdlib/float.lt deleted file mode 100644 index c4e5e16..0000000 --- a/lt-stdlib/float.lt +++ /dev/null @@ -1,61 +0,0 @@ -export { - /* Platform Specific Types */ - type machine.Float16 = IEEE-754.half ~ ; - type machine.Float32 = IEEE-754.single ~ ; - type machine.Float64 = IEEE-754.double ~ ; - - overload + = λ{ - a:ℝ ~ machine.Float16 ; - b:ℝ ~ machine.Float16 ; - } -> ℝ ~ machine.Float16 ↦ { - machine.Float16.add a b; - }; - - overload * = λ{ - a:ℝ ~ machine.Float16 ; - b:ℝ ~ machine.Float16 ; - } -> ℝ ~ machine.Float16 ↦ { - machine.Float16.mul a b; - }; - - let Sign = enum { Positive; Negative; }; - let Sign.Positive : = 0; - let Sign.Negative : = 1; - - let softfloat16-mul = λ{ - { - a.sign: Sign - ~ - ; - a.exponent: ℤ_[-14,15] - ~ - ~ ℤ_32 - ~ - ~ ~Bit > - ~ - ; - a.significand: ℤ_2048 - ~ - ~ ~ Bit> - ~ - ; - } : ℝ - ~ IEEE-754.Half - ~ - ; - { - b.sign: ; - } : ℝ ~ IEEE-754.Half ~ ; - } -> result: ℝ ~ IEEE~754.Half ~ ↦ { - - /* 1. unify */ - - /* 2. add exponent */ - + a.exponent b.exponent; - - /* 3. normaize */ - - result.sign = bit-xor a.sign b.sign ; - } -} - diff --git a/lt-stdlib/image.lt b/lt-stdlib/image.lt deleted file mode 100644 index 36fd73a..0000000 --- a/lt-stdlib/image.lt +++ /dev/null @@ -1,138 +0,0 @@ -/* C++ */ - -template -struct Sample { - T value; -}; - -template<> struct Sample< uint8_t > { - constexpr uint8_t min = std::numeric_limits::min(); - constexpr uint8_t max = std::numeric_limits::max(); -}; -template<> struct Sample< uint16_t > { - constexpr uint16_t min = std::numeric_limits::min(); - constexpr uint16_t max = std::numeric_limits::max(); -}; -template<> struct Sample< uint32_t > { - constexpr uint32_t min = std::numeric_limits::min(); - constexpr uint32_t max = std::numeric_limits::max(); -}; -template<> struct Sample< float > { - constexpr float min = 0.0; - constexpr float max = 1.0; -}; -template<> struct Sample< double > { - constexpr double min = 0.0; - constexpr double max = 1.0; -}; - -template < typename T1, typename T2 > -void transform_sample( - Sample const & in, - Sample & out -) { - out.value = static_cast( in.value * static_cast(Sample::max) ) / Sample::min; -} - - -/* LT IR */ - -@isomorphism -transform_sample - :: Sample ~ <ℝ 0,1> ~ f64 - -> Sample ~ <ℝ 0,1> ~ ℤ_2^256 ~ u8 -transform_sample f = floor( f * 256.0 ) as ℤ_2^256 ~ u8 - -@isomorphism -transform_sample :: Sample ~ <ℝ 0,1> ~ ℤ_2^256 ~ u8 - -> Sample ~ <ℝ 0,1> ~ f64 -transform_sample i = (i as ℝ~f64) / 256.0 - -transform_sample :: Sample~ℝ~T1 -> ℝ~T2 -transform_sample v - - -void main() { - - // read Audio streams - for( unsigned i = 0; i < ) -} - - - - - -/* LT IR */ - -type Color~RGB = { r|red: ℝ_0,1; g|green: ℝ_0,1; b|blue: ℝ_0,1; } -type Color~HSL = { h|hue: ℝ_0,1; s|saturation: ℝ_0,1; l|lightness: ℝ_0,1; } - -validate <ℝ> :: f64 -> {} -validate x = {} - -morph :: Color~RGB -> Color~HSL -morph (r,g,b) = { - let h = .. TODO .. - ... - (h,s,l) -} - -morph :: ℝ_0,1 ~ f64 -> ℝ_0,1 ~ ℤ_256 -morph x = (x * 256.0) % 256 - -morph :: ℝ_0,1 ~ ℤ_256 -> ℝ_0,1 ~ f64 -morph x = (x as f64 / 256.0) - -infix * :: ℝ~f64 -> ℝ~f64 -> ℝ~f64 -infix * a b = f64.mul a b - -clamp :: ℝ -> ℝ -> ℝ -> ℝ -clamp minVal maxVal x = if x < minVal { minVal } - else if x > maxVal { maxVal } - else { x } - -saturate :: ℝ -> Color~HSL -> Color~HSL -saturate f {h,s,l} = { h, clamp(f*s, 0.0, 1.0), l } - -saturate_image :: ℝ -> [Color~HSL] -> [Color~HSL] -saturate_image f pixels = map saturate pixels - -{ - let width : ℕ = 4; - let height : ℕ = 2; - let pixels - : [ - [ - [ Color - ~RGB - ~[ ℝ_0,1 - ~ℤ_256 - ~ - ~[~Char] - ; 3] - ; width] - ~~~[Char] - ; height] - ~~~[Char] - = [ - [000000, 001122, 22ff33, ffe384], - [ff3344, abcdef, ffeebb, 44bb22] - ]; - - pixels = saturate_image 0.3 pixels - - let packed_buf = array_layout_rot - < - [[Color~RGB~[ℝ_0,1; 3]; width]; height], - [[Color; width]; height]; 3] - > - pixels; - -} - - - -brighten_image :: ℕ -> ℕ -> [Color] [[ Color~RGB~[ℝ~f64; 3]; width]; height] ) - - - diff --git a/lt-stdlib/int.lt b/lt-stdlib/int.lt index 45e8344..1dab4e7 100644 --- a/lt-stdlib/int.lt +++ b/lt-stdlib/int.lt @@ -1,18 +1,95 @@ - - /* 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; }; -}; + import "./lt-stdlib/bool.lt"; + let int-sign = + λ x: machine.Int64~machine.Word + ↦ (bit-and (bit-shr (x des machine.Word) 63) 1) as Bool; + + let int-neg = + λ x: machine.Int64~machine.Word + ↦ i+ ((bit-neg x) as machine.Int64) 1; + + let int-abs = + λ x: machine.Int64~machine.Word + ↦ if( int-sign x ) { int-neg x; } else { x; }; + + let int-lt = + λ{ a: machine.Int64~machine.Word; + b: machine.Int64~machine.Word; } + ↦ int-sign (i- a b); + + let int-gt = + λ{ a: machine.Int64~machine.Word; + b: machine.Int64~machine.Word; } + ↦ int-sign (i- b a); + + let int-neq = + λ{ a: machine.Int64~machine.Word; + b: machine.Int64~machine.Word; } + ↦ (bit-xor a b) as Bool; + + let int-eq = + λ{ a: machine.Int64~machine.Word; + b: machine.Int64~machine.Word; } + ↦ bool-neg (int-neq a b); + + let int-lte = + λ{ a: machine.Int64~machine.Word; + b: machine.Int64~machine.Word; } + ↦ bool-or (int-lt a b) (int-eq a b); + + let int-gte = + λ{ a: machine.Int64~machine.Word; + b: machine.Int64~machine.Word; } + ↦ bool-or (int-gt a b) (int-eq a b); + + let int-min = + λ{ a: machine.Int64~machine.Word; + b: machine.Int64~machine.Word; } + ↦ if (int-lt a b) { a; } else { b; }; + + let int-max = + λ{ a:machine.Int64~machine.Word; + b:machine.Int64~machine.Word; } + ↦ if (int-gt a b) { a; } else { b; }; + +/* + type machine.UInt64 = ~ machine.Word; + impl ℤ_2^64 for machine.UInt64 { + let + = machine.UInt64.add; + let - = machine.UInt64.sub; + let * = machine.UInt64.mul; + let / = machine.UInt64.div; + let % = machine.UInt64.rem; + }; + + type machine.Int64 = ~ machine.Word; + let machine.Int64.add = + λ{ a: machine.Int64; + b: machine.Int64; } + ↦ ((u+ ((a des machine.Word) as machine.UInt64) + ((b des machine.Word) as machine.UInt64)) + des machine.Word) as machine.Int64; + + type ℤ =~ ~ ~ℤ_2^64~machine.UInt64>; + impl <ℤ -2^63-1 +2^63> for { + let + = machine.Int64.add; + let - = machine.Int64.sub; + let * = machine.Int64.mul; + let / = machine.Int64.div; + let % = machine.Int64.rem; + }; +*/ +/* + let int-onescomplement-neg = + λ x : <ℤ -2^63 +2^63> ~ ~ machine.Word + ↦ (bit-neg x) as <ℤ -2^63 +2^63> ~ ; + + let int-twoscomplement-neg = + λ x : <ℤ -2^63-1 +2^63> ~ ~ machine.Word + ↦ (i+ 1 ((bit-neg x) as machine.Int64)) as <ℤ -2^63-1 +2^63>; +*/ + +}; diff --git a/lt-stdlib/makefile b/lt-stdlib/makefile new file mode 100644 index 0000000..80f1934 --- /dev/null +++ b/lt-stdlib/makefile @@ -0,0 +1,11 @@ + +TARGETS=$(shell find -name '*.lt' | sed -E 's~\.lt~\.o~') + +all: $(TARGETS) + +%.o: %.lt + ltcc $< -o target/$@ + +clean: + cd target && rm $(TARGETS) + diff --git a/lt-stdlib/posint.lt b/lt-stdlib/posint.lt deleted file mode 100644 index 3b036b7..0000000 --- a/lt-stdlib/posint.lt +++ /dev/null @@ -1,63 +0,0 @@ - - -/* 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; - } - /* - ::> ℕ - ~ - ~ - ~ ℤ_radix - ~ ℤ_2^64 - ~ 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; -} - diff --git a/lt-stdlib/ratio.lt b/lt-stdlib/ratio.lt index f0d9517..2ed9034 100644 --- a/lt-stdlib/ratio.lt +++ b/lt-stdlib/ratio.lt @@ -1,19 +1,30 @@ export { + import "int.lt"; + import "euclidean.lt"; + /* Implementation of Rational Numbers */ + let ratio-sign = λ{ + p: machine.Int64 ~ machine.Word; + q: machine.Int64 ~ machine.Word; + } + ↦ bool-xor (int-sign p) (int-sign q); let ratio-scale = λ{ - {p:ℕ; q:ℕ;} : ℚ ~ ; - n : ℕ ~ machine.UInt64 ; + { + p: machine.Int64~machine.Word; + q: machine.Int64~machine.Word; + } : ℚ ~ ; + n : machine.Int64 ~machine.Word; } ↦ { i* q n; i* p n; }; let ratio-normalize = λ{ - p: ℤ~machine.Int64; - q: ℤ~machine.Int64; - } : ℚ ~ + p: machine.Int64 ~ machine.Word; + q: machine.Int64 ~ machine.Word; + } : ℚ ~ ↦ { let s = gcd p q; i/ q s; @@ -21,8 +32,14 @@ export { }; let ratio-add = λ{ - {ap:ℕ; aq:ℕ;}: ℚ ~ ; - {bp:ℕ; bq:ℕ;}: ℚ ~ ; + { + ap:machine.Int64~machine.Word; + aq:machine.Int64~machine.Word; + }: ℚ ~ ; + { + bp:machine.Int64~machine.Word; + bq:machine.Int64~machine.Word; + }: ℚ ~ ; } ↦ { let l = lcm aq bq; let a = i/ l aq; @@ -33,13 +50,20 @@ export { }; let ratio-mul = λ{ - {ap:ℤ; aq:ℤ;}: ℚ ~ ; - {bp:ℤ; bq:ℤ;}: ℚ ~ ; + { + ap:machine.Int64~machine.Word; + aq:machine.Int64~machine.Word; + }: ℚ ~ ; + { + bp:machine.Int64~machine.Word; + bq:machine.Int64~machine.Word; + }: ℚ ~ ; } ↦ ratio-normalize (i* ap bp) (i* aq bq); - +/* let fmt-ratio = λ{ p:ℤ; q:ℤ; }: ℚ~ ↦ { fmt-int q;':';fmt-int p; }; +*/ } diff --git a/lt-stdlib/stdio.lt b/lt-stdlib/stdio.lt index cfca557..742019a 100644 --- a/lt-stdlib/stdio.lt +++ b/lt-stdlib/stdio.lt @@ -1,6 +1,8 @@ export { + /* output nullterminated string directly from datastack */ + /* let print-nullterm = λ{} : < Seq Char~Ascii~machine.Word > ~ < NullTerminatedArray machine.Word > @@ -8,5 +10,6 @@ export { while(dup) { emit; } drop; }; + */ } diff --git a/lt-stdlib/string.lt b/lt-stdlib/string.lt deleted file mode 100644 index 3e620bc..0000000 --- a/lt-stdlib/string.lt +++ /dev/null @@ -1,41 +0,0 @@ - -#complexity O(n) -let strlen-nullterm = - λ str : &[Char~Ascii~machine::Word] - ~ & - ~ machine::Address - ~ machine::Word - -> ℤ - ~ ℤ_2^64 - ~ machine::UInt64 - ~ machine::Word -{ - let mut len = 0; - while ( @str ) { - ! len (i+ len 1); - ! str (i+ str 1); - } - len; -}; - -#complexity O(1) -let strlen-lenprefix = - λ str : &[Char~Ascii~machine::Word] - ~ & - ~ &{ - len : ℤ_2^64 - ~ machine::UInt64 - ~ machine::Word, - data : [machine::Word] - } - ~ machine::Address - ~ machine::Word - -> ℤ - ~ ℤ_2^64 - ~ machine::UInt64 - ~ machine::Word -{ - str.len -}; - - diff --git a/lt-stdlib/vec.lt b/lt-stdlib/vec.lt deleted file mode 100644 index e217df7..0000000 --- a/lt-stdlib/vec.lt +++ /dev/null @@ -1,70 +0,0 @@ - -type Vec = ΛT ↦ Struct { - len : ℤ_2^64 ~ machine.UInt64 ~ machine.Word ; - capacity : ℤ_2^64 ~ machine.UInt64 ~ machine.Word ; - data : ~ 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 - = - ℤ - ~ - ~ - ~ Char > - : CF03; - -λ{} -> {x y} : -↦ { - 10; - 5; -} - -let Vec.new = ΛT ↦ λ{} ↦ self:{ - let sizeofT = 1; - !self { - - }; - - !self.len 0; - !self.capacity 10; - !self.data malloc (i* self.capacity sizeofT); -}; - -let Vec.drop = ΛT ↦ λself: ↦ { - mfree self.data; -}; - -let vec-get = - Λ T - ↦ λ vec: - ↦ λ idx: ℤ_2^64 ~ machine.UInt64 ~ machine.Word - ↦ T { - if( int-lt idx vec.len ) { - let j = 0; - let sizeofT = 1; /* todo: */ - - 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' - }; - }; - diff --git a/lt-stdlib/vec3i.lt b/lt-stdlib/vec3i.lt deleted file mode 100644 index 09eb54c..0000000 --- a/lt-stdlib/vec3i.lt +++ /dev/null @@ -1,23 +0,0 @@ - -export { - /* Vec3i - */ - let vec3i-add = λ{ - { ax:ℤ_2^64; ay:ℤ_2^64; az:ℤ_2^64; } : ; - { bx:ℤ_2^64; by:ℤ_2^64; bz:ℤ_2^64; } : ; - } ↦ { - i+ az bz; - i+ ay by; - i+ ax bx; - }; - - let fmt-vec3i = - λ{ x:ℤ_2^64; y:ℤ_2^64; z:ℤ_2^64; } : - ↦ { - '}'; - fmt-int z; '='; 'z'; ' '; ';'; - fmt-int y; '='; 'y'; ' '; ';'; - fmt-int x; '='; 'x'; '{'; - }; -} - diff --git a/ltobjdump/src/main.rs b/ltobjdump/src/main.rs index 6e83928..46d9098 100644 --- a/ltobjdump/src/main.rs +++ b/ltobjdump/src/main.rs @@ -25,6 +25,7 @@ fn main() { println!("{}\n{}", source_path.bold().yellow(), "------------".green()); println!("{}", "Symbols".bold().white()); + obj_file.symbols.sort_by(|(n0,a0), (n1,a1)| a0.cmp(a1)); for (name, addr) in obj_file.symbols.iter() { println!("{} @ {}", name.bold().yellow(), format!("{:#010x}", addr).blue()); } @@ -47,4 +48,3 @@ fn main() { println!("{}\n", "============".green()); } } -