Class: MilkTea::Types::Task

Inherits:
Base
  • Object
show all
Defined in:
lib/milk_tea/core/types/types.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#accept, #bitwise?, #boolean?, #field_c_name, #float?, #integer?, #numeric?, #sendable?, #void?

Constructor Details

#initialize(result_type) ⇒ Task

Returns a new instance of Task.



593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
# File 'lib/milk_tea/core/types/types.rb', line 593

def initialize(result_type)
  @result_type = result_type
  void_ptr = GenericInstance.new("ptr", [Primitive.new("void")])
  wake_fn = Function.new(
    nil,
    params: [Parameter.new("frame", void_ptr)],
    return_type: Primitive.new("void"),
  )
  @fields = {
    "frame" => void_ptr,
    "ready" => Function.new(
      nil,
      params: [Parameter.new("frame", void_ptr)],
      return_type: Primitive.new("bool"),
    ),
    "set_waiter" => Function.new(
      nil,
      params: [
        Parameter.new("frame", void_ptr),
        Parameter.new("waiter_frame", void_ptr),
        Parameter.new("waiter", wake_fn),
      ],
      return_type: Primitive.new("void"),
    ),
    "release" => Function.new(
      nil,
      params: [Parameter.new("frame", void_ptr)],
      return_type: Primitive.new("void"),
    ),
    "take_result" => Function.new(
      nil,
      params: [Parameter.new("frame", void_ptr)],
      return_type: result_type,
    ),
    "cancel" => Function.new(
      nil,
      params: [Parameter.new("frame", void_ptr)],
      return_type: Primitive.new("void"),
    ),
  }.freeze
  @hash = [self.class, result_type].hash
  freeze
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



643
644
645
# File 'lib/milk_tea/core/types/types.rb', line 643

def hash
  @hash
end

#result_typeObject (readonly)

Returns the value of attribute result_type.



591
592
593
# File 'lib/milk_tea/core/types/types.rb', line 591

def result_type
  @result_type
end

Instance Method Details

#childrenObject



661
662
663
# File 'lib/milk_tea/core/types/types.rb', line 661

def children
  [result_type]
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


637
638
639
# File 'lib/milk_tea/core/types/types.rb', line 637

def eql?(other)
  other.is_a?(Task) && other.result_type == result_type
end

#field(name) ⇒ Object



653
654
655
# File 'lib/milk_tea/core/types/types.rb', line 653

def field(name)
  @fields[name]
end

#fieldsObject



649
650
651
# File 'lib/milk_tea/core/types/types.rb', line 649

def fields
  @fields
end

#nameObject



645
646
647
# File 'lib/milk_tea/core/types/types.rb', line 645

def name
  to_s
end

#to_sObject



657
658
659
# File 'lib/milk_tea/core/types/types.rb', line 657

def to_s
  "Task[#{result_type}]"
end