Skip to content

Commit

Permalink
Merge pull request #3817 from maxonfjvipon/bug/#3481/functions-instea…
Browse files Browse the repository at this point in the history
…d-of-lambdas

bug(#3481): use functions instead of lambdas
  • Loading branch information
yegor256 authored Jan 15, 2025
2 parents 6e5f99d + 2bfc50d commit cac0bc5
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 28 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ort.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ on:
- master
jobs:
ort:
if: false
runs-on: ubuntu-24.04
steps:
- run: git config --global url.https://github.com/.insteadOf ssh://[email protected]/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ SOFTWARE.
<xsl:element name="java">
<xsl:apply-templates select="/program" mode="license"/>
<xsl:apply-templates select="/program/metas/meta[head='package']" mode="head"/>
<xsl:text>import java.util.function.Function;</xsl:text>
<xsl:value-of select="eo:eol(0)"/>
<xsl:text>import org.eolang.*;</xsl:text>
<xsl:value-of select="eo:eol(0)"/>
<xsl:apply-templates select="/program/metas/meta[head='tests']" mode="head"/>
Expand Down Expand Up @@ -295,15 +297,21 @@ SOFTWARE.
<xsl:param name="indent"/>
<xsl:param name="parent"/>
<xsl:param name="context"/>
<xsl:variable name="name" select="eo:attr-name(@name)"/>
<xsl:if test="not(@name)">
<xsl:message terminate="yes">
<xsl:text>Unnamed attribute found in </xsl:text>
<xsl:value-of select="parent::*/@loc"/>
</xsl:message>
</xsl:if>
<xsl:variable name="name" select="eo:attr-name(@name)"/>
<xsl:value-of select="eo:eol($indent)"/>
<xsl:if test="$context!='this'">
<xsl:text>((PhDefault) </xsl:text>
</xsl:if>
<xsl:value-of select="$context"/>
<xsl:if test="$context!='this'">
<xsl:text>)</xsl:text>
</xsl:if>
<xsl:text>.add("</xsl:text>
<xsl:value-of select="$name"/>
<xsl:text>", </xsl:text>
Expand All @@ -322,7 +330,15 @@ SOFTWARE.
<xsl:value-of select="$name"/>
<xsl:text>")</xsl:text>
</xsl:template>
<!-- Atom as attribute -->
<!--
Atom as attribute.
We use new Function<>() {...} syntax instead of lambdas from Java 8 because
1. java does not manage to compile the code with 17+ nested lambdas.
It just freezes and fails in 5-10 min with heap overflow error.
So we can't compile nested-blah-test from runtime-tests.eo.
We haven't reported the bug to openjdk yet, but we will
2. it just works faster because dynamic dispatch is not happened
-->
<xsl:template match="atom">
<xsl:param name="parent"/>
<xsl:param name="name"/>
Expand All @@ -342,23 +358,29 @@ SOFTWARE.
</xsl:variable>
<xsl:text>new AtOnce(new AtComposite(</xsl:text>
<xsl:value-of select="$context"/>
<xsl:text>, </xsl:text>
<xsl:value-of select="eo:rho($context)"/>
<xsl:text> -&gt; {</xsl:text>
<xsl:text>, new Function&lt;&gt;() {</xsl:text>
<xsl:value-of select="eo:eol($indent + 1)"/>
<xsl:text>@Override</xsl:text>
<xsl:value-of select="eo:eol($indent + 1)"/>
<xsl:text>public Phi apply(final Phi </xsl:text>
<xsl:value-of select="eo:rho($context)"/>
<xsl:text>) {</xsl:text>
<xsl:value-of select="eo:eol($indent + 2)"/>
<xsl:text>Phi </xsl:text>
<xsl:value-of select="$variable"/>
<xsl:text> = new </xsl:text>
<xsl:value-of select="$class"/>
<xsl:text>();</xsl:text>
<xsl:apply-templates select="$argument" mode="located">
<xsl:with-param name="indent" select="$indent + 1"/>
<xsl:with-param name="indent" select="$indent + 2"/>
<xsl:with-param name="name" select="$variable"/>
</xsl:apply-templates>
<xsl:value-of select="eo:eol($indent + 1)"/>
<xsl:value-of select="eo:eol($indent + 2)"/>
<xsl:text>return </xsl:text>
<xsl:value-of select="$variable"/>
<xsl:text>;</xsl:text>
<xsl:value-of select="eo:eol($indent + 1)"/>
<xsl:text>}</xsl:text>
<xsl:value-of select="eo:eol($indent)"/>
<xsl:text>}))</xsl:text>
</xsl:template>
Expand All @@ -372,30 +394,36 @@ SOFTWARE.
<xsl:variable name="ctx" select="eo:context($context)"/>
<xsl:text>new AtOnce(new AtComposite(</xsl:text>
<xsl:value-of select="$context"/>
<xsl:text>, </xsl:text>
<xsl:value-of select="$rho"/>
<xsl:text> -&gt; {</xsl:text>
<xsl:text>, new Function&lt;&gt;() {</xsl:text>
<xsl:value-of select="eo:eol($indent + 1)"/>
<xsl:text>PhDefault </xsl:text>
<xsl:text>@Override</xsl:text>
<xsl:value-of select="eo:eol($indent + 1)"/>
<xsl:text>public Phi apply(final Phi </xsl:text>
<xsl:value-of select="$rho"/>
<xsl:text>) {</xsl:text>
<xsl:value-of select="eo:eol($indent + 2)"/>
<xsl:text>Phi </xsl:text>
<xsl:value-of select="$ctx"/>
<xsl:text> = new PhDefault();</xsl:text>
<xsl:apply-templates select="attr">
<xsl:with-param name="indent" select="$indent + 1"/>
<xsl:with-param name="indent" select="$indent + 2"/>
<xsl:with-param name="parent">
<xsl:value-of select="$parent"/>
<xsl:text>$</xsl:text>
<xsl:value-of select="eo:class-name($name, eo:suffix(@line, @pos))"/>
</xsl:with-param>
<xsl:with-param name="context" select="$ctx"/>
</xsl:apply-templates>
<!-- <xsl:apply-templates select="." mode="located">-->
<!-- <xsl:with-param name="name" select="$ctx"/>-->
<!-- <xsl:with-param name="indent" select="$indent + 1"/>-->
<!-- </xsl:apply-templates>-->
<xsl:value-of select="eo:eol($indent + 1)"/>
<xsl:apply-templates select="." mode="located">
<xsl:with-param name="name" select="$ctx"/>
<xsl:with-param name="indent" select="$indent + 2"/>
</xsl:apply-templates>
<xsl:value-of select="eo:eol($indent + 2)"/>
<xsl:text>return </xsl:text>
<xsl:value-of select="$ctx"/>
<xsl:text>;</xsl:text>
<xsl:value-of select="eo:eol($indent + 1)"/>
<xsl:text>}</xsl:text>
<xsl:value-of select="eo:eol($indent)"/>
<xsl:text>}))</xsl:text>
</xsl:template>
Expand All @@ -407,18 +435,24 @@ SOFTWARE.
<xsl:variable name="ctx" select="eo:context($context)"/>
<xsl:text>new AtOnce(new AtComposite(</xsl:text>
<xsl:value-of select="$context"/>
<xsl:text>, </xsl:text>
<xsl:text>, new Function&lt;&gt;() {</xsl:text>
<xsl:value-of select="eo:eol($indent + 1)"/>
<xsl:text>@Override</xsl:text>
<xsl:value-of select="eo:eol($indent + 1)"/>
<xsl:text>public Phi apply(final Phi </xsl:text>
<xsl:value-of select="$rho"/>
<xsl:text> -&gt; {</xsl:text>
<xsl:text>) {</xsl:text>
<xsl:apply-templates select="o">
<xsl:with-param name="name" select="$ctx"/>
<xsl:with-param name="indent" select="$indent + 1"/>
<xsl:with-param name="indent" select="$indent + 2"/>
<xsl:with-param name="rho" select="$rho"/>
</xsl:apply-templates>
<xsl:value-of select="eo:eol($indent + 1)"/>
<xsl:value-of select="eo:eol($indent + 2)"/>
<xsl:text>return </xsl:text>
<xsl:value-of select="$ctx"/>
<xsl:text>;</xsl:text>
<xsl:value-of select="eo:eol($indent + 1)"/>
<xsl:text>}</xsl:text>
<xsl:value-of select="eo:eol($indent)"/>
<xsl:text>}))</xsl:text>
</xsl:template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ sheets:
asserts:
- /program[not(errors)]
- //java[contains(text(), 'this.add("xyz",')]
- //java[contains(text(), 'r.add("bar",')]
- //java[contains(text(), 'rr.add("φ",')]
- //java[contains(text(), '((PhDefault) r).add("bar",')]
- //java[contains(text(), '((PhDefault) rr).add("φ",')]
- //java[contains(text(), 'Phi rrrbbb = new PhMethod(rrh, "ρ")')]
- //java[contains(text(), 'Phi rrrbb = new PhMethod(rrrbbb, "ρ")')]
- //java[contains(text(), 'Phi rrrb = new PhMethod(rrrbb, "this")')]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ sheets:
asserts:
- /program[not(errors)]
- //java[contains(text(), 'public final class EOtest extends PhDefault')]
- //java[contains(text(), 'PhDefault rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr = new PhDefault();')]
- //java[contains(text(), 'rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.add("blah39"')]
- //java[contains(text(), 'Phi rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr = new PhDefault();')]
- //java[contains(text(), '((PhDefault) rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr).add("blah39"')]
input: |
# No comments.
[] > test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ sheets:
asserts:
- /program[not(errors)]
- /program/objects/class/java[contains(text(), 'this.add("b"')]
- /program/objects/class/java[contains(text(), 'r.add("c",')]
- /program/objects/class/java[contains(text(), 'rr.add("φ",')]
- /program/objects/class/java[contains(text(), '((PhDefault) r).add("c",')]
- /program/objects/class/java[contains(text(), '((PhDefault) rr).add("φ",')]
- /program/objects/class/java[contains(text(), 'public void works() throws java.lang.Exception')]
- /program/objects/class/java[contains(text(), 'private static class EOΦabcφα0')]
- /program/objects/class/java[contains(text(), 'PhDefault r1 = new EOΦabcφα0boundα0();')]
Expand Down
62 changes: 61 additions & 1 deletion eo-runtime/src/test/eo/org/eolang/runtime-tests.eo
Original file line number Diff line number Diff line change
Expand Up @@ -383,4 +383,64 @@ true > global-test
[] > blah8
blah9 > @
[] > blah9
true > @
blah10 > @
[] > blah10
blah11 > @
[] > blah11
blah12 > @
[] > blah12
blah13 > @
[] > blah13
blah14 > @
[] > blah14
blah15 > @
[] > blah15
blah16 > @
[] > blah16
blah17 > @
[] > blah17
blah18 > @
[] > blah18
blah19 > @
[] > blah19
blah20 > @
[] > blah20
blah21 > @
[] > blah21
blah22 > @
[] > blah22
blah23 > @
[] > blah23
blah24 > @
[] > blah24
blah25 > @
[] > blah25
blah26 > @
[] > blah26
blah27 > @
[] > blah27
blah28 > @
[] > blah28
blah29 > @
[] > blah29
blah30 > @
[] > blah30
blah31 > @
[] > blah31
blah32 > @
[] > blah32
blah33 > @
[] > blah33
blah34 > @
[] > blah34
blah35 > @
[] > blah35
blah36 > @
[] > blah36
blah37 > @
[] > blah37
blah38 > @
[] > blah38
blah39 > @
[] > blah39
true > @

0 comments on commit cac0bc5

Please sign in to comment.