make MsbCont morphism generic over item type
This commit is contained in:
parent
4b824cbb7c
commit
1869176bb7
2 changed files with 16 additions and 24 deletions
|
@ -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;
|
||||
|
|
11
src/c_gen.rs
11
src/c_gen.rs
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue