# HG changeset patch # User Christian Humer # Date 1362591185 -3600 # Node ID 3862508afe2f941ac75fa610246824eafdc2f9be # Parent 703c09f8640c9f96ae690ee55a9ac6931835f2d7 Updated @NodeClass tests. diff -r 703c09f8640c -r 3862508afe2f graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/BinaryOperationTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/BinaryOperationTest.java Wed Mar 06 18:33:05 2013 +0100 @@ -0,0 +1,75 @@ +/* + * 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. + * + * 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.codegen.test; + +import com.oracle.truffle.api.codegen.*; + +public class BinaryOperationTest { + + static int convertInt(Object value) { + if (value instanceof Number) { + return ((Number) value).intValue(); + } else if (value instanceof String) { + return Integer.parseInt((String) value); + } + throw new RuntimeException("Invalid datatype"); + } + + @NodeClass(BinaryNode.class) + abstract static class BinaryNode extends ValueNode { + + @Child protected ValueNode leftNode; + @Child protected ValueNode rightNode; + + public BinaryNode(ValueNode left, ValueNode right) { + this.leftNode = left; + this.rightNode = right; + } + + public BinaryNode(BinaryNode prev) { + this(prev.leftNode, prev.rightNode); + } + + @Specialization + int add(int left, int right) { + return left + right; + } + + @Generic + int add(Object left, Object right) { + return convertInt(left) + convertInt(right); + } + + @Specialization + int sub(int left, int right) { + return left + right; + } + + @Generic + int sub(Object left, Object right) { + return convertInt(left) + convertInt(right); + } + + } + +} diff -r 703c09f8640c -r 3862508afe2f graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/BuiltinFunctionTest.java --- a/graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/BuiltinFunctionTest.java Wed Mar 06 18:32:33 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,132 +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. - * - * 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.codegen.test; - -import com.oracle.truffle.api.codegen.*; -import com.oracle.truffle.api.nodes.*; - -/** - * Generated code at {@link BuiltinFunctionTestFactory}. - */ -public class BuiltinFunctionTest { - - @TypeSystemReference(SimpleTypes.class) - abstract static class ValueNode extends Node { - - abstract int executeInt() throws UnexpectedResultException; - - abstract String executeString() throws UnexpectedResultException; - - abstract Object execute(); - - } - - abstract static class FunctionNode extends ValueNode { - - @Children ValueNode[] parameters; - - FunctionNode(ValueNode[] parameters) { - this.parameters = adoptChildren(parameters); - } - - FunctionNode(FunctionNode prev) { - this(prev.parameters); - } - } - - static int convertInt(Object value) { - if (value instanceof Number) { - return ((Number) value).intValue(); - } else if (value instanceof String) { - return Integer.parseInt((String) value); - } - throw new RuntimeException("Invalid datatype"); - } - - abstract static class MathAbsNode extends FunctionNode { - - MathAbsNode(ValueNode[] children) { - super(children); - } - - MathAbsNode(MathAbsNode prev) { - super(prev); - } - - @Specialization - int doInt(int value1) { - return Math.abs(value1); - } - - @Generic - int doGeneric(Object value0) { - return doInt(convertInt(value0)); - } - } - - abstract static class StringThisNode extends ValueNode { - - @Override - final String executeString() { - return (String) execute(); - } - - } - - @ExecuteChildren({"thisNode", "parameters"}) - abstract static class InstanceFunctionNode extends FunctionNode { - - @Child StringThisNode thisNode; - - InstanceFunctionNode(StringThisNode thisNode, ValueNode[] parameters) { - super(parameters); - this.thisNode = thisNode; - } - - InstanceFunctionNode(InstanceFunctionNode prev) { - this(prev.thisNode, prev.parameters); - } - } - - abstract static class StringSubstrNode extends InstanceFunctionNode { - - StringSubstrNode(StringThisNode thisNode, ValueNode[] parameters) { - super(thisNode, parameters); - } - - StringSubstrNode(StringSubstrNode prev) { - super(prev); - } - - @Specialization - String doInt(String thisValue, int beginIndex, int endIndex) { - return thisValue.substring(beginIndex, endIndex); - } - - @Generic - String doGeneric(String thisValue, Object beginIndex, Object endIndex) { - return thisValue.substring(convertInt(beginIndex), convertInt(endIndex)); - } - } - -} diff -r 703c09f8640c -r 3862508afe2f graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/RuntimeString.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/RuntimeString.java Wed Mar 06 18:33:05 2013 +0100 @@ -0,0 +1,78 @@ +/* + * 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. + * + * 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.codegen.test; + +import com.oracle.truffle.api.codegen.*; + +@NodeClass(RuntimeString.BuiltinNode.class) +public class RuntimeString { + + abstract static class BuiltinNode extends ValueNode { + + @Children ValueNode[] parameters; + + BuiltinNode(ValueNode[] parameters) { + this.parameters = adoptChildren(parameters); + } + + BuiltinNode(BuiltinNode prev) { + this(prev.parameters); + } + } + + private final String internal; + + public RuntimeString(String internal) { + this.internal = internal; + } + + @Specialization + RuntimeString substr(int beginIndex, int endIndex) { + return new RuntimeString(internal.substring(beginIndex, endIndex)); + } + + @Generic + static RuntimeString substr(Object s, Object beginIndex, Object endIndex) { + return ((RuntimeString) s).substr(convertInt(beginIndex), convertInt(endIndex)); + } + + @Specialization + static RuntimeString concat(RuntimeString s1, RuntimeString s2) { + return new RuntimeString(s1.internal + s2.internal); + } + + @Generic + static RuntimeString concat(Object s1, Object s2) { + return concat(((RuntimeString) s1), (RuntimeString) s2); + } + + static int convertInt(Object value) { + if (value instanceof Number) { + return ((Number) value).intValue(); + } else if (value instanceof String) { + return Integer.parseInt((String) value); + } + throw new RuntimeException("Invalid datatype"); + } + +} diff -r 703c09f8640c -r 3862508afe2f graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/ValueNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/ValueNode.java Wed Mar 06 18:33:05 2013 +0100 @@ -0,0 +1,37 @@ +/* + * 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. + * + * 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.codegen.test; + +import com.oracle.truffle.api.codegen.*; +import com.oracle.truffle.api.nodes.*; + +@TypeSystemReference(SimpleTypes.class) +abstract class ValueNode extends Node { + + abstract int executeInt() throws UnexpectedResultException; + + abstract RuntimeString executeString() throws UnexpectedResultException; + + abstract Object execute(); + +}