March, 2008


30
Mar 08

TinyURL a nuisance?

Although TinyURL is mostly useful it also has one very annoying minus. Indexing services like Google or Technocrati cannot resolve links through it, therefore all those links go unaccounted (or at least you can’t find them anyhow). Add to this that popular services like Twitter will automatically route the links through TinyURL and it’s a right nuisance. Can’t such services come up with a way for Google to track them?


26
Mar 08

Typesafe ASM — problems solved?

OK, I think I managed to solve both the primitive and the double slot problem introduced in the previous post. Basically I introduced another parametrized class — InvokeBuilder, which builds method invocations. The example now looks like this:

[java]
ClassWriter cw = new ClassWriter(COMPUTE_MAXS);

new ClassBuilder(cw, V1_4, ACC_PUBLIC, “HelloWorld”, “java/lang/Object”, null)
.beginMethod(ACC_PUBLIC, ““, void.class)
.loadVar0(Self.class)
.invoke().specVoid(Object.class, ““)
.returnVoid()
.endMethod()

.beginStaticMethod(ACC_PUBLIC | ACC_STATIC, “main”, void.class, String[].class)
.getStatic(System.class, “out”, PrintStream.class)
.loadVar0(String[].class)
.push(0)
.arrayLoad(String[].class, Integer.class, String.class)
.invoke().param(String.class).virtVoid(PrintStream.class, “println”)
.returnVoid()
.endMethod();
[/java]

Of course InvokeBuilder contains methods only for building invocation. The only inconvenience is that you have to specify parameters in reverse order to coincide with the way they are laid out on the stack. However it’s easy to add a bit of sugar for the most common cases.

Now all I have to do is overload the param() method for each primitive as well as make a paramTwoCell(), which consumes two stack slots (for long/double). Seems that only tedious work in implementing each and every instruction remains.

P.S. Thanks to Christian Vest Hansen for his input. It definitely helped me get this (last?) piece of the puzzle in place.


24
Mar 08

Typesafe DSLs in Java: Part 1 — Typesafe Bytecode

Domain Specific Languages (DSLs) have been brought to Java under the name of Fluent Interface. However most of them utilize a lot of strings and untyped behavior to make the interface fluent enough. It turns out that using Java 5 and a bag of tricks we can have the compiler to check a lot more. In this post we'll check out how to write Java bytecode using ASM in a typesafe way.

Continue reading →


23
Mar 08

MS Calc

Did you know that Microsoft calculator will calculate “2+2*2″ as 8 in standard view, but 6 in scientific view?!?!? Talk about unintuitive…


23
Mar 08

WTF Company

Next day I asked my mentor if I could replace the regexp based XML-parsing with some standard classes to make it cleaner and easier to extend. He said no, because their parsing works just fine, thank you. — Somehow this (part I, part II) is even scarier that reading it on DailyWTF. Does anyone recognize your own company? I sure hope not!