From b446ce9e54df1be5877f1a24d86e7b9664080822 Mon Sep 17 00:00:00 2001 From: Rajith Date: Mon, 27 Aug 2018 19:45:28 +0530 Subject: [PATCH] Fix math package with 0.981.0 ballerina version --- assembly/balo.xml | 35 +++ pom.xml | 223 ++++++++++++------ src/main/ballerina/Ballerina.toml | 3 + src/main/ballerina/math/natives.bal | 9 + .../ballerina/wso2/ballerina/math/natives.bal | 20 -- .../java/org/wso2/ballerina/math/AddInt.java | 50 ++++ .../java/org/wso2/ballerina/math/Exp.java | 69 ------ .../java/org/wso2/ballerina/math/Pow.java | 71 ------ .../java/org/wso2/ballerina/math/Random.java | 42 ---- 9 files changed, 245 insertions(+), 277 deletions(-) create mode 100644 assembly/balo.xml create mode 100644 src/main/ballerina/Ballerina.toml create mode 100644 src/main/ballerina/math/natives.bal delete mode 100644 src/main/ballerina/wso2/ballerina/math/natives.bal create mode 100644 src/main/java/org/wso2/ballerina/math/AddInt.java delete mode 100644 src/main/java/org/wso2/ballerina/math/Exp.java delete mode 100644 src/main/java/org/wso2/ballerina/math/Pow.java delete mode 100644 src/main/java/org/wso2/ballerina/math/Random.java diff --git a/assembly/balo.xml b/assembly/balo.xml new file mode 100644 index 0000000..04fec44 --- /dev/null +++ b/assembly/balo.xml @@ -0,0 +1,35 @@ + + + true + / + ballerina-binary-repo + + zip + + + + + ${project.build.directory}/generated-balo + / + + ** + + + + diff --git a/pom.xml b/pom.xml index 484394c..da37a62 100755 --- a/pom.xml +++ b/pom.xml @@ -18,96 +18,115 @@ - - org.ballerinalang - ballerina-parent - 0.89 - ../../pom.xml - org.wso2.ballerinalang 4.0.0 ballerina-math jar - 0.1 + 0.981.0-SNAPSHOT Ballerina - Native Implementation http://ballerinalang.org + + + + wso2-nexus + WSO2 internal Repository + http://maven.wso2.org/nexus/content/groups/wso2-public/ + + true + daily + ignore + + + + + wso2.releases + WSO2 internal Repository + http://maven.wso2.org/nexus/content/repositories/releases/ + + true + daily + ignore + + + + + + + + wso2.releases + WSO2 internal Repository + http://maven.wso2.org/nexus/content/repositories/releases/ + + true + daily + ignore + + + + + wso2-nexus + WSO2 internal Repository + http://maven.wso2.org/nexus/content/groups/wso2-public/ + + true + daily + ignore + + + + + + org.ballerinalang ballerina-core - 0.89 + ${ballerina.version} org.ballerinalang - annotation-processor - 0.89 + ballerina-builtin + ${ballerina.version} org.ballerinalang - ballerina-native - 0.89 + ballerina-builtin + zip + ballerina-binary-repo + ${ballerina.version} + + + org.ballerinalang + ballerina-runtime + zip + ballerina-binary-repo + ${ballerina.version} - - - - - - - - src/main/resources - - ballerina/** - - - - - - ${generated.ballerina.source.directory} - META-INF/natives - - - - - - - - - - - - - - - - - - - - - - - + + org.apache.maven.plugins + maven-compiler-plugin + ${maven.compiler.plugin.version} + + ${wso2.maven.compiler.source} + ${wso2.maven.compiler.target} + + org.bsc.maven maven-processor-plugin - 2.2.4 - org.ballerinalang.natives.annotation.processor.BallerinaAnnotationProcessor + org.ballerinalang.codegen.BallerinaAnnotationProcessor - ${native.constructs.provider.package1} - ${native.constructs.provider.class1} - ${ballerina.source.directory} - ${generated.ballerina.source.directory} - ${package.repository.provider.class} - ${ballerina.system.package.repository} + org.wso2.samplecon.generated.providers + StandardNativeElementProvider @@ -120,24 +139,78 @@ - + + org.apache.maven.plugins + maven-dependency-plugin + false + + + + unpack-dependencies + generate-resources + + unpack-dependencies + + + ballerina-binary-repo + ${project.build.directory}/lib + + + + + + org.codehaus.mojo + exec-maven-plugin + + + + gen-balo + + java + + compile + + + + BALLERINA_DEV_MODE_COMPILE + true + + + + false + ${basedir}/src/main/ballerina/ + ${project.build.directory}/generated-balo/repo/wso2 + ${project.build.directory} + ${project.version} + + org.ballerinalang.stdlib.utils.GenerateBalo + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + distribution + package + + attached + + + assembly + + + + - - ${project.build.directory}/../src/main/ballerina - org.wso2.ballerina.math.repository.BallerinaBuiltinPackageRepository - - false - - org.wso2.ballerina.math - MathNativeConstructsProvider - BallerinaBuiltinPackageRepository - - - - - ${project.build.directory}/../src/main/ballerina + 0.981.0 + 3.5.1 + 1.8 + 1.8 diff --git a/src/main/ballerina/Ballerina.toml b/src/main/ballerina/Ballerina.toml new file mode 100644 index 0000000..149f36b --- /dev/null +++ b/src/main/ballerina/Ballerina.toml @@ -0,0 +1,3 @@ +[project] +org-name="wso2" +version="0.0.0" diff --git a/src/main/ballerina/math/natives.bal b/src/main/ballerina/math/natives.bal new file mode 100644 index 0000000..e78a1eb --- /dev/null +++ b/src/main/ballerina/math/natives.bal @@ -0,0 +1,9 @@ + +documentation { + Add two integers and return the value. + + P{{a}} Value to be added + P{{b}} Value to be added + R{{}} Added value +} +public extern function addInt(int a, int b) returns int; diff --git a/src/main/ballerina/wso2/ballerina/math/natives.bal b/src/main/ballerina/wso2/ballerina/math/natives.bal deleted file mode 100644 index 9226619..0000000 --- a/src/main/ballerina/wso2/ballerina/math/natives.bal +++ /dev/null @@ -1,20 +0,0 @@ -package wso2.ballerina.math; - -import ballerina.doc; - - -@doc:Description { value:"Get the exp of provied float value"} -@doc:Param { value:"val: float value to get exp" } -@doc:Return { value:"float: exp value" } -native function exp (float val) (float); - -@doc:Description { value:"Returns the value of the 'a' raised to the power of 'b'"} -@doc:Param { value:"a: the base value" } -@doc:Param { value:"b: the exponent value" } -@doc:Return { value:"float: result value" } -native function pow (float a, float b) (float); - - -@doc:Description { value:"Returns a random number between 0.0 and 1.0"} -@doc:Return { value:"float: random value" } -native function random () (float); \ No newline at end of file diff --git a/src/main/java/org/wso2/ballerina/math/AddInt.java b/src/main/java/org/wso2/ballerina/math/AddInt.java new file mode 100644 index 0000000..e0f98e9 --- /dev/null +++ b/src/main/java/org/wso2/ballerina/math/AddInt.java @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ +package org.wso2.ballerina.math; + +import org.ballerinalang.bre.Context; +import org.ballerinalang.bre.bvm.BlockingNativeCallableUnit; +import org.ballerinalang.model.types.TypeKind; +import org.ballerinalang.model.values.BInteger; +import org.ballerinalang.natives.annotations.Argument; +import org.ballerinalang.natives.annotations.BallerinaFunction; +import org.ballerinalang.natives.annotations.ReturnType; + +/** + * Native function wso2.ballerina.math:addInt. + */ +@BallerinaFunction( + orgName = "wso2", + packageName = "math:0.0.0", + functionName = "addInt", + args = {@Argument(name = "a", type = TypeKind.INT), + @Argument(name = "b", type = TypeKind.INT)}, + returnType = {@ReturnType(type = TypeKind.INT)}, + isPublic = true +) +public class AddInt extends BlockingNativeCallableUnit { + + @Override + public void execute(Context context) { + System.out.println("**** Method addInt called ****"); + long a = context.getIntArgument(0); + long b = context.getIntArgument(1); + BInteger result = new BInteger(a + b); + context.setReturnValues(result); + } +} \ No newline at end of file diff --git a/src/main/java/org/wso2/ballerina/math/Exp.java b/src/main/java/org/wso2/ballerina/math/Exp.java deleted file mode 100644 index 9dd6559..0000000 --- a/src/main/java/org/wso2/ballerina/math/Exp.java +++ /dev/null @@ -1,69 +0,0 @@ -/* -* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -* -* WSO2 Inc. licenses this file to you under the Apache License, -* Version 2.0 (the "License"); you may not use this file except -* in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, -* software distributed under the License is distributed on an -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -* KIND, either express or implied. See the License for the -* specific language governing permissions and limitations -* under the License. -*/ -package org.wso2.ballerina.math; - -import org.ballerinalang.bre.Context; -import org.ballerinalang.model.types.SimpleTypeName; -import org.ballerinalang.model.types.TypeEnum; -import org.ballerinalang.model.values.BFloat; -import org.ballerinalang.model.values.BValue; -import org.ballerinalang.natives.AbstractNativeFunction; -import org.ballerinalang.natives.annotations.Argument; -import org.ballerinalang.natives.annotations.BallerinaFunction; -import org.ballerinalang.natives.annotations.ReturnType; -import org.ballerinalang.natives.exceptions.ArgumentOutOfRangeException; - -import javax.websocket.OnError; - -/** - * Native function wso2.ballerina.math:exp. - */ -@BallerinaFunction( - packageName = "wso2.ballerina.math", - functionName = "exp", - args = {@Argument(name = "val", type = TypeEnum.FLOAT)}, - returnType = {@ReturnType(type = TypeEnum.FLOAT)}, - isPublic = true -) -public class Exp extends AbstractNativeFunction { - private SimpleTypeName[] argTypeNamesTemp; - - public BValue[] execute(Context ctx) { - double value = getDoubleArgumentTemp(ctx, 0); - return getBValues(new BFloat(Math.exp(value))); - } - - //Below methods are temporary, these should come from super class, but at the moment, it is not, hence added here - public double getDoubleArgumentTemp(Context context, int index) { - if (index > -1 && index < this.argTypeNamesTemp.length) { - return context.getControlStackNew().getCurrentFrame().getDoubleLocalVars()[index]; - } else { - throw new ArgumentOutOfRangeException(index); - } - } - - @OnError - public void setArgTypeNames(SimpleTypeName[] argTypes) { - this.argTypeNamesTemp = argTypes; - } - - @OnError - public SimpleTypeName[] getArgumentTypeNames() { - return this.argTypeNamesTemp; - } -} diff --git a/src/main/java/org/wso2/ballerina/math/Pow.java b/src/main/java/org/wso2/ballerina/math/Pow.java deleted file mode 100644 index 2c5e6f8..0000000 --- a/src/main/java/org/wso2/ballerina/math/Pow.java +++ /dev/null @@ -1,71 +0,0 @@ -/* -* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -* -* WSO2 Inc. licenses this file to you under the Apache License, -* Version 2.0 (the "License"); you may not use this file except -* in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, -* software distributed under the License is distributed on an -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -* KIND, either express or implied. See the License for the -* specific language governing permissions and limitations -* under the License. -*/ -package org.wso2.ballerina.math; - -import org.ballerinalang.bre.Context; -import org.ballerinalang.model.types.SimpleTypeName; -import org.ballerinalang.model.types.TypeEnum; -import org.ballerinalang.model.values.BFloat; -import org.ballerinalang.model.values.BValue; -import org.ballerinalang.natives.AbstractNativeFunction; -import org.ballerinalang.natives.annotations.Argument; -import org.ballerinalang.natives.annotations.BallerinaFunction; -import org.ballerinalang.natives.annotations.ReturnType; -import org.ballerinalang.natives.exceptions.ArgumentOutOfRangeException; - -import javax.websocket.OnError; - -/** - * Native function wso2.ballerina.math:pow. - */ -@BallerinaFunction( - packageName = "wso2.ballerina.math", - functionName = "pow", - args = {@Argument(name = "a", type = TypeEnum.FLOAT), - @Argument(name = "b", type = TypeEnum.FLOAT)}, - returnType = {@ReturnType(type = TypeEnum.FLOAT)}, - isPublic = true -) -public class Pow extends AbstractNativeFunction { - private SimpleTypeName[] argTypeNamesTemp; - - public BValue[] execute(Context ctx) { - double a = getDoubleArgumentTemp(ctx, 0); - double b = getDoubleArgumentTemp(ctx, 1); - return getBValues(new BFloat(Math.pow(a, b))); - } - - //Below methods are temporary, these should come from super class, but at the moment, it is not, hence added here - public double getDoubleArgumentTemp(Context context, int index) { - if (index > -1 && index < this.argTypeNamesTemp.length) { - return context.getControlStackNew().getCurrentFrame().getDoubleLocalVars()[index]; - } else { - throw new ArgumentOutOfRangeException(index); - } - } - - @OnError - public void setArgTypeNames(SimpleTypeName[] argTypes) { - this.argTypeNamesTemp = argTypes; - } - - @OnError - public SimpleTypeName[] getArgumentTypeNames() { - return this.argTypeNamesTemp; - } -} diff --git a/src/main/java/org/wso2/ballerina/math/Random.java b/src/main/java/org/wso2/ballerina/math/Random.java deleted file mode 100644 index 3094b94..0000000 --- a/src/main/java/org/wso2/ballerina/math/Random.java +++ /dev/null @@ -1,42 +0,0 @@ -/* -* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -* -* WSO2 Inc. licenses this file to you under the Apache License, -* Version 2.0 (the "License"); you may not use this file except -* in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, -* software distributed under the License is distributed on an -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -* KIND, either express or implied. See the License for the -* specific language governing permissions and limitations -* under the License. -*/ -package org.wso2.ballerina.math; - -import org.ballerinalang.bre.Context; -import org.ballerinalang.model.types.TypeEnum; -import org.ballerinalang.model.values.BFloat; -import org.ballerinalang.model.values.BValue; -import org.ballerinalang.natives.AbstractNativeFunction; -import org.ballerinalang.natives.annotations.BallerinaFunction; -import org.ballerinalang.natives.annotations.ReturnType; - -/** - * Native function wso2.ballerina.math:pow. - */ -@BallerinaFunction( - packageName = "wso2.ballerina.math", - functionName = "random", - returnType = {@ReturnType(type = TypeEnum.FLOAT)}, - isPublic = true -) -public class Random extends AbstractNativeFunction { - - public BValue[] execute(Context ctx) { - return getBValues(new BFloat(Math.random())); - } -}