aboutsummaryrefslogtreecommitdiff
path: root/docs/notes/header_generation.txt
blob: 253aa21de779fb21d6da1f1076c35210cb4c97b8 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70

Make .lh headers optional and generate ".olh" files from the exported
stuff in the .lc file. The .olh files should be possible to read by both
a C compiler and a LRL compiler.

The Makefile can have a rule for generating .olh files from .lc files, e.g.

    .lc.olh:
            lrlc -h $< -o $@
    .SUFFIXES: .lc .olh


 1. Can we use #defines to replace LRL specific stuff with whitespace if
    the C compiler reads the file? some stuff are tricky, such as array
    parameters and optional types.
        - advantage: this would allow the C interop to be used for this.
        - advantage: if C or a language based on C is adds the features found
          in LRL (such as pointer ownership), then it can define _LRLinterop
          to some version, and all the _LRLxxx values, and then include the
          file directly.
 2. Or should we generate both C and LRL code, and select between them by an
    #ifdef?
 3. Use something like 1, but try to use as much C standard stuff as possible.
    Have a header that defines a "profile" with defaults. This format could be
    used by other programming languages too.
        - advantage: this would allow the C interop to be used for this.
        - advantage: C programmers could also add LRL stuff to their headers
          if they want to have minimal support for LRL (like they often do
          with C++).


Example of 1:

    /*#LRLHDR# Generated file. Do not modify. */
    #if !defined(_LRLinterop) || _LRLinterop < 1L
    #define _LRLinterop 1L
    #define _LRLptr *
    #define _LRLbyte uint8
    #define _LRLown
    #define _LRLrefown(r)
    #endif
    
    _LRLbyte _LRLptr find_space(_LRLbyte _LRLptr s);


Example of 2:

    /*#LRLHDR# Generated file. Do not modify. */
    #ifdef _LRL
    byte^ find_space(byte^ s);
    #else
    unsigned char *find_space(unsigned char *s);
    #endif

Example of 3:

    /*#INTEROPHDR# Generated file. Do not modify. */
    #ifdef _INTEROPHDR
    #define _IHptrdefault nonown const
    #define _IHargdefault const
    #define _IHfuncdefault nonpure
    #define _IHtype_charptr utf8zstring
    #define _IHtype_ucharptr binary
    #endif
    #define _IHownptr *

    char *find_space(char *s);
    char _IHownptr get_error_string(int errorcode);