]> ocean-lang.org Git - ocean-D/blob - Ocean-introspection
updates
[ocean-D] / Ocean-introspection
1 Here I collect thoughts about introspection.
2
3
4 Introspection can be at compile-time as well as runtime, and can have
5 quite a different role.
6 In edlib/python I use the documentation string of class methods to
7 indicate what 'key' they respond to.  I cannot easily do that in C,
8 but could if I have compile-time introspection.  I could do it
9 with a sed script that extracts an include file ...
10
11 The language would need to allow for extra stuff to be parsed into
12 an AST, then the introspection code would run over that AST before
13 it was further analysed.  This a bit like gcc pluggins, but
14 is writting if the language being compiled, and compiled like
15 any other code.
16
17 This would be part of a larger feature that any code could run at
18 compile time instead of later.  Constant-folding is already a common
19 practice and is an example of this.
20
21 I would need a simple and stable AST ADT to be manipulated.  Most uses
22 would be relatively simple, like collection functions into an array,
23 or pre-parsing some internal data structure, possibly sorting it.
24
25 It could be as simple as allowing strings in lots of places, and 
26 expecting the introspection to parse them - along with various object
27 names - and do stuff.
28
29
30 Separately there is runtime introspection.
31 This would be needed to handle anything not known at compile time.
32
33 Mostly this is probably underspecified type.  An 'sprintf'
34 type function to be introspected and transformed at compile time
35 providing the types of everything could be determined.  And if the
36 type isn't known... recording introspection info is probably not easier
37 that recording the appropriate dispatch function.
38
39 Then there is link-time information.  Compile-time introspection needs
40 to all be run at compile-time.  If I load a foreign module at run time
41 (or link time), it cannot ask questions that weren't already asked.
42
43 Maybe a "standard" compile-time introspector could encode any info
44 needed for link-time or runtime introspectors.
45
46
47 Introspection could be used for:
48
49  - preparsing data structures
50        e.g. sorting, adding links, ..
51  - annotating for run-time 
52        e.g. storing table of function, with names
53        providing serialization, de-serialization
54  - providing default values for missing args
55  - transforming n-ary args to arrays
56  - adding appropriate dispatch info when passing args to
57       a function that expects objects
58  - adding coverage tracking
59  - adding performance tracking