changeset 21493:99e3f4c5c853

SL: handle undefined functions gracefully.
author Christian Humer <christian.humer@gmail.com>
date Tue, 26 May 2015 20:04:07 +0200
parents 9e5947d24e63
children f5b49d881909
files graal/com.oracle.truffle.sl.test/tests/error/UndefinedFunction01.output graal/com.oracle.truffle.sl.test/tests/error/UndefinedFunction01.sl graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLDispatchNode.java graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLUndefinedFunctionException.java
diffstat 5 files changed, 50 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/tests/error/UndefinedFunction01.output	Tue May 26 20:04:07 2015 +0200
@@ -0,0 +1,1 @@
+Undefined function: foo
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/tests/error/UndefinedFunction01.sl	Tue May 26 20:04:07 2015 +0200
@@ -0,0 +1,3 @@
+function main() {  
+  foo();
+}  
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java	Tue May 26 20:02:07 2015 +0200
+++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java	Tue May 26 20:04:07 2015 +0200
@@ -248,6 +248,8 @@
                     }
                 } catch (UnsupportedSpecializationException ex) {
                     out.println(formatTypeError(ex));
+                } catch (SLUndefinedFunctionException ex) {
+                    out.println(String.format("Undefined function: %s", ex.getFunctionName()));
                 }
                 long end = System.nanoTime();
                 totalRuntime += end - start;
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLDispatchNode.java	Tue May 26 20:02:07 2015 +0200
+++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLDispatchNode.java	Tue May 26 20:04:07 2015 +0200
@@ -34,6 +34,11 @@
 
     public abstract Object executeDispatch(VirtualFrame frame, SLFunction function, Object[] arguments);
 
+    @Specialization(guards = "function.getCallTarget() == null")
+    protected Object doUndefinedFunction(SLFunction function, @SuppressWarnings("unused") Object[] arguments) {
+        throw new SLUndefinedFunctionException(function.getName());
+    }
+
     /**
      * Inline cached specialization of the dispatch.
      *
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLUndefinedFunctionException.java	Tue May 26 20:04:07 2015 +0200
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.truffle.sl.nodes.call;
+
+public class SLUndefinedFunctionException extends RuntimeException {
+
+    private static final long serialVersionUID = 1L;
+
+    private final String functionName;
+
+    public SLUndefinedFunctionException(String functionName) {
+        this.functionName = functionName;
+    }
+
+    public String getFunctionName() {
+        return functionName;
+    }
+
+}