comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLContext.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 f675818d9ad0
children abe7128ca473
comparison
equal deleted inserted replaced
15842:eb947cc7bff9 15891:09ac9ac9c4fc
22 */ 22 */
23 package com.oracle.truffle.sl.runtime; 23 package com.oracle.truffle.sl.runtime;
24 24
25 import java.io.*; 25 import java.io.*;
26 26
27 import com.oracle.truffle.api.*;
27 import com.oracle.truffle.api.dsl.*; 28 import com.oracle.truffle.api.dsl.*;
28 import com.oracle.truffle.api.frame.*; 29 import com.oracle.truffle.api.frame.*;
30 import com.oracle.truffle.api.instrument.*;
29 import com.oracle.truffle.api.nodes.*; 31 import com.oracle.truffle.api.nodes.*;
30 import com.oracle.truffle.api.source.*;
31 import com.oracle.truffle.sl.builtins.*; 32 import com.oracle.truffle.sl.builtins.*;
32 import com.oracle.truffle.sl.nodes.*; 33 import com.oracle.truffle.sl.nodes.*;
33 import com.oracle.truffle.sl.nodes.local.*; 34 import com.oracle.truffle.sl.nodes.local.*;
34 import com.oracle.truffle.sl.parser.*; 35 import com.oracle.truffle.sl.parser.*;
35 36
41 * <p> 42 * <p>
42 * It would be an error to have two different context instances during the execution of one script. 43 * It would be an error to have two different context instances during the execution of one script.
43 * However, if two separate scripts run in one Java VM at the same time, they have a different 44 * However, if two separate scripts run in one Java VM at the same time, they have a different
44 * context. Therefore, the context is not a singleton. 45 * context. Therefore, the context is not a singleton.
45 */ 46 */
46 public final class SLContext { 47 public final class SLContext extends ExecutionContext {
47 private final SourceManager sourceManager;
48 private final BufferedReader input; 48 private final BufferedReader input;
49 private final PrintStream output; 49 private final PrintStream output;
50 private final SLFunctionRegistry functionRegistry; 50 private final SLFunctionRegistry functionRegistry;
51 private SourceCallback sourceCallback = null;
51 52
52 public SLContext(SourceManager sourceManager, BufferedReader input, PrintStream output) { 53 public SLContext(BufferedReader input, PrintStream output) {
53 this.sourceManager = sourceManager;
54 this.input = input; 54 this.input = input;
55 this.output = output; 55 this.output = output;
56 this.functionRegistry = new SLFunctionRegistry(); 56 this.functionRegistry = new SLFunctionRegistry();
57
58 installBuiltins(); 57 installBuiltins();
59 } 58 }
60 59
61 /** 60 @Override
62 * Returns the source manger that controls all SL source code that is executed. 61 public String getLanguageShortName() {
63 */ 62 return "Simple";
64 public SourceManager getSourceManager() { 63 }
65 return sourceManager; 64
65 @Override
66 public void setSourceCallback(SourceCallback sourceCallback) {
67 this.sourceCallback = sourceCallback;
66 } 68 }
67 69
68 /** 70 /**
69 * Returns the default input, i.e., the source for the {@link SLReadlnBuiltin}. To allow unit 71 * Returns the default input, i.e., the source for the {@link SLReadlnBuiltin}. To allow unit
70 * testing, we do not use {@link System#in} directly. 72 * testing, we do not use {@link System#in} directly.
84 /** 86 /**
85 * Returns the registry of all functions that are currently defined. 87 * Returns the registry of all functions that are currently defined.
86 */ 88 */
87 public SLFunctionRegistry getFunctionRegistry() { 89 public SLFunctionRegistry getFunctionRegistry() {
88 return functionRegistry; 90 return functionRegistry;
91 }
92
93 public SourceCallback getSourceCallback() {
94 return sourceCallback;
89 } 95 }
90 96
91 /** 97 /**
92 * Adds all builtin functions to the {@link SLFunctionRegistry}. This method lists all 98 * Adds all builtin functions to the {@link SLFunctionRegistry}. This method lists all
93 * {@link SLBuiltinNode builtin implementation classes}. 99 * {@link SLBuiltinNode builtin implementation classes}.