Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat Boolean.False as false primitive #6090

Merged
merged 3 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.NodeInfo;
import com.oracle.truffle.api.nodes.RootNode;
import org.enso.interpreter.runtime.EnsoContext;
import org.enso.interpreter.runtime.callable.atom.AtomConstructor;

@NodeInfo(
Expand Down Expand Up @@ -36,7 +37,16 @@ public AtomConstructor getAtomConstructor() {
*/
public Object execute(VirtualFrame frame) {
if (atomConstructor.getArity() == 0) {
return atomConstructor.newInstance();
var trueCtor = EnsoContext.get(this).getBuiltins().bool().getTrue();
var falseCtor = EnsoContext.get(this).getBuiltins().bool().getFalse();
// This matches the shortcuts provided in ConstructorNode
if (atomConstructor == trueCtor) {
return true;
} else if (atomConstructor == falseCtor) {
return false;
} else {
return atomConstructor.newInstance();
}
} else {
return atomConstructor;
}
Expand Down
82 changes: 55 additions & 27 deletions engine/runtime/src/test/scala/org/enso/std/test/BooleanTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ class BooleanTest extends InterpreterTest {
interpreterContext: InterpreterContext
): Unit = {

val defaultImports =
"""
|from Standard.Base.Data.Boolean import all
|import Standard.Base.IO
|""".stripMargin

"support if_then_else" in {
val code =
"""from Standard.Base.Data.Boolean import all
|import Standard.Base.IO
|
|main =
| if True then IO.println "true when true" else IO.println "false when true"
| if False then IO.println "true when false" else IO.println "false when false"
|""".stripMargin
s"""$defaultImports
|
|main =
| if True then IO.println "true when true" else IO.println "false when true"
| if False then IO.println "true when false" else IO.println "false when false"
|""".stripMargin
eval(code)
consumeOut shouldEqual List("true when true", "false when false")
}
Expand Down Expand Up @@ -57,32 +62,55 @@ class BooleanTest extends InterpreterTest {

"support logical AND and OR operators" in {
val code =
"""from Standard.Base.Data.Boolean import all
|import Standard.Base.IO
|
|main =
| IO.println True&&False
| IO.println True&&True
| IO.println False||False
| IO.println True||False
| IO.println ((True && False) || (True && True))
|""".stripMargin
s"""$defaultImports
|
|main =
| IO.println True&&False
| IO.println True&&True
| IO.println True&&Boolean.True
| IO.println False||False
| IO.println True||False
| IO.println ((True && False) || (True && True))
|""".stripMargin
eval(code)
consumeOut shouldEqual List("False", "True", "False", "True", "True")
consumeOut shouldEqual List(
"False",
"True",
"True",
"False",
"True",
"True"
)
}

"support negation" in {
val code =
"""from Standard.Base.Data.Boolean import all
|import Standard.Base.IO
|
|main =
| IO.println True.not
| IO.println False.not
| IO.println (1==2 . not)
|""".stripMargin
s"""$defaultImports
|
|main =
| IO.println True.not
| IO.println Boolean.True.not
| IO.println False.not
| IO.println Boolean.False.not
| IO.println (1==2 . not)
|""".stripMargin
eval(code)
consumeOut shouldEqual List("False", "False", "True", "True", "True")
}

"literal equals atom constructor" in {
val code =
s"""$defaultImports
|
|main =
| IO.println (False == Boolean.False)
| IO.println (Boolean.False == False)
| IO.println (True == Boolean.True)
| IO.println (Boolean.True == True)
|
|""".stripMargin
eval(code)
consumeOut shouldEqual List("False", "True", "True")
consumeOut shouldEqual List("True", "True", "True", "True")
}
}
}
2 changes: 1 addition & 1 deletion project/DistributionPackage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ object DistributionPackage {
path.globRecursive("*.enso").get().toSet
) { diff =>
if (diff.modified.nonEmpty) {
println(s"Generating index for ${libName} ")
log.info(s"Generating index for $libName")
Copy link
Member Author

Choose a reason for hiding this comment

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

@hubertp I hope it is not a problem to replace this with log.info. I did it because locally, I connect to the SBT server via socket, and it sends me back only messages from logging, and this message was just discarded.

val command = Seq(
Platform.executableFileName(ensoExecutable.toString),
"--no-compile-dependencies",
Expand Down