1

I'm writing a compiler for a subset of java, and I'm almost done. The one thing I have problems with is handling classes, fields and method that are named like jasmin-keywords.

For example:

class Test {
public static void main(String[] args) {
    int a;
    a = new pop().run();
}
}

class pop {

    int lcmp;
    int stack;
    int isub;
    int iload_0;

    public int run() {
        int aaload;
        lcmp = 1;
        aaload = lcmp;
        return aaload;
    }

    public int swap() {
        return 0;   
    }

    public int iload_0() {
        int istore;
        boolean ret;
        return 0;
    }
}

Which would compile into jasmin like this:

.source evul_names.java
.class Test
.super java/lang/Object
.method public <init>()V
    aload_0
    invokespecial java/lang/Object/<init>()V
    return
.end method

.method public static main([Ljava/lang/String;)V
.limit locals 2
.limit stack 2
.var 0 is a I
.line 4
    new pop
    dup
    invokespecial pop/<init>()V
    invokevirtual pop/run()I
    istore_0 ; a
    return
.end method

.source evul_names.java
.class pop
.super java/lang/Object

.field public lcmp I
.field public stack I
.field public isub I
.field public iload_0 I

.method public <init>()V
    aload_0
    invokespecial java/lang/Object/<init>()V
    return
.end method

.method public run()I
.limit locals 3
.limit stack 2
.line 15
.var 0 is <this> Lpop;
.var 1 is aaload I
.line 17
    iconst_1
    aload_0 ; this
    swap
    putfield pop/lcmp I
.line 18
    aload_0 ; this
    getfield pop/lcmp I
    istore_1 ; aaload
.line 19
    iload_1 ; aaload
    ireturn
.end method

.method public swap()I
.limit locals 2
.limit stack 1
.line 22
.var 0 is <this> Lpop;
.line 23
    iconst_0
    ireturn
.end method

.method public iload_0()I
.limit locals 4
.limit stack 1
.line 26
.var 0 is <this> Lpop;
.var 1 is istore I
.var 2 is ret Z
.line 29
    iconst_0
    ireturn
.end method

The problem is the .class and .field directives, they cause compile error if the name is a keyword. I have tried putting both single quotes and double quotes around them; using single quotes the jasmin assembles into class files, but then one get verify error (and it seems like it actually includes the quotation in the name, which is suboptimal). Using double quotes it doesn't compile at all.

Is there any solution at all to this, or is it impossible to do this in jasmin?

Torandi
  • 1,615
  • 2
  • 9
  • 12

1 Answers1

0

After trying for hours I decided to patch jasmin. When I had submitted the patch I realised that the code in the repo wasn't the latest version. Then after getting the latest version of the code I realised the feature I had implemented already existed, but for some reason the 2.4 in debian did not have that, but the 2.4 from sourceforge had.

Torandi
  • 1,615
  • 2
  • 9
  • 12
  • 1
    Yes, single quoting solves it, IF you use a recent version of jasmin. The jasmin in ubunt/debian repos is not recent. – Torandi Sep 24 '12 at 19:32