Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLNull.java @ 13821:b16ec83edc73
Documentation and more refactoring of Simple Language
author | Christian Wimmer <christian.wimmer@oracle.com> |
---|---|
date | Wed, 29 Jan 2014 20:45:43 -0800 |
parents | 71991b7a0f14 |
children | 1d3c23e675ed |
comparison
equal
deleted
inserted
replaced
13820:20e7727588e8 | 13821:b16ec83edc73 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
20 * or visit www.oracle.com if you need additional information or have any | 20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. | 21 * questions. |
22 */ | 22 */ |
23 package com.oracle.truffle.sl.runtime; | 23 package com.oracle.truffle.sl.runtime; |
24 | 24 |
25 /** | |
26 * The SL type for a {@code null} (i.e., undefined) value. In Truffle, it is generally discouraged | |
27 * to use the Java {@code null} value to represent the guest language {@code null} value. It is not | |
28 * possible to specialize on Java {@code null} (since you cannot ask it for the Java class), and | |
29 * there is always the danger of a spurious {@link NullPointerException}. Representing the guest | |
30 * language {@code null} as a singleton, as in {@link #SINGLETON this class}, is the recommended | |
31 * practice. | |
32 * */ | |
25 public final class SLNull { | 33 public final class SLNull { |
26 | 34 |
27 public static final SLNull INSTANCE = new SLNull(); | 35 /** |
36 * The canonical value to represent {@code null} in SL. | |
37 */ | |
38 public static final SLNull SINGLETON = new SLNull(); | |
28 | 39 |
40 /** | |
41 * Disallow instantiation from outside to ensure that the {@link #SINGLETON} is the only | |
42 * instance. | |
43 */ | |
29 private SLNull() { | 44 private SLNull() { |
30 } | 45 } |
31 | 46 |
47 /** | |
48 * This method is, e.g., called when using the {@code null} value in a string concatenation. So | |
49 * changing it has an effect on SL programs. | |
50 */ | |
51 @Override | |
52 public String toString() { | |
53 return "null"; | |
54 } | |
32 } | 55 } |