Class: Mirah::JVM::Types::JavaDynamicMethod

Inherits:
JavaMethod show all
Defined in:
lib/mirah/jvm/types/methods.rb

Instance Attribute Summary

Attributes inherited from JavaCallable

#member

Instance Method Summary collapse

Methods inherited from JavaMethod

#abstract?, #call_special, #constructor?, #static?, #void?

Methods inherited from JavaConstructor

#constructor?, #exceptions

Methods inherited from JavaCallable

#field?, #name, #parameter_types

Methods included from ArgumentConversion

#convert_args

Constructor Details

#initialize(name, *types) ⇒ JavaDynamicMethod

Returns a new instance of JavaDynamicMethod.



259
260
261
262
# File 'lib/mirah/jvm/types/methods.rb', line 259

def initialize(name, *types)
  @name = name
  @types = types
end

Instance Method Details

#argument_typesObject



272
273
274
# File 'lib/mirah/jvm/types/methods.rb', line 272

def argument_types
  @types
end

#call(compiler, ast, expression) ⇒ Object



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'lib/mirah/jvm/types/methods.rb', line 276

def call(compiler, ast, expression)
  target = ast.target.inferred_type
  ast.target.compile(compiler, true)

  ast.parameters.each do |param|
    param.compile(compiler, true)
  end
  handle = compiler.method.mh_invokestatic(
    org.dynalang.dynalink.DefaultBootstrapper,
    "bootstrap",
    java.lang.invoke.CallSite,
    java.lang.invoke.MethodHandles::Lookup,
    java.lang.String,
    java.lang.invoke.MethodType)
  compiler.method.invokedynamic(
    "dyn:callPropWithThis:#{name}",
    [return_type, target, *@types],
    handle)

  unless expression
    return_type.pop(compiler.method)
  end
end

#declaring_classObject



268
269
270
# File 'lib/mirah/jvm/types/methods.rb', line 268

def declaring_class
  java.lang.Object
end

#return_typeObject



264
265
266
# File 'lib/mirah/jvm/types/methods.rb', line 264

def return_type
  AST.type(nil, 'dynamic')
end