make MsbCont morphism generic over item type

This commit is contained in:
Michael Sippel 2025-03-20 19:49:03 +01:00
parent 4b824cbb7c
commit 1869176bb7
Signed by: senvas
GPG key ID: F96CF119C34B64A6
2 changed files with 16 additions and 24 deletions

View file

@ -27,37 +27,20 @@ morph_array_as_lenpfx_to_valterm (Terminator:native.UInt8)
return 0;
```
morph_array_as_lenpfx_to_continuation_bit_8 ()
<Seq~<LengthPrefix native.UInt64> native.UInt8>
--> <Seq~MsbCont native.UInt8>
morph_array_as_lenpfx_to_continuation_bit (T:Type)
<Seq~<LengthPrefix native.UInt64> T>
--> <Seq~MsbCont T>
```
for( uint64_t i = 0; i < src->len; ++i ) {
if( src->items[i] & (1<<7) ) {
const size_t n_bits = 8*sizeof(T);
if( src->items[i] & (1<<(n_bits-1)) ) {
fprintf(stderr, "error: value to high for MsbContinuation\n");
return -1;
}
dst[i] = src->items[i];
if( i+1 < src->len )
dst[i] |= (1<<7);
}
return 0;
```
morph_array_as_lenpfx_to_continuation_bit_16 ()
<Seq~<LengthPrefix native.UInt64> native.UInt16>
--> <Seq~MsbCont native.UInt16>
```
for( uint64_t i = 0; i < src->len; ++i ) {
if( src->items[i] & (1<<15) ) {
fprintf(stderr, "error: value to high for MsbContinuation\n");
return -1;
}
dst[i] = src->items[i];
if( i+1 < src->len )
dst[i] |= (1<<15);
dst[i] |= (1<<(n_bits-1));
}
return 0;

View file

@ -295,7 +295,16 @@ int {} ( {} const * restrict src, {} * restrict dst ) {{
));
for (ty_id, kind) in self.type_args.iter() {
if let Some(val) = σ.get(ty_id) {
s.push_str(&format!(" #define {} {}\n", dict.get_typename(&ty_id).unwrap(), encode_type_to_value(dict, val)));
eprintln!("val = {}", dict.unparse(&val));
let type_var_value =
if let Some(c_repr_type) = get_c_repr_type(dict, val.clone(), true) {
c_repr_type
} else {
encode_type_to_value(dict, val)
};
s.push_str(&format!(" #define {} {}\n", dict.get_typename(&ty_id).unwrap(), type_var_value));
}
}