comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLScript.java @ 13455:69d2e4baa215

Truffle: new infrastructure related to instrumentation, and in particular debugging: support for managing Source objects; framework for generalized "instrumentation proxy nodes" (to be inserted into ASTs with no runtime cost when inactive), and "probes" (which can be attached to proxy nodes to receive event notification); a rudimentary interface and abstract implementation for a "debug manager" (mostly a placeholder at this point); and the beginning of a language-agnostic ExecutionContext interface.
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Tue, 17 Dec 2013 20:22:45 -0800
parents 71991b7a0f14
children 3f27e57439ed
comparison
equal deleted inserted replaced
13306:dfb780080923 13455:69d2e4baa215
1 /* 1 /*
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any 20 * or visit www.oracle.com if you need additional information or have any
21 * questions. 21 * questions.
22 */ 22 */
23 package com.oracle.truffle.sl; 23 package com.oracle.truffle.sl;
24
25 import java.io.*;
26 24
27 import javax.script.*; 25 import javax.script.*;
28 26
29 import com.oracle.truffle.api.*; 27 import com.oracle.truffle.api.*;
30 import com.oracle.truffle.sl.parser.*; 28 import com.oracle.truffle.sl.parser.*;
55 @Override 53 @Override
56 public String toString() { 54 public String toString() {
57 return main.toString(); 55 return main.toString();
58 } 56 }
59 57
60 public static SLScript create(SLContext context, String input) throws ScriptException { 58 public static SLScript create(SLContext context, Source source) throws ScriptException {
61 return create(context, new ByteArrayInputStream(input.getBytes()));
62
63 }
64
65 public static SLScript create(SLContext context, InputStream input) throws ScriptException {
66 SLNodeFactory factory = new SLNodeFactory(context); 59 SLNodeFactory factory = new SLNodeFactory(context);
67 Parser parser = new Parser(new Scanner(input), factory); 60 Parser parser = new Parser(new Scanner(source.getInputStream()), factory);
68 factory.setParser(parser); 61 factory.setParser(parser);
69 factory.setSource(new Source() { 62 factory.setSource(source);
70 public String getName() {
71 return "Unknown";
72 }
73
74 public String getCode() {
75 return null;
76 }
77 });
78 String error = parser.ParseErrors(); 63 String error = parser.ParseErrors();
79 if (!error.isEmpty()) { 64 if (!error.isEmpty()) {
80 throw new ScriptException(String.format("Error(s) parsing script: %s", error)); 65 throw new ScriptException(String.format("Error(s) parsing script: %s", error));
81 } 66 }
82 67