-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add templating mechanism to automatically generate .c
/.h
files
#2
Conversation
VALUE RBS_AST_Declarations; | ||
VALUE RBS_AST_Directives; | ||
VALUE RBS_AST_Members; | ||
VALUE RBS_Parser; | ||
VALUE RBS_Types; | ||
VALUE RBS_Types_Bases; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are special-cased in the template. The rest of the file is code-genned, but in a different order than the original. All the same constants are still here, though.
VALUE rbs_bases_void(VALUE location); | ||
VALUE rbs_bases_top(VALUE location); | ||
VALUE rbs_bases_self(VALUE location); | ||
VALUE rbs_bases_nil(VALUE location); | ||
VALUE rbs_bases_instance(VALUE location); | ||
VALUE rbs_bases_class(VALUE location); | ||
VALUE rbs_bases_bottom(VALUE location); | ||
VALUE rbs_bases_bool(VALUE location); | ||
VALUE rbs_bases_any(VALUE location); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All 9 of these types used to have their own Ruby classes, but shared the same "constructor" (rbs_base_type()
).
We will eventually want 9 different C structs to model these (to keep a simple 1:1 correspondence to the Ruby classes), with 9 different constructor functions. We did that here, since it simplifies automation.
VALUE rbs_ast_members_method_definition(VALUE name, VALUE kind, VALUE overloads, VALUE annotations, VALUE location, VALUE comment, VALUE overloading, VALUE visibility); | ||
VALUE rbs_ast_members_method_definition_overload(VALUE annotations, VALUE method_type); | ||
VALUE rbs_ast_members_mixin(VALUE klass, VALUE name, VALUE args, VALUE annotations, VALUE location, VALUE comment); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was split into 3 functions:
rbs_ast_members_extend()
rbs_ast_members_include()
rbs_ast_members_prepend()
@@ -963,25 +963,25 @@ static VALUE parse_simple(parserstate *state) { | |||
return type; | |||
} | |||
case kBOOL: | |||
return rbs_base_type(RBS_Types_Bases_Bool, rbs_location_current_token(state)); | |||
return rbs_bases_bool(rbs_location_current_token(state)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a note to rename these methods later to a name that is easier to generate so we can avoid some of the complexity in template.rb
templates/template.rb
Outdated
@name = yaml["name"].split("::").last | ||
@c_function_name = if @full_name =~ /^RBS::Types/ | ||
name = @full_name.gsub("::", "_").underscore | ||
name.gsub("_types_", "_") # TODO: should we rename these methods? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's change this TODO to explain that we're going to do this next and remove this whole if
statement
bdbd95f
to
b8d3eb3
Compare
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]>
b8d3eb3
to
a888013
Compare
Opened ruby#2098 |
This PR automates the creation of these pre-existing files:
constants.h
constants.c
ruby_objs.h
ruby_objs.c
In this initial PR, we aim to generate these files to match as closely to their original hand-authored versions. To facilitate this, we added some trickery to the ERB files, to get it as close as practical. These will be removed in a follow-up PR.