Skip to content

Commit

Permalink
FEAT: automatically collecting base code from C sources
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Oldes committed Jun 14, 2018
1 parent 1c86e01 commit a7b0562
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ make/libr3.dll
src/boot/boot-code.r
src/boot/host-init.r
src/boot/tmp-natives.r
src/boot/tmp-symbols.r
src/core/b-boot.c
src/include/ext-types.h
src/include/host-*
Expand All @@ -21,6 +22,7 @@ src/include/reb-types.h
src/include/tmp-*
src/tools/reb-lib-doc.txt
src/reb-lib-doc.txt
src/mezz/base-collected.r

#################
## Eclipse
Expand Down
1 change: 1 addition & 0 deletions src/mezz/boot-files.r
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ REBOL [
%base-files.r
%base-debug.r
%base-defs.r
%base-collected.r ; contains automatically collected code from C files
]

;-- sys: low-level sys context:
Expand Down
48 changes: 44 additions & 4 deletions src/tools/make-headers.r
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ print "------ Building headers"

r3: system/version > 2.100.0

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

verbose: false
chk-dups: true
dups: make block! 10000 ; get pick [map! hash!] r3 1000
dup-found: false

do %form-header.r
file-base: load %file-base.r

tmp: context [

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


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

process: func [file /local sym p] [
process: func [file /local sym p comm spec commented?] [
if verbose [?? file]
data: read the-file: file
if r3 [data: deline to-string data]
Expand All @@ -150,19 +161,45 @@ process: func [file /local sym p] [
"/*" thru "*/"
| "//" to newline
| "SYM_" copy sym some sym-chars (
if not find sym-chars p/0 [
if not find sym-chars either zero-index? [p/0][p/-1] [
append symbols sym
]
)
| 1 skip
]
]
]

;collect Rebol code which may be evaluated on startup
parse data [
any [
;Search only in /*...*/ comments
thru "^//*" copy comm to "*/" (
parse/all comm [any [
thru {^/**} [
any [#" " | #"^-"]
"Base-code:"
any [#" " | #"^-"] newline
copy spec to "^/*" (
if not commented? [
append base-code rejoin [{^/;- code from: } mold file lf lf]
commented?: true
]
append base-code spec
)
| to newline
]
]]
)
]
]
]

emit-header "Function Prototypes" %funcs.h

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

;do
[
Expand All @@ -172,7 +209,9 @@ files: sort read %./
]

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

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

]
write %../mezz/base-collected.r base-code
write %../boot/tmp-natives.r natives
write %../include/tmp-funcs.h output

Expand Down

0 comments on commit a7b0562

Please sign in to comment.