Commit 93a6432
committed
[[ LCB ]] Improve builtin module emission and loading
This patch reworks the way builtin modules are handled.
When lc-compile is run in --outputc mode, it will now emit a C
byte array for each module which is passed on the command line
along with a unique global class instance which calls
MCScriptRegisterBuiltinModule in its constructor. This function takes
a fixed format static record which contains the module data and its
(C) initializer and finalizer. When called, the function will link
the static record into a singly-linked list of builtin modules.
When MCScriptInitialize is called, it will now iterate through this
list loading each module, and setting each one's initializer and
finalizer. It will then ensure each builtin module is usable.
The initializer and finalizer are now called by libscript itself -
the initializer when the module is made usable, and the finalizer
when the module is (finally) destroyed.
This new mechanism means that builtin modules do not all have to be
compiled together into one C file, but compiled and linked into the
engine separately.
Note: It is necessary to 'force_load' (Mac/iOS), 'WHOLEARCHIVE' (Win)
and 'whole-archive/no-whole-archive' (Linux) any libs containing
builtin modules when linking the final executable, otherwise the
global objects used for registration will be stripped.
Note: We need to use 'all_dependent_settings' on Mac, iOS and Win to
broadcast the linker setting to the top-level target. This is in
contrast to 'direct_dependent_settings' on Linux and Android to stop
multiple repeats of the same linker option.1 parent f83d351 commit 93a6432
File tree
17 files changed
+178
-197
lines changed- engine
- src
- libfoundation/src
- libscript
- include/libscript
- src
- toolchain/lc-compile
- src
17 files changed
+178
-197
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 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 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
33 | 87 | | |
34 | 88 | | |
35 | 89 | | |
| |||
47 | 101 | | |
48 | 102 | | |
49 | 103 | | |
50 | | - | |
| 104 | + | |
51 | 105 | | |
52 | 106 | | |
53 | 107 | | |
| |||
62 | 116 | | |
63 | 117 | | |
64 | 118 | | |
65 | | - | |
| 119 | + | |
66 | 120 | | |
67 | 121 | | |
68 | 122 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | 53 | | |
57 | 54 | | |
58 | 55 | | |
| |||
73 | 70 | | |
74 | 71 | | |
75 | 72 | | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | 73 | | |
83 | 74 | | |
84 | 75 | | |
| |||
148 | 139 | | |
149 | 140 | | |
150 | 141 | | |
151 | | - | |
152 | 142 | | |
153 | 143 | | |
154 | 144 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | 133 | | |
137 | 134 | | |
138 | 135 | | |
| |||
218 | 215 | | |
219 | 216 | | |
220 | 217 | | |
221 | | - | |
222 | | - | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
223 | 221 | | |
224 | 222 | | |
225 | 223 | | |
| |||
329 | 327 | | |
330 | 328 | | |
331 | 329 | | |
332 | | - | |
333 | 330 | | |
334 | 331 | | |
335 | 332 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | 35 | | |
39 | 36 | | |
40 | 37 | | |
| |||
64 | 61 | | |
65 | 62 | | |
66 | 63 | | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | 64 | | |
72 | 65 | | |
73 | 66 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2001 | 2001 | | |
2002 | 2002 | | |
2003 | 2003 | | |
2004 | | - | |
2005 | | - | |
2006 | | - | |
2007 | 2004 | | |
2008 | 2005 | | |
2009 | 2006 | | |
| |||
2023 | 2020 | | |
2024 | 2021 | | |
2025 | 2022 | | |
2026 | | - | |
2027 | | - | |
| 2023 | + | |
| 2024 | + | |
| 2025 | + | |
2028 | 2026 | | |
2029 | 2027 | | |
2030 | 2028 | | |
| |||
2076 | 2074 | | |
2077 | 2075 | | |
2078 | 2076 | | |
2079 | | - | |
2080 | 2077 | | |
2081 | 2078 | | |
2082 | 2079 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | | - | |
61 | 59 | | |
62 | 60 | | |
63 | 61 | | |
| |||
1971 | 1969 | | |
1972 | 1970 | | |
1973 | 1971 | | |
1974 | | - | |
1975 | 1972 | | |
1976 | 1973 | | |
1977 | 1974 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2053 | 2053 | | |
2054 | 2054 | | |
2055 | 2055 | | |
2056 | | - | |
2057 | | - | |
2058 | 2056 | | |
2059 | 2057 | | |
2060 | 2058 | | |
| |||
2065 | 2063 | | |
2066 | 2064 | | |
2067 | 2065 | | |
2068 | | - | |
2069 | | - | |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
2070 | 2069 | | |
2071 | 2070 | | |
2072 | 2071 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
612 | 612 | | |
613 | 613 | | |
614 | 614 | | |
615 | | - | |
616 | | - | |
617 | | - | |
618 | 615 | | |
619 | 616 | | |
620 | | - | |
621 | | - | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
622 | 620 | | |
623 | 621 | | |
624 | 622 | | |
| |||
672 | 670 | | |
673 | 671 | | |
674 | 672 | | |
675 | | - | |
676 | 673 | | |
677 | 674 | | |
678 | 675 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
237 | 237 | | |
238 | 238 | | |
239 | 239 | | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
240 | 243 | | |
241 | 244 | | |
242 | 245 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
168 | 171 | | |
169 | 172 | | |
170 | 173 | | |
| |||
0 commit comments