Skip to content

Commit a7b0562

Browse files
committed
FEAT: automatically collecting base code from C sources
If such a comment is used in C file: ``` /********************************************************************** ** Base-code: if find system/codecs 'wav [ system/codecs/wav/suffixes: [%.wav %.wave] system/codecs/wav/type: 'binary! append append system/options/file-types system/codecs/wav/suffixes 'wav ] ***********************************************************************/ ``` The Rebol code from it is extracted and included just after content of the src/mezz/base-defs.r Note that at this stage there is just a minimal system available, so one must be careful, what code is used.
1 parent 1c86e01 commit a7b0562

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ make/libr3.dll
1010
src/boot/boot-code.r
1111
src/boot/host-init.r
1212
src/boot/tmp-natives.r
13+
src/boot/tmp-symbols.r
1314
src/core/b-boot.c
1415
src/include/ext-types.h
1516
src/include/host-*
@@ -21,6 +22,7 @@ src/include/reb-types.h
2122
src/include/tmp-*
2223
src/tools/reb-lib-doc.txt
2324
src/reb-lib-doc.txt
25+
src/mezz/base-collected.r
2426

2527
#################
2628
## Eclipse

src/mezz/boot-files.r

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ REBOL [
2020
%base-files.r
2121
%base-debug.r
2222
%base-defs.r
23+
%base-collected.r ; contains automatically collected code from C files
2324
]
2425

2526
;-- sys: low-level sys context:

src/tools/make-headers.r

+44-4
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ print "------ Building headers"
1717

1818
r3: system/version > 2.100.0
1919

20+
zero-index?: not none? pick next system/platform 0 ;@@ used to be able compile using old R3 versions which were using path/0 instead of path/-1
21+
2022
verbose: false
2123
chk-dups: true
2224
dups: make block! 10000 ; get pick [map! hash!] r3 1000
2325
dup-found: false
2426

2527
do %form-header.r
28+
file-base: load %file-base.r
2629

2730
tmp: context [
2831

@@ -31,6 +34,14 @@ change-dir %../core/
3134
count: 0
3235
output: make string! 20000
3336
natives: make string! 20000
37+
base-code: make string! 2000
38+
insert base-code {REBOL [
39+
title: "Rebol base code collected from C sources"
40+
purpose: "This is code which must be evaluated just after code from base-defs.r file"
41+
commment: "AUTO-GENERATED FILE - Do not modify. (From: make-headers.r)"
42+
]
43+
}
44+
3445

3546
emit: func [d] [append repend output d newline]
3647
emit-rl: func [d] [append repend rlib d newline]
@@ -131,7 +142,7 @@ sym-chars: charset [#"A" - #"Z" #"_" #"0" - #"9"]
131142
sym-check: charset "/S"
132143
symbols: make block! 256
133144

134-
process: func [file /local sym p] [
145+
process: func [file /local sym p comm spec commented?] [
135146
if verbose [?? file]
136147
data: read the-file: file
137148
if r3 [data: deline to-string data]
@@ -150,19 +161,45 @@ process: func [file /local sym p] [
150161
"/*" thru "*/"
151162
| "//" to newline
152163
| "SYM_" copy sym some sym-chars (
153-
if not find sym-chars p/0 [
164+
if not find sym-chars either zero-index? [p/0][p/-1] [
154165
append symbols sym
155166
]
156167
)
157168
| 1 skip
158169
]
159170
]
160171
]
172+
173+
;collect Rebol code which may be evaluated on startup
174+
parse data [
175+
any [
176+
;Search only in /*...*/ comments
177+
thru "^//*" copy comm to "*/" (
178+
parse/all comm [any [
179+
thru {^/**} [
180+
any [#" " | #"^-"]
181+
"Base-code:"
182+
any [#" " | #"^-"] newline
183+
copy spec to "^/*" (
184+
if not commented? [
185+
append base-code rejoin [{^/;- code from: } mold file lf lf]
186+
commented?: true
187+
]
188+
append base-code spec
189+
)
190+
| to newline
191+
]
192+
]]
193+
)
194+
]
195+
]
161196
]
162197

163198
emit-header "Function Prototypes" %funcs.h
164199

165-
files: sort read %./
200+
;in original source all files in core folder were parsed
201+
;now only the files specified in file-base/core are processed
202+
files: file-base/core
166203

167204
;do
168205
[
@@ -172,7 +209,9 @@ files: sort read %./
172209
]
173210

174211
foreach file files [
212+
file: to file! file
175213
if all [
214+
exists? file
176215
%.c = suffix? file
177216
not find/match file "host-"
178217
not find/match file "os-"
@@ -182,12 +221,13 @@ foreach file files [
182221
symbols: sort unique symbols ;contains all symbols (like: SYM_CALL) used in above processed C files (without the SYM_ part)
183222
symbols: new-line/skip symbols true 1
184223

185-
save/header %../boot/tmp-symbols.r symbols [
224+
save/header %../boot/tmp-symbols.r symbols [
186225
title: "C Symbols"
187226
purpose: "Automaticly collected symbols from C files"
188227
commment: "AUTO-GENERATED FILE - Do not modify. (From: make-headers.r)"
189228

190229
]
230+
write %../mezz/base-collected.r base-code
191231
write %../boot/tmp-natives.r natives
192232
write %../include/tmp-funcs.h output
193233

0 commit comments

Comments
 (0)