# HG changeset patch # User Thomas Wuerthinger # Date 1432666110 -7200 # Node ID ac86179c56ad7eae552fc6b771821cebe5449157 # Parent fac827422011f66231c05a56e42ac2306aa62a16# Parent f5b49d881909fbee15dc0618462bd79903e45580 Merge. diff -r fac827422011 -r ac86179c56ad graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ExpectError.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ExpectError.java Tue May 26 20:48:30 2015 +0200 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, 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.api.dsl.test; + +import java.lang.annotation.*; + +/** + * This annotation is internally known by the dsl processor and used to expect errors for testing + * purposes. This is not part of public API. + */ +@Retention(RetentionPolicy.RUNTIME) +public @interface ExpectError { + + String[] value(); + +} diff -r fac827422011 -r ac86179c56ad graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/examples/MathPow.java --- a/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/examples/MathPow.java Tue May 26 20:23:22 2015 +0200 +++ b/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/examples/MathPow.java Tue May 26 20:48:30 2015 +0200 @@ -105,7 +105,6 @@ } @Specialization(contains = "doPowCached", guards = {"exponent == cachedExponent", "cachedExponent <= 10"}) - @ExplodeLoop double doPowCachedExponent(double base, int exponent, @Cached("exponent") int cachedExponent) { doPowCachedExponent++; double result = 1.0; diff -r fac827422011 -r ac86179c56ad graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/processor/LanguageRegistrationTest.java --- a/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/processor/LanguageRegistrationTest.java Tue May 26 20:23:22 2015 +0200 +++ b/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/processor/LanguageRegistrationTest.java Tue May 26 20:48:30 2015 +0200 @@ -22,10 +22,11 @@ */ package com.oracle.truffle.api.dsl.test.processor; -import com.oracle.truffle.api.TruffleLanguage; -import com.oracle.truffle.api.dsl.ExpectError; -import com.oracle.truffle.api.source.Source; -import java.io.IOException; +import java.io.*; + +import com.oracle.truffle.api.*; +import com.oracle.truffle.api.dsl.test.*; +import com.oracle.truffle.api.source.*; public class LanguageRegistrationTest { diff -r fac827422011 -r ac86179c56ad graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/processor/TruffleProcessorTest.java --- a/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/processor/TruffleProcessorTest.java Tue May 26 20:23:22 2015 +0200 +++ b/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/processor/TruffleProcessorTest.java Tue May 26 20:48:30 2015 +0200 @@ -22,16 +22,18 @@ */ package com.oracle.truffle.api.dsl.test.processor; -import com.oracle.truffle.api.dsl.ExpectError; -import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.dsl.processor.verify.VerifyTruffleProcessor; -import java.util.Locale; -import java.util.ServiceLoader; -import javax.annotation.processing.Processor; -import javax.tools.Diagnostic; -import javax.tools.JavaFileObject; import static org.junit.Assert.*; -import org.junit.Test; + +import java.util.*; + +import javax.annotation.processing.*; +import javax.tools.*; + +import org.junit.*; + +import com.oracle.truffle.api.dsl.test.*; +import com.oracle.truffle.api.nodes.*; +import com.oracle.truffle.dsl.processor.verify.*; /** * Verify errors emitted by the processor. diff -r fac827422011 -r ac86179c56ad graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/ExpectError.java --- a/graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/ExpectError.java Tue May 26 20:23:22 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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.api.dsl; - -import java.lang.annotation.*; - -/** - * This annotation is internally known by the dsl processor and used to expect errors for testing - * purposes. This is not part of public API. - */ -@Retention(RetentionPolicy.RUNTIME) -public @interface ExpectError { - - String[] value(); - -} diff -r fac827422011 -r ac86179c56ad graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/ExpectError.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/ExpectError.java Tue May 26 20:48:30 2015 +0200 @@ -0,0 +1,70 @@ +/* + * 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.dsl.processor; + +import java.util.*; + +import javax.annotation.processing.*; +import javax.lang.model.element.*; +import javax.tools.Diagnostic.*; + +public class ExpectError { + + public static void assertNoErrorExpected(ProcessingEnvironment processingEnv, Element element) { + TypeElement eee = processingEnv.getElementUtils().getTypeElement(TruffleTypes.EXPECT_ERROR_CLASS_NAME); + if (eee != null) { + for (AnnotationMirror am : element.getAnnotationMirrors()) { + if (am.getAnnotationType().asElement().equals(eee)) { + processingEnv.getMessager().printMessage(Kind.ERROR, "Expected an error, but none found!", element); + } + } + } + } + + public static boolean isExpectedError(ProcessingEnvironment processingEnv, Element element, String message) { + TypeElement eee = processingEnv.getElementUtils().getTypeElement(TruffleTypes.EXPECT_ERROR_CLASS_NAME); + if (eee != null) { + for (AnnotationMirror am : element.getAnnotationMirrors()) { + if (am.getAnnotationType().asElement().equals(eee)) { + Map vals = am.getElementValues(); + if (vals.size() == 1) { + AnnotationValue av = vals.values().iterator().next(); + if (av.getValue() instanceof List) { + List arr = (List) av.getValue(); + for (Object o : arr) { + if (o instanceof AnnotationValue) { + AnnotationValue ov = (AnnotationValue) o; + if (message.equals(ov.getValue())) { + return true; + } + } + } + } + } + } + } + } + return false; + } + +} diff -r fac827422011 -r ac86179c56ad graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/LanguageRegistrationProcessor.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/LanguageRegistrationProcessor.java Tue May 26 20:23:22 2015 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/LanguageRegistrationProcessor.java Tue May 26 20:48:30 2015 +0200 @@ -22,30 +22,18 @@ */ package com.oracle.truffle.dsl.processor; -import com.oracle.truffle.api.TruffleLanguage; +import java.io.*; +import java.util.*; + +import javax.annotation.processing.*; +import javax.lang.model.*; +import javax.lang.model.element.*; +import javax.lang.model.type.*; +import javax.tools.Diagnostic.Kind; +import javax.tools.*; + +import com.oracle.truffle.api.*; import com.oracle.truffle.api.TruffleLanguage.Registration; -import com.oracle.truffle.api.dsl.ExpectError; -import java.io.IOException; -import java.io.OutputStream; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; -import javax.annotation.processing.AbstractProcessor; -import javax.annotation.processing.RoundEnvironment; -import javax.annotation.processing.SupportedAnnotationTypes; -import javax.lang.model.SourceVersion; -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.AnnotationValue; -import javax.lang.model.element.Element; -import javax.lang.model.element.ElementKind; -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.Modifier; -import javax.lang.model.element.TypeElement; -import javax.lang.model.type.TypeMirror; -import javax.tools.Diagnostic.Kind; -import javax.tools.FileObject; -import javax.tools.StandardLocation; @SupportedAnnotationTypes("com.oracle.truffle.api.*") public final class LanguageRegistrationProcessor extends AbstractProcessor { @@ -123,35 +111,14 @@ } void assertNoErrorExpected(Element e) { - TypeElement eee = processingEnv.getElementUtils().getTypeElement(ExpectError.class.getName()); - for (AnnotationMirror am : e.getAnnotationMirrors()) { - if (am.getAnnotationType().asElement().equals(eee)) { - processingEnv.getMessager().printMessage(Kind.ERROR, "Expected an error, but none found!", e); - } - } + ExpectError.assertNoErrorExpected(processingEnv, e); } void emitError(String msg, Element e) { - TypeElement eee = processingEnv.getElementUtils().getTypeElement(ExpectError.class.getName()); - for (AnnotationMirror am : e.getAnnotationMirrors()) { - if (am.getAnnotationType().asElement().equals(eee)) { - Map vals = am.getElementValues(); - if (vals.size() == 1) { - AnnotationValue av = vals.values().iterator().next(); - if (av.getValue() instanceof List) { - List arr = (List) av.getValue(); - for (Object o : arr) { - if (o instanceof AnnotationValue) { - AnnotationValue ov = (AnnotationValue) o; - if (msg.equals(ov.getValue())) { - return; - } - } - } - } - } - } + if (ExpectError.isExpectedError(processingEnv, e, msg)) { + return; } processingEnv.getMessager().printMessage(Kind.ERROR, msg, e); } + } diff -r fac827422011 -r ac86179c56ad graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/TruffleTypes.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/TruffleTypes.java Tue May 26 20:23:22 2015 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/TruffleTypes.java Tue May 26 20:48:30 2015 +0200 @@ -44,6 +44,8 @@ */ public final class TruffleTypes { + public static final String EXPECT_ERROR_CLASS_NAME = "com.oracle.truffle.api.dsl.test.ExpectError"; + private final DeclaredType node; private final ArrayType nodeArray; private final TypeMirror unexpectedValueException; @@ -94,7 +96,7 @@ nodeFactory = getRequired(context, NodeFactory.class); nodeFactoryBase = getRequired(context, NodeFactoryBase.class); dslMetadata = getRequired(context, DSLMetadata.class); - expectError = (TypeElement) getRequired(context, ExpectError.class).asElement(); + expectError = getOptional(context, EXPECT_ERROR_CLASS_NAME); generateNodeFactory = getRequired(context, GenerateNodeFactory.class); } @@ -158,6 +160,10 @@ return (DeclaredType) type; } + private static TypeElement getOptional(ProcessorContext context, String name) { + return context.getEnvironment().getElementUtils().getTypeElement(name); + } + public TypeMirror getInvalidAssumption() { return invalidAssumption; } diff -r fac827422011 -r ac86179c56ad graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/TypeSystemParser.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/TypeSystemParser.java Tue May 26 20:23:22 2015 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/TypeSystemParser.java Tue May 26 20:48:30 2015 +0200 @@ -37,7 +37,7 @@ @DSLOptions public class TypeSystemParser extends AbstractParser { - public static final List> ANNOTATIONS = Arrays.asList(TypeSystem.class, ExpectError.class); + public static final List> ANNOTATIONS = Arrays.asList(TypeSystem.class); @Override public Class getAnnotationType() { diff -r fac827422011 -r ac86179c56ad graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/verify/VerifyTruffleProcessor.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/verify/VerifyTruffleProcessor.java Tue May 26 20:23:22 2015 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/verify/VerifyTruffleProcessor.java Tue May 26 20:48:30 2015 +0200 @@ -34,8 +34,8 @@ import javax.tools.Diagnostic.Kind; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; -import com.oracle.truffle.api.dsl.ExpectError; import com.oracle.truffle.api.nodes.Node.Child; +import com.oracle.truffle.dsl.processor.*; @SupportedAnnotationTypes({"com.oracle.truffle.api.CompilerDirectives.TruffleBoundary", "com.oracle.truffle.api.nodes.Node.Child"}) public class VerifyTruffleProcessor extends AbstractProcessor { @@ -125,37 +125,15 @@ return false; } - void assertNoErrorExpected(Element e) { - TypeElement eee = processingEnv.getElementUtils().getTypeElement(ExpectError.class.getName()); - for (AnnotationMirror am : e.getAnnotationMirrors()) { - if (am.getAnnotationType().asElement().equals(eee)) { - processingEnv.getMessager().printMessage(Kind.ERROR, "Expected an error, but none found!", e); - } - } + void assertNoErrorExpected(Element element) { + ExpectError.assertNoErrorExpected(processingEnv, element); } - void emitError(String msg, Element e) { - TypeElement eee = processingEnv.getElementUtils().getTypeElement(ExpectError.class.getName()); - for (AnnotationMirror am : e.getAnnotationMirrors()) { - if (am.getAnnotationType().asElement().equals(eee)) { - Map vals = am.getElementValues(); - if (vals.size() == 1) { - AnnotationValue av = vals.values().iterator().next(); - if (av.getValue() instanceof List) { - List arr = (List) av.getValue(); - for (Object o : arr) { - if (o instanceof AnnotationValue) { - AnnotationValue ov = (AnnotationValue) o; - if (msg.equals(ov.getValue())) { - return; - } - } - } - } - } - } + void emitError(String message, Element element) { + if (ExpectError.isExpectedError(processingEnv, element, message)) { + return; } - processingEnv.getMessager().printMessage(Kind.ERROR, msg, e); + processingEnv.getMessager().printMessage(Kind.ERROR, message, element); } /** diff -r fac827422011 -r ac86179c56ad 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:48:30 2015 +0200 @@ -0,0 +1,1 @@ +Undefined function: foo diff -r fac827422011 -r ac86179c56ad 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:48:30 2015 +0200 @@ -0,0 +1,3 @@ +function main() { + foo(); +} diff -r fac827422011 -r ac86179c56ad 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:23:22 2015 +0200 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java Tue May 26 20:48:30 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 fac827422011 -r ac86179c56ad 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:23:22 2015 +0200 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLDispatchNode.java Tue May 26 20:48:30 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 fac827422011 -r ac86179c56ad 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:48:30 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; + } + +} diff -r fac827422011 -r ac86179c56ad graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLLogicalOrNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLLogicalOrNode.java Tue May 26 20:23:22 2015 +0200 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLLogicalOrNode.java Tue May 26 20:48:30 2015 +0200 @@ -52,7 +52,7 @@ return left instanceof Boolean && needsRightNode(((Boolean) left).booleanValue()); } - @Specialization(rewriteOn = RuntimeException.class) + @Specialization protected boolean doBoolean(boolean left, boolean hasRight, boolean right) { return left || right; }