diff --git a/eo-maven-plugin/src/it/custom_goals/README.md b/eo-maven-plugin/src/it/custom_goals/README.md index 740f551359..c353a54fae 100644 --- a/eo-maven-plugin/src/it/custom_goals/README.md +++ b/eo-maven-plugin/src/it/custom_goals/README.md @@ -13,6 +13,7 @@ can check in the [pom.xml](pom.xml) in `eo-maven-plugin` description: register parse optimize + shake discover-foreign probe pull diff --git a/eo-maven-plugin/src/it/custom_goals/pom.xml b/eo-maven-plugin/src/it/custom_goals/pom.xml index 2263de36ae..0a3db5dae2 100644 --- a/eo-maven-plugin/src/it/custom_goals/pom.xml +++ b/eo-maven-plugin/src/it/custom_goals/pom.xml @@ -43,6 +43,7 @@ SOFTWARE. register parse optimize + shake discover-foreign probe pull diff --git a/eo-maven-plugin/src/it/custom_goals/verify.groovy b/eo-maven-plugin/src/it/custom_goals/verify.groovy index 32034df190..be1ba9c4f8 100644 --- a/eo-maven-plugin/src/it/custom_goals/verify.groovy +++ b/eo-maven-plugin/src/it/custom_goals/verify.groovy @@ -26,7 +26,8 @@ 'target/eo/foreign.csv', 'target/eo/1-parse', 'target/eo/2-optimize', - 'target/eo/3-pull', + 'target/eo/3-shake', + 'target/eo/4-pull', ].each { assert new File(basedir, it).exists() } /** @@ -35,9 +36,9 @@ * and only on the next step it starts to resolve the dependencies. */ [ - 'target/eo/4-resolve', - 'target/eo/5-pre', - 'target/eo/6-transpile', + 'target/eo/5-resolve', + 'target/eo/6-pre', + 'target/eo/7-transpile', ].each { assert !new File(basedir, it).exists() } true diff --git a/eo-maven-plugin/src/it/fibonacci/verify.groovy b/eo-maven-plugin/src/it/fibonacci/verify.groovy index 6ea0e741cd..42b79c9c9f 100644 --- a/eo-maven-plugin/src/it/fibonacci/verify.groovy +++ b/eo-maven-plugin/src/it/fibonacci/verify.groovy @@ -46,8 +46,8 @@ private static boolean online() { 'target/eo/1-parse/org/eolang/examples/app.xmir', 'target/eo/2-optimization-steps/org/eolang/examples/app/00-not-empty-atoms.xml', 'target/eo/2-optimize/org/eolang/examples/app.xmir', - 'target/eo/5-pre/org/eolang/examples/app/01-classes.xml', - 'target/eo/6-transpile/org/eolang/examples/app.xmir', + 'target/eo/6-pre/org/eolang/examples/app/01-classes.xml', + 'target/eo/7-transpile/org/eolang/examples/app.xmir', 'target/eo/sodg/org/eolang/error.sodg', 'target/eo/sodg/org/eolang/error.sodg.xe', 'target/eo/sodg/org/eolang/error.sodg.graph.xml', @@ -57,7 +57,7 @@ private static boolean online() { [ 'target/classes/EOorg/EOeolang/EOexamples/EOapp.class', 'target/eo/placed.json', - 'target/eo/3-pull/org/eolang/tuple.eo', + 'target/eo/4-pull/org/eolang/tuple.eo', ].each { assert new File(basedir, it).exists() || !online() } String log = new File(basedir, 'build.log').text diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/AssembleMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/AssembleMojo.java index 8f4accf673..9120e938e4 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/AssembleMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/AssembleMojo.java @@ -203,6 +203,7 @@ public void exec() throws IOException { final Moja[] mojas = { new Moja<>(ParseMojo.class), new Moja<>(OptimizeMojo.class), + new Moja<>(ShakeMojo.class), new Moja<>(DiscoverMojo.class), new Moja<>(ProbeMojo.class), new Moja<>(PullMojo.class), diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java index a5de16c6e2..f491347a1d 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java @@ -128,7 +128,7 @@ public void exec() throws IOException { final Names names = new Names(targetDir.toPath().getParent()); new File(this.targetDir.toPath().resolve("Lib/").toString()).mkdirs(); for (final ForeignTojo tojo : this.scopedTojos().withOptimized()) { - final Path file = tojo.optimized(); + final Path file = tojo.shaken(); final XML input = new XMLDocument(file); final List nodes = this.addRust(input).nodes("/program/rusts/rust"); for (final XML node: nodes) { diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/DiscoverMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/DiscoverMojo.java index b988123f83..8e4e2c2802 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/DiscoverMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/DiscoverMojo.java @@ -60,7 +60,7 @@ public void exec() throws FileNotFoundException { final Collection tojos = this.scopedTojos().notDiscovered(); final Collection discovered = new HashSet<>(); for (final ForeignTojo tojo : tojos) { - final Path src = tojo.optimized(); + final Path src = tojo.shaken(); final Collection names = this.discover(src, tojo.identifier()); discovered.addAll(names); for (final String name : names) { diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/LatexMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/LatexMojo.java index d93622d2f6..2ca3049eed 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/LatexMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/LatexMojo.java @@ -82,7 +82,7 @@ static String last(final String input) { @Override void exec() throws IOException { for (final ForeignTojo tojo : this.scopedTojos().withOptimized()) { - final Path file = tojo.optimized(); + final Path file = tojo.shaken(); final Place place = new Place( LatexMojo.last(new XMLDocument(file).xpath("/program/@name").get(0)) ); diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/OptimizeMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/OptimizeMojo.java index ae824d622b..36c8ce243f 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/OptimizeMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/OptimizeMojo.java @@ -26,6 +26,7 @@ import com.jcabi.log.Logger; import com.jcabi.xml.XML; import com.jcabi.xml.XMLDocument; +import com.yegor256.xsline.TrDefault; import java.io.IOException; import java.nio.file.Path; import java.util.Collection; @@ -170,9 +171,12 @@ private Scalar task( private Optimization optimization() { Optimization opt; if (this.trackOptimizationSteps) { - opt = new OptSpy(this.targetDir.toPath().resolve(OptimizeMojo.STEPS)); + opt = new OptSpy( + new ParsingTrain(), + this.targetDir.toPath().resolve(OptimizeMojo.STEPS) + ); } else { - opt = new OptTrain(); + opt = new OptTrain(new ParsingTrain()); } if (this.failOnError) { opt = new OptTrain(opt, "/org/eolang/parser/fail-on-errors.xsl"); @@ -183,7 +187,7 @@ private Optimization optimization() { if (this.failOnError) { opt = new OptTrain(opt, "/org/eolang/parser/fail-on-critical.xsl"); } else { - opt = new OptTrain(opt, new ParsingTrain().empty()); + opt = new OptTrain(opt, new TrDefault<>()); } return opt; } diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/ProbeMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/ProbeMojo.java index 6b33081605..c02ba8d1e0 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/ProbeMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/ProbeMojo.java @@ -109,7 +109,7 @@ public void exec() throws IOException { final Collection probed = new HashSet<>(1); final Collection tojos = this.scopedTojos().unprobed(); for (final ForeignTojo tojo : tojos) { - final Path src = tojo.optimized(); + final Path src = tojo.shaken(); final Collection objects = this.probes(src); if (!objects.isEmpty()) { Logger.info(this, "Probing object(s): %s", objects); diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/PullMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/PullMojo.java index cabe003512..b224c5714c 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/PullMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/PullMojo.java @@ -58,7 +58,7 @@ public final class PullMojo extends SafeMojo { /** * The directory where to process to. */ - public static final String DIR = "3-pull"; + public static final String DIR = "4-pull"; /** * The Git tag to pull objects from, in objectionary. diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/ResolveMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/ResolveMojo.java index a4b4abde4a..013c337cd3 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/ResolveMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/ResolveMojo.java @@ -65,7 +65,7 @@ public final class ResolveMojo extends SafeMojo { /** * The directory where to resolve to. */ - public static final String DIR = "4-resolve"; + public static final String DIR = "5-resolve"; /** * Skip artifact with the version 0.0.0. diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/ShakeMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/ShakeMojo.java new file mode 100644 index 0000000000..bcb2a0c2b3 --- /dev/null +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/ShakeMojo.java @@ -0,0 +1,204 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2023 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.eolang.maven; + +import com.jcabi.log.Logger; +import com.jcabi.xml.XML; +import com.jcabi.xml.XMLDocument; +import java.io.IOException; +import java.nio.file.Path; +import java.util.Collection; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.cactoos.Scalar; +import org.cactoos.experimental.Threads; +import org.cactoos.iterable.Filtered; +import org.cactoos.iterable.Mapped; +import org.cactoos.number.SumOf; +import org.eolang.maven.optimization.OptCached; +import org.eolang.maven.optimization.OptSpy; +import org.eolang.maven.optimization.OptTrain; +import org.eolang.maven.optimization.Optimization; +import org.eolang.maven.tojos.ForeignTojo; +import org.eolang.maven.util.HmBase; +import org.eolang.maven.util.Rel; + +/** + * Shake (prepare) XML files after optimizations for translation to java. + * + * @since 0.33.0 + * @todo #2577:30min Resolve code duplication between {@link OptimizeMojo} and {@link ShakeMojo}. + * ShakeMojo was created in order to split two optimization stages: optimizations themselves and + * preparations for translation to java. Now these two mojo look almost the same and there's a lot + * of code duplication. So it's needed to resolve that. Don't forget to remove the puzzle + * @todo #2577:30min Add tests for ShakeMojo. ShakeMojo was created in order to split two + * optimization stages: optimizations themselves and preparations for translation to java + * Need to create tests for {@link ShakeMojo} in order to be sure that it does only it's job. + */ +@Mojo( + name = "shake", + defaultPhase = LifecyclePhase.PROCESS_SOURCES, + threadSafe = true +) +public final class ShakeMojo extends SafeMojo { + /** + * The directory where to shake to. + */ + public static final String DIR = "3-shake"; + + /** + * Subdirectory for shaken cache. + */ + static final String SHAKEN = "shaken"; + + /** + * The directory where to place intermediary files. + */ + static final String STEPS = "3-shake-steps"; + + /** + * Track optimization steps into intermediate XML files? + * + * @checkstyle MemberNameCheck (7 lines) + * @since 0.24.0 + */ + @SuppressWarnings("PMD.LongVariable") + @Parameter(property = "eo.trackOptimizationSteps", required = true, defaultValue = "false") + private boolean trackOptimizationSteps; + + @Override + void exec() throws IOException { + final Collection tojos = this.scopedTojos().withOptimized(); + final Optimization opt = this.optimization(); + final int total = new SumOf( + new Threads<>( + Runtime.getRuntime().availableProcessors(), + new Mapped<>( + tojo -> this.task(tojo, opt), + new Filtered<>( + ForeignTojo::notShaken, + tojos + ) + ) + ) + ).intValue(); + if (total > 0) { + Logger.info( + this, + "Shaken %d out of %d XMIR program(s)", total, + tojos.size() + ); + } else { + Logger.debug(this, "No XMIR programs out of %d shaken", tojos.size()); + } + } + + /** + * Converts tojo to optimization task. + * + * @param tojo Tojo that should be optimized. + * @param common Optimization. + * @return Optimization task. + */ + private Scalar task( + final ForeignTojo tojo, + final Optimization common + ) { + final Path src = tojo.optimized(); + Logger.debug( + this, "Adding optimization task for %s", + src + ); + return () -> { + tojo.withShaken( + this.make( + this.optimization(tojo, common).apply(new XMLDocument(src)), + src + ).toAbsolutePath() + ); + return 1; + }; + } + + /** + * Shake optimizations for tojos. + * @return Shake optimizations + */ + private Optimization optimization() { + final Optimization opt; + if (this.trackOptimizationSteps) { + opt = new OptSpy(this.targetDir.toPath().resolve(ShakeMojo.STEPS)); + } else { + opt = new OptTrain(); + } + return opt; + } + + /** + * Optimization for specific tojo. + * + * @param tojo Tojo + * @param common Optimization + * @return Optimization for specific Tojo + */ + private Optimization optimization(final ForeignTojo tojo, final Optimization common) { + final Optimization res; + if (tojo.hasHash()) { + res = new OptCached( + common, + this.cache.resolve(ShakeMojo.SHAKEN).resolve(tojo.hash()) + ); + } else { + res = common; + } + return res; + } + + /** + * Make a path with optimized XML file after parsing. + * + * @param xml Optimized xml + * @param file EO file + * @return The file with optimized XMIR + * @throws IOException If fails + */ + private Path make(final XML xml, final Path file) throws IOException { + final String name = new XMLDocument(file).xpath("/program/@name").get(0); + final Place place = new Place(name); + final Path dir = this.targetDir.toPath(); + final Path target = place.make( + dir.resolve(ShakeMojo.DIR), TranspileMojo.EXT + ); + new HmBase(dir).save( + xml.toString(), + dir.relativize(target) + ); + Logger.debug( + this, "Optimized %s (program:%s) to %s", + new Rel(file), name, new Rel(target) + ); + return target; + } +} diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/SodgMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/SodgMojo.java index 1abc860d35..7894914095 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/SodgMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/SodgMojo.java @@ -366,7 +366,7 @@ public void exec() throws IOException { continue; } final Path sodg = new Place(name).make(home, "sodg"); - final Path xmir = tojo.optimized(); + final Path xmir = tojo.shaken(); if (sodg.toFile().lastModified() >= xmir.toFile().lastModified()) { Logger.debug( this, "Already converted %s to %s (it's newer than the source)", diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/TranspileMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/TranspileMojo.java index ea18c537d3..294055c910 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/TranspileMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/TranspileMojo.java @@ -71,7 +71,7 @@ public final class TranspileMojo extends SafeMojo { /** * The directory where to transpile to. */ - public static final String DIR = "6-transpile"; + public static final String DIR = "7-transpile"; /** * Extension for compiled sources in XMIR format (XML). @@ -107,7 +107,7 @@ public final class TranspileMojo extends SafeMojo { /** * The directory where to put pre-transpile files. */ - private static final String PRE = "5-pre"; + private static final String PRE = "6-pre"; /** * Target directory. @@ -185,7 +185,7 @@ public void exec() throws IOException { */ private int transpile(final ForeignTojo tojo) throws IOException { final int saved; - final Path file = tojo.optimized(); + final Path file = tojo.shaken(); final XML input = new XMLDocument(file); final String name = input.xpath("/program/@name").get(0); final Place place = new Place(name); diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/OptSpy.java b/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/OptSpy.java index 4f08514772..444db880b0 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/OptSpy.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/OptSpy.java @@ -25,6 +25,8 @@ import com.jcabi.log.Logger; import com.jcabi.xml.XML; +import com.yegor256.xsline.Shift; +import com.yegor256.xsline.Train; import java.nio.file.Path; import org.eolang.maven.Place; import org.eolang.maven.SpyTrain; @@ -35,6 +37,10 @@ * @since 0.28.12 */ public final class OptSpy implements Optimization { + /** + * Optimizations train. + */ + private final Train train; /** * Where to track optimization steps. @@ -42,10 +48,20 @@ public final class OptSpy implements Optimization { private final Path target; /** - * The main constructor. + * Ctor. * @param target Where to track optimization steps. */ public OptSpy(final Path target) { + this(OptTrain.DEFAULT_TRAIN, target); + } + + /** + * The main constructor. + * @param trn Optimizations train + * @param target Where to track optimization steps. + */ + public OptSpy(final Train trn, final Path target) { + this.train = trn; this.target = target; } @@ -57,6 +73,6 @@ public XML apply(final XML xml) { this, "Optimization steps will be tracked to %s", new Rel(dir) ); - return new OptTrain(new SpyTrain(OptTrain.DEFAULT_TRAIN, dir)).apply(xml); + return new OptTrain(new SpyTrain(this.train, dir)).apply(xml); } } diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/OptTrain.java b/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/OptTrain.java index 33ba24510c..b9fd483eef 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/OptTrain.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/OptTrain.java @@ -31,7 +31,6 @@ import com.yegor256.xsline.TrFast; import com.yegor256.xsline.Train; import com.yegor256.xsline.Xsline; -import org.eolang.parser.ParsingTrain; /** * Optimisation train of XLS`s. @@ -49,7 +48,7 @@ public final class OptTrain implements Optimization { */ static final Train DEFAULT_TRAIN = new TrFast( new TrClasspath<>( - new ParsingTrain(), + new TrDefault<>(), "/org/eolang/parser/optimize/globals-to-abstracts.xsl", "/org/eolang/parser/optimize/remove-refs.xsl", "/org/eolang/parser/optimize/abstracts-float-up.xsl", @@ -87,7 +86,7 @@ public OptTrain() { * * @param shifts XLS shifts. */ - OptTrain(final Train shifts) { + public OptTrain(final Train shifts) { this(xml -> xml, shifts); } diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/tojos/ForeignTojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/tojos/ForeignTojo.java index 4059aea906..b84ed6bfc4 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/tojos/ForeignTojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/tojos/ForeignTojo.java @@ -77,6 +77,14 @@ public Path optimized() { return Paths.get(this.delegate.get(ForeignTojos.Attribute.OPTIMIZED.key())); } + /** + * The tojo shaken xmir. + * @return The shaken xmir. + */ + public Path shaken() { + return Paths.get(this.delegate.get(ForeignTojos.Attribute.SHAKEN.key())); + } + /** * The tojo eo object. * @return The eo object. @@ -142,6 +150,26 @@ public boolean notOptimized() { return res; } + /** + * Checks if tojo was not already shaken. + * @return True if shake is required, false otherwise. + */ + public boolean notShaken() { + final Path src = this.optimized(); + boolean res = true; + if (this.delegate.exists(ForeignTojos.Attribute.SHAKEN.key())) { + final Path tgt = this.shaken(); + if (tgt.toFile().lastModified() >= src.toFile().lastModified()) { + Logger.debug( + this, "Already shaken %s to %s", + new Rel(src), new Rel(tgt) + ); + res = false; + } + } + return res; + } + /** * Check if the given tojo has not been parsed. * @@ -223,6 +251,16 @@ public ForeignTojo withOptimized(final Path xmir) { return this; } + /** + * Set the shaken xmir. + * @param xmir The shaken xmir. + * @return The tojo itself. + */ + public ForeignTojo withShaken(final Path xmir) { + this.delegate.set(ForeignTojos.Attribute.SHAKEN.key(), xmir.toString()); + return this; + } + /** * Set the eo path. * @param source The eo path. diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/tojos/ForeignTojos.java b/eo-maven-plugin/src/main/java/org/eolang/maven/tojos/ForeignTojos.java index 2e611f71a4..5353913432 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/tojos/ForeignTojos.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/tojos/ForeignTojos.java @@ -313,6 +313,11 @@ enum Attribute { */ OPTIMIZED("optimized"), + /** + * Path to the shaken xmir file. + */ + SHAKEN("shaken"), + /** * Absolute location of SODG file. */ diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/FakeMaven.java b/eo-maven-plugin/src/test/java/org/eolang/maven/FakeMaven.java index 10e75434e0..1d55cfcc76 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/FakeMaven.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/FakeMaven.java @@ -572,7 +572,6 @@ public Iterator> iterator() { * @since 0.28.12 */ static final class Optimize implements Iterable> { - @Override public Iterator> iterator() { return Arrays.>asList( @@ -593,6 +592,7 @@ public Iterator> iterator() { return Arrays.>asList( ParseMojo.class, OptimizeMojo.class, + ShakeMojo.class, VerifyMojo.class ).iterator(); } @@ -610,6 +610,7 @@ public Iterator> iterator() { return Arrays.>asList( ParseMojo.class, OptimizeMojo.class, + ShakeMojo.class, LatexMojo.class ).iterator(); } @@ -627,6 +628,7 @@ public Iterator> iterator() { return Arrays.>asList( ParseMojo.class, OptimizeMojo.class, + ShakeMojo.class, TranspileMojo.class ).iterator(); } @@ -644,6 +646,7 @@ public Iterator> iterator() { return Arrays.>asList( ParseMojo.class, OptimizeMojo.class, + ShakeMojo.class, BinarizeMojo.class ).iterator(); } @@ -661,6 +664,7 @@ public Iterator> iterator() { return Arrays.>asList( ParseMojo.class, OptimizeMojo.class, + ShakeMojo.class, BinarizeParseMojo.class ).iterator(); } @@ -678,6 +682,7 @@ public Iterator> iterator() { return Arrays.>asList( ParseMojo.class, OptimizeMojo.class, + ShakeMojo.class, ResolveMojo.class ).iterator(); } @@ -695,6 +700,7 @@ public Iterator> iterator() { return Arrays.>asList( ParseMojo.class, OptimizeMojo.class, + ShakeMojo.class, TranslateToPhiMojo.class ).iterator(); } @@ -712,6 +718,7 @@ public Iterator> iterator() { return Arrays.>asList( ParseMojo.class, OptimizeMojo.class, + ShakeMojo.class, ResolveMojo.class, PlaceMojo.class ).iterator(); @@ -730,6 +737,7 @@ public Iterator> iterator() { return Arrays.>asList( ParseMojo.class, OptimizeMojo.class, + ShakeMojo.class, SodgMojo.class ).iterator(); } @@ -760,6 +768,7 @@ public Iterator> iterator() { return Arrays.>asList( ParseMojo.class, OptimizeMojo.class, + ShakeMojo.class, DiscoverMojo.class, ProbeMojo.class ).iterator(); @@ -778,6 +787,7 @@ public Iterator> iterator() { return Arrays.>asList( ParseMojo.class, OptimizeMojo.class, + ShakeMojo.class, DiscoverMojo.class, ProbeMojo.class, PullMojo.class @@ -797,6 +807,7 @@ public Iterator> iterator() { return Arrays.>asList( ParseMojo.class, OptimizeMojo.class, + ShakeMojo.class, DiscoverMojo.class ).iterator(); } diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/ResolveMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/ResolveMojoTest.java index 6048482bec..75e6553f7e 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/ResolveMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/ResolveMojoTest.java @@ -56,7 +56,7 @@ void resolvesWithSingleDependency(@TempDir final Path temp) throws IOException { "[] > foo /int" ) ).execute(new FakeMaven.Resolve()); - final Path path = temp.resolve("target/4-resolve/org.eolang/eo-runtime/-/0.7.0"); + final Path path = temp.resolve("target/5-resolve/org.eolang/eo-runtime/-/0.7.0"); MatcherAssert.assertThat(path.toFile(), FileMatchers.anExistingDirectory()); MatcherAssert.assertThat( path.resolve("eo-runtime-0.7.0.jar").toFile(), @@ -74,7 +74,7 @@ void resolvesWithoutAnyDependencies(@TempDir final Path temp) throws IOException ); maven.foreignTojos().add("sum").withDiscovered(0); maven.execute(new FakeMaven.Resolve()); - final Path path = temp.resolve("target/4-resolve/org.eolang/eo-runtime/-/"); + final Path path = temp.resolve("target/5-resolve/org.eolang/eo-runtime/-/"); MatcherAssert.assertThat(path.toFile(), FileMatchers.anExistingDirectory()); MatcherAssert.assertThat( path, diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/TranspileMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/TranspileMojoTest.java index ffe06d81c4..c8d355d408 100755 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/TranspileMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/TranspileMojoTest.java @@ -106,7 +106,7 @@ void recompilesIfExpired(@TempDir final Path temp) throws IOException { .execute(new FakeMaven.Transpile()) .result(); final Path java = res.get(this.compiled); - final Path xmir = res.get("target/6-transpile/foo/x/main.xmir"); + final Path xmir = res.get("target/7-transpile/foo/x/main.xmir"); MatcherAssert.assertThat(java.toFile(), FileMatchers.anExistingFile()); MatcherAssert.assertThat(xmir.toFile(), FileMatchers.anExistingFile()); MatcherAssert.assertThat(java.toFile().setLastModified(0L), Matchers.is(true)); diff --git a/eo-runtime/src/main/eo/org/eolang/rust.eo b/eo-runtime/src/main/eo/org/eolang/rust.eo index f1c0edc7df..a497331255 100644 --- a/eo-runtime/src/main/eo/org/eolang/rust.eo +++ b/eo-runtime/src/main/eo/org/eolang/rust.eo @@ -26,4 +26,4 @@ +rt jvm org.eolang:eo-runtime:0.0.0 +version 0.0.0 -[code params] > rust /? +[code portal params] > rust /? diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java index 8a1304c82c..86b5487aea 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java @@ -138,6 +138,7 @@ public class EOrust extends PhDefault { public EOrust(final Phi sigma) { super(sigma); this.add("code", new AtFree()); + this.add("portal", new AtFree()); this.add("params", new AtFree()); this.add( Attr.LAMBDA, @@ -161,10 +162,7 @@ public EOrust(final Phi sigma) { byte[].class ); } - final Phi portal = new PhWith( - rho.attr("params").get().attr("at").get().copy(), - 0, new Data.ToPhi(0L) - ); + final Phi portal = rho.attr("portal").get(); return this.translate( (byte[]) method.invoke( null, diff --git a/eo-runtime/src/test/eo/org/eolang/rust-tests.eo b/eo-runtime/src/test/eo/org/eolang/rust-tests.eo index 6c5ac8af5c..9012c7e6af 100644 --- a/eo-runtime/src/test/eo/org/eolang/rust-tests.eo +++ b/eo-runtime/src/test/eo/org/eolang/rust-tests.eo @@ -37,8 +37,8 @@ Some(EOInt(2)) } """ + [] * - [] eq. > @ r 2 @@ -55,8 +55,8 @@ Some(EOInt(-10)) } """ + [] * - [] eq. > @ r -10 @@ -72,8 +72,8 @@ Some(EOFloat(1.23456789)) } """ + [] * - [] eq. > @ r 1.23456789 @@ -89,8 +89,8 @@ Some(EOFloat(-1.23456789)) } """ + [] * - [] eq. > @ r -1.23456789 @@ -112,17 +112,12 @@ ) } """ + [] * - [] eq. > @ my-bytes 00-1A-EE -# @todo #2555:30min Enable rust tests when it's possible to get an abstract object from tuple. -# Many rust tests were disabled because "portal" inside EOrust stopped working because of new -# implementation of "tuple". Now it's not possible to put an abstract object into tuple and take -# it back. Need to enable the next tests when it's possible: rust-find-returns-int, -# rust-returns-vertex, rust-copy-not-fails, rust-dataize-not-fails, rust-plus, rust-bind-to-copy [] > rust-find-returns-int 123 > a QQ.rust > r @@ -137,13 +132,12 @@ ) } """ + [] * - [] - not. > res + not. > @ lt. r 0 - nop > @ [] > rust-returns-vertex "content" > book @@ -158,12 +152,11 @@ Some(EOVertex(v)) } """ + [] * - [] - eq. > res + eq. > @ read "content" - nop > @ [] > rust-is-string QQ.rust > content @@ -176,8 +169,8 @@ Some(EOString("Привет world".to_string())) } """ + [] * - [] eq. > @ content "Привет world" @@ -193,8 +186,8 @@ Some(EOError("put failed".to_string())) } """ + [] * - [] eq. > @ slice. try @@ -223,8 +216,8 @@ Some(EOInt(0 as i64)) } """ + [] * - [] try > res! [] insert > @ @@ -250,12 +243,11 @@ Some(EOVertex(copy)) } """ + [] * - [] - eq. > res + eq. > @ copy 123 - nop > @ [] > rust-dataize-not-fails 1 > a @@ -270,14 +262,12 @@ Some(EOInt(v as i64)) } """ + [] * - [] - 3 - not. > res + not. > @ lt. dataized 0 - nop > @ [] > rust-plus 5 > a @@ -302,15 +292,15 @@ Some(EOInt(a + b)) } """ + [] * - [] "byteorder:1.4.3" - eq. > res + eq. > @ plus 15 - nop > @ [] > rust-error + "Rust insert failed " > message! QQ.rust > err! """ use eo_env::EOEnv; @@ -321,22 +311,21 @@ Some(EOError("Custom error".to_string())) } """ + [] * - [] try > res [] err > @ [e] e > @ nop - nop > @ - and. - eq. - res - "Rust insert failed " - eq. - res - "'Custom error'" + eq. > @ + slice. + res + 0 + length. + message + message [] > rust-put-to-copy QQ.rust > data @@ -352,8 +341,8 @@ Some(EOVertex(copy)) } """ + [] * - [] eq. > @ data 00-1A-EE @@ -375,9 +364,8 @@ Some(EOVertex(copy)) } """ + [] * - [] - eq. > res + eq. > @ applied.content "qwerty" - nop > @ diff --git a/eo-runtime/src/test/groovy/check-folders-numbering.groovy b/eo-runtime/src/test/groovy/check-folders-numbering.groovy index 6b205608cc..1fda93602f 100644 --- a/eo-runtime/src/test/groovy/check-folders-numbering.groovy +++ b/eo-runtime/src/test/groovy/check-folders-numbering.groovy @@ -35,10 +35,11 @@ List directories = target.toFile().listFiles(new FileFilter() { List allowed = [ '1-parse', '2-optimize', - '3-pull', - '4-resolve', - '5-pre', - '6-transpile', + '3-shake', + '4-pull', + '5-resolve', + '6-pre', + '7-transpile', ] List allowedDirs = allowed.stream() .map { target.resolve(it).toFile() }