On Sep 7, 8:33 pm, Charles Oliver Nutter <[email protected]> wrote: > <[email protected]> wrote: > > [snip] > > The initial problem is how to load classes referred to in the source > > code, i.e., how to handle imports. Do I need to use something like ASM > > to locate and load references to classes, or is it possible to use a > > custom class loader to do this? What is the general approach followed > > by other implementations? > > [/snip] > > > I would be grateful for a reply to this question as the first thing I > > want to tackle in my new language is the import statement. > > The equivalent to Java's import in JRuby is called "java_import" and > takes a class name (or a shortcut dotted Java-like name if the package > starts with java, javax, org, or com) with an optional closure (for > providing an alternative name). "java_import" simply defines a new > Ruby constant on whatever scope it is called from, pointing at our > proxy representation of the class.
Why is a proxy needed? > The trickiest bit with importing classes at runtime is that there's no > standard way to get a list of all classes in a given package. Jython > uses a trick where it pre-scans jars and saves an index to be used for > package listings. JRuby just installs a "const_missing" hook into the > appropriate scope which then does the equivalent of Class.forName. > > Since Go is statically typed, you'll want to do something closer to > Java. What will "import" actually be loading for Ravi? Classes? Jar > files? In JRuby you can also "require" a Jar file, and then we add it > to the URLClassLoader which Ruby-land uses to locate classes. Yes, it needs to be quite similar to Java. My intention is to support exactly the same facilities as in Java - i.e., class path containing directories containing compiled classes, or jar files. >From a compiler's perspective, I guess all I need initially is to get the class definitions so that I can resolve references. I suppose the easiest place to look for what I need is a Java compiler; but dread the prospect of going through tons of code to figure out how it is done. Thanks for the info on JRuby. Regards Dibyendu -- You received this message because you are subscribed to the Google Groups "JVM Languages" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/jvm-languages?hl=en.
