Mercurial > hg > truffle
diff truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLLanguage.java @ 22066:78c3d3d8d86e
Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Thu, 06 Aug 2015 08:31:49 +0200 |
parents | 503529c65456 |
children | e206ebd965f2 |
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLLanguage.java Wed Aug 05 10:19:41 2015 -0700 +++ b/truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLLanguage.java Thu Aug 06 08:31:49 2015 +0200 @@ -153,19 +153,24 @@ * */ @TruffleLanguage.Registration(name = "SL", version = "0.5", mimeType = "application/x-sl") -public class SLLanguage extends TruffleLanguage { +public class SLLanguage extends TruffleLanguage<SLContext> { private static List<NodeFactory<? extends SLBuiltinNode>> builtins = Collections.emptyList(); private static Visualizer visualizer = new SLDefaultVisualizer(); private static ASTProber registeredASTProber; // non-null if prober already registered - private final SLContext context; private DebugSupportProvider debugSupport; - public SLLanguage(Env env) { - super(env); - context = new SLContext(this, new BufferedReader(env().stdIn()), new PrintWriter(env().stdOut(), true)); + private SLLanguage() { + } + + public static final SLLanguage INSTANCE = new SLLanguage(); + + @Override + protected SLContext createContext(Env env) { + SLContext context = new SLContext(this, new BufferedReader(env.stdIn()), new PrintWriter(env.stdOut(), true)); for (NodeFactory<? extends SLBuiltinNode> builtin : builtins) { context.installBuiltin(builtin, true); } + return context; } // TODO (mlvdv) command line options @@ -378,10 +383,6 @@ return result.toString(); } - public static SLLanguage find() { - return SLLanguage.findContext(SLLanguage.class); - } - @Override protected CallTarget parse(Source code, Node node, String... argumentNames) throws IOException { final SLContext c = new SLContext(this); @@ -401,8 +402,7 @@ if (failed[0] != null) { throw new IllegalStateException(failed[0]); } - SLLanguage current = SLLanguage.find(); - SLContext fillIn = current.context; + SLContext fillIn = getContext(); final SLFunctionRegistry functionRegistry = fillIn.getFunctionRegistry(); for (SLFunction f : c.getFunctionRegistry().getFunctions()) { RootCallTarget callTarget = f.getCallTarget(); @@ -418,7 +418,7 @@ } @Override - protected Object findExportedSymbol(String globalName, boolean onlyExplicit) { + protected Object findExportedSymbol(SLContext context, String globalName, boolean onlyExplicit) { for (SLFunction f : context.getFunctionRegistry().getFunctions()) { if (globalName.equals(f.getName())) { return f; @@ -428,7 +428,7 @@ } @Override - protected Object getLanguageGlobal() { + protected Object getLanguageGlobal(SLContext context) { return context; } @@ -492,7 +492,7 @@ } public SLContext getContext() { - return context; + return findContext(); } private final class SLDebugProvider implements DebugSupportProvider {