Skip to content

Commit e6cbbdc

Browse files
committed
2 parents 7f173d0 + 9471c5f commit e6cbbdc

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

java_bytecode.j

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ return
1212
.limit stack 100
1313
.line 1
1414
iconst_0
15-
istore_2
15+
istore_1
1616
iconst_0
17-
istore_3
17+
istore_2
1818
fconst_0
19-
fstore_4
19+
fstore_3
2020
return
2121
.end method

semantic_actions_utils.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,24 @@ namespace semantic_actions_util {
6868
void defineVariable(string name, int varType) {
6969
declareVariable(name, varType);
7070
if (varType == INT_TYPE) {
71-
appendToCode("iconst_0\nistore_" + to_string(currentVariableIndex));
71+
appendToCode("iconst_0\nistore_" + to_string(currentVariableIndex -1));
7272
} else if (varType == FLOAT_TYPE) {
73-
appendToCode("fconst_0\nfstore_" + to_string(currentVariableIndex));
73+
appendToCode("fconst_0\nfstore_" + to_string(currentVariableIndex -1));
7474
}
7575

7676
}
7777

7878
void generateHeader() {
7979
//TO-DO get file name
8080
//appendToCode(".source " + outfileName);
81-
appendToCode(".class public test\n.super java/lang/Object\n");
81+
appendToCode(".class public java_class\n.super java/lang/Object\n");
8282
appendToCode(".method public <init>()V");
8383
appendToCode("aload_0");
8484
appendToCode("invokenonvirtual java/lang/Object/<init>()V");
8585
appendToCode("return");
8686
appendToCode(".end method\n");
8787
appendToCode(".method public static main([Ljava/lang/String;)V");
8888
appendToCode(".limit locals 100\n.limit stack 100");
89-
90-
91-
9289
appendToCode(".line 1");
9390
}
9491

test.class

-247 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)