Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Mar 21, 2024
2 parents 8e914d7 + d39d26b commit 4fb47cb
Show file tree
Hide file tree
Showing 25 changed files with 112 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ SOFTWARE.
</xsl:choose>
</xsl:when>
<xsl:when test="../@base = 'org.eolang.error'">
<xsl:text>"α"</xsl:text>
<xsl:text>"message"</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="position() - 1"/>
Expand Down
11 changes: 4 additions & 7 deletions eo-runtime/src/main/eo/org/eolang/bool.eo
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
^.as-bytes
x.as-bytes

# If true, return "t", otherwise "f".
[t f] > if /?

# NOT.
[] > not
eq. > @
Expand All @@ -47,20 +44,20 @@

# AND.
[x] > and
if. > @
if > @
^
if.
if
x
TRUE
FALSE
FALSE

# OR.
[x] > or
if. > @
if > @
^
TRUE
if.
if
x
TRUE
FALSE
Expand Down
38 changes: 1 addition & 37 deletions eo-runtime/src/main/eo/org/eolang/cage.eo
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,4 @@
# This object is doing exactly the same as "memory", but allows
# you to store objects, not only data. In other words, it doesn't
# do dataization when objects are being stored.
# Attention: your program will fail with StackOverflow exception if you try to
# write to "cage" an object that was obtained by any manipulations with the
# same "cage".
# For example, the code below fails
# [] > example
# cage > cge
# plus.
# 0
# 0
# seq > @
# cge.write
# plus.
# cge
# 1
# cge
#
# The reason of failing is described in detail here:
# https://github.com/objectionary/eo/issues/1698#issuecomment-1675224923
# To prevent failing you have to make a copy of "cage" before writing:
# [] > example
# cage > cge
# plus.
# 0
# 0
# seq > @
# cge.write
# plus.
# cge' # <--copy is made here
# 1
# cge
# @todo #1698:60min Make up with an idea how to prevent StackOverflow exception
# or warn a user if he writes cage into the same cage. Options: 1) xsl file
# that somehow checks if cage is about to write to the same cage 2) catch
# StackOverflow exception at the top level and say to the user that maybe he
# writes cage to the same cage.
[] > cage /?

[enclosure write] > cage /?
2 changes: 1 addition & 1 deletion eo-runtime/src/main/eo/org/eolang/error.eo
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
# The first attempt to dataize it will lead to runtime error and program
# termination. The only way to catch such an error is by using
# the object 'try'.
[] > error /?
[message] > error /?
2 changes: 1 addition & 1 deletion eo-runtime/src/main/eo/org/eolang/float.eo
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
nan > nan-as-bytes!
0.0 > pos-zero-as-bytes!
-0.0 > neg-zero-as-bytes!
if. > @
if > @
or.
eq.
x-as-bytes
Expand Down
2 changes: 1 addition & 1 deletion eo-runtime/src/main/eo/org/eolang/heap.eo
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
plus. > new-next!
s
^.malloc.next.as-int
if. > @
if > @
gt.
new-next
size
Expand Down
32 changes: 32 additions & 0 deletions eo-runtime/src/main/eo/org/eolang/if.eo
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2024 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.

+architect [email protected]
+home https://github.com/objectionary/eo
+package org.eolang
+rt jvm org.eolang:eo-runtime:0.0.0
+version 0.0.0

