Skip to content

Commit 574ccd1

Browse files
amomchilovMorriar
andcommitted
Add templating mechanism to generate .c/.h files
Generate the c/h code for constant definitions and object initialization. We make sure the Rake task builds the required templates so we can compile the extension. Co-authored-by: Alexandre Terrasa <[email protected]>
1 parent 5576405 commit 574ccd1

File tree

12 files changed

+1371
-253
lines changed

12 files changed

+1371
-253
lines changed

Rakefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,15 @@ task :confirm_annotation do
4343
sh "git diff --exit-code core stdlib"
4444
end
4545

46+
task :templates do
47+
sh "bundle exec ruby templates/template.rb ext/rbs_extension/constants.h"
48+
sh "bundle exec ruby templates/template.rb ext/rbs_extension/ruby_objs.h"
49+
sh "bundle exec ruby templates/template.rb ext/rbs_extension/constants.c"
50+
sh "bundle exec ruby templates/template.rb ext/rbs_extension/ruby_objs.c"
51+
end
52+
4653
task :compile => "ext/rbs_extension/lexer.c"
54+
Rake::Task[:compile].prereqs.prepend :templates
4755

4856
task :test_doc do
4957
files = Dir.chdir(File.expand_path('..', __FILE__)) do

config.yml

Lines changed: 323 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,323 @@
1+
nodes:
2+
- name: RBS::AST::Annotation
3+
fields:
4+
- name: string
5+
- name: location
6+
- name: RBS::AST::Comment
7+
fields:
8+
- name: string
9+
- name: location
10+
- name: RBS::AST::Declarations::Class
11+
fields:
12+
- name: name
13+
- name: type_params
14+
- name: super_class
15+
- name: members
16+
- name: annotations
17+
- name: location
18+
- name: comment
19+
- name: RBS::AST::Declarations::Class::Super
20+
fields:
21+
- name: name
22+
- name: args
23+
- name: location
24+
- name: RBS::AST::Declarations::ClassAlias
25+
fields:
26+
- name: new_name
27+
- name: old_name
28+
- name: location
29+
- name: comment
30+
- name: RBS::AST::Declarations::Constant
31+
fields:
32+
- name: name
33+
- name: type
34+
- name: location
35+
- name: comment
36+
- name: RBS::AST::Declarations::Global
37+
fields:
38+
- name: name
39+
- name: type
40+
- name: location
41+
- name: comment
42+
- name: RBS::AST::Declarations::Interface
43+
fields:
44+
- name: name
45+
- name: type_params
46+
- name: members
47+
- name: annotations
48+
- name: location
49+
- name: comment
50+
- name: RBS::AST::Declarations::Module
51+
fields:
52+
- name: name
53+
- name: type_params
54+
- name: self_types
55+
- name: members
56+
- name: annotations
57+
- name: location
58+
- name: comment
59+
- name: RBS::AST::Declarations::Module::Self
60+
fields:
61+
- name: name
62+
- name: args
63+
- name: location
64+
- name: RBS::AST::Declarations::ModuleAlias
65+
fields:
66+
- name: new_name
67+
- name: old_name
68+
- name: location
69+
- name: comment
70+
- name: RBS::AST::Declarations::TypeAlias
71+
fields:
72+
- name: name
73+
- name: type_params
74+
- name: type
75+
- name: annotations
76+
- name: location
77+
- name: comment
78+
- name: RBS::AST::Directives::Use
79+
fields:
80+
- name: clauses
81+
- name: location
82+
- name: RBS::AST::Directives::Use::SingleClause
83+
fields:
84+
- name: type_name
85+
- name: new_name
86+
- name: location
87+
- name: RBS::AST::Directives::Use::WildcardClause
88+
fields:
89+
- name: namespace
90+
- name: location
91+
- name: RBS::AST::Members::Alias
92+
fields:
93+
- name: new_name
94+
- name: old_name
95+
- name: kind
96+
- name: annotations
97+
- name: location
98+
- name: comment
99+
- name: RBS::AST::Members::AttrAccessor
100+
fields:
101+
- name: name
102+
- name: type
103+
- name: ivar_name
104+
- name: kind
105+
- name: annotations
106+
- name: location
107+
- name: comment
108+
- name: visibility
109+
- name: RBS::AST::Members::AttrReader
110+
fields:
111+
- name: name
112+
- name: type
113+
- name: ivar_name
114+
- name: kind
115+
- name: annotations
116+
- name: location
117+
- name: comment
118+
- name: visibility
119+
- name: RBS::AST::Members::AttrWriter
120+
fields:
121+
- name: name
122+
- name: type
123+
- name: ivar_name
124+
- name: kind
125+
- name: annotations
126+
- name: location
127+
- name: comment
128+
- name: visibility
129+
- name: RBS::AST::Members::ClassInstanceVariable
130+
fields:
131+
- name: name
132+
- name: type
133+
- name: location
134+
- name: comment
135+
- name: RBS::AST::Members::ClassVariable
136+
fields:
137+
- name: name
138+
- name: type
139+
- name: location
140+
- name: comment
141+
- name: RBS::AST::Members::Extend
142+
fields:
143+
- name: name
144+
- name: args
145+
- name: annotations
146+
- name: location
147+
- name: comment
148+
- name: RBS::AST::Members::Include
149+
fields:
150+
- name: name
151+
- name: args
152+
- name: annotations
153+
- name: location
154+
- name: comment
155+
- name: RBS::AST::Members::InstanceVariable
156+
fields:
157+
- name: name
158+
- name: type
159+
- name: location
160+
- name: comment
161+
- name: RBS::AST::Members::MethodDefinition
162+
fields:
163+
- name: name
164+
- name: kind
165+
- name: overloads
166+
- name: annotations
167+
- name: location
168+
- name: comment
169+
- name: overloading
170+
- name: visibility
171+
- name: RBS::AST::Members::MethodDefinition::Overload
172+
fields:
173+
- name: annotations
174+
- name: method_type
175+
- name: RBS::AST::Members::Prepend
176+
fields:
177+
- name: name
178+
- name: args
179+
- name: annotations
180+
- name: location
181+
- name: comment
182+
- name: RBS::AST::Members::Private
183+
fields:
184+
- name: location
185+
- name: RBS::AST::Members::Public
186+
fields:
187+
- name: location
188+
- name: RBS::AST::TypeParam
189+
fields:
190+
- name: name
191+
- name: variance
192+
- name: upper_bound
193+
- name: default_type
194+
- name: location
195+
- name: RBS::MethodType
196+
fields:
197+
- name: type_params
198+
- name: type
199+
- name: block
200+
- name: location
201+
- name: RBS::Namespace
202+
fields:
203+
- name: path
204+
- name: absolute
205+
- name: RBS::TypeName
206+
fields:
207+
- name: namespace
208+
- name: name
209+
- name: RBS::Types::Alias
210+
fields:
211+
- name: name
212+
c_name: typename # Temporary name to match existing C code. Will be removed in next PR.
213+
- name: args
214+
- name: location
215+
- name: RBS::Types::Bases::Any
216+
fields:
217+
- name: location
218+
- name: RBS::Types::Bases::Bool
219+
fields:
220+
- name: location
221+
- name: RBS::Types::Bases::Bottom
222+
fields:
223+
- name: location
224+
- name: RBS::Types::Bases::Class
225+
fields:
226+
- name: location
227+
- name: RBS::Types::Bases::Instance
228+
fields:
229+
- name: location
230+
- name: RBS::Types::Bases::Nil
231+
fields:
232+
- name: location
233+
- name: RBS::Types::Bases::Self
234+
fields:
235+
- name: location
236+
- name: RBS::Types::Bases::Top
237+
fields:
238+
- name: location
239+
- name: RBS::Types::Bases::Void
240+
fields:
241+
- name: location
242+
- name: RBS::Types::Block
243+
fields:
244+
- name: type
245+
- name: required
246+
- name: self_type
247+
- name: RBS::Types::ClassInstance
248+
fields:
249+
- name: name
250+
c_name: typename # Temporary name to match existing C code. Will be removed in next PR.
251+
- name: args
252+
c_name: type_args # Temporary name to match existing C code. Will be removed in next PR.
253+
- name: location
254+
- name: RBS::Types::ClassSingleton
255+
fields:
256+
- name: name
257+
c_name: typename # Temporary name to match existing C code. Will be removed in next PR.
258+
- name: location
259+
- name: RBS::Types::Function
260+
fields:
261+
- name: required_positionals
262+
c_name: required_positional_params # Temporary name to match existing C code. Will be removed in next PR.
263+
- name: optional_positionals
264+
c_name: optional_positional_params # Temporary name to match existing C code. Will be removed in next PR.
265+
- name: rest_positionals
266+
c_name: rest_positional_params # Temporary name to match existing C code. Will be removed in next PR.
267+
- name: trailing_positionals
268+
c_name: trailing_positional_params # Temporary name to match existing C code. Will be removed in next PR.
269+
- name: required_keywords
270+
- name: optional_keywords
271+
- name: rest_keywords
272+
- name: return_type
273+
- name: RBS::Types::Function::Param
274+
fields:
275+
- name: type
276+
- name: name
277+
- name: location
278+
- name: RBS::Types::Interface
279+
fields:
280+
- name: name
281+
c_name: typename # Temporary name to match existing C code. Will be removed in next PR.
282+
- name: args
283+
c_name: type_args # Temporary name to match existing C code. Will be removed in next PR.
284+
- name: location
285+
- name: RBS::Types::Intersection
286+
fields:
287+
- name: types
288+
- name: location
289+
- name: RBS::Types::Literal
290+
fields:
291+
- name: literal
292+
- name: location
293+
- name: RBS::Types::Optional
294+
fields:
295+
- name: type
296+
- name: location
297+
- name: RBS::Types::Proc
298+
fields:
299+
- name: type
300+
c_name: function # Temporary name to match existing C code. Will be removed in next PR.
301+
- name: block
302+
- name: location
303+
- name: self_type
304+
- name: RBS::Types::Record
305+
fields:
306+
- name: all_fields
307+
c_name: fields # Temporary name to match existing C code. Will be removed in next PR.
308+
- name: location
309+
- name: RBS::Types::Tuple
310+
fields:
311+
- name: types
312+
- name: location
313+
- name: RBS::Types::Union
314+
fields:
315+
- name: types
316+
- name: location
317+
- name: RBS::Types::UntypedFunction
318+
fields:
319+
- name: return_type
320+
- name: RBS::Types::Variable
321+
fields:
322+
- name: name
323+
- name: location

0 commit comments

Comments
 (0)