Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #33507
| From | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: methodhandles lookup |
| Date | 2016-01-22 11:27 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <n7t3nc$qov$1@dont-email.me> (permalink) |
| References | <1abadfac-e34b-4ff0-8ba5-613355fa928b@googlegroups.com> |
On Fri, 22 Jan 2016 00:19:07 -0800, Philipp Kraus wrote:
> Hello,
>
> I'm trying to create a flexible (dynamic) binding for method calls and I
> have got a problem with overloaded method binding.
> In detail: I have created an own programming language which should call
> a java method. In my own language I have got grammar constructs like
> "foo/bar( "myobject" );". Internal I have got a Map<String, Object>
> which maps the string parameter to an object which will be invoked.
> foo/bar points to the method, in this case foo is the classname and bar
> the method name. So in this example I need a binding to the method
> "public void bar();".
> My language should also use calls like "foo/bar( "myobject", 1 );". In
> this case the Java method "void bar( int x );" should be called.
>
> The basic invoking call works well, but I overloaded method creates a
> problem. If I have got the class
>
> class foo {
> public void bar()
> {
> System.out.println("test");
> }
> }
>
> I do the following:
>
> final Multimap<String, MethodHandle> y = HashMultimap.create();
> for ( final Method x : foo.class.getDeclaredMethods() )
> y.put( x.getSimpleName(), MethodHandles.lookup().unreflect(x) );
>
> This multimap is put to the parser / lexer of my language to resolve
> method names but on calling / invoking I get the problem, that I need
> the correct methodhandle within the multimap depend on the signature.
>
> The problem is a class like class foo {
> public void bar()
> {
> System.out.println("test");
> }
>
> public void bar( int x )
> {
> System.out.println("test " + x);
> }
> }
>
> So my question is, how can I create a dynamic binding on method handles
> depend on the signature?
> And can I cache the method handles / is it a good choice of caching all
> handles? In my case I know during runtime the concrete signature of the
> method, "foo/bar" is executed and on this time I know all arguments of
> the method, so I can create at this point the binding. How can I do this
> in a fast way?
>
Also not answering your specific question, but have you considered using
a compiler generator such as Coco/R?
http://www.ssw.uni-linz.ac.at/Research/Projects/Coco/
Compiler generators read a definition of the input language and generate
the equivalent output which, in the case of the Java version of Coco/R,
would be a Java program that can parse and process files written in the
input language.
What the generated program does with its input is entirely up to its
author: in your case you'd probably want it to be a preprocessor that can
read your language and output the equivalent logic as compilable Java
source code, but it could equally interpret the input as a script and
execute it as its being read, or even generate bytecode directly.
Personal use cases:
I've used lex and yacc, C equivalents of Coco/R, to parse a complex data
definition language and use SQL statements to create database tables from
it which formed an active data dictionary that managed the input of data
into a data warehouse.
I used Coco/R to generate Java code to parsed and interpret C
preprocessor directives as part of a C documentation generator that does
a similar job to Javadocs.
--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
methodhandles lookup Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2016-01-22 00:19 -0800
Re: methodhandles lookup Jeff Higgins <jeff@invalid.invalid> - 2016-01-22 08:57 +0000
Re: methodhandles lookup Jeff Higgins <jeff@invalid.invalid> - 2016-01-22 11:01 +0000
Re: methodhandles lookup Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2016-01-22 03:13 -0800
Re: methodhandles lookup Jeff Higgins <jeff@invalid.invalid> - 2016-01-22 11:43 +0000
Re: methodhandles lookup Jeff Higgins <jeff@invalid.invalid> - 2016-01-22 12:03 +0000
Re: methodhandles lookup Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2016-01-24 01:59 -0800
Re: methodhandles lookup Jeff Higgins <jeff@invalid.invalid> - 2016-01-22 12:16 +0000
Re: methodhandles lookup Jan Burse <janburse@fastmail.fm> - 2016-01-22 17:12 +0100
Re: methodhandles lookup Martin Gregorie <martin@address-in-sig.invalid> - 2016-01-22 11:27 +0000
Re: methodhandles lookup Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2016-01-24 01:56 -0800
Re: methodhandles lookup Jan Burse <janburse@fastmail.fm> - 2016-01-22 16:49 +0100
csiph-web