Mercurial > hg > truffle
diff 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 |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLContext.java Tue Nov 18 23:02:58 2014 +0100 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLContext.java Tue Nov 18 12:08:51 2014 +0100 @@ -30,6 +30,7 @@ import com.oracle.truffle.api.frame.*; import com.oracle.truffle.api.instrument.*; import com.oracle.truffle.api.nodes.*; +import com.oracle.truffle.api.object.*; import com.oracle.truffle.api.source.*; import com.oracle.truffle.sl.*; import com.oracle.truffle.sl.builtins.*; @@ -49,9 +50,12 @@ * context. Therefore, the context is not a singleton. */ public final class SLContext extends ExecutionContext { + private static final Layout LAYOUT = Layout.createLayout(); + private final BufferedReader input; private final PrintStream output; private final SLFunctionRegistry functionRegistry; + private final Shape emptyShape; private SourceCallback sourceCallback = null; public SLContext(BufferedReader input, PrintStream output) { @@ -59,6 +63,8 @@ this.output = output; this.functionRegistry = new SLFunctionRegistry(); installBuiltins(); + + this.emptyShape = LAYOUT.createShape(new ObjectType()); } @Override @@ -180,4 +186,16 @@ } main.getCallTarget().call(); } + + public DynamicObject createObject() { + return LAYOUT.newInstance(emptyShape); + } + + public static boolean isSLObject(Object value) { + return LAYOUT.getType().isInstance(value); + } + + public static DynamicObject castSLObject(Object value) { + return LAYOUT.getType().cast(value); + } }