Skip to content

Commit 6fbc815

Browse files
committed
Add missing messages 'isBoolean' and 'asBoolean'.
1 parent 687efcc commit 6fbc815

File tree

1 file changed

+22
-1
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints

1 file changed

+22
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/PInt.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2019, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -27,9 +27,13 @@
2727

2828
import java.math.BigInteger;
2929

30+
import com.oracle.graal.python.PythonLanguage;
3031
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
3132
import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
33+
import com.oracle.graal.python.runtime.PythonContext;
3234
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
35+
import com.oracle.truffle.api.dsl.Cached.Shared;
36+
import com.oracle.truffle.api.dsl.CachedContext;
3337
import com.oracle.truffle.api.interop.InteropLibrary;
3438
import com.oracle.truffle.api.interop.UnsupportedMessageException;
3539
import com.oracle.truffle.api.library.CachedLibrary;
@@ -59,6 +63,23 @@ public boolean isZero() {
5963
return value.equals(BigInteger.ZERO);
6064
}
6165

66+
@ExportMessage
67+
public boolean isBoolean(
68+
@Shared("context") @CachedContext(PythonLanguage.class) PythonContext context) {
69+
return this == context.getCore().getTrue() || this == context.getCore().getFalse();
70+
}
71+
72+
@ExportMessage
73+
public boolean asBoolean(
74+
@Shared("context") @CachedContext(PythonLanguage.class) PythonContext context) throws UnsupportedMessageException {
75+
if (this == context.getCore().getTrue()) {
76+
return true;
77+
} else if (this == context.getCore().getFalse()) {
78+
return false;
79+
}
80+
throw UnsupportedMessageException.create();
81+
}
82+
6283
@ExportMessage
6384
@SuppressWarnings("static-method")
6485
public boolean isNumber() {

0 commit comments

Comments
 (0)