annotate graal/com.oracle.truffle.api.codegen/src/com/oracle/truffle/api/codegen/TypeSystem.java @ 10490:dcbdf71c4507

remove scheduledNext from ScheduledNode
author Lukas Stadler <lukas.stadler@jku.at>
date Mon, 24 Jun 2013 08:01:33 +0200
parents 8b2573c8d47f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7291
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1 /*
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved.
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
4 *
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
8 *
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
13 * accompanied this code).
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
14 *
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
18 *
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
21 * questions.
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
22 */
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
23 package com.oracle.truffle.api.codegen;
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
24
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
25 import java.lang.annotation.*;
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
26
10443
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
27 import com.oracle.truffle.api.nodes.*;
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
28
7291
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
29 /**
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
30 * <p>
10443
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
31 * Each {@link Node} has one {@link TypeSystem} at its root to define the types that can be used
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
32 * throughout the system. Multiple {@link TypeSystem}s are allowed, but they cannot be mixed inside
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
33 * a single {@link Node} hierarchy. A {@link TypeSystem} defines a list of types as its child
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
34 * elements, in which every type precedes its super types.The latter condition ensures that the most
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
35 * concrete type is found first when searching the list sequentially for the type of a given generic
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
36 * value.
7291
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
37 * </p>
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7527
diff changeset
38 *
7291
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
39 * <p>
10443
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
40 * Each {@link #value()} is represented as a java type. A type can specify two annotations:
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
41 * {@link TypeCheck} and {@link TypeCast}. The {@link TypeCheck} checks whether a given generic
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
42 * value matches to the current type. The {@link TypeCast} casts a generic type value to the current
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
43 * type. If the {@link TypeCheck} and {@link TypeCast} annotations are not declared in the
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
44 * {@link TypeSystem} the a default implementation is provided. The default implementation of
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
45 * {@link TypeCheck} returns <code>true</code> only on an exact type match and {@link TypeCast} is
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
46 * only a cast to this type. Specified methods with {@link TypeCheck} and {@link TypeCast} may be
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
47 * used to extend the definition of a type in the language. In our example, the
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
48 * <code>isInteger</code> and <code>asInteger</code> methods are defined in a way so that they
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
49 * accept also {@link Integer} values, implicitly converting them to {@link Double} . This example
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
50 * points out how we express implicit type conversions.
7291
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
51 * </p>
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7527
diff changeset
52 *
10443
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
53 * <p>
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
54 * <b>Example:</b> The {@link TypeSystem} contains the types {@link Boolean}, {@link Integer}, and
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
55 * {@link Double}. The type {@link Object} is always used implicitly as the generic type represent
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
56 * all values.
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
57 *
7291
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
58 * <pre>
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7527
diff changeset
59 *
10443
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
60 * {@literal @}TypeSystem(types = {boolean.class, int.class, double.class})
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
61 * public abstract class ExampleTypeSystem {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7527
diff changeset
62 *
7527
2232848be438 replace HTML escape sequence for '@' symbol with {@literal @}
Doug Simon <doug.simon@oracle.com>
parents: 7502
diff changeset
63 * {@literal @}TypeCheck
7291
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
64 * public boolean isInteger(Object value) {
10443
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
65 * return value instanceof Integer || value instanceof Double;
7291
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
66 * }
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7527
diff changeset
67 *
7527
2232848be438 replace HTML escape sequence for '@' symbol with {@literal @}
Doug Simon <doug.simon@oracle.com>
parents: 7502
diff changeset
68 * {@literal @}TypeCast
10443
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
69 * public double asInteger(Object value) {
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
70 * return ((Number)value).doubleValue();
7291
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
71 * }
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
72 * }
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
73 * </pre>
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7527
diff changeset
74 *
10443
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
75 * </p>
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
76 *
7291
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
77 * @see TypeCast
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
78 * @see TypeCheck
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
79 */
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
80 @Retention(RetentionPolicy.CLASS)
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
81 @Target({ElementType.TYPE})
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
82 public @interface TypeSystem {
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
83
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
84 /**
10443
8b2573c8d47f dsl cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
85 * The list of types as child elements of the {@link TypeSystem}. Each precedes its super type.
7291
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
86 */
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
87 Class[] value();
7291
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
88
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
89 }