Compare commits
2 commits
4c7302c4a3
...
f67f8c0118
Author | SHA1 | Date | |
---|---|---|---|
f67f8c0118 | |||
e29a5a3475 |
14 changed files with 266 additions and 332 deletions
|
@ -14,8 +14,8 @@ ldmc:
|
||||||
|
|
||||||
posint-dec-to-hex-generated.c: ldmc target
|
posint-dec-to-hex-generated.c: ldmc target
|
||||||
ldmc \
|
ldmc \
|
||||||
"ℕ~<PosInt 10 BigEndian>~<Seq~<ValueTerminated '\\0'> <Digit 10>~Char~Ascii~x86.UInt8>" \
|
"ℕ~<PosInt 10 BigEndian>~<Seq~<ValueTerminated '\\0'> <Digit 10>~Char~Ascii~native.UInt8>" \
|
||||||
"ℕ~<PosInt 16 BigEndian>~<Seq~<ValueTerminated '\\0'> <Digit 16>~Char~Ascii~x86.UInt8>" \
|
"ℕ~<PosInt 16 BigEndian>~<Seq~<ValueTerminated '\\0'> <Digit 16>~Char~Ascii~native.UInt8>" \
|
||||||
../morphisms/*.morphism-base >| target/$@
|
../morphisms/*.morphism-base >| target/$@
|
||||||
|
|
||||||
posint-dec-to-hex-generated-gcc: posint-dec-to-hex-generated.c target
|
posint-dec-to-hex-generated-gcc: posint-dec-to-hex-generated.c target
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
```
|
```
|
||||||
|
|
||||||
morph_digit_as_char_to_uint8 (Radix:ℤ)
|
morph_digit_as_char_to_uint8 (Radix:ℤ)
|
||||||
<Digit Radix> ~ Char ~ Ascii ~ x86.UInt8
|
<Digit Radix> ~ Char ~ Ascii ~ native.UInt8
|
||||||
--> <Digit Radix> ~ x86.UInt8
|
--> <Digit Radix> ~ native.UInt8
|
||||||
```
|
```
|
||||||
if( *src >= '0' && *src <= '9' )
|
if( *src >= '0' && *src <= '9' )
|
||||||
*dst = *src - '0';
|
*dst = *src - '0';
|
||||||
|
@ -26,8 +26,8 @@ morph_digit_as_char_to_uint8 (Radix:ℤ)
|
||||||
```
|
```
|
||||||
|
|
||||||
morph_digit_as_char_to_uint64 (Radix:ℤ)
|
morph_digit_as_char_to_uint64 (Radix:ℤ)
|
||||||
<Digit Radix> ~ Char ~ Ascii ~ x86.UInt8
|
<Digit Radix> ~ Char ~ Ascii ~ native.UInt8
|
||||||
--> <Digit Radix> ~ x86.UInt64
|
--> <Digit Radix> ~ native.UInt64
|
||||||
```
|
```
|
||||||
if( *src >= '0' && *src <= '9' )
|
if( *src >= '0' && *src <= '9' )
|
||||||
*dst = *src - '0';
|
*dst = *src - '0';
|
||||||
|
@ -49,8 +49,8 @@ morph_digit_as_char_to_uint64 (Radix:ℤ)
|
||||||
```
|
```
|
||||||
|
|
||||||
morph_digit_as_uint8_to_char (Radix:ℤ_16)
|
morph_digit_as_uint8_to_char (Radix:ℤ_16)
|
||||||
<Digit Radix> ~ x86.UInt8
|
<Digit Radix> ~ native.UInt8
|
||||||
--> <Digit Radix> ~ Char ~ Ascii ~ x86.UInt8
|
--> <Digit Radix> ~ Char ~ Ascii ~ native.UInt8
|
||||||
```
|
```
|
||||||
if ( *src < 10 )
|
if ( *src < 10 )
|
||||||
*dst = *src + '0';
|
*dst = *src + '0';
|
||||||
|
@ -65,8 +65,8 @@ morph_digit_as_uint8_to_char (Radix:ℤ_16)
|
||||||
```
|
```
|
||||||
|
|
||||||
morph_digit_as_uint64_to_char (Radix:ℤ_16)
|
morph_digit_as_uint64_to_char (Radix:ℤ_16)
|
||||||
<Digit Radix> ~ x86.UInt64
|
<Digit Radix> ~ native.UInt64
|
||||||
--> <Digit Radix> ~ Char ~ Ascii ~ x86.UInt8
|
--> <Digit Radix> ~ Char ~ Ascii ~ native.UInt8
|
||||||
```
|
```
|
||||||
if ( *src < 10 )
|
if ( *src < 10 )
|
||||||
*dst = *src + '0';
|
*dst = *src + '0';
|
||||||
|
|
|
@ -3,21 +3,21 @@
|
||||||
#include <array/length-prefix.h>
|
#include <array/length-prefix.h>
|
||||||
```
|
```
|
||||||
|
|
||||||
morph_array_as_valterm_to_lenpfx (Terminator:x86.UInt8)
|
morph_array_as_valterm_to_lenpfx (Terminator:native.UInt8)
|
||||||
<Seq~<ValueTerminated Terminator> x86.UInt8>
|
<Seq~<ValueTerminated Terminator> native.UInt8>
|
||||||
--> <Seq~<LengthPrefix x86.UInt64> x86.UInt8>
|
--> <Seq~<LengthPrefix native.UInt64> native.UInt8>
|
||||||
```
|
```
|
||||||
length_prefix_uint8_array_clear(dst);
|
length_prefix_uint64_t_array_uint8_t_clear(dst);
|
||||||
while( *src != Terminator )
|
while( *src != Terminator )
|
||||||
length_prefix_uint8_array_push(dst, *src++);
|
length_prefix_uint64_t_array_uint8_t_push(dst, *src++);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
morph_array_as_lenpfx_to_valterm (Terminator:x86.UInt8)
|
morph_array_as_lenpfx_to_valterm (Terminator:native.UInt8)
|
||||||
<Seq~<LengthPrefix x86.UInt64> x86.UInt8>
|
<Seq~<LengthPrefix native.UInt64> native.UInt8>
|
||||||
--> <Seq~<ValueTerminated Terminator> x86.UInt8>
|
--> <Seq~<ValueTerminated Terminator> native.UInt8>
|
||||||
```
|
```
|
||||||
for( uint64_t i = 0; i < src->len; ++i )
|
for( uint64_t i = 0; i < src->len; ++i )
|
||||||
*dst++ = src->items[i];
|
*dst++ = src->items[i];
|
||||||
|
@ -28,8 +28,8 @@ morph_array_as_lenpfx_to_valterm (Terminator:x86.UInt8)
|
||||||
```
|
```
|
||||||
|
|
||||||
morph_array_as_lenpfx_to_continuation_bit_8 ()
|
morph_array_as_lenpfx_to_continuation_bit_8 ()
|
||||||
<Seq~<LengthPrefix x86.UInt64> x86.UInt8>
|
<Seq~<LengthPrefix native.UInt64> native.UInt8>
|
||||||
--> <Seq~MsbCont x86.UInt8>
|
--> <Seq~MsbCont native.UInt8>
|
||||||
```
|
```
|
||||||
for( uint64_t i = 0; i < src->len; ++i ) {
|
for( uint64_t i = 0; i < src->len; ++i ) {
|
||||||
if( src->items[i] & (1<<7) ) {
|
if( src->items[i] & (1<<7) ) {
|
||||||
|
@ -46,8 +46,8 @@ morph_array_as_lenpfx_to_continuation_bit_8 ()
|
||||||
```
|
```
|
||||||
|
|
||||||
morph_array_as_lenpfx_to_continuation_bit_16 ()
|
morph_array_as_lenpfx_to_continuation_bit_16 ()
|
||||||
<Seq~<LengthPrefix x86.UInt64> x86.UInt16>
|
<Seq~<LengthPrefix native.UInt64> native.UInt16>
|
||||||
--> <Seq~MsbCont x86.UInt16>
|
--> <Seq~MsbCont native.UInt16>
|
||||||
```
|
```
|
||||||
for( uint64_t i = 0; i < src->len; ++i ) {
|
for( uint64_t i = 0; i < src->len; ++i ) {
|
||||||
if( src->items[i] & (1<<15) ) {
|
if( src->items[i] & (1<<15) ) {
|
||||||
|
|
|
@ -4,10 +4,10 @@
|
||||||
|
|
||||||
morph_nat_as_u64_to_pos ()
|
morph_nat_as_u64_to_pos ()
|
||||||
ℕ
|
ℕ
|
||||||
~ x86.UInt64
|
~ native.UInt64
|
||||||
--> ℕ
|
--> ℕ
|
||||||
~ <PosInt 0 LittleEndian>
|
~ <PosInt 0 LittleEndian>
|
||||||
~ <Seq~<LengthPrefix x86.UInt64> <Digit 0>~x86.UInt64>
|
~ <Seq~<LengthPrefix native.UInt64> <Digit 0>~native.UInt64>
|
||||||
```
|
```
|
||||||
dst->len = 1;
|
dst->len = 1;
|
||||||
dst->items[0] = *src;
|
dst->items[0] = *src;
|
||||||
|
@ -17,9 +17,9 @@ morph_nat_as_u64_to_pos ()
|
||||||
morph_nat_as_pos_to_u64 (Endianness:Type)
|
morph_nat_as_pos_to_u64 (Endianness:Type)
|
||||||
ℕ
|
ℕ
|
||||||
~ <PosInt 0 Endianness>
|
~ <PosInt 0 Endianness>
|
||||||
~ <Seq~<LengthPrefix x86.UInt64> <Digit 0>~x86.UInt64>
|
~ <Seq~<LengthPrefix native.UInt64> <Digit 0>~native.UInt64>
|
||||||
--> ℕ
|
--> ℕ
|
||||||
~ x86.UInt64
|
~ native.UInt64
|
||||||
```
|
```
|
||||||
*dst = src->items[0];
|
*dst = src->items[0];
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -28,10 +28,10 @@ morph_nat_as_pos_to_u64 (Endianness:Type)
|
||||||
morph_posint_radix_le (SrcRadix:ℤ, DstRadix:ℤ)
|
morph_posint_radix_le (SrcRadix:ℤ, DstRadix:ℤ)
|
||||||
ℕ
|
ℕ
|
||||||
~ <PosInt SrcRadix LittleEndian>
|
~ <PosInt SrcRadix LittleEndian>
|
||||||
~ <Seq~<LengthPrefix x86.UInt64> <Digit SrcRadix>~x86.UInt64>
|
~ <Seq~<LengthPrefix native.UInt64> <Digit SrcRadix>~native.UInt64>
|
||||||
--> ℕ
|
--> ℕ
|
||||||
~ <PosInt DstRadix LittleEndian>
|
~ <PosInt DstRadix LittleEndian>
|
||||||
~ <Seq~<LenghtPrefix x86.UInt64> <Digit DstRadix>~x86.UInt64>
|
~ <Seq~<LenghtPrefix native.UInt64> <Digit DstRadix>~native.UInt64>
|
||||||
```
|
```
|
||||||
uint64_t value = 0;
|
uint64_t value = 0;
|
||||||
|
|
||||||
|
@ -40,15 +40,15 @@ morph_posint_radix_le (SrcRadix:ℤ, DstRadix:ℤ)
|
||||||
value += src->items[src->len - i - 1];
|
value += src->items[src->len - i - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
length_prefix_uint64_array_clear( dst );
|
length_prefix_uint64_t_array_uint64_t_clear( dst );
|
||||||
|
|
||||||
#if DstRadix==0
|
#if DstRadix==0
|
||||||
length_prefix_uint64_array_push( dst, value );
|
length_prefix_uint64_t_array_uint64_t_push( dst, value );
|
||||||
#else
|
#else
|
||||||
if( value == 0 ) {
|
if( value == 0 ) {
|
||||||
length_prefix_uint64_array_push( dst, 0 );
|
length_prefix_uint64_t_array_uint64_t_push( dst, 0 );
|
||||||
} else while( value > 0 ) {
|
} else while( value > 0 ) {
|
||||||
length_prefix_uint64_array_push( dst, value % DstRadix );
|
length_prefix_uint64_t_array_uint64_t_push( dst, value % DstRadix );
|
||||||
value /= DstRadix;
|
value /= DstRadix;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -59,10 +59,10 @@ morph_posint_radix_le (SrcRadix:ℤ, DstRadix:ℤ)
|
||||||
morph_posint_radix_be (SrcRadix:ℤ, DstRadix:ℤ)
|
morph_posint_radix_be (SrcRadix:ℤ, DstRadix:ℤ)
|
||||||
ℕ
|
ℕ
|
||||||
~ <PosInt SrcRadix BigEndian>
|
~ <PosInt SrcRadix BigEndian>
|
||||||
~ <Seq~<LengthPrefix x86.UInt64> <Digit SrcRadix>~x86.UInt64>
|
~ <Seq~<LengthPrefix native.UInt64> <Digit SrcRadix>~native.UInt64>
|
||||||
--> ℕ
|
--> ℕ
|
||||||
~ <PosInt DstRadix BigEndian>
|
~ <PosInt DstRadix BigEndian>
|
||||||
~ <Seq~<LengthPrefix x86.UInt64> <Digit DstRadix>~x86.UInt64>
|
~ <Seq~<LengthPrefix native.UInt64> <Digit DstRadix>~native.UInt64>
|
||||||
```
|
```
|
||||||
uint64_t value = 0;
|
uint64_t value = 0;
|
||||||
|
|
||||||
|
@ -98,21 +98,21 @@ morph_posint_radix_be (SrcRadix:ℤ, DstRadix:ℤ)
|
||||||
morph_posint_endianness (Radix:ℤ)
|
morph_posint_endianness (Radix:ℤ)
|
||||||
ℕ
|
ℕ
|
||||||
~ <PosInt Radix LittleEndian>
|
~ <PosInt Radix LittleEndian>
|
||||||
~ <Seq~<LengthPrefix x86.UInt64> <Digit Radix> ~ x86.UInt64>
|
~ <Seq~<LengthPrefix native.UInt64> <Digit Radix> ~ native.UInt64>
|
||||||
--> ℕ
|
--> ℕ
|
||||||
~ <PosInt Radix BigEndian>
|
~ <PosInt Radix BigEndian>
|
||||||
~ <Seq~<LengthPrefix x86.UInt64> <Digit Radix> ~ x86.UInt64>
|
~ <Seq~<LengthPrefix native.UInt64> <Digit Radix> ~ native.UInt64>
|
||||||
```
|
```
|
||||||
return length_prefix_uint64_array_reverse( src, dst );
|
return length_prefix_uint64_t_array_uint64_t_reverse( src, dst );
|
||||||
```
|
```
|
||||||
|
|
||||||
morph_posint_endianness (Radix:ℤ)
|
morph_posint_endianness (Radix:ℤ)
|
||||||
ℕ
|
ℕ
|
||||||
~ <PosInt Radix BigEndian>
|
~ <PosInt Radix BigEndian>
|
||||||
~ <Seq~<LengthPrefix x86.UInt64> <Digit Radix> ~ x86.UInt64>
|
~ <Seq~<LengthPrefix native.UInt64> <Digit Radix> ~ native.UInt64>
|
||||||
--> ℕ
|
--> ℕ
|
||||||
~ <PosInt Radix LittleEndian>
|
~ <PosInt Radix LittleEndian>
|
||||||
~ <Seq~<LengthPrefix x86.UInt64> <Digit Radix> ~ x86.UInt64>
|
~ <Seq~<LengthPrefix native.UInt64> <Digit Radix> ~ native.UInt64>
|
||||||
```
|
```
|
||||||
return length_prefix_uint64_array_reverse( src, dst );
|
return length_prefix_uint64_t_array_uint64_t_reverse( src, dst );
|
||||||
```
|
```
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
```
|
```
|
||||||
|
|
||||||
morph_real_as_decimalstr_to_float ()
|
morph_real_as_decimalstr_to_float ()
|
||||||
ℝ ~ <PosInt 10 BigEndian> ~ <Seq~<ValueTerminated 0> <Digit 10>~Char~Ascii~x86.UInt8>
|
ℝ ~ <PosInt 10 BigEndian> ~ <Seq~<ValueTerminated 0> <Digit 10>~Char~Ascii~native.UInt8>
|
||||||
--> ℝ ~ native.Float
|
--> ℝ ~ native.Float
|
||||||
```
|
```
|
||||||
sscanf(src, "%f", dst);
|
sscanf(src, "%f", dst);
|
||||||
|
@ -11,7 +11,7 @@ morph_real_as_decimalstr_to_float ()
|
||||||
```
|
```
|
||||||
|
|
||||||
morph_real_as_decimalstr_to_double ()
|
morph_real_as_decimalstr_to_double ()
|
||||||
ℝ ~ <PosInt 10 BigEndian> ~ <Seq~<ValueTerminated 0> <Digit 10>~Char~Ascii~x86.UInt8>
|
ℝ ~ <PosInt 10 BigEndian> ~ <Seq~<ValueTerminated 0> <Digit 10>~Char~Ascii~native.UInt8>
|
||||||
--> ℝ ~ native.Double
|
--> ℝ ~ native.Double
|
||||||
```
|
```
|
||||||
sscanf(src, "%lf", dst);
|
sscanf(src, "%lf", dst);
|
||||||
|
@ -20,7 +20,7 @@ morph_real_as_decimalstr_to_double ()
|
||||||
|
|
||||||
morph_real_as_float_to_decimalstr ()
|
morph_real_as_float_to_decimalstr ()
|
||||||
ℝ ~ native.Float
|
ℝ ~ native.Float
|
||||||
--> ℝ ~ <PosInt 10 BigEndian> ~ <Seq~<ValueTerminated 0> <Digit 10>~Char~Ascii~x86.UInt8>
|
--> ℝ ~ <PosInt 10 BigEndian> ~ <Seq~<ValueTerminated 0> <Digit 10>~Char~Ascii~native.UInt8>
|
||||||
```
|
```
|
||||||
sprintf(dst, "%f", *src);
|
sprintf(dst, "%f", *src);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -28,7 +28,7 @@ morph_real_as_float_to_decimalstr ()
|
||||||
|
|
||||||
morph_real_as_double_to_decimalstr ()
|
morph_real_as_double_to_decimalstr ()
|
||||||
ℝ ~ native.Double
|
ℝ ~ native.Double
|
||||||
--> ℝ ~ <PosInt 10 BigEndian> ~ <Seq~<ValueTerminated 0> <Digit 10>~Char~Ascii~x86.UInt8>
|
--> ℝ ~ <PosInt 10 BigEndian> ~ <Seq~<ValueTerminated 0> <Digit 10>~Char~Ascii~native.UInt8>
|
||||||
```
|
```
|
||||||
sprintf(dst, "%f", *src);
|
sprintf(dst, "%f", *src);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -53,7 +53,7 @@ morph_real_as_double_to_float ()
|
||||||
```
|
```
|
||||||
|
|
||||||
morph_real_as_u64_to_float ()
|
morph_real_as_u64_to_float ()
|
||||||
ℝ ~ ℕ ~ x86.UInt64
|
ℝ ~ ℕ ~ native.UInt64
|
||||||
--> ℝ ~ native.Float
|
--> ℝ ~ native.Float
|
||||||
```
|
```
|
||||||
fprintf(stderr, "Warning: morphin UInt64 -> Float. Precision loss!");
|
fprintf(stderr, "Warning: morphin UInt64 -> Float. Precision loss!");
|
||||||
|
@ -62,7 +62,7 @@ morph_real_as_u64_to_float ()
|
||||||
```
|
```
|
||||||
|
|
||||||
morph_real_as_u64_to_double ()
|
morph_real_as_u64_to_double ()
|
||||||
ℝ ~ ℕ ~ x86.UInt64
|
ℝ ~ ℕ ~ native.UInt64
|
||||||
--> ℝ ~ native.Double
|
--> ℝ ~ native.Double
|
||||||
```
|
```
|
||||||
fprintf(stderr, "Warning: morphin UInt64 -> Double. Precision loss!");
|
fprintf(stderr, "Warning: morphin UInt64 -> Double. Precision loss!");
|
||||||
|
@ -71,7 +71,7 @@ morph_real_as_u64_to_double ()
|
||||||
```
|
```
|
||||||
|
|
||||||
morph_real_as_quantized_linear_to_float (Begin: ℝ, End: ℝ, Steps: ℤ)
|
morph_real_as_quantized_linear_to_float (Begin: ℝ, End: ℝ, Steps: ℤ)
|
||||||
ℝ ~ <QuantizedLinear Begin End Steps> ~ ℕ ~ x86.UInt64
|
ℝ ~ <QuantizedLinear Begin End Steps> ~ ℕ ~ native.UInt64
|
||||||
--> ℝ ~ native.Float
|
--> ℝ ~ native.Float
|
||||||
```
|
```
|
||||||
*dst = (float)Begin + ( *src * ((float)End - (float)Begin) ) / (float)Steps;
|
*dst = (float)Begin + ( *src * ((float)End - (float)Begin) ) / (float)Steps;
|
||||||
|
@ -80,7 +80,7 @@ morph_real_as_quantized_linear_to_float (Begin: ℝ, End: ℝ, Steps: ℤ)
|
||||||
|
|
||||||
morph_real_as_float_to_quantized_linear (Begin: ℝ, End: ℝ, Steps: ℤ)
|
morph_real_as_float_to_quantized_linear (Begin: ℝ, End: ℝ, Steps: ℤ)
|
||||||
ℝ ~ native.Float
|
ℝ ~ native.Float
|
||||||
--> ℝ ~ <QuantizedLinear Begin End Steps> ~ ℕ ~ x86.UInt64
|
--> ℝ ~ <QuantizedLinear Begin End Steps> ~ ℕ ~ native.UInt64
|
||||||
```
|
```
|
||||||
*dst = ((*src - (float)Begin) * (float)Steps) / ((float)End - (float)Begin);
|
*dst = ((*src - (float)Begin) * (float)Steps) / ((float)End - (float)Begin);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -89,7 +89,7 @@ morph_real_as_float_to_quantized_linear (Begin: ℝ, End: ℝ, Steps: ℤ)
|
||||||
|
|
||||||
|
|
||||||
morph_real_as_quantized_linear_to_double (Begin: ℝ, End: ℝ, Steps: ℤ)
|
morph_real_as_quantized_linear_to_double (Begin: ℝ, End: ℝ, Steps: ℤ)
|
||||||
ℝ ~ <QuantizedLinear Begin End Steps> ~ ℕ ~ x86.UInt64
|
ℝ ~ <QuantizedLinear Begin End Steps> ~ ℕ ~ native.UInt64
|
||||||
--> ℝ ~ native.Double
|
--> ℝ ~ native.Double
|
||||||
```
|
```
|
||||||
*dst = (double)Begin + ( *src * ((double)End - (double)Begin) ) / (double)Steps;
|
*dst = (double)Begin + ( *src * ((double)End - (double)Begin) ) / (double)Steps;
|
||||||
|
@ -98,7 +98,7 @@ morph_real_as_quantized_linear_to_double (Begin: ℝ, End: ℝ, Steps: ℤ)
|
||||||
|
|
||||||
morph_real_as_double_to_quantized_linear (Begin: ℝ, End: ℝ, Steps: ℤ)
|
morph_real_as_double_to_quantized_linear (Begin: ℝ, End: ℝ, Steps: ℤ)
|
||||||
ℝ ~ native.Double
|
ℝ ~ native.Double
|
||||||
--> ℝ ~ <QuantizedLinear Begin End Steps> ~ ℕ ~ x86.UInt64
|
--> ℝ ~ <QuantizedLinear Begin End Steps> ~ ℕ ~ native.UInt64
|
||||||
```
|
```
|
||||||
*dst = ((*src - (double)Begin) * (double)Steps) / ((double)End - (double)Begin);
|
*dst = ((*src - (double)Begin) * (double)Steps) / ((double)End - (double)Begin);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -1,70 +1,101 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
/* UInt8 */
|
// Macro to define length-prefixed array structures and functions
|
||||||
|
#define DEFINE_LENGTH_PREFIX_ARRAY(LEN_TYPE, ITEM_TYPE) \
|
||||||
|
typedef struct { \
|
||||||
|
LEN_TYPE len; \
|
||||||
|
ITEM_TYPE items[]; \
|
||||||
|
} LengthPrefix_##LEN_TYPE##_Array_##ITEM_TYPE; \
|
||||||
|
\
|
||||||
|
static inline void length_prefix_##LEN_TYPE##_array_##ITEM_TYPE##_clear( \
|
||||||
|
LengthPrefix_##LEN_TYPE##_Array_##ITEM_TYPE *data) { \
|
||||||
|
data->len = 0; \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
static inline void length_prefix_##LEN_TYPE##_array_##ITEM_TYPE##_push( \
|
||||||
|
LengthPrefix_##LEN_TYPE##_Array_##ITEM_TYPE *data, \
|
||||||
|
ITEM_TYPE value) { \
|
||||||
|
data->items[data->len++] = value; \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
static inline int length_prefix_##LEN_TYPE##_array_##ITEM_TYPE##_reverse( \
|
||||||
|
LengthPrefix_##LEN_TYPE##_Array_##ITEM_TYPE const * restrict src, \
|
||||||
|
LengthPrefix_##LEN_TYPE##_Array_##ITEM_TYPE *restrict dst) { \
|
||||||
|
for (LEN_TYPE i = 0; i < src->len; i++) { \
|
||||||
|
dst->items[i] = src->items[src->len - 1 - i]; \
|
||||||
|
} \
|
||||||
|
dst->len = src->len; \
|
||||||
|
return 0; \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
static inline void length_prefix_##LEN_TYPE##_array_##ITEM_TYPE##_dump( \
|
||||||
|
LengthPrefix_##LEN_TYPE##_Array_##ITEM_TYPE const * data) { \
|
||||||
|
printf("Length: %llu\n", (unsigned long long) data->len); \
|
||||||
|
for (LEN_TYPE i = 0; i < data->len; i++) { \
|
||||||
|
printf("%llu ", (unsigned long long) data->items[i]); \
|
||||||
|
} \
|
||||||
|
printf("\n"); \
|
||||||
|
}
|
||||||
|
|
||||||
struct LengthPrefixUInt8Array {
|
|
||||||
uint64_t len;
|
|
||||||
uint8_t items[];
|
|
||||||
};
|
|
||||||
|
|
||||||
void length_prefix_uint8_array_clear(
|
// Define all combinations of length and item types
|
||||||
struct LengthPrefixUInt8Array * data
|
DEFINE_LENGTH_PREFIX_ARRAY(uint8_t, uint8_t)
|
||||||
);
|
DEFINE_LENGTH_PREFIX_ARRAY(uint8_t, uint16_t)
|
||||||
void length_prefix_uint8_array_push(
|
DEFINE_LENGTH_PREFIX_ARRAY(uint8_t, uint32_t)
|
||||||
struct LengthPrefixUInt8Array * data,
|
DEFINE_LENGTH_PREFIX_ARRAY(uint8_t, uint64_t)
|
||||||
uint8_t value
|
DEFINE_LENGTH_PREFIX_ARRAY(uint16_t, uint8_t)
|
||||||
);
|
DEFINE_LENGTH_PREFIX_ARRAY(uint16_t, uint16_t)
|
||||||
int length_prefix_uint8_array_reverse(
|
DEFINE_LENGTH_PREFIX_ARRAY(uint16_t, uint32_t)
|
||||||
struct LengthPrefixUInt8Array const * restrict src,
|
DEFINE_LENGTH_PREFIX_ARRAY(uint16_t, uint64_t)
|
||||||
struct LengthPrefixUInt8Array * restrict dst
|
DEFINE_LENGTH_PREFIX_ARRAY(uint32_t, uint8_t)
|
||||||
);
|
DEFINE_LENGTH_PREFIX_ARRAY(uint32_t, uint16_t)
|
||||||
void length_prefix_uint8_array_dump(
|
DEFINE_LENGTH_PREFIX_ARRAY(uint32_t, uint32_t)
|
||||||
struct LengthPrefixUInt8Array const * data
|
DEFINE_LENGTH_PREFIX_ARRAY(uint32_t, uint64_t)
|
||||||
);
|
DEFINE_LENGTH_PREFIX_ARRAY(uint64_t, uint8_t)
|
||||||
|
DEFINE_LENGTH_PREFIX_ARRAY(uint64_t, uint16_t)
|
||||||
/* UInt64 */
|
DEFINE_LENGTH_PREFIX_ARRAY(uint64_t, uint32_t)
|
||||||
|
DEFINE_LENGTH_PREFIX_ARRAY(uint64_t, uint64_t)
|
||||||
struct LengthPrefixUInt64Array {
|
|
||||||
uint64_t len;
|
|
||||||
uint64_t items[];
|
|
||||||
};
|
|
||||||
|
|
||||||
void length_prefix_uint64_array_clear(
|
|
||||||
struct LengthPrefixUInt64Array * data
|
|
||||||
);
|
|
||||||
void length_prefix_uint64_array_push(
|
|
||||||
struct LengthPrefixUInt64Array * data,
|
|
||||||
uint64_t value
|
|
||||||
);
|
|
||||||
int length_prefix_uint64_array_reverse(
|
|
||||||
struct LengthPrefixUInt64Array const * restrict src,
|
|
||||||
struct LengthPrefixUInt64Array * restrict dst
|
|
||||||
);
|
|
||||||
void length_prefix_uint64_array_dump(
|
|
||||||
struct LengthPrefixUInt64Array const * data
|
|
||||||
);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Map
|
* Map
|
||||||
*/
|
*/
|
||||||
int length_prefix_array_map_64_to_64(
|
// Macro to define map function between different item types
|
||||||
int (*f) ( uint64_t const * restrict, uint64_t * restrict ),
|
#define DEFINE_LENGTH_PREFIX_ARRAY_MAP(LEN_TYPE, SRC_ITEM_TYPE, DST_ITEM_TYPE) \
|
||||||
struct LengthPrefixUInt64Array const * restrict src,
|
static inline int length_prefix_##LEN_TYPE##_array_map_##SRC_ITEM_TYPE##_to_##DST_ITEM_TYPE( \
|
||||||
struct LengthPrefixUInt64Array * restrict dst
|
int (*f)(SRC_ITEM_TYPE const * restrict, DST_ITEM_TYPE * restrict), \
|
||||||
);
|
LengthPrefix_##LEN_TYPE##_Array_##SRC_ITEM_TYPE const * restrict src, \
|
||||||
int length_prefix_array_map_8_to_64(
|
LengthPrefix_##LEN_TYPE##_Array_##DST_ITEM_TYPE * restrict dst) \
|
||||||
int (*f) ( uint8_t const * restrict, uint64_t * restrict ),
|
{ \
|
||||||
struct LengthPrefixUInt8Array const * restrict src,
|
if (dst->len < src->len) return -1; /* Ensure enough space */ \
|
||||||
struct LengthPrefixUInt64Array * restrict dst
|
for (LEN_TYPE i = 0; i < src->len; i++) { \
|
||||||
);
|
if (f(&src->items[i], &dst->items[i]) != 0) return -1; \
|
||||||
int length_prefix_array_map_64_to_8(
|
} \
|
||||||
int (*f) ( uint64_t const * restrict, uint8_t * restrict ),
|
dst->len = src->len; \
|
||||||
struct LengthPrefixUInt64Array const * restrict src,
|
return 0; \
|
||||||
struct LengthPrefixUInt8Array * restrict dst
|
}
|
||||||
);
|
|
||||||
int length_prefix_array_map_8_to_8(
|
#define DEFINE_ALL_MAPS(LEN_TYPE) \
|
||||||
int (*f) ( uint8_t const * restrict, uint8_t * restrict ),
|
DEFINE_LENGTH_PREFIX_ARRAY_MAP(LEN_TYPE, uint8_t, uint8_t) \
|
||||||
struct LengthPrefixUInt8Array const * restrict src,
|
DEFINE_LENGTH_PREFIX_ARRAY_MAP(LEN_TYPE, uint8_t, uint16_t) \
|
||||||
struct LengthPrefixUInt8Array * restrict dst
|
DEFINE_LENGTH_PREFIX_ARRAY_MAP(LEN_TYPE, uint8_t, uint32_t) \
|
||||||
);
|
DEFINE_LENGTH_PREFIX_ARRAY_MAP(LEN_TYPE, uint8_t, uint64_t) \
|
||||||
|
DEFINE_LENGTH_PREFIX_ARRAY_MAP(LEN_TYPE, uint16_t, uint8_t) \
|
||||||
|
DEFINE_LENGTH_PREFIX_ARRAY_MAP(LEN_TYPE, uint16_t, uint16_t) \
|
||||||
|
DEFINE_LENGTH_PREFIX_ARRAY_MAP(LEN_TYPE, uint16_t, uint32_t) \
|
||||||
|
DEFINE_LENGTH_PREFIX_ARRAY_MAP(LEN_TYPE, uint16_t, uint64_t) \
|
||||||
|
DEFINE_LENGTH_PREFIX_ARRAY_MAP(LEN_TYPE, uint32_t, uint8_t) \
|
||||||
|
DEFINE_LENGTH_PREFIX_ARRAY_MAP(LEN_TYPE, uint32_t, uint16_t) \
|
||||||
|
DEFINE_LENGTH_PREFIX_ARRAY_MAP(LEN_TYPE, uint32_t, uint32_t) \
|
||||||
|
DEFINE_LENGTH_PREFIX_ARRAY_MAP(LEN_TYPE, uint32_t, uint64_t) \
|
||||||
|
DEFINE_LENGTH_PREFIX_ARRAY_MAP(LEN_TYPE, uint64_t, uint8_t) \
|
||||||
|
DEFINE_LENGTH_PREFIX_ARRAY_MAP(LEN_TYPE, uint64_t, uint16_t) \
|
||||||
|
DEFINE_LENGTH_PREFIX_ARRAY_MAP(LEN_TYPE, uint64_t, uint32_t) \
|
||||||
|
DEFINE_LENGTH_PREFIX_ARRAY_MAP(LEN_TYPE, uint64_t, uint64_t)
|
||||||
|
|
||||||
|
DEFINE_ALL_MAPS(uint8_t)
|
||||||
|
DEFINE_ALL_MAPS(uint16_t)
|
||||||
|
DEFINE_ALL_MAPS(uint32_t)
|
||||||
|
DEFINE_ALL_MAPS(uint64_t)
|
||||||
|
|
|
@ -1,137 +0,0 @@
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include <array/length-prefix.h>
|
|
||||||
|
|
||||||
void length_prefix_uint64_array_clear(
|
|
||||||
struct LengthPrefixUInt64Array * data
|
|
||||||
) {
|
|
||||||
data->len = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void length_prefix_uint64_array_push(
|
|
||||||
struct LengthPrefixUInt64Array * data,
|
|
||||||
uint64_t value
|
|
||||||
) {
|
|
||||||
data->items[ data->len ] = value;
|
|
||||||
data->len += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int length_prefix_uint64_array_reverse(
|
|
||||||
struct LengthPrefixUInt64Array const * restrict src,
|
|
||||||
struct LengthPrefixUInt64Array * restrict dst
|
|
||||||
) {
|
|
||||||
dst->len = src->len;
|
|
||||||
for(uint64_t i = 0; i < src->len; ++i) {
|
|
||||||
dst->items[i] = src->items[src->len - i - 1];
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int length_prefix_array_map_8_to_8(
|
|
||||||
int (*f) ( uint8_t const * restrict, uint8_t * restrict ),
|
|
||||||
struct LengthPrefixUInt8Array const * restrict src,
|
|
||||||
struct LengthPrefixUInt8Array * restrict dst
|
|
||||||
) {
|
|
||||||
dst->len = src->len;
|
|
||||||
for( uint64_t i = 0; i < src->len; ++i ) {
|
|
||||||
int result = f( &src->items[i], &dst->items[i] );
|
|
||||||
if( result ) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int length_prefix_array_map_64_to_64(
|
|
||||||
int (*f) ( uint64_t const * restrict, uint64_t * restrict ),
|
|
||||||
struct LengthPrefixUInt64Array const * restrict src,
|
|
||||||
struct LengthPrefixUInt64Array * restrict dst
|
|
||||||
) {
|
|
||||||
dst->len = src->len;
|
|
||||||
for( uint64_t i = 0; i < src->len; ++i ) {
|
|
||||||
int result = f( &src->items[i], &dst->items[i] );
|
|
||||||
if( result ) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int length_prefix_array_map_8_to_64(
|
|
||||||
int (*f) ( uint8_t const * restrict, uint64_t * restrict ),
|
|
||||||
struct LengthPrefixUInt8Array const * restrict src,
|
|
||||||
struct LengthPrefixUInt64Array * restrict dst
|
|
||||||
) {
|
|
||||||
dst->len = src->len;
|
|
||||||
for( uint64_t i = 0; i < src->len; ++i ) {
|
|
||||||
int result = f( &src->items[i], &dst->items[i] );
|
|
||||||
if( result ) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int length_prefix_array_map_64_to_8(
|
|
||||||
int (*f) ( uint64_t const * restrict, uint8_t * restrict ),
|
|
||||||
struct LengthPrefixUInt64Array const * restrict src,
|
|
||||||
struct LengthPrefixUInt8Array * restrict dst
|
|
||||||
) {
|
|
||||||
dst->len = src->len;
|
|
||||||
for( uint64_t i = 0; i < src->len; ++i ) {
|
|
||||||
int result = f( &src->items[i], &dst->items[i] );
|
|
||||||
if( result ) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void length_prefix_uint64_array_dump(
|
|
||||||
struct LengthPrefixUInt64Array const * data
|
|
||||||
) {
|
|
||||||
printf("Len = %d, [", data->len);
|
|
||||||
for( uint64_t i = 0; i < data->len; ++i ) {
|
|
||||||
printf("%d; ", data->items[i]);
|
|
||||||
}
|
|
||||||
printf("]\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void length_prefix_uint8_array_clear(
|
|
||||||
struct LengthPrefixUInt8Array * data
|
|
||||||
) {
|
|
||||||
data->len = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void length_prefix_uint8_array_push(
|
|
||||||
struct LengthPrefixUInt8Array * data,
|
|
||||||
uint8_t value
|
|
||||||
) {
|
|
||||||
data->items[ data->len ] = value;
|
|
||||||
data->len += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int length_prefix_uint8_array_reverse(
|
|
||||||
struct LengthPrefixUInt8Array const * restrict src,
|
|
||||||
struct LengthPrefixUInt8Array * restrict dst
|
|
||||||
) {
|
|
||||||
dst->len = src->len;
|
|
||||||
for(uint64_t i = 0; i < src->len; ++i) {
|
|
||||||
dst->items[i] = src->items[src->len - i - 1];
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void length_prefix_uint8_array_dump(
|
|
||||||
struct LengthPrefixUInt8Array const * data
|
|
||||||
) {
|
|
||||||
printf("Len = %d, [", data->len);
|
|
||||||
for( uint64_t i = 0; i < data->len; ++i ) {
|
|
||||||
printf("%d; ", data->items[i]);
|
|
||||||
}
|
|
||||||
printf("]\n");
|
|
||||||
}
|
|
|
@ -3,8 +3,8 @@
|
||||||
```
|
```
|
||||||
|
|
||||||
morph_unixtime_to_iso ()
|
morph_unixtime_to_iso ()
|
||||||
TimePoint ~ <TimeSince UnixEpoch> ~ Duration ~ Seconds ~ ℝ ~ <QuantizedLinear 0 1 1> ~ ℕ ~ x86.UInt64
|
TimePoint ~ <TimeSince UnixEpoch> ~ Duration ~ Seconds ~ ℝ ~ <QuantizedLinear 0 1 1> ~ ℕ ~ native.UInt64
|
||||||
--> TimePoint ~ ISO8601 ~ <Seq~<ValueTerminated 0> Char~Ascii~x86.UInt8>
|
--> TimePoint ~ ISO8601 ~ <Seq~<ValueTerminated 0> Char~Ascii~native.UInt8>
|
||||||
```
|
```
|
||||||
time_t rawtime = (time_t)(*src);
|
time_t rawtime = (time_t)(*src);
|
||||||
struct tm *timeinfo = gmtime(&rawtime);
|
struct tm *timeinfo = gmtime(&rawtime);
|
||||||
|
|
|
@ -3,10 +3,10 @@
|
||||||
```
|
```
|
||||||
|
|
||||||
morph_string_as_ascii_to_utf8 ()
|
morph_string_as_ascii_to_utf8 ()
|
||||||
<Seq ~ <ValueTerminated 0> Char~Ascii~x86.UInt8>
|
<Seq ~ <ValueTerminated 0> Char~Ascii~native.UInt8>
|
||||||
--> <Seq Char~Unicode>
|
--> <Seq Char~Unicode>
|
||||||
~ UTF-8
|
~ UTF-8
|
||||||
~ <Seq~<ValueTerminated 0> x86.UInt8>
|
~ <Seq~<ValueTerminated 0> native.UInt8>
|
||||||
```
|
```
|
||||||
while( *src ) { *dst++ = *src++; }
|
while( *src ) { *dst++ = *src++; }
|
||||||
*dst = 0;
|
*dst = 0;
|
||||||
|
@ -16,8 +16,8 @@ morph_string_as_ascii_to_utf8 ()
|
||||||
morph_string_as_utf8_to_ascii ()
|
morph_string_as_utf8_to_ascii ()
|
||||||
<Seq Char~Unicode>
|
<Seq Char~Unicode>
|
||||||
~ UTF-8
|
~ UTF-8
|
||||||
~ <Seq~<ValueTerminated 0> x86.UInt8>
|
~ <Seq~<ValueTerminated 0> native.UInt8>
|
||||||
--> <Seq ~ <ValueTerminated 0> Char~Ascii~x86.UInt8>
|
--> <Seq ~ <ValueTerminated 0> Char~Ascii~native.UInt8>
|
||||||
```
|
```
|
||||||
while( *src ) {
|
while( *src ) {
|
||||||
if( *src < 128 ) {
|
if( *src < 128 ) {
|
||||||
|
@ -32,10 +32,10 @@ morph_string_as_utf8_to_ascii ()
|
||||||
```
|
```
|
||||||
|
|
||||||
morph_string_as_ascii_to_utf32 ()
|
morph_string_as_ascii_to_utf32 ()
|
||||||
<Seq ~ <ValueTerminated 0> Char~Ascii~x86.UInt8>
|
<Seq ~ <ValueTerminated 0> Char~Ascii~native.UInt8>
|
||||||
--> <Seq Char~Unicode>
|
--> <Seq Char~Unicode>
|
||||||
~ UTF-32LE
|
~ UTF-32LE
|
||||||
~ <Seq~<ValueTerminated 0> x86.UInt32>
|
~ <Seq~<ValueTerminated 0> native.UInt32>
|
||||||
```
|
```
|
||||||
while( *src ) { *dst++ = *src++; }
|
while( *src ) { *dst++ = *src++; }
|
||||||
*dst = 0;
|
*dst = 0;
|
||||||
|
@ -46,11 +46,11 @@ morph_string_as_utf8_to_utf32 ()
|
||||||
|
|
||||||
<Seq Char~Unicode>
|
<Seq Char~Unicode>
|
||||||
~ UTF-8
|
~ UTF-8
|
||||||
~ <Seq~<ValueTerminated 0> x86.UInt8>
|
~ <Seq~<ValueTerminated 0> native.UInt8>
|
||||||
|
|
||||||
--> <Seq Char~Unicode>
|
--> <Seq Char~Unicode>
|
||||||
~ UTF-32LE
|
~ UTF-32LE
|
||||||
~ <Seq~<ValueTerminated 0> x86.UInt32>
|
~ <Seq~<ValueTerminated 0> native.UInt32>
|
||||||
|
|
||||||
```
|
```
|
||||||
bool has_multibyte = false;
|
bool has_multibyte = false;
|
||||||
|
|
|
@ -6,25 +6,25 @@
|
||||||
morph_seqseq_valsep_uint8 (T: Type, SrcDelim: T, DstDelim: T)
|
morph_seqseq_valsep_uint8 (T: Type, SrcDelim: T, DstDelim: T)
|
||||||
< Seq <Seq T> >
|
< Seq <Seq T> >
|
||||||
~ < ValueSep SrcDelim T >
|
~ < ValueSep SrcDelim T >
|
||||||
~ < Seq~<LengthPrefix x86.UInt64> T >
|
~ < Seq~<LengthPrefix native.UInt64> T >
|
||||||
|
|
||||||
--> < Seq <Seq T> >
|
--> < Seq <Seq T> >
|
||||||
~ < ValueSep DstDelim T >
|
~ < ValueSep DstDelim T >
|
||||||
~ < Seq~<LengthPrefix x86.UInt64> T >
|
~ < Seq~<LengthPrefix native.UInt64> T >
|
||||||
```
|
```
|
||||||
length_prefix_uint8_array_clear( dst );
|
length_prefix_uint64_t_array_uint8_t_clear( dst );
|
||||||
|
|
||||||
uint8_t * dst_items = dst->items;
|
uint8_t * dst_items = dst->items;
|
||||||
for( uint64_t i = 0; i < src->len; ++i ) {
|
for( uint64_t i = 0; i < src->len; ++i ) {
|
||||||
if( src->items[i] == SrcDelim ) {
|
if( src->items[i] == SrcDelim ) {
|
||||||
length_prefix_uint8_array_push( dst, DstDelim );
|
length_prefix_uint64_t_array_uint8_t_push( dst, DstDelim );
|
||||||
} else if( src->items[i] == DstDelim ) {
|
} else if( src->items[i] == DstDelim ) {
|
||||||
if( DstDelim == '\n' ) {
|
if( DstDelim == '\n' ) {
|
||||||
length_prefix_uint8_array_push( dst, '\\' );
|
length_prefix_uint64_t_array_uint8_t_push( dst, '\\' );
|
||||||
length_prefix_uint8_array_push( dst, 'n' );
|
length_prefix_uint64_t_array_uint8_t_push( dst, 'n' );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
length_prefix_uint8_array_push( dst, src->items[i] );
|
length_prefix_uint64_t_array_uint8_t_push( dst, src->items[i] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,18 +35,18 @@ morph_seqseq_valsep_uint8 (T: Type, SrcDelim: T, DstDelim: T)
|
||||||
morph_seqseq_as_valsep_to_lenpfx (T: Type, Delim: T, EscKey: T)
|
morph_seqseq_as_valsep_to_lenpfx (T: Type, Delim: T, EscKey: T)
|
||||||
< Seq <Seq T> >
|
< Seq <Seq T> >
|
||||||
~ < ValueSep T Delim >
|
~ < ValueSep T Delim >
|
||||||
~ < Seq~<LengthPrefix x86.UInt64> T >
|
~ < Seq~<LengthPrefix native.UInt64> T >
|
||||||
|
|
||||||
--> < Seq~<LengthPrefix x86.UInt64>
|
--> < Seq~<LengthPrefix native.UInt64>
|
||||||
<Seq~<LengthPrefix x86.UInt64> T >
|
<Seq~<LengthPrefix native.UInt64> T >
|
||||||
~ <RefMut < Seq~<LengthPrefix x86.UInt64> T>>
|
~ <RefMut < Seq~<LengthPrefix native.UInt64> T>>
|
||||||
~ x86.Address
|
~ native.Address
|
||||||
~ x86.UInt64
|
~ native.UInt64
|
||||||
>
|
>
|
||||||
```
|
```
|
||||||
length_prefix_uint64_array_clear( dst );
|
length_prefix_uint64_t_array_uint64_t_clear( dst );
|
||||||
|
|
||||||
struct LengthPrefixUInt8Array * cur_item = NULL;
|
struct LengthPrefix_uint64_t_Array_uint8_t * cur_item = NULL;
|
||||||
|
|
||||||
uint8_t const * start = &src->items[0];
|
uint8_t const * start = &src->items[0];
|
||||||
uint8_t const * cur = start;
|
uint8_t const * cur = start;
|
||||||
|
@ -60,7 +60,7 @@ morph_seqseq_as_valsep_to_lenpfx (T: Type, Delim: T, EscKey: T)
|
||||||
cur_item->len = len;
|
cur_item->len = len;
|
||||||
memcpy( cur_item->items, start, len );
|
memcpy( cur_item->items, start, len );
|
||||||
|
|
||||||
length_prefix_uint64_array_push( dst, (uint64_t)cur_item );
|
length_prefix_uint64_t_array_uint64_t_push( dst, (uint64_t)cur_item );
|
||||||
start = ++cur;
|
start = ++cur;
|
||||||
} else {
|
} else {
|
||||||
cur++;
|
cur++;
|
||||||
|
@ -71,27 +71,27 @@ morph_seqseq_as_valsep_to_lenpfx (T: Type, Delim: T, EscKey: T)
|
||||||
```
|
```
|
||||||
|
|
||||||
morph_seqeq_as_lenpfx_to_valsep (T: Type, Delim: T, EscKey: T)
|
morph_seqeq_as_lenpfx_to_valsep (T: Type, Delim: T, EscKey: T)
|
||||||
< Seq~<LengthPrefix x86.UInt64>
|
< Seq~<LengthPrefix native.UInt64>
|
||||||
<Seq~<LengthPrefix x86.UInt64> T >
|
<Seq~<LengthPrefix native.UInt64> T >
|
||||||
~ <RefMut < Seq~<LengthPrefix x86.UInt64> T>>
|
~ <RefMut < Seq~<LengthPrefix native.UInt64> T>>
|
||||||
~ x86.Address
|
~ native.Address
|
||||||
~ x86.UInt64
|
~ native.UInt64
|
||||||
>
|
>
|
||||||
--> < Seq <Seq T> >
|
--> < Seq <Seq T> >
|
||||||
~ < ValueSep T Delim >
|
~ < ValueSep T Delim >
|
||||||
~ < Seq~<LengthPrefix x86.UInt64> T >
|
~ < Seq~<LengthPrefix native.UInt64> T >
|
||||||
```
|
```
|
||||||
length_prefix_uint8_array_clear( dst );
|
length_prefix_uint64_t_array_uint8_t_clear( dst );
|
||||||
|
|
||||||
for( uint64_t i = 0; i < src->len; ++i ) {
|
for( uint64_t i = 0; i < src->len; ++i ) {
|
||||||
LengthPrefixUInt8Array * item = src->items[i];
|
LengthPrefix_uint64_t_Array_uint8_t * item = src->items[i];
|
||||||
|
|
||||||
for( uint64_t j = 0; j < item->len; ++j ) {
|
for( uint64_t j = 0; j < item->len; ++j ) {
|
||||||
length_prefix_uint8_array_push( items->items[j] );
|
length_prefix_uint64_t_array_uint8_t_push( items->items[j] );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( i+1 < src->len ) {
|
if( i+1 < src->len ) {
|
||||||
length_prefix_uint8_array_push( Delim );
|
length_prefix_uint64_t_array_uint8_t_push( Delim );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
```
|
```
|
||||||
|
|
||||||
morph_i64_as_twos_complement_to_zigzag ()
|
morph_i64_as_twos_complement_to_zigzag ()
|
||||||
ℤ ~ x86.Int64
|
ℤ ~ native.Int64
|
||||||
--> ℤ ~ ZigZagInt ~ ℕ ~ x86.UInt64
|
--> ℤ ~ ZigZagInt ~ ℕ ~ native.UInt64
|
||||||
```
|
```
|
||||||
if( *src >= 0 ) {
|
if( *src >= 0 ) {
|
||||||
*dst = (2 * (uint64_t)*src)
|
*dst = (2 * (uint64_t)*src)
|
||||||
|
@ -15,8 +15,8 @@ morph_i64_as_twos_complement_to_zigzag ()
|
||||||
```
|
```
|
||||||
|
|
||||||
morph_i64_as_zigzag_to_twos_complement ()
|
morph_i64_as_zigzag_to_twos_complement ()
|
||||||
ℤ ~ ZigZagInt ~ ℕ ~ x86.UInt64
|
ℤ ~ ZigZagInt ~ ℕ ~ native.UInt64
|
||||||
--> ℤ ~ x86.Int64
|
--> ℤ ~ native.Int64
|
||||||
```
|
```
|
||||||
if( *src % 2 == 0 ) {
|
if( *src % 2 == 0 ) {
|
||||||
*dst = *src / 2;
|
*dst = *src / 2;
|
||||||
|
|
96
src/c_gen.rs
96
src/c_gen.rs
|
@ -20,15 +20,15 @@ pub fn get_c_repr_type(dict: &mut impl TypeDict, t: laddertypes::TypeTerm, skip_
|
||||||
match lnf.last() {
|
match lnf.last() {
|
||||||
Some(t) => {
|
Some(t) => {
|
||||||
if t == &dict.parse("Byte").expect("parse")
|
if t == &dict.parse("Byte").expect("parse")
|
||||||
|| t == &dict.parse("x86.UInt8").expect("parse")
|
|| t == &dict.parse("native.UInt8").expect("parse")
|
||||||
|| t == &dict.parse("<StaticLength 8 Bit>").expect("parse")
|
|| t == &dict.parse("<StaticLength 8 Bit>").expect("parse")
|
||||||
{
|
{
|
||||||
Some("uint8_t".into())
|
Some("uint8_t".into())
|
||||||
} else if t == &dict.parse("x86.UInt16").expect("parse") {
|
} else if t == &dict.parse("native.UInt16").expect("parse") {
|
||||||
Some("uint16_t".into())
|
Some("uint16_t".into())
|
||||||
} else if t == &dict.parse("x86.UInt32").expect("parse") {
|
} else if t == &dict.parse("native.UInt32").expect("parse") {
|
||||||
Some("uint32_t".into())
|
Some("uint32_t".into())
|
||||||
} else if t == &dict.parse("x86.UInt64").expect("parse") {
|
} else if t == &dict.parse("native.UInt64").expect("parse") {
|
||||||
Some("uint64_t".into())
|
Some("uint64_t".into())
|
||||||
} else if t == &dict.parse("native.Float").expect("parse") {
|
} else if t == &dict.parse("native.Float").expect("parse") {
|
||||||
Some("float".into())
|
Some("float".into())
|
||||||
|
@ -39,15 +39,31 @@ pub fn get_c_repr_type(dict: &mut impl TypeDict, t: laddertypes::TypeTerm, skip_
|
||||||
laddertypes::TypeTerm::App(args) => {
|
laddertypes::TypeTerm::App(args) => {
|
||||||
if args[0] == laddertypes::TypeTerm::TypeID(dict.get_typeid(&"LengthPrefix".into()).unwrap())
|
if args[0] == laddertypes::TypeTerm::TypeID(dict.get_typeid(&"LengthPrefix".into()).unwrap())
|
||||||
{
|
{
|
||||||
let _length_type = args[1].clone();
|
let length_c_type : String = get_c_repr_type(dict, args[1].clone(), false)?;
|
||||||
let item_c_type : String = get_c_repr_type(dict, args[2].clone(), false)?;
|
let item_c_type : String = get_c_repr_type(dict, args[2].clone(), false)?;
|
||||||
match item_c_type.as_str() {
|
|
||||||
"uint8_t" => Some(format!("struct LengthPrefixUInt8Array")),
|
match length_c_type.as_str() {
|
||||||
"uint16_t" => Some(format!("struct LengthPrefixUInt16Array")),
|
"uint8_t" |
|
||||||
"uint32_t" => Some(format!("struct LengthPrefixUInt32Array")),
|
"uint16_t" |
|
||||||
"uint64_t" => Some(format!("struct LengthPrefixUInt64Array")),
|
"uint32_t" |
|
||||||
_ => None
|
"uint64_t" => {}
|
||||||
|
_ => {
|
||||||
|
eprintln!("invalid length type!");
|
||||||
|
return None;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
match item_c_type.as_str() {
|
||||||
|
"uint8_t" |
|
||||||
|
"uint16_t" |
|
||||||
|
"uint32_t" |
|
||||||
|
"uint64_t" => {}
|
||||||
|
_ => {
|
||||||
|
eprintln!("invalid item type!");
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Some(format!("LengthPrefix_{}_Array_{}", length_c_type, item_c_type))
|
||||||
}
|
}
|
||||||
else if args[0] == laddertypes::TypeTerm::TypeID(dict.get_typeid(&"ValueTerminated".into()).unwrap())
|
else if args[0] == laddertypes::TypeTerm::TypeID(dict.get_typeid(&"ValueTerminated".into()).unwrap())
|
||||||
{
|
{
|
||||||
|
@ -174,7 +190,7 @@ write(2, in_str, strlen(in_str));
|
||||||
write(2, out_str, strlen(out_str));
|
write(2, out_str, strlen(out_str));
|
||||||
|
|
||||||
int l = read(0, bufA, sizeof(bufA));
|
int l = read(0, bufA, sizeof(bufA));
|
||||||
fprintf(stderr, "read %d bytes\n", l);
|
//fprintf(stderr, "read %d bytes\n", l);
|
||||||
|
|
||||||
"#,
|
"#,
|
||||||
type_dict.unparse(&src_type).replace("\\", "\\\\"),
|
type_dict.unparse(&src_type).replace("\\", "\\\\"),
|
||||||
|
@ -205,26 +221,26 @@ halo Ψ = {}
|
||||||
let is_string = false;
|
let is_string = false;
|
||||||
if let Ok((halo, σ)) = laddertypes::subtype_unify(
|
if let Ok((halo, σ)) = laddertypes::subtype_unify(
|
||||||
&dst_type,
|
&dst_type,
|
||||||
&type_dict.parse("<Seq~<ValueTerminated 0> x86.UInt8>").unwrap()
|
&type_dict.parse("<Seq~<ValueTerminated 0> native.UInt8>").unwrap()
|
||||||
) {
|
) {
|
||||||
println!(r#"
|
println!(r#"
|
||||||
printf("%s\n", {});"#, out_buf);
|
printf("%s\n", {});"#, out_buf);
|
||||||
} else if let Ok((halo, σ)) = laddertypes::subtype_unify(
|
} else if let Ok((halo, σ)) = laddertypes::subtype_unify(
|
||||||
&dst_type,
|
&dst_type,
|
||||||
&type_dict.parse("<Seq~<LengthPrefix x86.UInt64> x86.UInt8>").unwrap()
|
&type_dict.parse("<Seq~<LengthPrefix native.UInt64> native.UInt8>").unwrap()
|
||||||
) {
|
) {
|
||||||
println!(r#"
|
println!(r#"
|
||||||
/* write output
|
/* write output
|
||||||
*/
|
*/
|
||||||
{{
|
{{
|
||||||
struct LengthPrefixUInt8Array * buf = (void*){};
|
LengthPrefix_uint64_t_Array_uint8_t * buf = (void*){};
|
||||||
write(1, {}, sizeof(uint64_t) + buf->len);
|
write(1, {}, sizeof(uint64_t) + buf->len);
|
||||||
}}"#, out_buf, out_buf);
|
}}"#, out_buf, out_buf);
|
||||||
} else {
|
} else {
|
||||||
println!(r#"
|
println!(r#"
|
||||||
write(1, {}, {});"#,
|
write(1, {}, sizeof({}));"#,
|
||||||
out_buf,
|
out_buf,
|
||||||
"sizeof(bufA)"
|
out_buf
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,18 +335,42 @@ impl LdmcMorphism {
|
||||||
'}');
|
'}');
|
||||||
}
|
}
|
||||||
LdmcMorphism::LengthPrefixMap { length_prefix_type, item_morph } => {
|
LdmcMorphism::LengthPrefixMap { length_prefix_type, item_morph } => {
|
||||||
let src_c_type = get_c_repr_type(dict, self.get_type().src_type.clone().apply_substitution(&|k| σ.get(k).cloned()).clone(), true).expect("cant get c-repr type for src type");
|
let src_type = self.get_type().src_type.clone().apply_substitution(&|k| σ.get(k).cloned()).clone();
|
||||||
let dst_c_type = get_c_repr_type(dict, self.get_type().dst_type.clone().apply_substitution(&|k| σ.get(k).cloned()).clone(), true).expect("cant get c-repr type for dst type");
|
let dst_type = self.get_type().dst_type.clone().apply_substitution(&|k| σ.get(k).cloned()).clone();
|
||||||
|
|
||||||
let map_fn = match (src_c_type.as_str(), dst_c_type.as_str()) {
|
eprintln!("length prefix type ={:?}", length_prefix_type);
|
||||||
("struct LengthPrefixUInt64Array", "struct LengthPrefixUInt64Array") => "length_prefix_array_map_64_to_64",
|
eprintln!("src_type ={:?}", src_type);
|
||||||
("struct LengthPrefixUInt8Array", "struct LengthPrefixUInt64Array") => "length_prefix_array_map_8_to_64",
|
eprintln!("dst_type = {:?}", dst_type);
|
||||||
("struct LengthPrefixUInt64Array", "struct LengthPrefixUInt8Array") => "length_prefix_array_map_64_to_8",
|
|
||||||
("struct LengthPrefixUInt8Array", "struct LengthPrefixUInt8Array") => "length_prefix_array_map_8_to_8",
|
dict.add_varname("S".into());
|
||||||
_ => {
|
|
||||||
"{{ ERROR: no map function implemented }}"
|
let γ_src = laddertypes::unify(
|
||||||
}
|
&dict.parse("<Seq~<LengthPrefix S> T>").expect("parse template"),
|
||||||
};
|
&src_type
|
||||||
|
).expect("cant get src item type");
|
||||||
|
|
||||||
|
let γ_dst = laddertypes::unify(
|
||||||
|
&dict.parse("<Seq~<LengthPrefix S> T>").expect("parse template"),
|
||||||
|
&dst_type
|
||||||
|
).expect("cant get dst item type");
|
||||||
|
|
||||||
|
let src_length_type = γ_src.get(&dict.get_typeid(&"S".into()).unwrap()).expect("cant get src-length type").clone();
|
||||||
|
let dst_length_type = γ_src.get(&dict.get_typeid(&"S".into()).unwrap()).expect("cant get dst-length type").clone();
|
||||||
|
|
||||||
|
let length_type = src_length_type;
|
||||||
|
|
||||||
|
let src_item_type = γ_src.get(&dict.get_typeid(&"T".into()).unwrap()).expect("cant get src-item type").clone();
|
||||||
|
let dst_item_type = γ_dst.get(&dict.get_typeid(&"T".into()).unwrap()).expect("cant get src-item type").clone();
|
||||||
|
|
||||||
|
let length_c_type = get_c_repr_type(dict, length_type, true).expect("cant c-repr type for array length");
|
||||||
|
let src_item_c_type = get_c_repr_type(dict, src_item_type, true).expect("cant c-repr type for src item");
|
||||||
|
let dst_item_c_type = get_c_repr_type(dict, dst_item_type, true).expect("cant c-repr type for dst item");
|
||||||
|
let src_c_type = get_c_repr_type(dict, src_type, true).expect("cant get c-repr type for src type");
|
||||||
|
let dst_c_type = get_c_repr_type(dict, dst_type, true).expect("cant get c-repr type for dst type");
|
||||||
|
|
||||||
|
let map_fn = format!("length_prefix_{}_array_map_{}_to_{}",
|
||||||
|
length_c_type, src_item_c_type, dst_item_c_type
|
||||||
|
);
|
||||||
|
|
||||||
let src_buf = if i%2 == 0 { "bufA" } else { "bufB" };
|
let src_buf = if i%2 == 0 { "bufA" } else { "bufB" };
|
||||||
let dst_buf = if i%2 == 0 { "bufB" } else { "bufA" };
|
let dst_buf = if i%2 == 0 { "bufB" } else { "bufA" };
|
||||||
|
|
|
@ -25,7 +25,7 @@ fn main() {
|
||||||
let mut morphism_base = laddertypes::MorphismBase::<LdmcMorphism>::new(vec![
|
let mut morphism_base = laddertypes::MorphismBase::<LdmcMorphism>::new(vec![
|
||||||
//type_dict.parse("Seq~MsbCont").expect(""),
|
//type_dict.parse("Seq~MsbCont").expect(""),
|
||||||
//type_dict.parse("Seq~<ValueTerminated '\\0'>").expect(""),
|
//type_dict.parse("Seq~<ValueTerminated '\\0'>").expect(""),
|
||||||
type_dict.parse("Seq~<LengthPrefix x86.UInt64>").expect("")
|
type_dict.parse("Seq~<LengthPrefix native.UInt64>").expect("")
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let mut args = std::env::args().skip(1);
|
let mut args = std::env::args().skip(1);
|
||||||
|
|
30
test/test.sh
30
test/test.sh
|
@ -11,7 +11,7 @@ Running test case ${TEST_NAME}"
|
||||||
ldmc "${SRC_TYPE}" "${DST_TYPE}" ../morphisms/*.morphism-base 2>|.tmp/ldmc_err 1>| target/src/${TEST_NAME}.c \
|
ldmc "${SRC_TYPE}" "${DST_TYPE}" ../morphisms/*.morphism-base 2>|.tmp/ldmc_err 1>| target/src/${TEST_NAME}.c \
|
||||||
|| (echo "... error at generation:"; cat .tmp/ldmc_err; return -1);
|
|| (echo "... error at generation:"; cat .tmp/ldmc_err; return -1);
|
||||||
|
|
||||||
gcc -I../morphisms/runtime/include target/src/${TEST_NAME}.c ../morphisms/runtime/src/*.c -o target/${TEST_NAME} \
|
gcc -I../morphisms/runtime/include target/src/${TEST_NAME}.c -o target/${TEST_NAME} \
|
||||||
|| (echo "... error at compilation:"; return -2);
|
|| (echo "... error at compilation:"; return -2);
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,50 +34,50 @@ Running test case ${TEST_NAME}"
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_NAME=test-radix-convert
|
TEST_NAME=test-radix-convert
|
||||||
SRC_TYPE="ℕ ~ <PosInt 10 BigEndian> ~ <Seq~<ValueTerminated 0> <Digit 10> ~ Char ~ Ascii ~ x86.UInt8>"
|
SRC_TYPE="ℕ ~ <PosInt 10 BigEndian> ~ <Seq~<ValueTerminated 0> <Digit 10> ~ Char ~ Ascii ~ native.UInt8>"
|
||||||
DST_TYPE="ℕ ~ <PosInt 16 BigEndian> ~ <Seq~<ValueTerminated 0> <Digit 16> ~ Char ~ Ascii ~ x86.UInt8>"
|
DST_TYPE="ℕ ~ <PosInt 16 BigEndian> ~ <Seq~<ValueTerminated 0> <Digit 16> ~ Char ~ Ascii ~ native.UInt8>"
|
||||||
INPUT="255"
|
INPUT="255"
|
||||||
EXPECT="ff"
|
EXPECT="ff"
|
||||||
run_test_case
|
run_test_case
|
||||||
|
|
||||||
TEST_NAME=test-msb-cont
|
TEST_NAME=test-msb-cont
|
||||||
SRC_TYPE="<Seq~<ValueTerminated 0> x86.UInt8>"
|
SRC_TYPE="<Seq~<ValueTerminated 0> native.UInt8>"
|
||||||
DST_TYPE="<Seq~MsbCont x86.UInt8>"
|
DST_TYPE="<Seq~MsbCont native.UInt8>"
|
||||||
INPUT=$(printf '\x01\x02\x03')
|
INPUT=$(printf '\x01\x02\x03')
|
||||||
EXPECT=$(printf '\x81\x82\x03')
|
EXPECT=$(printf '\x81\x82\x03')
|
||||||
run_test_case
|
run_test_case
|
||||||
|
|
||||||
TEST_NAME=test-value-sep1
|
TEST_NAME=test-value-sep1
|
||||||
SRC_TYPE="<Seq <Seq Char~x86.UInt8>> ~ <ValueSep ':' Char~x86.UInt8> ~ <Seq~<ValueTerminated 0> Char~x86.UInt8>"
|
SRC_TYPE="<Seq <Seq Char~native.UInt8>> ~ <ValueSep ':' Char~native.UInt8> ~ <Seq~<ValueTerminated 0> Char~native.UInt8>"
|
||||||
DST_TYPE="<Seq <Seq Char~x86.UInt8>> ~ <ValueSep ',' Char~x86.UInt8> ~ <Seq~<ValueTerminated 0> Char~x86.UInt8>"
|
DST_TYPE="<Seq <Seq Char~native.UInt8>> ~ <ValueSep ',' Char~native.UInt8> ~ <Seq~<ValueTerminated 0> Char~native.UInt8>"
|
||||||
INPUT="abc:def:hello world:test"
|
INPUT="abc:def:hello world:test"
|
||||||
EXPECT="abc,def,hello world,test"
|
EXPECT="abc,def,hello world,test"
|
||||||
run_test_case
|
run_test_case
|
||||||
|
|
||||||
TEST_NAME=test-value-sep2
|
TEST_NAME=test-value-sep2
|
||||||
SRC_TYPE="<Seq <Seq x86.UInt8>> ~ <ValueSep ':' x86.UInt8> ~ <Seq~<ValueTerminated 0> x86.UInt8>"
|
SRC_TYPE="<Seq <Seq native.UInt8>> ~ <ValueSep ':' native.UInt8> ~ <Seq~<ValueTerminated 0> native.UInt8>"
|
||||||
DST_TYPE="<Seq <Seq x86.UInt8>> ~ <ValueSep '\\n' x86.UInt8> ~ <Seq~<ValueTerminated 0> x86.UInt8>"
|
DST_TYPE="<Seq <Seq native.UInt8>> ~ <ValueSep '\\n' native.UInt8> ~ <Seq~<ValueTerminated 0> native.UInt8>"
|
||||||
INPUT="abc:def:hello world:test"
|
INPUT="abc:def:hello world:test"
|
||||||
EXPECT=$(echo -en "abc\ndef\nhello world\ntest")
|
EXPECT=$(echo -en "abc\ndef\nhello world\ntest")
|
||||||
run_test_case
|
run_test_case
|
||||||
|
|
||||||
TEST_NAME=test-value-sep-digit
|
TEST_NAME=test-value-sep-digit
|
||||||
SRC_TYPE="<Seq <Seq <Digit 16>~Char~Ascii~x86.UInt8>> ~ <ValueSep ':' Char~Ascii~x86.UInt8> ~ <Seq~<ValueTerminated '\0'> Char~Ascii~x86.UInt8>"
|
SRC_TYPE="<Seq <Seq <Digit 16>~Char~Ascii~native.UInt8>> ~ <ValueSep ':' Char~Ascii~native.UInt8> ~ <Seq~<ValueTerminated '\0'> Char~Ascii~native.UInt8>"
|
||||||
DST_TYPE="<Seq <Seq <Digit 16>~Char~Ascii~x86.UInt8>> ~ <ValueSep '.' Char~Ascii~x86.UInt8> ~ <Seq~<ValueTerminated '\0'> Char~Ascii~x86.UInt8>"
|
DST_TYPE="<Seq <Seq <Digit 16>~Char~Ascii~native.UInt8>> ~ <ValueSep '.' Char~Ascii~native.UInt8> ~ <Seq~<ValueTerminated '\0'> Char~Ascii~native.UInt8>"
|
||||||
INPUT="c0:ff:ee"
|
INPUT="c0:ff:ee"
|
||||||
EXPECT=$(echo -en "c0.ff.ee")
|
EXPECT=$(echo -en "c0.ff.ee")
|
||||||
run_test_case
|
run_test_case
|
||||||
|
|
||||||
TEST_NAME=test-utf8-to-ascii
|
TEST_NAME=test-utf8-to-ascii
|
||||||
SRC_TYPE="<Seq Char~Unicode> ~ UTF-8 ~ <Seq ~ <ValueTerminated 0> x86.UInt8>"
|
SRC_TYPE="<Seq Char~Unicode> ~ UTF-8 ~ <Seq ~ <ValueTerminated 0> native.UInt8>"
|
||||||
DST_TYPE="<Seq~<ValueTerminated 0> Char ~ Ascii ~ x86.UInt8>"
|
DST_TYPE="<Seq~<ValueTerminated 0> Char ~ Ascii ~ native.UInt8>"
|
||||||
INPUT="Hℵelαlo WΓΓΓorl⇒d"
|
INPUT="Hℵelαlo WΓΓΓorl⇒d"
|
||||||
EXPECT="Hello World"
|
EXPECT="Hello World"
|
||||||
run_test_case
|
run_test_case
|
||||||
|
|
||||||
TEST_NAME=test-value-sep-posint
|
TEST_NAME=test-value-sep-posint
|
||||||
SRC_TYPE="<Seq ℕ~<PosInt 16 BigEndian>~<Seq <Digit 16>~Char~Ascii~x86.UInt8>> ~ <ValueSep ':' Char~Ascii~x86.UInt8> ~ <Seq~<ValueTerminated '\0'> Char~Ascii~x86.UInt8>"
|
SRC_TYPE="<Seq ℕ~<PosInt 16 BigEndian>~<Seq <Digit 16>~Char~Ascii~native.UInt8>> ~ <ValueSep ':' Char~Ascii~native.UInt8> ~ <Seq~<ValueTerminated '\0'> Char~Ascii~native.UInt8>"
|
||||||
DST_TYPE="<Seq ℕ~<PosInt 16 BigEndian>~<Seq <Digit 16>~Char~Ascii~x86.UInt8>> ~ <ValueSep '.' Char~Ascii~x86.UInt8> ~ <Seq~<ValueTerminated '\0'> Char~Ascii~x86.UInt8>"
|
DST_TYPE="<Seq ℕ~<PosInt 16 BigEndian>~<Seq <Digit 16>~Char~Ascii~native.UInt8>> ~ <ValueSep '.' Char~Ascii~native.UInt8> ~ <Seq~<ValueTerminated '\0'> Char~Ascii~native.UInt8>"
|
||||||
INPUT="c0:ff:ee"
|
INPUT="c0:ff:ee"
|
||||||
EXPECT=$(echo -en "c0.ff.ee")
|
EXPECT=$(echo -en "c0.ff.ee")
|
||||||
run_test_case
|
run_test_case
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue