Small strict compiler improvement
Closed this issue · 3 comments
xpenatan commented
The second compiler is new to me. After analyzing that it reuse variables for some operations, I detected that it sometimes a variable receive the same variable (ex: var t1 = 10; t1 = t1;).
Its not much but its better to keep small issues away.
public int get(int i) {
return 0;
}
@DragomeCompilerSettings(CompilerType.Strict)
public void strictTest() {
int i = 0;
float test = (long)get(i++) << 32;
}
The code above generates:
$get___int$int: function (i)
{
return 0;
},
$strictTest$void : function()
{
var __r0, __r1, __r2, __r3, __r5, __r6;
__r6 = this;
var __next_label = -1;
while (1) {
switch (__next_label) {
case -1:
__r0 = 0;
__r1 = __r0 + 1;
__r3 = __r6.$get___int$int(__r0);
__r3 = __r3;
__r5 = 32;
__r3 = __r3 << 5;
__r2 = __r3 * 1.0;
return this;
default:
alert("XMLVM internal error: reached default of switch");
}
}
},
The issue is "r3 = r3" is not needed.
JavaScript is slow and removing code that is not needed is a plus.
xpenatan commented
@fpetrola there is also something wrong in "__r3 = __r3 << 5;" ? I think it should be "__r3 = __r3 << __r5;", no ?
fpetrola commented
May be 5 is a literal
xpenatan commented
it seems its forgetting to add '__r'. Because doing:
public int get(int i) {
return 0;
}
@DragomeCompilerSettings(CompilerType.Strict)
public void strictTest() {
int i = 0;
int t = 32;
float test = (long)get(i++) << t;
}
generates:
$get___int$int: function (i)
{
return 0;
},
$strictTest$void : function()
{
var __r0, __r1, __r2, __r3, __r4, __r6;
__r6 = this;
var __next_label = -1;
while (1) {
switch (__next_label) {
case -1:
__r0 = 0;
__r2 = 32;
__r1 = __r0 + 1;
__r4 = __r6.$get___int$int(__r0);
__r4 = __r4;
__r4 = __r4 << 2;
__r3 = __r4 * 1.0;
return this;
default:
alert("XMLVM internal error: reached default of switch");
}
}
},
if __r is added to 2 it will match the variable that have value 32. same goes to 5 in the other code.