-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Compile them as just another private method in the same class This means lambdas cannot be invoked (if not through reflection) and they have access to all public, default, private, protected members without any access restrictions. - Use INDY to generate the actual lambda implementation class at runtime This allows us to change the algorithm at any point without having to touch the compiler, allowing for an easier language evolution over time. Moreover, it also allows us to put the various classes in the correct package and, potentially, as nest-mates of the owner, bypassing all access restrictions. Furthermore, it gives us flexibility for compatibility with newer Java versions. Signed-off-by: TheSilkMiner <[email protected]>
- Loading branch information
1 parent
8b80696
commit a6ccc82
Showing
8 changed files
with
1,076 additions
and
73 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
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
47 changes: 47 additions & 0 deletions
47
...Compiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/LambdaClosureInfo.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,47 @@ | ||
package org.openzen.zenscript.javabytecode.compiler; | ||
|
||
import org.openzen.zenscript.codemodel.expression.LambdaClosure; | ||
import org.openzen.zenscript.codemodel.expression.captured.CapturedExpression; | ||
import org.openzen.zenscript.codemodel.expression.captured.CapturedThisExpression; | ||
import org.openzen.zenscript.codemodel.type.TypeID; | ||
import org.openzen.zenscript.javabytecode.JavaBytecodeContext; | ||
import org.openzen.zenscript.javashared.JavaClass; | ||
|
||
public final class LambdaClosureInfo { | ||
private final LambdaClosure closure; | ||
private final TypeID thisCapture; | ||
private final boolean isDifferent; | ||
|
||
private LambdaClosureInfo(final LambdaClosure closure, final TypeID thisCapture, final boolean isDifferent) { | ||
this.closure = closure; | ||
this.thisCapture = thisCapture; | ||
this.isDifferent = isDifferent; | ||
} | ||
|
||
static LambdaClosureInfo from(final JavaBytecodeContext context, final LambdaClosure closure, final JavaClass thisClass) { | ||
CapturedThisExpression capturedThis = null; | ||
for (final CapturedExpression capture : closure.captures) { | ||
if (capture instanceof CapturedThisExpression) { | ||
capturedThis = (CapturedThisExpression) capture; | ||
break; | ||
} | ||
} | ||
|
||
final TypeID thisType = capturedThis == null? null : capturedThis.type; | ||
final boolean isDifferent = capturedThis != null && !thisClass.internalName.equals(context.getInternalName(capturedThis.type)); | ||
|
||
return new LambdaClosureInfo(closure, thisType, isDifferent); | ||
} | ||
|
||
public LambdaClosure closure() { | ||
return this.closure; | ||
} | ||
|
||
public TypeID thisType() { | ||
return this.thisCapture; | ||
} | ||
|
||
public boolean isDifferentThis() { | ||
return this.isDifferent; | ||
} | ||
} |
Oops, something went wrong.