Skip to content

Commit

Permalink
feat(objectionary#2437): with bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
maxonfjvipon committed Sep 28, 2023
1 parent 7c8c223 commit e5f7a77
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public final class TranspileMojo extends SafeMojo {
*/
static final Train<Shift> TRAIN = new TrJoined<>(
new TrClasspath<>(
new ParsingTrain().empty().with(new StUnhex()),
"/org/eolang/maven/pre/classes.xsl",
"/org/eolang/maven/pre/package.xsl",
"/org/eolang/maven/pre/tests.xsl",
Expand Down
75 changes: 40 additions & 35 deletions eo-maven-plugin/src/main/resources/org/eolang/maven/pre/data.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ SOFTWARE.
<xsl:element name="value">
<xsl:choose>
<xsl:when test="@data='bytes'">
<xsl:variable name="array">
<!-- <xsl:variable name="array">-->
<xsl:text>new byte[] {</xsl:text>
<xsl:for-each select="tokenize(text(), ' ')">
<xsl:if test="position() &gt; 1">
Expand All @@ -47,40 +47,45 @@ SOFTWARE.
<xsl:value-of select="."/>
</xsl:for-each>
<xsl:text>}</xsl:text>
</xsl:variable>
<xsl:choose>
<xsl:when test="@base='org.eolang.string' or @base='string'">
<xsl:text>new String(</xsl:text>
<xsl:value-of select="$array"/>
<xsl:text>, java.nio.charset.StandardCharsets.UTF_8</xsl:text>
<xsl:text>)</xsl:text>
</xsl:when>
<xsl:when test="@base='org.eolang.bool' or @base='bool'">
<xsl:choose>
<xsl:when test="text() = '01'">
<xsl:text>Boolean.TRUE</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>Boolean.FALSE</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="@base='org.eolang.bytes' or @base='bytes'">
<xsl:value-of select="$array"/>
</xsl:when>
<xsl:when test="@base='org.eolang.int' or @base='int'">
<xsl:text>java.nio.ByteBuffer.wrap(</xsl:text>
<xsl:value-of select="$array"/>
<xsl:text>).getLong()</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">
<xsl:text>Unsupported type: '</xsl:text>
<xsl:value-of select="@base"/>
<xsl:text>'</xsl:text>
</xsl:message>
</xsl:otherwise>
</xsl:choose>
<!-- </xsl:variable>-->
<!-- <xsl:choose>-->
<!-- <xsl:when test="@base='org.eolang.string' or @base='string'">-->
<!-- <xsl:text>new String(</xsl:text>-->
<!-- <xsl:value-of select="$array"/>-->
<!-- <xsl:text>, java.nio.charset.StandardCharsets.UTF_8</xsl:text>-->
<!-- <xsl:text>)</xsl:text>-->
<!-- </xsl:when>-->
<!-- <xsl:when test="@base='org.eolang.bool' or @base='bool'">-->
<!-- <xsl:choose>-->
<!-- <xsl:when test="text() = '01'">-->
<!-- <xsl:text>Boolean.TRUE</xsl:text>-->
<!-- </xsl:when>-->
<!-- <xsl:otherwise>-->
<!-- <xsl:text>Boolean.FALSE</xsl:text>-->
<!-- </xsl:otherwise>-->
<!-- </xsl:choose>-->
<!-- </xsl:when>-->
<!-- <xsl:when test="@base='org.eolang.bytes' or @base='bytes'">-->
<!-- <xsl:value-of select="$array"/>-->
<!-- </xsl:when>-->
<!-- <xsl:when test="@base='org.eolang.int' or @base='int'">-->
<!-- <xsl:text>java.nio.ByteBuffer.wrap(</xsl:text>-->
<!-- <xsl:value-of select="$array"/>-->
<!-- <xsl:text>).getLong()</xsl:text>-->
<!-- </xsl:when>-->
<!-- <xsl:when test="@base='org.eolang.float' or @base='float'">-->
<!-- <xsl:text>java.nio.ByteBuffer.wrap(</xsl:text>-->
<!-- <xsl:value-of select="$array"/>-->
<!-- <xsl:text>).getDouble()</xsl:text>-->
<!-- </xsl:when>-->
<!-- <xsl:otherwise>-->
<!-- <xsl:message terminate="yes">-->
<!-- <xsl:text>Unsupported type: '</xsl:text>-->
<!-- <xsl:value-of select="@base"/>-->
<!-- <xsl:text>'</xsl:text>-->
<!-- </xsl:message>-->
<!-- </xsl:otherwise>-->
<!-- </xsl:choose>-->
</xsl:when>
<xsl:when test="@data='string'">
<xsl:text>"</xsl:text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ SOFTWARE.
</xsl:otherwise>
</xsl:choose>
<xsl:variable name="type" select="concat(//meta[head='package']/tail, '.', @name)"/>
<xsl:if test="$literal-objects[text()=$type]">
<!-- <xsl:if test="$literal-objects[text()=$type]">-->
<xsl:if test="$type='org.eolang.bytes'">
<xsl:value-of select="eo:eol(2)"/>
<xsl:text>this.add("Δ", new AtFree(new AtSimple(), this.initialized));</xsl:text>
</xsl:if>
Expand Down Expand Up @@ -621,7 +622,7 @@ SOFTWARE.
<xsl:value-of select="$name"/>
<xsl:text> = new PhWith(</xsl:text>
<xsl:value-of select="$name"/>
<xsl:text>, "Δ", new Data.Value&lt;&gt;(</xsl:text>
<xsl:text>, 0, new Data.Value&lt;&gt;(</xsl:text>
<xsl:value-of select="text()"/>
<xsl:text>));</xsl:text>
<xsl:value-of select="eo:eol(0)"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
xsls:
- /org/eolang/parser/add-default-package.xsl
- /org/eolang/parser/explicit-data.xsl
- /org/eolang/maven/pre/classes.xsl
- /org/eolang/maven/pre/attrs.xsl
- /org/eolang/maven/pre/data.xsl
- /org/eolang/maven/pre/to-java.xsl
tests:
- /program/errors[count(*)=0]
- //java[contains(text(), 'Boolean.TRUE')]
- //java[contains(text(), 'Boolean.FALSE')]
- //java[contains(text(), 'ret = new PhWith(ret, 0, new Data.Value<>(new byte[] {(byte) 0x01}));')]
- //java[contains(text(), 'ret = new PhWith(ret, 0, new Data.Value<>(new byte[] {(byte) 0x00}));')]
- //java[contains(text(), 'ret = new PhWith(ret, 0, new Data.Value<>(new byte[] {(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x2A}));')]
- //java[contains(text(), 'ret = new PhWith(ret, 0, new Data.Value<>(new byte[] {(byte) 0x40, (byte) 0x0C, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00}));')]
- //java[contains(text(), 'ret = new PhWith(ret, 0, new Data.Value<>(new byte[] {(byte) 0x01, (byte) 0xAF}));')]
eo: |
[] > t
TRUE > @
[] > f
FALSE > @
[] > i
42 > @
[] > f
float 3.5 > @
[] > b
01-AF > @
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ tests:
- /program/errors[count(*)=0]
- //java[contains(text(), 'Phi ret_a2_a1 = new EOorg.EOeolang.EOint(')]
- //java[contains(text(), 'Phi[] ret_2_a = new Phi[0]')]
- //java[contains(text(), 'new String(new byte[]')]
- //java[contains(text(), 'ret = new PhWith(ret, 0, new Data.Value<>(new byte[] {(byte) 0xD0, (byte) 0xB0, (byte) 0xD0, (byte) 0xB1, (byte) 0xD0, (byte) 0xB2, (byte) 0xD0, (byte) 0xB3, (byte) 0xD0, (byte) 0xB4}));')]
eo: |
[] > foo
* 1 2 (* 3 4) > @
Expand Down
4 changes: 3 additions & 1 deletion eo-runtime/src/main/eo/org/eolang/bool.eo
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
+rt jvm org.eolang:eo-runtime:0.0.0
+version 0.0.0

[] > bool
[data] > bool
bytes data > @

# Equal to another object?
[x] > eq
eq. > @
Expand Down
7 changes: 3 additions & 4 deletions eo-runtime/src/main/eo/org/eolang/float.eo
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
+rt jvm org.eolang:eo-runtime:0.0.0
+version 0.0.0

[] > float
[data] > float
bytes data > @

# Tests that $ = x
[x] > eq
x > value!
Expand Down Expand Up @@ -103,6 +105,3 @@

# Quotient of the division of $ by x
[x...] > div /float

# Converts this to bytes
[] > as-bytes /bytes
7 changes: 3 additions & 4 deletions eo-runtime/src/main/eo/org/eolang/int.eo
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
+rt jvm org.eolang:eo-runtime:0.0.0
+version 0.0.0

[] > int
[data] > int
bytes data > @

# Tests that $ = x
[x] > eq
if. > @
Expand Down Expand Up @@ -98,6 +100,3 @@

# Divide this one by another int
[x...] > div /int

# Converts this to bytes
[] > as-bytes /bytes
7 changes: 3 additions & 4 deletions eo-runtime/src/main/eo/org/eolang/string.eo
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
+rt jvm org.eolang:eo-runtime:0.0.0
+version 0.0.0

[] > string
[data] > string
bytes data > @

# Is true if both objects are equal
[x] > eq
eq. > @
Expand All @@ -36,8 +38,5 @@
# Get the length of it
[] > length /int

# Turn it into bytes.
[] > as-bytes /bytes

# Takes a piece of a string as another string
[start len] > slice /string

0 comments on commit e5f7a77

Please sign in to comment.