Skip to content

Commit c1857ff

Browse files
committed
FEAT: Automatically collecting symbols (like SYM_PLAY) so one can use them in C code without adding new words into boot/words.r file (which is still in use)
1 parent fb1ca88 commit c1857ff

File tree

2 files changed

+55
-8
lines changed

2 files changed

+55
-8
lines changed

src/tools/make-boot.r

+26-7
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,16 @@ emit-line: func [prefix word cmt /var /define /code /decl /up1 /local str][
164164

165165
str: any [
166166
if define [rejoin [prefix str]]
167-
if code [rejoin [" " prefix str cmt]]
167+
if code [rejoin [tab prefix str cmt]]
168168
if decl [rejoin [prefix str cmt]]
169-
rejoin [" " prefix str ","]
169+
rejoin [tab prefix str ","]
170170
]
171171
if any [code decl] [cmt: none]
172172
if cmt [
173-
len: 31 - length? str
174-
loop to-integer len / 4 [append str tab]
173+
append/dup str #" " (31 - length? str)
175174
any [
176175
if define [repend str cmt]
177-
if cmt [repend str ["// " cmt]]
176+
if cmt [repend str ["// " cmt]]
178177
]
179178
]
180179
append str newline
@@ -187,7 +186,7 @@ emit-head: func [title [string!] file [file!]] [
187186
]
188187

189188
emit-end: func [/easy] [
190-
if not easy [remove find/last out #","]
189+
if not easy [change find/last out #"," #" "]
191190
append out {^};^/}
192191
]
193192

@@ -720,9 +719,13 @@ emit {
720719
SYM_NOT_USED = 0,
721720
}
722721

722+
used-words: copy []
723+
723724
n: 1
724725
foreach :type-record boot-types [
725-
emit-line "SYM_" join type "_type" n
726+
word: join type "_type"
727+
append used-words to-c-name word
728+
emit-line "SYM_" word n
726729
n: n + 1
727730
]
728731

@@ -731,9 +734,25 @@ boot-words: load %words.r
731734
replace boot-words '*port-modes* load %modes.r
732735

733736
foreach word boot-words [
737+
append used-words to-c-name word
734738
emit-line "SYM_" word reform [n "-" word]
735739
n: n + 1
736740
]
741+
742+
if exists? %../boot/tmp-symbols.r [
743+
emit {^/ // follows symbols used in C sources, but not defined in %words.r list...^/}
744+
745+
foreach word load %../boot/tmp-symbols.r [
746+
if not find used-words word [
747+
append boot-words to word! lowercase word
748+
emit-line "SYM_" word form n
749+
n: n + 1
750+
]
751+
]
752+
753+
delete %../boot/tmp-symbols.r
754+
]
755+
737756
emit-end
738757

739758
;-- Generate Action Constants ------------------------------------------------

src/tools/make-headers.r

+29-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ native-header: [
127127
)
128128
]
129129

130-
process: func [file] [
130+
sym-chars: charset [#"A" - #"Z" #"_" #"0" - #"9"]
131+
sym-check: charset "/S"
132+
symbols: make block! 256
133+
134+
process: func [file /local sym p] [
131135
if verbose [?? file]
132136
data: read the-file: file
133137
if r3 [data: deline to-string data]
@@ -139,6 +143,21 @@ process: func [file] [
139143
]
140144
]
141145
]
146+
;collect all SYM_* uses
147+
parse/all/case data [
148+
any [
149+
to sym-check p: [
150+
"/*" thru "*/"
151+
| "//" to newline
152+
| "SYM_" copy sym some sym-chars (
153+
if not find sym-chars p/0 [
154+
append symbols sym
155+
]
156+
)
157+
| 1 skip
158+
]
159+
]
160+
]
142161
]
143162

144163
emit-header "Function Prototypes" %funcs.h
@@ -160,6 +179,15 @@ foreach file files [
160179
][process file]
161180
]
162181

182+
symbols: sort unique symbols ;contains all symbols (like: SYM_CALL) used in above processed C files (without the SYM_ part)
183+
symbols: new-line/skip symbols true 1
184+
185+
save/header %../boot/tmp-symbols.r symbols [
186+
title: "C Symbols"
187+
purpose: "Automaticly collected symbols from C files"
188+
commment: "AUTO-GENERATED FILE - Do not modify. (From: make-headers.r)"
189+
190+
]
163191
write %../boot/tmp-natives.r natives
164192
write %../include/tmp-funcs.h output
165193

0 commit comments

Comments
 (0)