read morphism body definitions from morphism-base file and generate instantiations based on type-variable substitutions
This commit is contained in:
parent
3f4a99ad79
commit
cea1f36e63
8 changed files with 244 additions and 255 deletions
morphisms/morphism-base
|
@ -1,31 +1,27 @@
|
|||
morph_digit_as_char_to_uint8 (Radix:ℤ_16)
|
||||
<Digit Radix> ~ Char ~ Ascii ~ x86.UInt8
|
||||
--> <Digit Radix> ~ x86.UInt8
|
||||
@lib/libmorph-posint.so:src/posint.c
|
||||
|
||||
morph_digit_as_uint8_to_char (Radix:ℤ_16)
|
||||
<Digit Radix> ~ x86.UInt8
|
||||
--> <Digit Radix> ~ Char ~ Ascii ~ x86.UInt8
|
||||
@lib/libmorph-posint.so:src/posint.c
|
||||
|
||||
morph_digit_as_char_to_uint64 (Radix:ℤ_16)
|
||||
<Digit Radix> ~ Char ~ Ascii ~ x86.UInt8
|
||||
--> <Digit Radix> ~ x86.UInt64
|
||||
@lib/libmorph-posint.so:src/posint.c
|
||||
|
||||
morph_digit_as_uint64_to_char (Radix:ℤ_16)
|
||||
<Digit Radix> ~ x86.UInt64
|
||||
--> <Digit Radix> ~ Char ~ Ascii ~ x86.UInt8
|
||||
@lib/libmorph-posint.so:src/posint.c
|
||||
|
||||
morph_posint_radix_le (SrcRadix:ℤ, DstRadix:ℤ)
|
||||
ℕ
|
||||
~ <PosInt SrcRadix LittleEndian>
|
||||
~ <Seq~<LengthPrefix x86.UInt64> <Digit SrcRadix>~x86.UInt64>
|
||||
--> ℕ
|
||||
~ <PosInt DstRadix LittleEndian>
|
||||
~ <Seq~<LengthPrefix x86.UInt64> <Digit DstRadix>~x86.UInt64>
|
||||
@lib/libmorph-posint.so:src/posint.c
|
||||
~ <Seq~<LenghtPrefix x86.UInt64> <Digit DstRadix>~x86.UInt64>
|
||||
```
|
||||
uint64_t value = 0;
|
||||
|
||||
for( uint64_t i = 0; i < src->len; ++i ) {
|
||||
value *= SrcRadix;
|
||||
value += src->items[src->len - i - 1];
|
||||
}
|
||||
|
||||
length_prefix_uint64_array_clear( dst );
|
||||
|
||||
while( value > 0 ) {
|
||||
length_prefix_uint64_array_push( dst, value % DstRadix );
|
||||
value /= DstRadix;
|
||||
}
|
||||
|
||||
return 0;
|
||||
```
|
||||
|
||||
morph_posint_radix_be (SrcRadix:ℤ, DstRadix:ℤ)
|
||||
ℕ
|
||||
|
@ -34,7 +30,29 @@ morph_posint_radix_be (SrcRadix:ℤ, DstRadix:ℤ)
|
|||
--> ℕ
|
||||
~ <PosInt DstRadix BigEndian>
|
||||
~ <Seq~<LengthPrefix x86.UInt64> <Digit DstRadix>~x86.UInt64>
|
||||
@lib/libmorph-posint.so:src/posint.c
|
||||
```
|
||||
uint64_t value = 0;
|
||||
|
||||
for( uint64_t i = 0; i < src->len; ++i ) {
|
||||
value *= SrcRadix;
|
||||
value += src->items[i];
|
||||
}
|
||||
|
||||
uint64_t v = value;
|
||||
dst->len = 0;
|
||||
while( v ) {
|
||||
dst->len++;
|
||||
v /= DstRadix;
|
||||
}
|
||||
|
||||
uint64_t i = dst->len;
|
||||
while( value > 0 ) {
|
||||
dst->items[--i] = ( dst, value % DstRadix );
|
||||
value /= DstRadix;
|
||||
}
|
||||
|
||||
return 0;
|
||||
```
|
||||
|
||||
morph_posint_endianness (Radix:ℤ)
|
||||
ℕ
|
||||
|
@ -43,7 +61,9 @@ morph_posint_endianness (Radix:ℤ)
|
|||
--> ℕ
|
||||
~ <PosInt Radix BigEndian>
|
||||
~ <Seq~<LengthPrefix x86.UInt64> <Digit Radix> ~ x86.UInt64>
|
||||
@lib/libmorph-posint.so:src/posint.c
|
||||
```
|
||||
return length_prefix_uint64_array_reverse( src, dst );
|
||||
```
|
||||
|
||||
morph_posint_endianness (Radix:ℤ)
|
||||
ℕ
|
||||
|
@ -52,4 +72,6 @@ morph_posint_endianness (Radix:ℤ)
|
|||
--> ℕ
|
||||
~ <PosInt Radix LittleEndian>
|
||||
~ <Seq~<LengthPrefix x86.UInt64> <Digit Radix> ~ x86.UInt64>
|
||||
@lib/libmorph-posint.so:src/posint.c
|
||||
```
|
||||
return length_prefix_uint64_array_reverse( src, dst );
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue