Skip to content

Commit 8ad3748

Browse files
committed
Some untangling of %sys-ext.h
The dependencies of %sys-ext.h were a bit unclear. This moves the builtin extensions table--as well as the API table--into their own .c files so that what #includes they use can be just what's needed for the table and not get mixed up with the file they're .inc'd into. It also makes the ExtensionCollator definition part of %sys-core.h since in general extensions shouldn't need to define that or the IDX_ values.
1 parent fd10570 commit 8ad3748

14 files changed

+105
-91
lines changed

configs/emscripten.r

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ ldflags: compose [
219219
{-s ERROR_ON_UNDEFINED_SYMBOLS=0}
220220
])
221221

222-
; Generated by %make-reb-lib.r, see notes there. Pertains to this:
222+
; Generated by %make-librebol.r, see notes there. Pertains to this:
223223
; https://github.com/emscripten-core/emscripten/issues/4240
224224
;
225225
(if host = #node [
@@ -280,7 +280,7 @@ ldflags: compose [
280280
;
281281
(if debug-javascript-extension [{--minify 0}])
282282

283-
; %reb-lib.js is produced by %make-reb-lib.js - It contains the wrapper
283+
; %reb-lib.js is produced by %make-librebol.js - It contains the wrapper
284284
; code that proxies JavaScript calls to `rebElide(...)` etc. into calls
285285
; to the functions that take a `va_list` pointer, e.g. `_RL_rebElide()`.
286286
;

extensions/javascript/mod-javascript.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ enum Reb_Native_State {
327327
// The resolve will be called if it reaches the end of the input and the
328328
// reject if there is a failure.
329329
//
330-
// Note: See %make-reb-lib.r for code that produces the `rebPromise(...)` API,
330+
// Note: See %make-librebol.r for code that produces the `rebPromise(...)` API,
331331
// which ties the returned integer into the resolve and reject branches of an
332332
// actual JavaScript ES6 Promise.
333333
//

extensions/javascript/tools/prep-libr3-js.reb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ REBOL [
2626
]
2727

2828
; Note: There are no `import` statements here because this is run via DO LOAD
29-
; within the %make-reb-lib.r script's context. This is done in order to
29+
; within the %make-librebol.r script's context. This is done in order to
3030
; inherit the `api` object, and the `for-each-api` enumerator. As a result
3131
; it also inherits access to CWRAP and other tools. Review.
3232

3333

3434
e-cwrap: make-emitter "JavaScript C Wrapper functions" (
35-
join output-dir %reb-lib.js
35+
join prep-dir %include/reb-lib.js
3636
)
3737

3838
=== "ASYNCIFY_BLACKLIST TOLERANT CWRAP" ===
@@ -912,7 +912,7 @@ json-collect: func [
912912
}]
913913
]
914914

915-
write (join output-dir %libr3.exports.json) json-collect [
915+
write (join prep-dir %include/libr3.exports.json) json-collect [
916916
for-each-api [keep unspaced ["RL_" name]]
917917
keep "malloc" ; !!! Started requiring, did not before (?)
918918
]
@@ -944,7 +944,7 @@ write (join output-dir %libr3.exports.json) json-collect [
944944
; the final return value of a JS-AWAITER can be returned with it.
945945
; </review>
946946

947-
write (join output-dir %asyncify-blacklist.json) delimit newline collect [
947+
write (join prep-dir %include/asyncify-blacklist.json) delimit newline collect [
948948
keep "["
949949
for-next names load %../asyncify-blacklist.r [
950950
keep unspaced [_ _ _ _ {"} names/1 {"} if not last? names [","]]
@@ -968,7 +968,7 @@ write (join output-dir %asyncify-blacklist.json) delimit newline collect [
968968
;
969969

970970
e-node-preload: make-emitter "Emterpreter Preload for Node.js" (
971-
join output-dir %node-preload.js
971+
join prep-dir %include/node-preload.js
972972
)
973973

974974
e-node-preload/emit {

extensions/tcc/tools/prep-libr3-tcc.reb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ REBOL [
2929
]
3030

3131
; Note: There are no `import` statements here because this is run via DO LOAD
32-
; within the %make-reb-lib.r script's context. This is done in order to
32+
; within the %make-librebol.r script's context. This is done in order to
3333
; inherit the `api` object, and the `for-each-api` enumerator. As a result
3434
; it also inherits access to CWRAP and other tools. Review.
3535

3636

3737
e: make-emitter "libRebol exports for tcc_add_symbol()" (
38-
join output-dir %tmp-librebol-symbols.inc
38+
join prep-dir %include/tmp-librebol-symbols.inc
3939
)
4040

4141
for-each-api [

make.r

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1930,7 +1930,7 @@ prep: make rebmake/entry-class [
19301930
"GIT_COMMIT=$(GIT_COMMIT)"
19311931
]
19321932
keep [
1933-
"$(REBOL)" join tools-dir %make-reb-lib.r
1933+
"$(REBOL)" join tools-dir %make-librebol.r
19341934
unspaced ["OS_ID=" platform-config/id]
19351935
]
19361936

@@ -1969,7 +1969,7 @@ prep: make rebmake/entry-class [
19691969
]
19701970

19711971
keep [
1972-
"$(REBOL)" join tools-dir %make-boot-ext-header.r
1972+
"$(REBOL)" join tools-dir %make-extensions-table.r
19731973
unspaced [
19741974
"EXTENSIONS=" delimit ":" map-each ext extensions [
19751975
if ext/mode = <builtin> [to text! ext/name]

src/core/a-lib.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
//=////////////////////////////////////////////////////////////////////////=//
2323
//
2424
// This is the "external" API, and %rebol.h contains its exported
25-
// definitions. That file (and %make-reb-lib.r which generates it) contains
25+
// definitions. That file (and %make-librebol.r which generates it) contains
2626
// comments and notes which will help understand it.
2727
//
2828
// What characterizes the external API is that it is not necessary to #include
@@ -2845,8 +2845,6 @@ DECLARE_NATIVE(api_transient)
28452845
}
28462846

28472847

2848-
#include "sys-ext.h"
2849-
28502848
//
28512849
// rebCollateExtension_internal: RL_API
28522850
//

src/core/f-extension.c

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,6 @@
3232
#include "sys-core.h"
3333

3434

35-
// We wish to define a table of API functions to pass to extensions. The way
36-
// functions like `rebValue()` work when called from an extension is to
37-
// delegate to a function from this table. (When called from the core, they
38-
//
39-
#include "tmp-reb-lib-table.inc" // declares g_librebol
40-
41-
42-
// Building Rebol as a library may still entail a desire to ship that library
43-
// with built-in extensions (e.g. building libr3.js wants to have JavaScript
44-
// natives as an extension). So there is no meaning to "built-in extensions"
45-
// for a library otherwise...as every client will be making their own EXE, and
46-
// there's no way to control their build process from Rebol's build process.
47-
//
48-
// Hence, the generated header for boot extensions is included here--to allow
49-
// clients to get access to those extensions through an API.
50-
//
51-
#include "tmp-boot-extensions.inc"
52-
53-
5435
//
5536
// Startup_Extension_Loader: C
5637
//
@@ -91,20 +72,24 @@ DECLARE_NATIVE(builtin_extensions)
9172
// (`-`): Don't build at all
9273
//
9374
// Command-line processing or other code that uses Rebol may need to make
94-
// decisions on when to initialize these built-in extensions. So rebStartup()
95-
// does initialize them automatically. Instead, this merely returns the
96-
// list of descriptions of the extensions, which can then be loaded with the
97-
// LOAD-EXTENSION function.
75+
// decisions on when to initialize these built-in extensions. Also, building
76+
// Rebol as a library may still entail a desire to ship that library with
77+
// built-in extensions (e.g. building libr3.js wants to have JavaScript
78+
// natives as an extension).
79+
//
80+
// So rebStartup() doesn't initialize extensions automatically. Instead, this
81+
// merely returns the list of descriptions of the extensions, which can then
82+
// be loaded with the LOAD-EXTENSION function.
9883
//
9984
// 1. Built-in extensions do not receive the RebolApiTable, because they are
10085
// able to use direct calls to the RL_Xxx() versions, which is faster.
10186
{
10287
INCLUDE_PARAMS_OF_BUILTIN_EXTENSIONS;
10388

104-
Array* list = Make_Array(NUM_BUILTIN_EXTENSIONS);
89+
Array* list = Make_Array(g_num_builtin_extensions);
10590
REBLEN i;
106-
for (i = 0; i != NUM_BUILTIN_EXTENSIONS; ++i) {
107-
RebolExtensionCollator* collator = g_builtin_collators[i];
91+
for (i = 0; i != g_num_builtin_extensions; ++i) {
92+
ExtensionCollator* collator = g_builtin_collators[i];
10893

10994
Value* details = (*collator)(nullptr); // don't pass g_librebol [1]
11095
assert(Is_Block(details));

src/include/sys-ext.h

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,8 @@
5151
#define RX_COLLATE_NAME(ext_name) RX_Collate_##ext_name
5252
#endif
5353

54-
// The init function does not actually decompress any of the script or spec
55-
// code, make any natives, or run any startup. It just returns an aggregate
56-
// of all the information that would be needed to make the extension module.
57-
//
58-
// !!! This aggregate may become an ACTION! as opposed to an array of handle
59-
// values, but this is a work in progress.
60-
//
61-
#if defined(_WIN32)
62-
typedef RebolValue* (__cdecl RebolExtensionCollator)(RebolApiTable*);
63-
#else
64-
typedef RebolValue* (RebolExtensionCollator)(RebolApiTable*);
65-
#endif
6654

6755
//=//// EXTENSION MACROS //////////////////////////////////////////////////=//
6856

69-
#define DECLARE_EXT_COLLATE(ext_name) \
57+
#define DECLARE_EXTENSION_COLLATOR(ext_name) \
7058
EXT_API RebolValue* RX_COLLATE_NAME(ext_name)(RebolApiTable* api)
71-
72-
// !!! Currently used for just a BLOCK!, but may become Phase_Details()
73-
//
74-
#define IDX_COLLATOR_SCRIPT 0
75-
#define IDX_COLLATOR_SCRIPT_NUM_CODEPOINTS 1
76-
#define IDX_COLLATOR_CFUNCS 2
77-
#define IDX_COLLATOR_MAX 3

src/include/sys-hooks.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,30 @@ typedef REBINT (COMPARE_HOOK)(
5151
void N_##n(Atom* out, Phase* phase, Value* arg)
5252

5353

54+
//
55+
// EXTENSION COLLATOR FUNCTION DEFINITION
56+
//
57+
// Rebol Extensions generate DLLs (or embed into the EXE) with a function
58+
// that does initialization. But that init function does not actually
59+
// decompress any of the script or spec code, make any natives, or run
60+
// any startup. It just returns an aggregate of all the information that
61+
// would be needed to make the extension module. So it is called a
62+
// "collator", and it calls the API `rebExtensionCollate_internal()`
63+
//
64+
// !!! The result may become an ACTION! as opposed to a BLOCK! of handle
65+
// values, but this is a work in progress.
66+
//
67+
#if defined(_WIN32)
68+
typedef Value* (__cdecl ExtensionCollator)(RebolApiTable*);
69+
#else
70+
typedef Value* (ExtensionCollator)(RebolApiTable*);
71+
#endif
72+
#define IDX_COLLATOR_SCRIPT 0
73+
#define IDX_COLLATOR_SCRIPT_NUM_CODEPOINTS 1
74+
#define IDX_COLLATOR_CFUNCS 2
75+
#define IDX_COLLATOR_MAX 3
76+
77+
5478
// PER-TYPE MAKE HOOKS: for `make datatype def`
5579
//
5680
// These functions must return a Value* to the type they are making

tools/file-base.r

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,19 @@ generated: [
222222
tmp-boot-block.c
223223
tmp-type-hooks.c
224224
tmp-typesets.c
225+
tmp-builtin-extension-table.c
226+
tmp-rebol-api-table.c
225227
]
226228

227229
made: [
228-
make-boot.r core/tmp-boot-block.c
229-
make-headers.r include/tmp-internals.h
230+
make-boot.r core/tmp-boot-block.c
231+
make-extension-table.r core/tmp-builtin-extension-table.c
232+
make-librebol.r core/tmp-rebol-api-table.c
230233

231-
make-host-init.r include/host-init.h
232-
make-reb-lib.r include/rebol.h
234+
make-headers.r include/tmp-internals.h
235+
236+
make-host-init.r include/host-init.h
237+
make-librebol.r include/rebol.h
233238
]
234239

235240
main: 'main.c

tools/make-boot.r

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,13 @@ e-boot/emit [fields {
11171117
EXTERN_C const REBLEN g_num_core_natives;
11181118
EXTERN_C CFunction* const g_core_native_cfuncs[];
11191119
1120+
/*
1121+
* Builtin Extensions
1122+
*/
1123+
EXTERN_C const unsigned int g_num_builtin_extensions;
1124+
EXTERN_C ExtensionCollator* const g_builtin_collators[];
1125+
1126+
11201127
typedef struct REBOL_Boot_Block {
11211128
$[Fields];
11221129
} BOOT_BLK;

tools/make-boot-ext-header.r renamed to tools/make-extensions-table.r

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
REBOL [
22
System: "REBOL [R3] Language Interpreter and Run-time Environment"
3-
Title: "Generate extention native header files"
4-
File: %make-boot-ext-header.r ; EMIT-HEADER uses to note emitting script
3+
Title: "Generate table of ExtensionCollators for all built-in extensions"
4+
File: %make-extensions-table.r ; EMIT-HEADER uses this filename
55
Rights: {
66
Copyright 2017 Atronix Engineering
7-
Copyright 2017-2018 Ren-C Open Source Contributors
7+
Copyright 2017-2024 Ren-C Open Source Contributors
88
REBOL is a trademark of REBOL Technologies
99
}
1010
License: {
@@ -30,10 +30,10 @@ REBOL [
3030
be gathered in a table to be gathered up so the system can find them.
3131
3232
This script gets the list of *only* the built-in extensions on the
33-
command line, then builds that table. It is included as part of
34-
%a-lib.h, which exposes it via the rebBuiltinExtensions() API to
35-
whatever client (C, JavaScript, etc.) that may want to start them
36-
up selectively...which must be at some point *after* rebStartup().
33+
command line, then builds that table. It is exposed via the
34+
rebBuiltinExtensions() API to whatever client (C, JavaScript, etc.)
35+
that may want to start them up selectively...which must be at some
36+
point *after* rebStartup().
3737
}
3838
]
3939

@@ -46,37 +46,48 @@ import <bootstrap-shim.r>
4646
import <common.r>
4747
import <common-emitter.r>
4848

49-
r3: system/version > 2.100.0
50-
5149
args: parse-args system/script/args ; either from command line or DO/ARGS
5250
output-dir: join system/options/path %prep/
53-
mkdir/deep (join output-dir %include/)
5451

5552
extensions: map-each e (split args/EXTENSIONS #":") [
5653
to-c-name e ; so SOME-EXTENSION becomes SOME_EXTENSION for C macros
5754
]
5855

59-
e: make-emitter "Boot Modules" (
60-
join output-dir %include/tmp-boot-extensions.inc
56+
e: make-emitter "Built-in Extensions" (
57+
join output-dir %core/tmp-builtin-extension-table.c
6158
)
6259

6360
e/emit [extensions {
64-
#include "sys-ext.h"
61+
#include "sys-core.h" /* ExtensionCollator type, Value*, etc. */
62+
#include "sys-ext.h" /* DECLARE_EXTENSION_COLLATOR(), etc. */
63+
64+
#ifdef __cplusplus
65+
extern "C" {
66+
#endif
6567
66-
DECLARE_EXT_COLLATE($[Extensions]);
68+
DECLARE_EXTENSION_COLLATOR($[Extensions]);
6769
6870
#define NUM_BUILTIN_EXTENSIONS $<length of extensions>
6971
72+
/*
73+
* NUM_BUILTIN_EXTENSIONS macro not visible outside this file, export
74+
*/
75+
const unsigned int g_num_builtin_extensions = NUM_BUILTIN_EXTENSIONS;
76+
7077
/*
7178
* List of C functions that can be called to fetch the collated info that
7279
* the system needs to bring an extension into being. No startup or
7380
* decompression code is run when these functions are called...they just
7481
* return information needed for later reifying those extensions.
7582
*/
76-
static RebolExtensionCollator *g_builtin_collators[] = {
83+
ExtensionCollator* const g_builtin_collators[] = {
7784
RX_COLLATE_NAME($[Extensions]),
7885
nullptr /* Just for guaranteeing length > 0, as C++ requires it */
7986
};
87+
88+
#ifdef __cplusplus
89+
} /* end extern "C" */
90+
#endif
8091
}]
8192

8293
e/write-emitted

tools/make-headers.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ emit-proto: func [
8181
switch header/2 [
8282
'RL_API [
8383
; Currently the RL_API entries should only occur in %a-lib.c, and
84-
; are processed by %make-reb-lib.r. Their RL_XxxYyy() forms are
84+
; are processed by %make-librebol.r. Their RL_XxxYyy() forms are
8585
; not in the %tmp-internals.h file, but core includes %rebol.h
8686
; and considers itself to have "non-extension linkage" to the API,
8787
; so the calls can be directly linked without a struct.

0 commit comments

Comments
 (0)