Skip to content

Commit

Permalink
feat(objectionary#329): add more puzzles
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Jul 12, 2024
1 parent 201ea69 commit 9cf330b
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 20 deletions.
10 changes: 8 additions & 2 deletions src/main/java/org/eolang/opeo/ast/DynamicInvocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
/**
* Dynamic invocation.
* @since 0.5
* @todo ! test args
* @todo #329:90min Add Unit Test To Test DynamicInvocation Arguments.
* I added {@link DynamicInvocation#arguments} field althogether with parsing and translation
* logic. But I didn't test this logic. We need to add unit tests for arguments parsing
* and translation.
*/
public final class DynamicInvocation implements AstNode, Typed {

Expand Down Expand Up @@ -74,12 +77,13 @@ public final class DynamicInvocation implements AstNode, Typed {
* @param root XMIR node to parse.
*/
public DynamicInvocation(final XmlNode root) {
this(root, (node) -> new Empty());
this(root, node -> new Empty());
}

/**
* Constructor.
* @param root XMIR node to parse.
* @param parser Parser to find AST nodes of children.
*/
public DynamicInvocation(final XmlNode root, final Parser parser) {
this(root, root.children().collect(Collectors.toList()), parser);
Expand All @@ -90,6 +94,7 @@ public DynamicInvocation(final XmlNode root, final Parser parser) {
* Added for efficiency to receive children nodes only once.
* @param root XMIR node to parse.
* @param chldren XMIR node children.
* @param parser Parser to find AST nodes of children.
*/
public DynamicInvocation(final XmlNode root, final List<XmlNode> chldren, final Parser parser) {
this(
Expand Down Expand Up @@ -149,6 +154,7 @@ public DynamicInvocation(
* @param attributes Method attributes.
* @param farguments Factory method arguments.
* @param arguments Dynamic invocation arguments.
* @checkstyle ParameterNumberCheck (5 lines)
*/
public DynamicInvocation(
final String name,
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/org/eolang/opeo/ast/Reference.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@
*/
package org.eolang.opeo.ast;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.xembly.Directive;

Expand Down Expand Up @@ -91,10 +88,6 @@ public Iterable<Directive> toXmir() {

@Override
public List<AstNode> opcodes() {
// final List<AstNode> res = new ArrayList<>(0);
// res.addAll(this.ref.get().opcodes());
// res.add(new Opcode(Opcodes.DUP));
// return res;
return this.ref.get().opcodes();
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/eolang/opeo/ast/Return.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public List<AstNode> opcodes() {
/**
* Get opcode.
* @return Opcode.
* @checkstyle CyclomaticComplexityCheck (20 lines)
*/
private Opcode opcode() {
final Type type = this.type();
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/eolang/opeo/ast/StoreArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
/**
* Store array element.
* @since 0.1
* @todo #329:90min Remove ad-hoc solution with storing array in a field.
* In the {@link StoreArray#opcodes()} I added ad-hoc solution to solve the problem with
* array elements storage if the array is a field.
* See the 'if' statement.
* This ad-hoc solution means we have architectural problem with array elements storage opcodes
* generation.
*/
public final class StoreArray implements AstNode, Typed {

Expand Down Expand Up @@ -106,7 +112,6 @@ public Iterable<Directive> toXmir() {
public List<AstNode> opcodes() {
final List<AstNode> res = new ArrayList<>(0);
if (this.array instanceof FieldRetrieval) {
//@todo!!!
res.addAll(this.array.opcodes());
} else {
res.addAll(this.array.opcodes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
* Opcodes: aastore
* Stack [before]->[after]: "arrayref, index, value →"
* @since 0.1
* @todo ! references? wtf?
* @todo #329:90min Avoid using 'instance of' in {@link StoreToArrayHandler#findRef(AstNode)}.
* Here we use 'instance of' statement to find a Reference.
* The solution related to Reference looks incorrect, in general.
* We should invent a proper solution without the use of this statement.
*/
public final class StoreToArrayHandler implements InstructionHandler {

Expand All @@ -47,13 +50,9 @@ public void handle(final DecompilerState state) {
final AstNode value = state.stack().pop();
final AstNode index = state.stack().pop();
final AstNode array = state.stack().pop();
// try {
final Reference ref = this.findRef(array);
ref.link(new StoreArray(ref.object(), index, value));
state.stack().push(ref);
// } catch (final IllegalStateException exception) {
// state.stack().push(new Reference(new StoreArray(array, index, value)));
// }
final Reference ref = this.findRef(array);
ref.link(new StoreArray(ref.object(), index, value));
state.stack().push(ref);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/it/DetectiveIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ final class DetectiveIT {
@Disabled
@ParameterizedTest
@CsvSource(
// "./target/it/spring-fat/target/generated-sources/jeo-disassemble-xmir, ./target/it/spring-fat/target/generated-sources/opeo-compile-xmir"
"./target/it/streams/target/generated-sources/jeo-decompile-xmir/org/eolang/streams/Main.xmir, ./target/it/streams/target/generated-sources/opeo-compile-xmir/org/eolang/streams/Main.xmir"
"./target/it/spring-fat/target/generated-sources/jeo-disassemble-xmir, ./target/it/spring-fat/target/generated-sources/opeo-compile-xmir"
)
void findsTheProblem(final String etalon, final String target) {
final Path golden = Paths.get(etalon);
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/org/eolang/opeo/SameXml.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ public void describeTo(final Description description) {
* Remove 'line' attributes from the XML document.
* @param original Original XML document.
* @return XML document without 'line' attributes.
* @todo #329:30min Avoid Using Public Static Method From SameXml Class.
* I exposed this method to avoid the problem with XMIR comparision in {@link it.DetectiveIT}
* test. But it's much better to hide this static method and invent more OOP-suitable solution.
*/
@SuppressWarnings("PMD.ProhibitPublicStaticMethods")
public static XML withoutLines(final XML original) {
try {
return new XMLDocument(
Expand Down

0 comments on commit 9cf330b

Please sign in to comment.