Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/TypeSystem.java @ 10597:79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 01 Jul 2013 20:58:32 +0200 |
parents | |
children | 494b818b527c |
comparison
equal
deleted
inserted
replaced
10596:f43eb2f1bbbc | 10597:79041ab43660 |
---|---|
1 /* | |
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
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 | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.truffle.api.dsl; | |
24 | |
25 import java.lang.annotation.*; | |
26 | |
27 import com.oracle.truffle.api.nodes.*; | |
28 | |
29 /** | |
30 * <p> | |
31 * Each {@link Node} has one {@link TypeSystem} at its root to define the types that can be used | |
32 * throughout the system. Multiple {@link TypeSystem}s are allowed, but they cannot be mixed inside | |
33 * a single {@link Node} hierarchy. A {@link TypeSystem} defines a list of types as its child | |
34 * elements, in which every type precedes its super types.The latter condition ensures that the most | |
35 * concrete type is found first when searching the list sequentially for the type of a given generic | |
36 * value. | |
37 * </p> | |
38 * | |
39 * <p> | |
40 * Each {@link #value()} is represented as a java type. A type can specify two annotations: | |
41 * {@link TypeCheck} and {@link TypeCast}. The {@link TypeCheck} checks whether a given generic | |
42 * value matches to the current type. The {@link TypeCast} casts a generic type value to the current | |
43 * type. If the {@link TypeCheck} and {@link TypeCast} annotations are not declared in the | |
44 * {@link TypeSystem} the a default implementation is provided. The default implementation of | |
45 * {@link TypeCheck} returns <code>true</code> only on an exact type match and {@link TypeCast} is | |
46 * only a cast to this type. Specified methods with {@link TypeCheck} and {@link TypeCast} may be | |
47 * used to extend the definition of a type in the language. In our example, the | |
48 * <code>isInteger</code> and <code>asInteger</code> methods are defined in a way so that they | |
49 * accept also {@link Integer} values, implicitly converting them to {@link Double} . This example | |
50 * points out how we express implicit type conversions. | |
51 * </p> | |
52 * | |
53 * <p> | |
54 * <b>Example:</b> The {@link TypeSystem} contains the types {@link Boolean}, {@link Integer}, and | |
55 * {@link Double}. The type {@link Object} is always used implicitly as the generic type represent | |
56 * all values. | |
57 * | |
58 * <pre> | |
59 * | |
60 * {@literal @}TypeSystem(types = {boolean.class, int.class, double.class}) | |
61 * public abstract class ExampleTypeSystem { | |
62 * | |
63 * {@literal @}TypeCheck | |
64 * public boolean isInteger(Object value) { | |
65 * return value instanceof Integer || value instanceof Double; | |
66 * } | |
67 * | |
68 * {@literal @}TypeCast | |
69 * public double asInteger(Object value) { | |
70 * return ((Number)value).doubleValue(); | |
71 * } | |
72 * } | |
73 * </pre> | |
74 * | |
75 * </p> | |
76 * | |
77 * @see TypeCast | |
78 * @see TypeCheck | |
79 */ | |
80 @Retention(RetentionPolicy.CLASS) | |
81 @Target({ElementType.TYPE}) | |
82 public @interface TypeSystem { | |
83 | |
84 /** | |
85 * The list of types as child elements of the {@link TypeSystem}. Each precedes its super type. | |
86 */ | |
87 Class[] value(); | |
88 | |
89 } |