Class: CastOff::Compiler::Iseq::Args

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/cast_off/compile/iseq.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#bug, #dlog, #todo, #vlog

Constructor Details

#initialize(args, iseq) ⇒ Args

Returns a new instance of Args.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/cast_off/compile/iseq.rb', line 15

def initialize(args, iseq)
  @iseq = iseq
  case args
  when Integer
    @argc, @opts, @post_len, @post_start, @rest_index, @block_index, @simple = args, [], 0, 0, -1, -1, 1
  when Array
    bug() unless args.size == 7
    @argc, @opts, @post_len, @post_start, @rest_index, @block_index, @simple = args
  else
    bug()
  end
  @opt_len = @opts.empty? ? 0 : (@opts.size() - 1)
  @arg_size = @argc + @opt_len + @post_len + (@rest_index == -1 ? 0 : 1) + (@block_index == -1 ? 0 : 1)

  case @iseq.itype
  when :method
    bug() if @simple == 2
  when :block
    # nothing to do
  else
    bug()
  end

  if @rest_index != -1
    bug() unless @rest_index + 1 == @post_start
    bug() unless @argc + @opt_len == @rest_index
  end
end

Instance Attribute Details

#arg_sizeObject (readonly)

Returns the value of attribute arg_size.



13
14
15
# File 'lib/cast_off/compile/iseq.rb', line 13

def arg_size
  @arg_size
end

#argcObject (readonly)

Returns the value of attribute argc.



13
14
15
# File 'lib/cast_off/compile/iseq.rb', line 13

def argc
  @argc
end

#block_indexObject (readonly)

Returns the value of attribute block_index.



13
14
15
# File 'lib/cast_off/compile/iseq.rb', line 13

def block_index
  @block_index
end

#opt_lenObject (readonly)

Returns the value of attribute opt_len.



13
14
15
# File 'lib/cast_off/compile/iseq.rb', line 13

def opt_len
  @opt_len
end

#optsObject (readonly)

Returns the value of attribute opts.



13
14
15
# File 'lib/cast_off/compile/iseq.rb', line 13

def opts
  @opts
end

#post_lenObject (readonly)

Returns the value of attribute post_len.



13
14
15
# File 'lib/cast_off/compile/iseq.rb', line 13

def post_len
  @post_len
end

#post_startObject (readonly)

Returns the value of attribute post_start.



13
14
15
# File 'lib/cast_off/compile/iseq.rb', line 13

def post_start
  @post_start
end

#rest_indexObject (readonly)

Returns the value of attribute rest_index.



13
14
15
# File 'lib/cast_off/compile/iseq.rb', line 13

def rest_index
  @rest_index
end

Instance Method Details

#block?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/cast_off/compile/iseq.rb', line 52

def block?
  @block_index != -1
end

#opt?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/cast_off/compile/iseq.rb', line 56

def opt?
  not @opts.empty?
end

#post?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/cast_off/compile/iseq.rb', line 44

def post?
  @post_len != 0
end

#rest?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/cast_off/compile/iseq.rb', line 48

def rest?
  @rest_index != -1
end

#simple?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/cast_off/compile/iseq.rb', line 60

def simple?
  (@simple & 0x01) != 0
end

#splat?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/cast_off/compile/iseq.rb', line 64

def splat?
  (@simple & 0x02 == 0) && (@argc + @post_len > 0)
end