Module: MilkTea::CompileTime::Reflection
- Defined in:
- lib/milk_tea/core/compile_time.rb
Class Method Summary collapse
- .core_evaluate_type_returning(callee_name, type_args, evaluate_value:, resolve_type_ref:, pointer_to:, const_pointer_to:, top_level_functions:, evaluate_type_returning_function_body: nil) ⇒ Object
- .core_field_handle(struct_handle, field_name) ⇒ Object
- .core_field_handles(struct_handle) ⇒ Object
- .core_member_handles(type) ⇒ Object
Class Method Details
.core_evaluate_type_returning(callee_name, type_args, evaluate_value:, resolve_type_ref:, pointer_to:, const_pointer_to:, top_level_functions:, evaluate_type_returning_function_body: nil) ⇒ Object
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 |
# File 'lib/milk_tea/core/compile_time.rb', line 547 def self.core_evaluate_type_returning( callee_name, type_args, evaluate_value:, resolve_type_ref:, pointer_to:, const_pointer_to:, top_level_functions:, evaluate_type_returning_function_body: nil ) case callee_name when "ptr", "const_ptr", "span", "array", "str_buffer", "Task" evaluated_args = (type_args || []).map do |arg| value = arg.value if value.is_a?(AST::Identifier) evaluate_value.call(value) elsif value.is_a?(AST::TypeRef) resolve_type_ref.call(value) elsif value.is_a?(AST::IntegerLiteral) Types::LiteralTypeArg.new(value.value) end end return nil if evaluated_args.any?(&:nil?) case callee_name when "ptr" then pointer_to.call(evaluated_args.first) when "const_ptr" then const_pointer_to.call(evaluated_args.first) when "span" then Types::Registry.span(evaluated_args.first) when "array" then Types::Registry.generic_instance("array", evaluated_args) when "str_buffer" then Types::Registry.generic_instance("str_buffer", evaluated_args) when "Task" then Types::Registry.task(evaluated_args.first) end else func = top_level_functions.call(callee_name) return nil unless func return nil unless func.body_return_type == Types::BUILTIN_TYPE_META_TYPE if type_args && func.ast && evaluate_type_returning_function_body value = evaluate_type_returning_function_body.call(func, type_args) return value if value end Types::BUILTIN_TYPE_META_TYPE end end |
.core_field_handle(struct_handle, field_name) ⇒ Object
532 533 534 535 536 537 |
# File 'lib/milk_tea/core/compile_time.rb', line 532 def self.core_field_handle(struct_handle, field_name) field_decl = struct_handle.declaration.fields.find { |f| f.name == field_name } return nil unless field_decl Types::FieldHandle.new(struct_handle, field_name, field_decl) end |
.core_field_handles(struct_handle) ⇒ Object
539 540 541 |
# File 'lib/milk_tea/core/compile_time.rb', line 539 def self.core_field_handles(struct_handle) struct_handle.declaration.fields.map { |f| Types::FieldHandle.new(struct_handle, f.name, f) } end |
.core_member_handles(type) ⇒ Object
543 544 545 |
# File 'lib/milk_tea/core/compile_time.rb', line 543 def self.core_member_handles(type) type.members.map { |name| Types::MemberHandle.new(nil, name, type.member_value(name)) } end |