Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLContext.java @ 13761:7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
author | Christian Wimmer <christian.wimmer@oracle.com> |
---|---|
date | Fri, 24 Jan 2014 18:16:24 -0800 |
parents | 69d2e4baa215 |
children | b16ec83edc73 |
comparison
equal
deleted
inserted
replaced
13760:a12017c18d5d | 13761:7c418666c6c9 |
---|---|
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.dsl.*; | |
27 import com.oracle.truffle.api.source.*; | 28 import com.oracle.truffle.api.source.*; |
28 import com.oracle.truffle.sl.builtins.*; | 29 import com.oracle.truffle.sl.builtins.*; |
30 import com.oracle.truffle.sl.nodes.*; | |
29 | 31 |
30 public final class SLContext { | 32 public final class SLContext { |
33 private final SourceManager sourceManager; | |
34 private final PrintStream output; | |
35 private final SLFunctionRegistry functionRegistry; | |
31 | 36 |
32 private final PrintStream printOutput; | 37 public SLContext(SourceManager sourceManager, PrintStream output) { |
33 private final SLFunctionRegistry functionRegistry; | 38 this.sourceManager = sourceManager; |
34 private final SourceManager sourceManager; | 39 this.output = output; |
40 this.functionRegistry = new SLFunctionRegistry(); | |
35 | 41 |
36 public SLContext(PrintStream print) { | 42 installBuiltins(); |
37 this.printOutput = print; | 43 } |
38 this.functionRegistry = new SLFunctionRegistry(); | 44 |
39 DefaultBuiltins.install(this); | 45 public SourceManager getSourceManager() { |
40 this.sourceManager = new SourceManager(); | 46 return sourceManager; |
41 } | 47 } |
42 | 48 |
43 public PrintStream getPrintOutput() { | 49 public PrintStream getPrintOutput() { |
44 return printOutput; | 50 return output; |
45 } | 51 } |
46 | 52 |
47 public SLFunctionRegistry getFunctionRegistry() { | 53 public SLFunctionRegistry getFunctionRegistry() { |
48 return functionRegistry; | 54 return functionRegistry; |
49 } | 55 } |
50 | 56 |
51 public SourceManager getSourceManager() { | 57 private void installBuiltins() { |
52 return sourceManager; | 58 installBuiltin(SLPrintBuiltinFactory.getInstance(), "print"); |
59 installBuiltin(SLTimeBuiltinFactory.getInstance(), "time"); | |
60 installBuiltin(SLDefineFunctionBuiltinFactory.getInstance(), "defineFunction"); | |
53 } | 61 } |
54 | 62 |
63 private void installBuiltin(NodeFactory<? extends SLBuiltinNode> factory, String name) { | |
64 getFunctionRegistry().register(name, SLRootNode.createBuiltin(this, factory, name)); | |
65 } | |
55 } | 66 } |