Mercurial > hg > graal-jvmci-8
diff graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java @ 21468:99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Fri, 22 May 2015 13:41:10 +0200 |
parents | 2170de9acab0 |
children | 286aef83a9a7 |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java Fri May 22 10:50:43 2015 +0200 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java Fri May 22 13:41:10 2015 +0200 @@ -32,6 +32,7 @@ import com.oracle.truffle.api.nodes.*; import com.oracle.truffle.api.source.*; import com.oracle.truffle.api.tools.*; +import com.oracle.truffle.api.vm.TruffleVM; import com.oracle.truffle.sl.builtins.*; import com.oracle.truffle.sl.factory.*; import com.oracle.truffle.sl.nodes.*; @@ -129,7 +130,13 @@ * <em>default printer</em>. * */ -public class SLMain { +@TruffleLanguage.Registration(name = "sl", mimeType = "application/x-sl") +public class SLMain extends TruffleLanguage { + private final SLContext context; + + public SLMain() { + this.context = SLContextFactory.create(new BufferedReader(new InputStreamReader(System.in)), System.out); + } /* Demonstrate per-type tabulation of node execution counts */ private static boolean nodeExecCounts = false; @@ -142,22 +149,21 @@ * The main entry point. Use the mx command "mx sl" to run it with the correct class path setup. */ public static void main(String[] args) throws IOException { - - SLContext context = SLContextFactory.create(new BufferedReader(new InputStreamReader(System.in)), System.out); - - Source source; - if (args.length == 0) { - source = Source.fromReader(new InputStreamReader(System.in), "stdin"); - } else { - source = Source.fromFileName(args[0]); - } + TruffleVM vm = TruffleVM.create(); + assert vm.getLanguages().containsKey("application/x-sl"); int repeats = 1; if (args.length >= 2) { repeats = Integer.parseInt(args[1]); } - run(context, source, System.out, repeats); + while (repeats-- > 0) { + if (args.length == 0) { + vm.eval("application/x-sl", new InputStreamReader(System.in)); + } else { + vm.eval(new File(args[0]).toURI()); + } + } } /** @@ -341,4 +347,25 @@ return result.toString(); } + @Override + protected Object eval(Source code) throws IOException { + context.executeMain(code); + return null; + } + + @Override + protected Object findExportedSymbol(String globalName) { + return null; + } + + @Override + protected Object getLanguageGlobal() { + return null; + } + + @Override + protected boolean isObjectOfLanguage(Object object) { + return false; + } + }