-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat: Change abstract to interface
- Loading branch information
Showing
9 changed files
with
166 additions
and
9 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/main/java/com/caoccao/javet/buddy/ts2java/ast/ITs2JavaAstAppend.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,26 @@ | ||
/* | ||
* Copyright (c) 2024-2024. caoccao.com Sam Cao | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.caoccao.javet.buddy.ts2java.ast; | ||
|
||
import com.caoccao.javet.swc4j.ast.Swc4jAst; | ||
import net.bytebuddy.implementation.bytecode.ByteCodeAppender; | ||
|
||
import java.util.List; | ||
|
||
public interface ITs2JavaAstAppend<AST extends Swc4jAst> { | ||
void append(List<ByteCodeAppender> appenders, AST ast); | ||
} |
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
51 changes: 51 additions & 0 deletions
51
src/main/java/com/caoccao/javet/buddy/ts2java/ast/Ts2JavaAstBinExpr.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,51 @@ | ||
/* | ||
* Copyright (c) 2024-2024. caoccao.com Sam Cao | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.caoccao.javet.buddy.ts2java.ast; | ||
|
||
import com.caoccao.javet.swc4j.ast.expr.Swc4jAstBinExpr; | ||
import net.bytebuddy.implementation.Implementation; | ||
import net.bytebuddy.implementation.bytecode.ByteCodeAppender; | ||
import net.bytebuddy.implementation.bytecode.StackManipulation; | ||
import net.bytebuddy.implementation.bytecode.member.MethodReturn; | ||
import net.bytebuddy.jar.asm.MethodVisitor; | ||
import net.bytebuddy.jar.asm.Opcodes; | ||
|
||
import java.util.List; | ||
|
||
public final class Ts2JavaAstBinExpr implements ITs2JavaAstAppend<Swc4jAstBinExpr> { | ||
@Override | ||
public void append(List<ByteCodeAppender> appenders, Swc4jAstBinExpr ast) { | ||
// TODO | ||
appenders.add((methodVisitor, implementationContext, instrumentedMethod) -> { | ||
StackManipulation.Size size = new StackManipulation.Compound( | ||
new StackManipulation.Simple(( | ||
MethodVisitor simpleMethodVisitor, | ||
Implementation.Context simpleImplementationContext) -> { | ||
simpleMethodVisitor.visitVarInsn(Opcodes.ILOAD, 1); | ||
simpleMethodVisitor.visitVarInsn(Opcodes.ILOAD, 2); | ||
simpleMethodVisitor.visitInsn(Opcodes.IADD); | ||
return new StackManipulation.Size(2, 0); | ||
}), | ||
MethodReturn.INTEGER | ||
).apply(methodVisitor, implementationContext); | ||
return new ByteCodeAppender.Size( | ||
size.getMaximalSize(), | ||
instrumentedMethod.getStackSize()); | ||
} | ||
); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/caoccao/javet/buddy/ts2java/ast/Ts2JavaAstBlockStmt.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,39 @@ | ||
/* | ||
* Copyright (c) 2024-2024. caoccao.com Sam Cao | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.caoccao.javet.buddy.ts2java.ast; | ||
|
||
import com.caoccao.javet.buddy.ts2java.Ts2JavaException; | ||
import com.caoccao.javet.swc4j.ast.stmt.Swc4jAstBlockStmt; | ||
import com.caoccao.javet.swc4j.ast.stmt.Swc4jAstReturnStmt; | ||
import net.bytebuddy.implementation.bytecode.ByteCodeAppender; | ||
|
||
import java.util.List; | ||
|
||
public final class Ts2JavaAstBlockStmt implements ITs2JavaAstAppend<Swc4jAstBlockStmt> { | ||
@Override | ||
public void append(List<ByteCodeAppender> appenders, Swc4jAstBlockStmt ast) { | ||
ast.getStmts().forEach(stmt -> { | ||
switch (stmt.getType()) { | ||
case ReturnStmt: | ||
new Ts2JavaAstReturnStmt().append(appenders, stmt.as(Swc4jAstReturnStmt.class)); | ||
break; | ||
default: | ||
throw new Ts2JavaException(stmt.getType().name() + " is not supported"); | ||
} | ||
}); | ||
} | ||
} |
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
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
39 changes: 39 additions & 0 deletions
39
src/main/java/com/caoccao/javet/buddy/ts2java/ast/Ts2JavaAstReturnStmt.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,39 @@ | ||
/* | ||
* Copyright (c) 2024-2024. caoccao.com Sam Cao | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.caoccao.javet.buddy.ts2java.ast; | ||
|
||
import com.caoccao.javet.buddy.ts2java.Ts2JavaException; | ||
import com.caoccao.javet.swc4j.ast.expr.Swc4jAstBinExpr; | ||
import com.caoccao.javet.swc4j.ast.stmt.Swc4jAstReturnStmt; | ||
import net.bytebuddy.implementation.bytecode.ByteCodeAppender; | ||
|
||
import java.util.List; | ||
|
||
public final class Ts2JavaAstReturnStmt implements ITs2JavaAstAppend<Swc4jAstReturnStmt> { | ||
@Override | ||
public void append(List<ByteCodeAppender> appenders, Swc4jAstReturnStmt ast) { | ||
ast.getArg().ifPresent(arg -> { | ||
switch (arg.getType()) { | ||
case BinExpr: | ||
new Ts2JavaAstBinExpr().append(appenders, arg.as(Swc4jAstBinExpr.class)); | ||
break; | ||
default: | ||
throw new Ts2JavaException(arg.getType().name() + " is not supported"); | ||
} | ||
}); | ||
} | ||
} |