Mercurial > hg > graal-jvmci-8
annotate graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLNull.java @ 21689:ed234a3178af
Behavior of null-like values is now part of the TCK
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Wed, 03 Jun 2015 10:17:19 +0200 |
parents | 1d3c23e675ed |
children | c76742cc2c6f |
rev | line source |
---|---|
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12752
diff
changeset
|
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.sl.runtime; |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
21689
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
15393
diff
changeset
|
25 import com.oracle.truffle.api.interop.ForeignAccessFactory; |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
15393
diff
changeset
|
26 import com.oracle.truffle.api.interop.TruffleObject; |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
15393
diff
changeset
|
27 |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12752
diff
changeset
|
28 /** |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12752
diff
changeset
|
29 * The SL type for a {@code null} (i.e., undefined) value. In Truffle, it is generally discouraged |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12752
diff
changeset
|
30 * to use the Java {@code null} value to represent the guest language {@code null} value. It is not |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12752
diff
changeset
|
31 * possible to specialize on Java {@code null} (since you cannot ask it for the Java class), and |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12752
diff
changeset
|
32 * there is always the danger of a spurious {@link NullPointerException}. Representing the guest |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12752
diff
changeset
|
33 * language {@code null} as a singleton, as in {@link #SINGLETON this class}, is the recommended |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12752
diff
changeset
|
34 * practice. |
15393
1d3c23e675ed
fixed some minor javadoc formatting issues
Doug Simon <doug.simon@oracle.com>
parents:
13821
diff
changeset
|
35 */ |
21689
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
15393
diff
changeset
|
36 public final class SLNull implements TruffleObject { |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12752
diff
changeset
|
38 /** |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12752
diff
changeset
|
39 * The canonical value to represent {@code null} in SL. |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12752
diff
changeset
|
40 */ |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12752
diff
changeset
|
41 public static final SLNull SINGLETON = new SLNull(); |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12752
diff
changeset
|
43 /** |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12752
diff
changeset
|
44 * Disallow instantiation from outside to ensure that the {@link #SINGLETON} is the only |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12752
diff
changeset
|
45 * instance. |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12752
diff
changeset
|
46 */ |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 private SLNull() { |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 } |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12752
diff
changeset
|
50 /** |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12752
diff
changeset
|
51 * This method is, e.g., called when using the {@code null} value in a string concatenation. So |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12752
diff
changeset
|
52 * changing it has an effect on SL programs. |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12752
diff
changeset
|
53 */ |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12752
diff
changeset
|
54 @Override |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12752
diff
changeset
|
55 public String toString() { |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12752
diff
changeset
|
56 return "null"; |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12752
diff
changeset
|
57 } |
21689
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
15393
diff
changeset
|
58 |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
15393
diff
changeset
|
59 @Override |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
15393
diff
changeset
|
60 public ForeignAccessFactory getForeignAccessFactory() { |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
15393
diff
changeset
|
61 return SLFunctionForeignAccess.INSTANCE; |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
15393
diff
changeset
|
62 } |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
63 } |