Class: Rubinius::CompiledCode

Inherits:
Object
  • Object
show all
Defined in:
lib/rubinius/bridge/compiled_code.rb

Constant Summary collapse

KernelMethodSerial =
47
CODE_ID_BYTES =
32

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCompiledCode

Returns a new instance of CompiledCode.



27
28
29
# File 'lib/rubinius/bridge/compiled_code.rb', line 27

def initialize
  @code_id = nil
end

Instance Attribute Details

#arityObject

Integer

number of arguments, negative if variadic.



23
24
25
# File 'lib/rubinius/bridge/compiled_code.rb', line 23

def arity
  @arity
end

#block_indexObject

Returns the value of attribute block_index.



25
26
27
# File 'lib/rubinius/bridge/compiled_code.rb', line 25

def block_index
  @block_index
end

#fileObject

Symbol

the file where this comes from



19
20
21
# File 'lib/rubinius/bridge/compiled_code.rb', line 19

def file
  @file
end

#hintsObject

added by the VM to indicate how it’s being used.



7
8
9
# File 'lib/rubinius/bridge/compiled_code.rb', line 7

def hints
  @hints
end

#iseqObject

Tuple

instructions to execute



10
11
12
# File 'lib/rubinius/bridge/compiled_code.rb', line 10

def iseq
  @iseq
end

#keywordsObject

Tuple

pairs of Symbol name, required flag



22
23
24
# File 'lib/rubinius/bridge/compiled_code.rb', line 22

def keywords
  @keywords
end

#linesObject

Tuple

tuple of the lines where its found



18
19
20
# File 'lib/rubinius/bridge/compiled_code.rb', line 18

def lines
  @lines
end

#literalsObject

Tuple

tuple of the literals



17
18
19
# File 'lib/rubinius/bridge/compiled_code.rb', line 17

def literals
  @literals
end

#local_countObject

Integer

number of local vars



12
13
14
# File 'lib/rubinius/bridge/compiled_code.rb', line 12

def local_count
  @local_count
end

#local_namesObject

Array<Symbol>

names of the local vars



20
21
22
# File 'lib/rubinius/bridge/compiled_code.rb', line 20

def local_names
  @local_names
end

#metadataObject

Tuple

extra data



8
9
10
# File 'lib/rubinius/bridge/compiled_code.rb', line 8

def 
  @metadata
end

#nameObject

Symbol

name of the method



9
10
11
# File 'lib/rubinius/bridge/compiled_code.rb', line 9

def name
  @name
end

#post_argsObject

Integer

number of args after splat



14
15
16
# File 'lib/rubinius/bridge/compiled_code.rb', line 14

def post_args
  @post_args
end

#primitiveObject

Returns the value of attribute primitive.



24
25
26
# File 'lib/rubinius/bridge/compiled_code.rb', line 24

def primitive
  @primitive
end

#required_argsObject

Integer

number of required args



13
14
15
# File 'lib/rubinius/bridge/compiled_code.rb', line 13

def required_args
  @required_args
end

#scopeObject

ConstantScope

scope for looking up constants



21
22
23
# File 'lib/rubinius/bridge/compiled_code.rb', line 21

def scope
  @scope
end

#splatObject

Integer

POSITION of the splat arg



16
17
18
# File 'lib/rubinius/bridge/compiled_code.rb', line 16

def splat
  @splat
end

#stack_sizeObject

Integer

size of stack at compile time



11
12
13
# File 'lib/rubinius/bridge/compiled_code.rb', line 11

def stack_size
  @stack_size
end

#total_argsObject

Integer

number of total args



15
16
17
# File 'lib/rubinius/bridge/compiled_code.rb', line 15

def total_args
  @total_args
end

Instance Method Details

#add_metadata(key, val) ⇒ Object

Raises:

  • (TypeError)


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/rubinius/bridge/compiled_code.rb', line 41

def (key, val)
  raise TypeError, "key must be a symbol" unless key.kind_of? Symbol

  case val
  when true, false, Symbol, Fixnum, String
    # ok
  else
    raise TypeError, "invalid type of value"
  end

  @metadata ||= nil # to deal with MRI seeing @metadata as not set

  unless @metadata
    @metadata = Tuple.new(2)
    @metadata[0] = key
    @metadata[1] = val
    return val
  end

  i = 0
  fin = @metadata.size

  while i < fin
    if @metadata[i] == key
      @metadata[i + 1] = val
      return val
    end

    i += 2
  end

  tup = Tuple.new(fin + 2)
  tup.copy_from @metadata, 0, fin, 0
  tup[fin] = key
  tup[fin + 1] = val

  @metadata = tup

  return val
end

#code_idObject



37
38
39
# File 'lib/rubinius/bridge/compiled_code.rb', line 37

def code_id
  @code_id || (@code_id = SecureRandom.hex(CODE_ID_BYTES))
end

#decode(bytecodes = @iseq) ⇒ Object



31
32
33
# File 'lib/rubinius/bridge/compiled_code.rb', line 31

def decode(bytecodes = @iseq)
  # TODO
end