-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Java 8 classes. Again. #28
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6675ae9
Replace hxjava-std with Java8.
posxposy 9e2cb23
Add jar tool sources.
posxposy 2e10924
Use defaul formatter setup for jar-tool
posxposy 3cf9be2
Slight change to remove code from constructors too.
posxposy d8876da
Clean up jar-tool a bit.
posxposy cb6a757
Remove redundant instructions. Just clean methods.
posxposy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
out |
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,108 @@ | ||
package; | ||
|
||
import haxe.io.Path; | ||
import sys.FileSystem; | ||
import java.StdTypes.Int8; | ||
import java.NativeArray; | ||
import java.io.FileOutputStream; | ||
import java.io.File; | ||
import java.nio.file.Files; | ||
import org.objectweb.asm.ClassReader; | ||
import org.objectweb.asm.ClassWriter; | ||
import org.objectweb.asm.ClassVisitor; | ||
import org.objectweb.asm.MethodVisitor; | ||
import org.objectweb.asm.Opcodes.Opcodes_Statics; | ||
import java.Lib.println; | ||
|
||
using StringTools; | ||
|
||
/** | ||
* HOW TO USE: | ||
* | ||
* 1) Unzip JAR file into some folder. For example "jar_content"; | ||
* 2) Run `java -jar Main.jar jar_content`; | ||
* 3) Pick up generated `hxjava-std.jar`. | ||
*/ | ||
final class Main { | ||
static function main():Void { | ||
function process(dir:String) { | ||
if (FileSystem.exists(dir)) { | ||
for (file in FileSystem.readDirectory(dir)) { | ||
final path = Path.join([dir, file]); | ||
if (!FileSystem.isDirectory(path)) { | ||
if (path.endsWith(".class")) { | ||
println('Process $path... '); | ||
final obj:NativeArray<Int8> = Files.readAllBytes(new File(path).toPath()); | ||
final reader = new ClassReader(obj); | ||
final writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); | ||
final visitor = new CustomClassVisitor(writer); | ||
|
||
reader.accept(visitor, 0); | ||
|
||
final stream = new FileOutputStream(path); | ||
stream.write(writer.toByteArray()); | ||
} | ||
} else { | ||
process(Path.addTrailingSlash(path)); | ||
} | ||
} | ||
} else { | ||
println('Wrong path. $dir is not exists'); | ||
} | ||
} | ||
|
||
final args:Array<String> = Sys.args(); | ||
if (args.length > 0) { | ||
final dir = args[0]; | ||
process(dir); | ||
println("\nPacking jar...\n"); | ||
if (Sys.command('jar', ["cvf", "hxjava-std.jar", "-C", dir, "."]) == 0) { | ||
println("\nDone!\n"); | ||
} else { | ||
println("Oops, something went wrong."); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@:nativeGen | ||
class CustomClassVisitor extends ClassVisitor { | ||
|
||
public function new(visitor:ClassVisitor) { | ||
super(Opcodes_Statics.ASM7, visitor); | ||
} | ||
|
||
@:overload | ||
override function visit(version:Int, access:Int, name:String, signature:String, superName:String, interfaces:NativeArray<String>):Void { | ||
cv.visit(version, access, name, signature, superName, interfaces); | ||
} | ||
|
||
/** | ||
* Starts the visit of the method's code, if any (i.e. non abstract method). | ||
*/ | ||
@:overload | ||
override function visitMethod(access:Int, name:String, desc:String, signature:String, exceptions:NativeArray<String>):MethodVisitor { | ||
final mv:MethodVisitor = cv.visitMethod(access, name, desc, signature, exceptions); | ||
if (mv != null) { | ||
return new CustomMethodVisitor(mv); | ||
} | ||
return mv; | ||
} | ||
} | ||
|
||
@:nativeGen | ||
class CustomMethodVisitor extends MethodVisitor { | ||
final target:MethodVisitor; | ||
|
||
public function new(target:MethodVisitor) { | ||
super(Opcodes_Statics.ASM7, null); | ||
this.target = target; | ||
} | ||
|
||
@:overload | ||
override function visitCode() { | ||
target.visitCode(); | ||
target.visitMaxs(0, 0); | ||
target.visitEnd(); | ||
} | ||
} |
Binary file not shown.
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,5 @@ | ||
-m Main | ||
-D jvm | ||
--java ./out | ||
|
||
--java-lib asm-7.1.jar |
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed the
COMPUTE_FRAMES
bit. I suppose that means it already re-calculates stack frames, so we don't have to do anything by hand.