# HG changeset patch # User Christian Humer # Date 1432663447 -7200 # Node ID 99e3f4c5c853c21c74ccdd2462be88af3be2661b # Parent 9e5947d24e63ec7c5110ec119bf4a8fa75ac44a2 SL: handle undefined functions gracefully. diff -r 9e5947d24e63 -r 99e3f4c5c853 graal/com.oracle.truffle.sl.test/tests/error/UndefinedFunction01.output --- /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 diff -r 9e5947d24e63 -r 99e3f4c5c853 graal/com.oracle.truffle.sl.test/tests/error/UndefinedFunction01.sl --- /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(); +} diff -r 9e5947d24e63 -r 99e3f4c5c853 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java --- 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; diff -r 9e5947d24e63 -r 99e3f4c5c853 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLDispatchNode.java --- 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. * diff -r 9e5947d24e63 -r 99e3f4c5c853 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLUndefinedFunctionException.java --- /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; + } + +}