Skip to content

Commit

Permalink
Add templating mechanism to generate .c/.h files
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
amomchilov and Morriar committed Nov 25, 2024
1 parent d9000d2 commit a888013
Show file tree
Hide file tree
Showing 12 changed files with 1,371 additions and 253 deletions.
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,15 @@ task :confirm_annotation do
sh "git diff --exit-code core stdlib"
end

task :templates do
sh "bundle exec ruby templates/template.rb ext/rbs_extension/constants.h"
sh "bundle exec ruby templates/template.rb ext/rbs_extension/ruby_objs.h"
sh "bundle exec ruby templates/template.rb ext/rbs_extension/constants.c"
sh "bundle exec ruby templates/template.rb ext/rbs_extension/ruby_objs.c"
end

task :compile => "ext/rbs_extension/lexer.c"
Rake::Task[:compile].prereqs.prepend :templates

task :test_doc do
files = Dir.chdir(File.expand_path('..', __FILE__)) do
Expand Down
323 changes: 323 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,323 @@
nodes:
- name: RBS::AST::Annotation
fields:
- name: string
- name: location
- name: RBS::AST::Comment
fields:
- name: string
- name: location
- name: RBS::AST::Declarations::Class
fields:
- name: name
- name: type_params
- name: super_class
- name: members
- name: annotations
- name: location
- name: comment
- name: RBS::AST::Declarations::Class::Super
fields:
- name: name
- name: args
- name: location
- name: RBS::AST::Declarations::ClassAlias
fields:
- name: new_name
- name: old_name
- name: location
- name: comment
- name: RBS::AST::Declarations::Constant
fields:
- name: name
- name: type
- name: location
- name: comment
- name: RBS::AST::Declarations::Global
fields:
- name: name
- name: type
- name: location
- name: comment
- name: RBS::AST::Declarations::Interface
fields:
- name: name
- name: type_params
- name: members
- name: annotations
- name: location
- name: comment
- name: RBS::AST::Declarations::Module
fields:
- name: name
- name: type_params
- name: self_types
- name: members
- name: annotations
- name: location
- name: comment
- name: RBS::AST::Declarations::Module::Self
fields:
- name: name
- name: args
- name: location
- name: RBS::AST::Declarations::ModuleAlias
fields:
- name: new_name
- name: old_name
- name: location
- name: comment
- name: RBS::AST::Declarations::TypeAlias
fields:
- name: name
- name: type_params
- name: type
- name: annotations
- name: location
- name: comment
- name: RBS::AST::Directives::Use
fields:
- name: clauses
- name: location
- name: RBS::AST::Directives::Use::SingleClause
fields:
- name: type_name
- name: new_name
- name: location
- name: RBS::AST::Directives::Use::WildcardClause
fields:
- name: namespace
- name: location
- name: RBS::AST::Members::Alias
fields:
- name: new_name
- name: old_name
- name: kind
- name: annotations
- name: location
- name: comment
- name: RBS::AST::Members::AttrAccessor
fields:
- name: name
- name: type
- name: ivar_name
- name: kind
- name: annotations
- name: location
- name: comment
- name: visibility
- name: RBS::AST::Members::AttrReader
fields:
- name: name
- name: type
- name: ivar_name
- name: kind
- name: annotations
- name: location
- name: comment
- name: visibility
- name: RBS::AST::Members::AttrWriter
fields:
- name: name
- name: type
- name: ivar_name
- name: kind
- name: annotations
- name: location
- name: comment
- name: visibility
- name: RBS::AST::Members::ClassInstanceVariable
fields:
- name: name
- name: type
- name: location
- name: comment
- name: RBS::AST::Members::ClassVariable
fields:
- name: name
- name: type
- name: location
- name: comment
- name: RBS::AST::Members::Extend
fields:
- name: name
- name: args
- name: annotations
- name: location
- name: comment
- name: RBS::AST::Members::Include
fields:
- name: name
- name: args
- name: annotations
- name: location
- name: comment
- name: RBS::AST::Members::InstanceVariable
fields:
- name: name
- name: type
- name: location
- name: comment
- name: RBS::AST::Members::MethodDefinition
fields:
- name: name
- name: kind
- name: overloads
- name: annotations
- name: location
- name: comment
- name: overloading
- name: visibility
- name: RBS::AST::Members::MethodDefinition::Overload
fields:
- name: annotations
- name: method_type
- name: RBS::AST::Members::Prepend
fields:
- name: name
- name: args
- name: annotations
- name: location
- name: comment
- name: RBS::AST::Members::Private
fields:
- name: location
- name: RBS::AST::Members::Public
fields:
- name: location
- name: RBS::AST::TypeParam
fields:
- name: name
- name: variance
- name: upper_bound
- name: default_type
- name: location
- name: RBS::MethodType
fields:
- name: type_params
- name: type
- name: block
- name: location
- name: RBS::Namespace
fields:
- name: path
- name: absolute
- name: RBS::TypeName
fields:
- name: namespace
- name: name
- name: RBS::Types::Alias
fields:
- name: name
c_name: typename # Temporary name to match existing C code. Will be removed in next PR.
- name: args
- name: location
- name: RBS::Types::Bases::Any
fields:
- name: location
- name: RBS::Types::Bases::Bool
fields:
- name: location
- name: RBS::Types::Bases::Bottom
fields:
- name: location
- name: RBS::Types::Bases::Class
fields:
- name: location
- name: RBS::Types::Bases::Instance
fields:
- name: location
- name: RBS::Types::Bases::Nil
fields:
- name: location
- name: RBS::Types::Bases::Self
fields:
- name: location
- name: RBS::Types::Bases::Top
fields:
- name: location
- name: RBS::Types::Bases::Void
fields:
- name: location
- name: RBS::Types::Block
fields:
- name: type
- name: required
- name: self_type
- name: RBS::Types::ClassInstance
fields:
- name: name
c_name: typename # Temporary name to match existing C code. Will be removed in next PR.
- name: args
c_name: type_args # Temporary name to match existing C code. Will be removed in next PR.
- name: location
- name: RBS::Types::ClassSingleton
fields:
- name: name
c_name: typename # Temporary name to match existing C code. Will be removed in next PR.
- name: location
- name: RBS::Types::Function
fields:
- name: required_positionals
c_name: required_positional_params # Temporary name to match existing C code. Will be removed in next PR.
- name: optional_positionals
c_name: optional_positional_params # Temporary name to match existing C code. Will be removed in next PR.
- name: rest_positionals
c_name: rest_positional_params # Temporary name to match existing C code. Will be removed in next PR.
- name: trailing_positionals
c_name: trailing_positional_params # Temporary name to match existing C code. Will be removed in next PR.
- name: required_keywords
- name: optional_keywords
- name: rest_keywords
- name: return_type
- name: RBS::Types::Function::Param
fields:
- name: type
- name: name
- name: location
- name: RBS::Types::Interface
fields:
- name: name
c_name: typename # Temporary name to match existing C code. Will be removed in next PR.
- name: args
c_name: type_args # Temporary name to match existing C code. Will be removed in next PR.
- name: location
- name: RBS::Types::Intersection
fields:
- name: types
- name: location
- name: RBS::Types::Literal
fields:
- name: literal
- name: location
- name: RBS::Types::Optional
fields:
- name: type
- name: location
- name: RBS::Types::Proc
fields:
- name: type
c_name: function # Temporary name to match existing C code. Will be removed in next PR.
- name: block
- name: location
- name: self_type
- name: RBS::Types::Record
fields:
- name: all_fields
c_name: fields # Temporary name to match existing C code. Will be removed in next PR.
- name: location
- name: RBS::Types::Tuple
fields:
- name: types
- name: location
- name: RBS::Types::Union
fields:
- name: types
- name: location
- name: RBS::Types::UntypedFunction
fields:
- name: return_type
- name: RBS::Types::Variable
fields:
- name: name
- name: location
Loading

0 comments on commit a888013

Please sign in to comment.