1 31 package org.jruby.util; 32 33 import java.io.BufferedInputStream ; 34 import java.io.IOException ; 35 import java.io.InputStream ; 36 37 import org.ablaf.ast.IAstDecoder; 38 import org.jruby.Ruby; 39 import org.jruby.ast.Node; 40 import org.jruby.ast.util.RubyAstMarshal; 41 import org.jruby.runtime.load.Library; 42 43 46 public class BuiltinScript implements Library { 47 private final String name; 48 49 public BuiltinScript(String name) { 50 this.name = name; 51 } 52 53 public void load(Ruby runtime) throws IOException { 54 runtime.loadNode("jruby builtin", getNode(runtime), false); 55 } 56 57 private Node getNode(Ruby runtime) throws IOException { 58 String resourceName = "/builtin/" + name + ".rb.ast.ser"; 59 InputStream in = getClass().getResourceAsStream(resourceName); 60 if (in == null) { 61 throw runtime.newIOError("Resource not found: " + resourceName); 62 } 63 in = new BufferedInputStream (in); 64 IAstDecoder decoder = RubyAstMarshal.getInstance().openDecoder(in); 65 try { 66 return decoder.readNode(); 67 } finally { 68 decoder.close(); 69 } 70 } 71 } 72 | Popular Tags |