# Control structure that allows for conditional execution of code.
# It evaluates a condition, which is a `bool` object, and behaves as `left` if the condition is
# `TRUE`. If the condition evaluates to `FALSE` - behaves as `right`.
[condition left right] > if /?
2 changes: 1 addition & 1 deletion eo-runtime/src/main/eo/org/eolang/memory.eo
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
# Storage of data in memory.
# @todo #2211:30min We can implement memory in EO instead of Java and let it use
# ram object. Let's not forget to update the "Origins of Objects" paper.
[] > memory /bytes
[enclosure write] > memory /bytes
12 changes: 6 additions & 6 deletions eo-runtime/src/main/eo/org/eolang/negative-infinity.eo
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@
num.eq -0.0
num.eq 0.0
num.eq 0
if. > @
if > @
is-nan-or-zero value
nan
if.
if
is-num-gt-zero value
negative-infinity
positive-infinity
Expand All @@ -101,7 +101,7 @@
# Here we check if 'num' is nan by comparing it with nan bytes, because 'num' is cached bytes.
[num] > is-nan
num.eq nan.as-bytes > @
if. > @
if > @
or.
is-nan value
value.eq pos-inf-as-bytes
Expand All @@ -116,7 +116,7 @@
# Here we check if 'num' is nan by comparing it with nan bytes, because 'num' is cached bytes.
[num] > is-nan
num.eq nan.as-bytes > @
if. > @
if > @
or.
is-nan value
value.eq neg-inf-as-bytes
Expand Down Expand Up @@ -146,10 +146,10 @@
[e]
0.0.lte num > @
FALSE
if. > @
if > @
is-nan-or-infinite value
nan
if.
if
is-num-gte-zero value
negative-infinity
positive-infinity
12 changes: 6 additions & 6 deletions eo-runtime/src/main/eo/org/eolang/positive-infinity.eo
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@
[e]
0.0.lt num > @
FALSE
if. > @
if > @
is-nan-or-zero value
nan
if.
if
is-num-gt-zero value
positive-infinity
negative-infinity
Expand All @@ -101,7 +101,7 @@
# Here we check if 'num' is nan by comparing it with nan bytes, because 'num' is cached bytes.
[num] > is-nan
num.eq nan.as-bytes > @
if. > @
if > @
or.
is-nan value
value.eq neg-inf-as-bytes
Expand All @@ -116,7 +116,7 @@
# Here we check if 'num' is nan by comparing it with nan bytes, because 'num' is cached bytes.
[num] > is-nan
num.eq nan.as-bytes > @
if. > @
if > @
or.
is-nan value
value.eq pos-inf-as-bytes
Expand Down Expand Up @@ -147,10 +147,10 @@
[e]
0.0.lte num > @
FALSE
if. > @
if > @
is-nan-or-infinite value
nan
if.
if
is-num-gte-zero value
positive-infinity
negative-infinity
6 changes: 3 additions & 3 deletions eo-runtime/src/main/eo/org/eolang/switch.eo
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@
# If case key is TRUE, return case value.
# Otherwise take next case.
[index] > case-at
if. > @
if > @
index.eq ^.len
TRUE
if.
if
at.
^.cases.at index > case
0
case.at 1
^.case-at
index.plus 1
if. > @
if > @
len.eq 0
error "switch cases are empty"
case-at 0
6 changes: 3 additions & 3 deletions eo-runtime/src/main/eo/org/eolang/tuple.eo
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@
[i] > at
i > idx!
^.length > len
if. > index!
if > index!
0.gt idx
len.plus idx
idx
if. > @
if > @
or.
0.gt index
len.lte index
error "Given index is out of tuple bounds"
if.
if
gt.
len.plus -1
index
Expand Down
4 changes: 2 additions & 2 deletions eo-runtime/src/main/java/EOorg/EOeolang/EOerror.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public final class EOerror extends PhDefault implements Atom {
*/
public EOerror(final Phi sigma) {
super(sigma);
this.add("α", new AtFree());
this.add("message", new AtFree());
}

/**
Expand All @@ -83,7 +83,7 @@ public static String message(final Throwable exp) {

@Override
public Phi lambda() {
throw new ExError(this.attr("α").get());
throw new ExError(this.attr("message").get());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,31 @@
/**
* IF.
*
* @since 1.0
* @since 0.36.0
* @checkstyle TypeNameCheck (5 lines)
*/
@Versionized
@XmirObject(oname = "bool.if")
public final class EObool$EOif extends PhDefault implements Atom {
@XmirObject(oname = "if")
public final class EOif extends PhDefault implements Atom {
/**
* Ctor.
* @param sigma Sigma
*/
public EObool$EOif(final Phi sigma) {
public EOif(final Phi sigma) {
super(sigma);
this.add("t", new AtFree());
this.add("f", new AtFree());
this.add("condition", new AtFree());
this.add("left", new AtFree());
this.add("right", new AtFree());
}

@Override
public Phi lambda() {
final boolean term = new Param(this).strong(Boolean.class);
final boolean term = new Param(this, "condition").strong(Boolean.class);
final Phi out;
if (term) {
out = this.attr("t").get();
out = this.attr("left").get();
} else {
out = this.attr("f").get();
out = this.attr("right").get();
}
return out;
}
Expand Down
17 changes: 4 additions & 13 deletions eo-runtime/src/test/eo/org/eolang/bool-tests.eo
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,6 @@
TRUE
42

# Test.
[] > forks-on-condition
eq. > @
if.
5.eq 8
123
42
42

# Test.
[] > iterates-over-simple-counter
memory 0 > x
Expand Down Expand Up @@ -161,7 +152,7 @@
arr.length.minus 1 > max
seq > res
*
if.
if
max.eq 0
acc.write
acc.as-int.plus
Expand Down Expand Up @@ -190,7 +181,7 @@
arr.length.minus 1 > max
seq > nop
*
if.
if
max.eq 0
acc.write
acc.as-int.plus
Expand Down Expand Up @@ -221,7 +212,7 @@
*
while.
[]
if. > @
if > @
iter.as-int.lt max
seq
*
Expand Down Expand Up @@ -249,7 +240,7 @@
*
while.
[]
if. > @
if > @
iter.as-int.lt max
seq
*
Expand Down
Loading

1 comment on commit 4fb47cb

@0pdd
Copy link

@0pdd 0pdd commented on 4fb47cb Mar 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1698-c7207422 disappeared from eo-runtime/src/main/eo/org/eolang/cage.eo), that's why I closed #2836. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

Please sign in to comment.