comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java @ 15891:09ac9ac9c4fc

Truffle: SourceManager renamed to SourceFactory - All methods are static, no longer accessed via ExecutionContext - Sources are indexed with weak references - File content caching is now optional; off by default
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Sat, 24 May 2014 10:34:43 -0700
parents 64dcb92ee75a
children 915ebb306fcc
comparison
equal deleted inserted replaced
15842:eb947cc7bff9 15891:09ac9ac9c4fc
25 import java.io.*; 25 import java.io.*;
26 import java.math.*; 26 import java.math.*;
27 27
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.instrument.*;
30 import com.oracle.truffle.api.nodes.*; 31 import com.oracle.truffle.api.nodes.*;
31 import com.oracle.truffle.api.source.*; 32 import com.oracle.truffle.api.source.*;
32 import com.oracle.truffle.sl.builtins.*; 33 import com.oracle.truffle.sl.builtins.*;
33 import com.oracle.truffle.sl.nodes.*; 34 import com.oracle.truffle.sl.nodes.*;
34 import com.oracle.truffle.sl.nodes.call.*; 35 import com.oracle.truffle.sl.nodes.call.*;
115 116
116 /** 117 /**
117 * The main entry point. Use the mx command "mx sl" to run it with the correct class path setup. 118 * The main entry point. Use the mx command "mx sl" to run it with the correct class path setup.
118 */ 119 */
119 public static void main(String[] args) throws IOException { 120 public static void main(String[] args) throws IOException {
120 SourceManager sourceManager = new SourceManager(); 121
122 SLContext context = new SLContext(new BufferedReader(new InputStreamReader(System.in)), System.out);
121 123
122 Source source; 124 Source source;
123 if (args.length == 0) { 125 if (args.length == 0) {
124 source = sourceManager.get("stdin", System.in); 126 source = SourceFactory.fromReader(new InputStreamReader(System.in), "stdin");
125 } else { 127 } else {
126 source = sourceManager.get(args[0]); 128 source = SourceFactory.fromFile(args[0]);
127 } 129 }
128 130
129 int repeats = 1; 131 int repeats = 1;
130 if (args.length >= 2) { 132 if (args.length >= 2) {
131 repeats = Integer.parseInt(args[1]); 133 repeats = Integer.parseInt(args[1]);
132 } 134 }
133 135
134 SLContext context = new SLContext(sourceManager, new BufferedReader(new InputStreamReader(System.in)), System.out);
135 run(context, source, System.out, repeats); 136 run(context, source, System.out, repeats);
136 } 137 }
137 138
138 /** 139 /**
139 * Parse and run the specified SL source. Factored out in a separate method so that it can also 140 * Parse and run the specified SL source. Factored out in a separate method so that it can also
142 public static void run(SLContext context, Source source, PrintStream logOutput, int repeats) { 143 public static void run(SLContext context, Source source, PrintStream logOutput, int repeats) {
143 if (logOutput != null) { 144 if (logOutput != null) {
144 logOutput.println("== running on " + Truffle.getRuntime().getName()); 145 logOutput.println("== running on " + Truffle.getRuntime().getName());
145 } 146 }
146 147
148 final SourceCallback sourceCallback = context.getSourceCallback();
149
147 /* Parse the SL source file. */ 150 /* Parse the SL source file. */
151 if (sourceCallback != null) {
152 sourceCallback.startLoading(source);
153 }
148 Parser.parseSL(context, source); 154 Parser.parseSL(context, source);
155 if (sourceCallback != null) {
156 sourceCallback.endLoading(source);
157 }
149 /* Lookup our main entry point, which is per definition always named "main". */ 158 /* Lookup our main entry point, which is per definition always named "main". */
150 SLFunction main = context.getFunctionRegistry().lookup("main"); 159 SLFunction main = context.getFunctionRegistry().lookup("main");
151 if (main.getCallTarget() == null) { 160 if (main.getCallTarget() == null) {
152 throw new SLException("No function main() defined in SL source file."); 161 throw new SLException("No function main() defined in SL source file.");
153 } 162 }