jaroslav@1648: /** jaroslav@1648: * Back 2 Browser Bytecode Translator jaroslav@1648: * Copyright (C) 2012 Jaroslav Tulach jaroslav@1648: * jaroslav@1648: * This program is free software: you can redistribute it and/or modify jaroslav@1648: * it under the terms of the GNU General Public License as published by jaroslav@1648: * the Free Software Foundation, version 2 of the License. jaroslav@1648: * jaroslav@1648: * This program is distributed in the hope that it will be useful, jaroslav@1648: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@1648: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@1648: * GNU General Public License for more details. jaroslav@1648: * jaroslav@1648: * You should have received a copy of the GNU General Public License jaroslav@1648: * along with this program. Look for COPYING file in the top folder. jaroslav@1648: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@1648: */ jaroslav@1648: package org.apidesign.vm4brwsr.dynamic; jaroslav@1648: jaroslav@1648: import java.lang.invoke.CallSite; jaroslav@1648: import java.lang.invoke.ConstantCallSite; jaroslav@1648: import java.lang.invoke.MethodHandles; jaroslav@1648: import java.lang.invoke.MethodType; jaroslav@1648: jaroslav@1648: public class InvokeDynamic { jaroslav@1648: jaroslav@1648: public static String dynamicSay() { jaroslav@1648: return TEST_dynamic_boot1(new InvokeDynamic()); jaroslav@1648: } jaroslav@1648: jaroslav@1648: private static String TEST_dynamic_boot1(InvokeDynamic instance) { jaroslav@1648: throw new IllegalStateException("Can't touch this"); jaroslav@1648: } jaroslav@1648: jaroslav@1648: public static CallSite boot1(MethodHandles.Lookup lookup, String name, MethodType type) { jaroslav@1648: try { jaroslav@1648: return new ConstantCallSite(lookup.findVirtual(InvokeDynamic.class, "instance_sayHello", MethodType.methodType(String.class))); jaroslav@1648: } catch (NoSuchMethodException | IllegalAccessException e) { jaroslav@1648: throw new IllegalStateException(e); jaroslav@1648: } jaroslav@1648: } jaroslav@1648: jaroslav@1648: public String instance_sayHello() { jaroslav@1648: return "Hello from Dynamic!"; jaroslav@1648: } jaroslav@1648: }