|Subject:||Some advice on a "simple" thing...|
|Date:||Wed, 9 Apr 2014 00:02:37 +0100|
I have almost completed a predicate called ‘jread’ which parses a Java .class file into a term that will allow me to create a database of all of the methods, fields, superclass and interfaces for that class and ultimately create a database for a complete “android.jar” file of any required API level.
I am, for educational purposes and my own learning, trying to build a system like Hoogle/Hayoo for Android. I do a lot of Android and I wanted to create a sytem I can wire into Emacs/IntelliJ or anything for that matter, a simple HTTP server that can supply a list of methods that have a certain type signature using a si mple query language. Searching by types it very very useful when using Haskell and I wanted to improve my Prolog so I figured why not do something like that in GNU Prolog? I have already started a simple HTTP library in pure GNU Prolog as well but this comes first now.
Progress so far is good…if I run it like this from a folder containing the unpacked android.jar file...
| ?- jread('javax/net/SocketFactory.class',X).
X = javaclass(super('java/lang/Object'),class('javax/net/SocketFactory'),implements(),
The place I am at now is decoding the bit flags for the class (and eventually the methods etc) into a term.
A typical value would be “1057” decimal, 0x421, this contains the flags:
So you can see that 0x421 means “ACC_PUBLIC, ACC_SUPER and ACC_ABSTRACT”. I would like to produce a term something like this:
It’s not that I don’t know how to do it or that I can’t do it but I am not sure what is the *most elegant* way to do it in Prolog! Heaven knows I have written bit shifting loops to test for flags in a dozen languages but not in Prolog.
So, there’s the challenge, what is the most elegant way to turn a list of bits into a list of atom terms. Ideally I would make the list of atoms a parameter so that I can reuse it for the other flag based values.
Consider the gauntlet thrown! In the meantime I am continuing to research the possibilities for myself. I will of course put it all on GitHub along with my Redis client. I may even create a Redis database with the information!
|[Prev in Thread]||Current Thread||[Next in Thread]|