summaryrefslogtreecommitdiff
path: root/common/rust_translation_notes.txt
blob: ece37a023473feb589b3a8524a18c7a9854a0b5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifdef LZ_PLT
#define PIXEL one_byte_pixel_t
#define FNAME(name) glz_plt_##name
#define ENCODE_PIXEL(e, pix) encode(e, (pix).a)   // gets the pixel and write only the needed bytes
                                                  // from the pixel
#define SAME_PIXEL(pix1, pix2) ((pix1).a == (pix2).a)
#define MIN_REF_ENCODE_SIZE 4
#define MAX_REF_ENCODE_SIZE 7
#define HASH_FUNC(v, p) {  \
    v = DJB2_START;        \
    DJB2_HASH(v, p[0].a);  \
    DJB2_HASH(v, p[1].a);  \
    DJB2_HASH(v, p[2].a);  \
    v &= HASH_MASK;        \
    }
#endif

is going to become:

templated functions for anything that looks like a function, using references
then I will make sure those functions are inlined.
assuming inlining happens early enough, the resulting code should be the same (!citation/proof needed!)

all functions produced by FNAME are to be templates. They are all statics and so called directly by
glz_encode.

Only problem is code optionally compiled. i.e.

fn if_i_only_could()
{
#ifdef PLT
    encode(magic_plt);
#endif
    encode(always_encode_this);
}

PIXEL type
FNAME(name) -> traits

Problems
========

no nested structs
no variadic argument C ABI (but can call external variadic argument C ABI fine, i.e. libc printf)
no preprocessor. poor grasp of traits
hard to use pointers. or I just don't like offset.

C to Rust
=========

static void f()
=>
fn f()

static by default - that is, for compilation unit which is a crate?. Anyway you need to 'pub' whatever you want visible outside (i.e. in the symbol table)