Mercurial > hg > truffle
annotate graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/SLNewObjectBuiltin.java @ 18411:dc2e000bed40
SL: add basic support for creating objects and accessing properties
author | Andreas Woess <andreas.woess@jku.at> |
---|---|
date | Tue, 18 Nov 2014 23:02:58 +0100 |
parents | |
children | 997bc9764a9a |
rev | line source |
---|---|
18411
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1 /* |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
2 * Copyright (c) 2014, 2014, Oracle and/or its affiliates. All rights reserved. |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
4 * |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
8 * |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
13 * accompanied this code). |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
14 * |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
18 * |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
21 * questions. |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
22 */ |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
23 package com.oracle.truffle.sl.builtins; |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
24 |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
25 import java.util.*; |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
26 |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
27 import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
28 import com.oracle.truffle.api.dsl.*; |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
29 import com.oracle.truffle.api.nodes.*; |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
30 import com.oracle.truffle.api.source.*; |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
31 import com.oracle.truffle.sl.runtime.*; |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
32 |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
33 /** |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
34 * Builtin function to write a value to the {@link SLContext#getOutput() standard output}. The |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
35 * different specialization leverage the typed {@code println} methods available in Java, i.e., |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
36 * primitive values are printed without converting them to a {@link String} first. |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
37 * <p> |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
38 * Printing involves a lot of Java code, so we need to tell the optimizing system that it should not |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
39 * unconditionally inline everything reachable from the println() method. This is done via the |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
40 * {@link TruffleBoundary} annotations. |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
41 */ |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
42 @NodeInfo(shortName = "new") |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
43 public abstract class SLNewObjectBuiltin extends SLBuiltinNode { |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
44 |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
45 public SLNewObjectBuiltin() { |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
46 super(new NullSourceSection("SL builtin", "new")); |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
47 } |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
48 |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
49 @Specialization |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
50 public Object newObject() { |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
51 return new HashMap<>(); |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
52 } |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
53 } |