-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
luaj4jvm: Add support for static invokedynamic call sites
Finally! Originally abandoned for its complexity, this was surprisingly manageable task. Of course, most of the linker has been rewritten since then... Other related changes: * Codified the ad-hoc compiler passes (assertions only, for now) * Added flag system for variables and converted mutability tracking to it * LuaLocalVars must NOT be mutated after IR_GEN pass, because the further passes can and will run more than once * Disabled upvalue type tracking, it is unsafe with mutable upvalues * Upcoming VARIABLE_TRACKING pass will allow re-enabling it
- Loading branch information
Showing
21 changed files
with
308 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
lua4jvm/src/main/java/fi/benjami/code4jvm/lua/compiler/CompilerPass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package fi.benjami.code4jvm.lua.compiler; | ||
|
||
public enum CompilerPass { | ||
|
||
/** | ||
* In this phase, lua4jvm IR is generated. | ||
*/ | ||
IR_GEN, | ||
|
||
/** | ||
* In this phase, variables are traced to determine their mutability and | ||
* other properties. TODO not yet implemented | ||
*/ | ||
VARIABLE_TRACING, | ||
|
||
/** | ||
* In analysis phase, types that can be statically inferred are inferred | ||
* to generate better code later. | ||
*/ | ||
TYPE_ANALYSIS, | ||
|
||
/** | ||
* Code generation. In this pass, code4jvm IR is generated. Actual bytecode | ||
* generation is done later by code4jvm, which has its own set of internal | ||
* passes. | ||
*/ | ||
CODEGEN | ||
; | ||
|
||
private static final ThreadLocal<CompilerPass> current = new ThreadLocal<>(); | ||
|
||
public static void setCurrent(CompilerPass pass) { | ||
current.set(pass); | ||
} | ||
|
||
public boolean active() { | ||
return current.get() == this; | ||
} | ||
|
||
public boolean inactive() { | ||
return current.get() != this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
lua4jvm/src/main/java/fi/benjami/code4jvm/lua/compiler/VariableFlag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package fi.benjami.code4jvm.lua.compiler; | ||
|
||
import fi.benjami.code4jvm.lua.ir.LuaLocalVar; | ||
|
||
/** | ||
* Flags that can be assigned to {@link LuaLocalVar local variables} in | ||
* {@link LuaContext compiler contexts}. Thus, these are unique per compilation | ||
* run. | ||
*/ | ||
public enum VariableFlag { | ||
|
||
/** | ||
* Variable is assigned to once or more. | ||
*/ | ||
ASSIGNED(null), | ||
|
||
/** | ||
* Variable is mutable; that is, it is assigned to at least twice. | ||
*/ | ||
MUTABLE(CompilerPass.TYPE_ANALYSIS) | ||
; | ||
|
||
/** | ||
* The flag must not be checked during this pass, but can be set. | ||
* Null to disable this check. When assertions are enabled, | ||
* {@link LuaContext#hasFlag(LuaLocalVar, VariableFlag)} checks this. | ||
* | ||
* <p>Locked passes are used to ensure that flags are not being mutated | ||
* and read at the same time. If unintentional, such actions could lead to | ||
* subtle but nasty bugs. | ||
*/ | ||
public final CompilerPass lockedPass; | ||
|
||
VariableFlag(CompilerPass lockedPass) { | ||
this.lockedPass = lockedPass; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,6 @@ public class LinkerTrace { | |
public Object callable; | ||
|
||
public Object currentPrototype; | ||
|
||
public int stableTargets; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,4 @@ | |
|
||
public sealed interface LuaVariable permits LuaLocalVar, TableField { | ||
|
||
void markMutable(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.