package com.ninty.nativee.lang;

import com.ninty.nativee.INativeMethod;
import com.ninty.nativee.NaMethodManager;
import com.ninty.runtime.NiFrame;
import com.ninty.runtime.heap.NiClass;
import com.ninty.runtime.heap.NiString;

/**
 * Created by ninty on 2018/10/21
 */
public class NaClassLoader {
    private final static String className = "java/lang/ClassLoader";

    public static void init() {
        NaMethodManager.register(className, "findLoadedClass0", "(Ljava/lang/String;)Ljava/lang/Class;", new
                findLoadedClass0());
    }

    public static class findLoadedClass0 implements INativeMethod {
        @Override
        public void invoke(NiFrame frame) {
            String classname = NiString.getString(frame.getLocalVars().getRef(1));
            NiClass clz = frame.getMethod().getClz().getLoader().getClass(classname);
            frame.getOperandStack().pushRef(clz != null ? clz.getjClass() : null);
        }
    }
}

@@ -537,24 +537,174 @@
 dClass0());%0A
+        NaMethodManager.register(className, %22findBootstrapClass%22, %22(Ljava/lang/String;)Ljava/lang/Class;%22, new%0A                findBootstrapClass());%0A
     %7D%0A%0A    p
@@ -1095,11 +1095,413 @@
  %7D%0A    %7D
+%0A%0A    public static class findBootstrapClass implements INativeMethod %7B%0A        @Override%0A        public void invoke(NiFrame frame) %7B%0A            String classname = NiString.getString(frame.getLocalVars().getRef(1));%0A            NiClass clz = frame.getMethod().getClz().getLoader().loadClass(classname);%0A            frame.getOperandStack().pushRef(clz != null ? clz.getjClass() : null);%0A        %7D%0A    %7D
 %0A%7D%0A

add native method: java.lang.ClassLoader.findBootstrapClass(Ljava/lang/String;)Ljava/lang/Class;