comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLContext.java @ 18412:997bc9764a9a

SL: use the truffle object storage model to represent SL objects
author Andreas Woess <andreas.woess@jku.at>
date Tue, 18 Nov 2014 12:08:51 +0100
parents dc2e000bed40
children e3c95cbbb50c
comparison
equal deleted inserted replaced
18411:dc2e000bed40 18412:997bc9764a9a
28 import com.oracle.truffle.api.*; 28 import com.oracle.truffle.api.*;
29 import com.oracle.truffle.api.dsl.*; 29 import com.oracle.truffle.api.dsl.*;
30 import com.oracle.truffle.api.frame.*; 30 import com.oracle.truffle.api.frame.*;
31 import com.oracle.truffle.api.instrument.*; 31 import com.oracle.truffle.api.instrument.*;
32 import com.oracle.truffle.api.nodes.*; 32 import com.oracle.truffle.api.nodes.*;
33 import com.oracle.truffle.api.object.*;
33 import com.oracle.truffle.api.source.*; 34 import com.oracle.truffle.api.source.*;
34 import com.oracle.truffle.sl.*; 35 import com.oracle.truffle.sl.*;
35 import com.oracle.truffle.sl.builtins.*; 36 import com.oracle.truffle.sl.builtins.*;
36 import com.oracle.truffle.sl.nodes.*; 37 import com.oracle.truffle.sl.nodes.*;
37 import com.oracle.truffle.sl.nodes.instrument.*; 38 import com.oracle.truffle.sl.nodes.instrument.*;
47 * It would be an error to have two different context instances during the execution of one script. 48 * It would be an error to have two different context instances during the execution of one script.
48 * However, if two separate scripts run in one Java VM at the same time, they have a different 49 * However, if two separate scripts run in one Java VM at the same time, they have a different
49 * context. Therefore, the context is not a singleton. 50 * context. Therefore, the context is not a singleton.
50 */ 51 */
51 public final class SLContext extends ExecutionContext { 52 public final class SLContext extends ExecutionContext {
53 private static final Layout LAYOUT = Layout.createLayout();
54
52 private final BufferedReader input; 55 private final BufferedReader input;
53 private final PrintStream output; 56 private final PrintStream output;
54 private final SLFunctionRegistry functionRegistry; 57 private final SLFunctionRegistry functionRegistry;
58 private final Shape emptyShape;
55 private SourceCallback sourceCallback = null; 59 private SourceCallback sourceCallback = null;
56 60
57 public SLContext(BufferedReader input, PrintStream output) { 61 public SLContext(BufferedReader input, PrintStream output) {
58 this.input = input; 62 this.input = input;
59 this.output = output; 63 this.output = output;
60 this.functionRegistry = new SLFunctionRegistry(); 64 this.functionRegistry = new SLFunctionRegistry();
61 installBuiltins(); 65 installBuiltins();
66
67 this.emptyShape = LAYOUT.createShape(new ObjectType());
62 } 68 }
63 69
64 @Override 70 @Override
65 public String getLanguageShortName() { 71 public String getLanguageShortName() {
66 return "Simple"; 72 return "Simple";
178 if (main.getCallTarget() == null) { 184 if (main.getCallTarget() == null) {
179 throw new SLException("No function main() defined in SL source file."); 185 throw new SLException("No function main() defined in SL source file.");
180 } 186 }
181 main.getCallTarget().call(); 187 main.getCallTarget().call();
182 } 188 }
189
190 public DynamicObject createObject() {
191 return LAYOUT.newInstance(emptyShape);
192 }
193
194 public static boolean isSLObject(Object value) {
195 return LAYOUT.getType().isInstance(value);
196 }
197
198 public static DynamicObject castSLObject(Object value) {
199 return LAYOUT.getType().cast(value);
200 }
183 } 201 }