Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ out/

*.xslt
*.xml
!.run/*.run.xml
24 changes: 24 additions & 0 deletions .run/tests_gradle.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="ZenCode Tests - Gradle" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value=":ScriptingExample:test" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>false</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>true</RunAsTest>
<method v="2" />
</configuration>
</component>
13 changes: 13 additions & 0 deletions .run/tests_intellij.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="ZenCode Tests - IntelliJ" type="JUnit" factoryName="JUnit">
<module name="ZenCode.ScriptingExample" />
<option name="PACKAGE_NAME" value="" />
<option name="MAIN_CLASS_NAME" value="" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="package" />
<option name="WORKING_DIRECTORY" value="$MODULE_DIR$" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
1 change: 1 addition & 0 deletions JavaBytecodeCompiler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ dependencies {
api libs.asm.commons
api project(':CodeModel')
api project(':JavaShared')
implementation project(':JavaRuntime')
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public String mangleScriptName(final SourceFile sourceFile) {
}

public String mangleScriptBodyMethod(final int methodsAmount) {
return "script-body" + (methodsAmount == 0? "" : ('-' + Integer.toString(methodsAmount)));
return "$body" + (methodsAmount == 0? "" : ('$' + Integer.toString(methodsAmount)));
}

public String mangleSourceFileName(final HighLevelDefinition definition) {
Expand Down Expand Up @@ -116,40 +116,41 @@ public int hashCode() {
return builder.toString();
}

public String mangleGeneratedLambdaName(final String interfaceName) {
public String mangleLambdaMethod(final String parentMethodName, final String interfaceName) {
final class LambdaId {
final String target;
final String interfaceName;
final String method;

LambdaId(final String target) {
this.target = target;
LambdaId(final String interfaceName, final String method) {
this.interfaceName = interfaceName;
this.method = method;
}

@Override
public boolean equals(final Object o) {
return this == o || o instanceof LambdaId && this.target.equals(((LambdaId) o).target);
return this == o || o instanceof LambdaId && this.interfaceName.equals(((LambdaId) o).interfaceName) && this.method.equals(((LambdaId) o).method);
}

@Override
public int hashCode() {
return 17 * this.target.hashCode();
return 17 * (this.interfaceName.hashCode() + 31 * this.method.hashCode());
}
}

final String interfaceTarget = interfaceName.replace('/', '_').replace('.', '_');
// TODO("Rework package structure")
return "zsynthetic/$Lambda$" + interfaceTarget + '$' + this.mangleCounters.get(new LambdaId(interfaceTarget));
}

public String mangleGeneratedLambdaName(final FunctionHeader header) {
return this.mangleGeneratedLambdaName("$Generated" + EXP_TAR_MANGLE_FUNCTION_ID + this.encodeLengthNameFormat(this.mangleFunctionHeader(header)));
}

public String mangleCapturedParameter(final int parameterId, final boolean isThis) {
if (isThis) {
return "$this";
final String sanitizedMethodName;
if (parentMethodName == null) {
sanitizedMethodName = "$null";
} else if ("<init>".equals(parentMethodName) || "<clinit>".equals(parentMethodName)) {
sanitizedMethodName = "$_" + parentMethodName.substring(1, parentMethodName.length() - 1) + '_';
} else {
return "$" + parameterId;
sanitizedMethodName = parentMethodName;
}
final String interfaceTarget = interfaceName.replace('/', '.');
final int lastDot = interfaceTarget.lastIndexOf('.');
final String canonicalInterfaceTarget = lastDot == -1 ? interfaceTarget : interfaceTarget.substring(lastDot + 1);
final LambdaId id = new LambdaId(canonicalInterfaceTarget, sanitizedMethodName);

return "$lambda$" + sanitizedMethodName + '$' + canonicalInterfaceTarget + '$' + this.mangleCounters.get(id);
}

private String mangleScriptName(final String rawName) {
Expand Down
Loading
Loading