Module: MilkTea::CompatibilityHelpers

Includes:
TypePredicates
Included in:
Lowerer, SemanticAnalyzer::Checker
Defined in:
lib/milk_tea/core/compatibility_helpers.rb

Constant Summary collapse

BUILTIN_CSTR =
Types::Registry.primitive("cstr")
EVENT_METHOD_KINDS =
{
  "subscribe" => :event_subscribe,
  "subscribe_once" => :event_subscribe_once,
  "unsubscribe" => :event_unsubscribe,
  "emit" => :event_emit,
  "wait" => :event_wait,
}.freeze
EVENT_METHOD_NAMES =
EVENT_METHOD_KINDS.invert.freeze
STR_BUFFER_METHOD_KINDS =
{
  "clear" => :str_buffer_clear,
  "assign" => :str_buffer_assign,
  "append" => :str_buffer_append,
  "assign_format" => :str_buffer_assign_format,
  "append_format" => :str_buffer_append_format,
  "len" => :str_buffer_len,
  "capacity" => :str_buffer_capacity,
  "as_str" => :str_buffer_as_str,
  "as_cstr" => :str_buffer_as_cstr,
}.freeze
STR_BUFFER_METHOD_NAMES =
STR_BUFFER_METHOD_KINDS.invert.freeze
ATOMIC_METHOD_KINDS =
{
  "load" => :atomic_load,
  "store" => :atomic_store,
  "add" => :atomic_add,
  "sub" => :atomic_sub,
  "exchange" => :atomic_exchange,
  "compare_exchange" => :atomic_compare_exchange,
}.freeze

Instance Method Summary collapse

Methods included from TypePredicates

#arity_error_message, #atomic_element_type, #atomic_type?, #call_arity_matches?, #callable_param_ref_supported?, #char_pointer_type?, #char_type?, #collection_loop_binding_type, #collection_loop_ref_element_type?, #collection_loop_type, #const_pointer_to, #const_pointer_type?, #contains_ref_type?, #contains_type_var?, #contextual_int_to_float_compatibility?, #contextual_int_to_float_target?, #dyn_type?, #exact_integer_constant_value, #exactly_representable_float32?, #external_numeric_compatibility?, #external_typed_null_pointer_compatibility?, #flatten_field_types, #float_constant_fits_type?, #foreign_boundary_element_compatible?, #foreign_char_pointer_buffer_boundary_compatible?, #foreign_external_layout_compatible?, #foreign_external_layout_field_compatible?, #foreign_function_type_projection_compatible?, #foreign_identity_projection_cast_compatible?, #foreign_identity_projection_compatible?, #foreign_identity_projection_reinterpret_compatible?, #foreign_opaque_c_name, #foreign_span_boundary_compatible?, #function_type_matches_proc_type?, #generic_integer_type_argument?, #integer_constant_fits_type?, #integer_like_char_source_type?, #integer_to_char_compatibility?, #integer_type_argument?, #lossless_external_integer_compatibility?, #lossless_integer_compatibility?, #method_dispatch_receiver_type, #mutable_pointer_type?, #mutable_to_const_pointer_compatibility?, #native_foreign_layout_compatible?, #null_assignable_to?, #numeric_constant_fits_type?, #opaque_type?, #own_to_raw_pointer_compatibility?, #own_type?, #owned_referent_type, #pointee_type, #pointer_type?, #proc_type?, #quat_vec4_layout_compatible?, #ref_lifetime, #ref_type?, #ref_type_without_lifetime?, #referenced_type, #same_external_opaque_c_name?, #same_external_opaque_handle_pointer_compatibility?, #string_builder_ref_type?, #string_builder_type?, #struct_with_target_type?, #task_root_proc_type?, #task_type?, #validate_generic_type!, #value_fits_integer_type?, #void_pointer_type?

Instance Method Details

#event_subscription_result_typeObject



61
62
63
# File 'lib/milk_tea/core/compatibility_helpers.rb', line 61

def event_subscription_result_type
  @ctx.types.fetch("Result").instantiate([@ctx.types.fetch("Subscription"), @ctx.types.fetch("EventError")])
end

#event_wait_result_type(event_type) ⇒ Object



65
66
67
# File 'lib/milk_tea/core/compatibility_helpers.rb', line 65

def event_wait_result_type(event_type)
  @ctx.types.fetch("Result").instantiate([event_type.payload_type || @ctx.types.fetch("void"), @ctx.types.fetch("EventError")])
end

#range_expr?(expression) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/milk_tea/core/compatibility_helpers.rb', line 69

def range_expr?(expression)
  expression.is_a?(AST::RangeExpr)
end

#type_ref_from_specialization(expression) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/milk_tea/core/compatibility_helpers.rb', line 44

def type_ref_from_specialization(expression)
  case expression.callee
  when AST::Identifier
    return nil if %w[zero default reinterpret].include?(expression.callee.name)

    AST::TypeRef.new(name: AST::QualifiedName.new(parts: [expression.callee.name]), arguments: expression.arguments, nullable: false)
  when AST::MemberAccess
    return nil unless expression.callee.receiver.is_a?(AST::Identifier)

    AST::TypeRef.new(
      name: AST::QualifiedName.new(parts: [expression.callee.receiver.name, expression.callee.member]),
      arguments: expression.arguments,
      nullable: false,
    )
  end
end