Ejemplo n.º 1
0
 public static boolean importPackage(String name) {
   CTX ctx = LocalCtx.get();
   // package ?
   try {
     Class<?> c = Class.forName(name + ".package-info");
     KonohaPackageAnnotation an = c.getAnnotation(KonohaPackageAnnotation.class);
     if (an != null) {
       KonohaPackageInitializer kp = an.getInitClass().newInstance();
       kp.init(ctx, ctx.ks);
       return true;
     }
   } catch (Exception e) {
   }
   // class ?
   try {
     Class<?> c = Class.forName(name);
     ctx.ks.cl.put(c.getSimpleName(), JavaClass.create(c));
     return true;
   } catch (ClassNotFoundException e) {
     e.printStackTrace();
     return false;
   }
 }
Ejemplo n.º 2
0
 private KObject evalBlock(CTX ctx, Block bk) {
   CompilerContext cc = ctx.cc;
   ctx.gamma.cc = cc;
   if (!bk.tyCheckAll(ctx, ctx.gamma)) return null;
   cc.evalBlock(bk);
   try {
     cc.writeClassFile(".");
     LocalCtx.set(ctx);
     // exec
     ClassLoader cl = cc.createClassLoader();
     Class<?> c = cl.loadClass("Script");
     Object r = c.getMethod("main").invoke(null);
     if (r != null) {
       return (KObject) r;
     } else {
       return null;
     }
   } catch (InvocationTargetException e) {
     e.getCause().printStackTrace();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }