|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. |
| 2 | + * Copyright (c) 2017, 2019, Oracle and/or its affiliates. |
3 | 3 | * Copyright (c) 2013, Regents of the University of California
|
4 | 4 | *
|
5 | 5 | * All rights reserved.
|
|
27 | 27 |
|
28 | 28 | import java.math.BigInteger;
|
29 | 29 |
|
| 30 | +import com.oracle.graal.python.PythonLanguage; |
30 | 31 | import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
|
31 | 32 | import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
|
| 33 | +import com.oracle.graal.python.runtime.PythonContext; |
32 | 34 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
| 35 | +import com.oracle.truffle.api.dsl.Cached.Shared; |
| 36 | +import com.oracle.truffle.api.dsl.CachedContext; |
33 | 37 | import com.oracle.truffle.api.interop.InteropLibrary;
|
34 | 38 | import com.oracle.truffle.api.interop.UnsupportedMessageException;
|
35 | 39 | import com.oracle.truffle.api.library.CachedLibrary;
|
@@ -59,6 +63,23 @@ public boolean isZero() {
|
59 | 63 | return value.equals(BigInteger.ZERO);
|
60 | 64 | }
|
61 | 65 |
|
| 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 | + |
62 | 83 | @ExportMessage
|
63 | 84 | @SuppressWarnings("static-method")
|
64 | 85 | public boolean isNumber() {
|
|
0 commit comments