Search in sources :

Example 26 with BType

use of org.ballerinalang.model.types.BType in project ballerina by ballerina-lang.

the class BLangVMUtils method createReturnRegValues.

public static int[] createReturnRegValues(WorkerDataIndex paramWDI, WorkerDataIndex retWDI, BType[] retTypes) {
    int[] result = new int[retWDI.retRegs.length];
    System.arraycopy(retWDI.retRegs, 0, result, 0, result.length);
    for (int i = 0; i < result.length; i++) {
        BType retType = retTypes[i];
        switch(retType.getTag()) {
            case TypeTags.INT_TAG:
                result[i] += paramWDI.longRegCount;
                break;
            case TypeTags.FLOAT_TAG:
                result[i] += paramWDI.doubleRegCount;
                break;
            case TypeTags.STRING_TAG:
                result[i] += paramWDI.stringRegCount;
                break;
            case TypeTags.BOOLEAN_TAG:
                result[i] += paramWDI.intRegCount;
                break;
            case TypeTags.BLOB_TAG:
                result[i] += paramWDI.byteRegCount;
                break;
            default:
                result[i] += paramWDI.refRegCount;
                break;
        }
    }
    return result;
}
Also used : BType(org.ballerinalang.model.types.BType)

Example 27 with BType

use of org.ballerinalang.model.types.BType in project ballerina by ballerina-lang.

the class BLangVMUtils method mergeResultData.

public static void mergeResultData(WorkerData sourceData, WorkerData targetData, BType[] types, int[] regIndexes) {
    int callersRetRegIndex;
    int longRegCount = 0;
    int doubleRegCount = 0;
    int stringRegCount = 0;
    int intRegCount = 0;
    int refRegCount = 0;
    int byteRegCount = 0;
    for (int i = 0; i < types.length; i++) {
        BType retType = types[i];
        callersRetRegIndex = regIndexes[i];
        switch(retType.getTag()) {
            case TypeTags.INT_TAG:
                targetData.longRegs[callersRetRegIndex] = sourceData.longRegs[longRegCount++];
                break;
            case TypeTags.FLOAT_TAG:
                targetData.doubleRegs[callersRetRegIndex] = sourceData.doubleRegs[doubleRegCount++];
                break;
            case TypeTags.STRING_TAG:
                targetData.stringRegs[callersRetRegIndex] = sourceData.stringRegs[stringRegCount++];
                break;
            case TypeTags.BOOLEAN_TAG:
                targetData.intRegs[callersRetRegIndex] = sourceData.intRegs[intRegCount++];
                break;
            case TypeTags.BLOB_TAG:
                targetData.byteRegs[callersRetRegIndex] = sourceData.byteRegs[byteRegCount++];
                break;
            default:
                targetData.refRegs[callersRetRegIndex] = sourceData.refRegs[refRegCount++];
                break;
        }
    }
}
Also used : BType(org.ballerinalang.model.types.BType)

Example 28 with BType

use of org.ballerinalang.model.types.BType in project ballerina by ballerina-lang.

the class BLangVMUtils method populateReturnData.

public static BValue[] populateReturnData(WorkerExecutionContext ctx, CallableUnitInfo callableUnitInfo, int[] retRegs) {
    WorkerData data = ctx.workerLocal;
    BType[] retTypes = callableUnitInfo.getRetParamTypes();
    BValue[] returnValues = new BValue[retTypes.length];
    for (int i = 0; i < returnValues.length; i++) {
        BType retType = retTypes[i];
        switch(retType.getTag()) {
            case TypeTags.INT_TAG:
                returnValues[i] = new BInteger(data.longRegs[retRegs[i]]);
                break;
            case TypeTags.FLOAT_TAG:
                returnValues[i] = new BFloat(data.doubleRegs[retRegs[i]]);
                break;
            case TypeTags.STRING_TAG:
                returnValues[i] = new BString(data.stringRegs[retRegs[i]]);
                break;
            case TypeTags.BOOLEAN_TAG:
                boolean boolValue = data.intRegs[retRegs[i]] == 1;
                returnValues[i] = new BBoolean(boolValue);
                break;
            case TypeTags.BLOB_TAG:
                returnValues[i] = new BBlob(data.byteRegs[retRegs[i]]);
                break;
            default:
                returnValues[i] = data.refRegs[retRegs[i]];
                break;
        }
    }
    return returnValues;
}
Also used : BType(org.ballerinalang.model.types.BType) BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) BFloat(org.ballerinalang.model.values.BFloat) BBoolean(org.ballerinalang.model.values.BBoolean) WorkerData(org.ballerinalang.bre.bvm.WorkerData) BBlob(org.ballerinalang.model.values.BBlob)

Example 29 with BType

use of org.ballerinalang.model.types.BType in project ballerina by ballerina-lang.

the class MethodListener method getRequestParameter.

/**
 * Returns BValue object corresponding to the protobuf request message.
 *
 * @param requestMessage protobuf request message.
 * @return b7a message.
 */
BValue getRequestParameter(Resource resource, Message requestMessage) {
    if (resource == null || resource.getParamDetails() == null || resource.getParamDetails().size() > 2) {
        throw new RuntimeException("Invalid resource input arguments. arguments must not be greater than two");
    }
    if (resource.getParamDetails().size() == 2) {
        BType requestType = resource.getParamDetails().get(MessageConstants.REQUEST_MESSAGE_PARAM_INDEX).getVarType();
        String requestName = resource.getParamDetails().get(MessageConstants.REQUEST_MESSAGE_PARAM_INDEX).getVarName();
        return generateRequestStruct(requestMessage, getProgramFile(resource), requestName, requestType);
    } else {
        return null;
    }
}
Also used : BType(org.ballerinalang.model.types.BType) BString(org.ballerinalang.model.values.BString)

Example 30 with BType

use of org.ballerinalang.model.types.BType in project ballerina by ballerina-lang.

the class DefaultStreamObserver method onError.

@Override
public void onError(Throwable t) {
    Resource onError = resourceMap.get(MessageConstants.ON_ERROR_RESOURCE);
    if (onError == null) {
        String message = "Error in listener service definition. onError resource does not exists";
        LOG.error(message);
        throw new RuntimeException(message);
    }
    List<ParamDetail> paramDetails = onError.getParamDetails();
    BValue[] signatureParams = new BValue[paramDetails.size()];
    if (paramDetails.size() != 1) {
        String message = "Error in onError resource definition. It must have only error params, but have " + paramDetails.size();
        LOG.error(message);
        throw new RuntimeException(message);
    }
    BType errorType = paramDetails.get(1).getVarType();
    BStruct errorStruct = MessageUtils.getConnectorError((BStructType) errorType, t);
    signatureParams[0] = errorStruct;
    CallableUnitCallback callback = new GrpcCallableUnitCallBack(null);
    Executor.submit(onError, callback, null, null, signatureParams);
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) GrpcCallableUnitCallBack(org.ballerinalang.net.grpc.GrpcCallableUnitCallBack) ParamDetail(org.ballerinalang.connector.api.ParamDetail) BValue(org.ballerinalang.model.values.BValue) BType(org.ballerinalang.model.types.BType) Resource(org.ballerinalang.connector.api.Resource) BString(org.ballerinalang.model.values.BString) CallableUnitCallback(org.ballerinalang.bre.bvm.CallableUnitCallback)

Aggregations

BType (org.ballerinalang.model.types.BType)48 BStructType (org.ballerinalang.model.types.BStructType)16 BString (org.ballerinalang.model.values.BString)16 BStruct (org.ballerinalang.model.values.BStruct)15 BValue (org.ballerinalang.model.values.BValue)13 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)12 BBoolean (org.ballerinalang.model.values.BBoolean)11 BArrayType (org.ballerinalang.model.types.BArrayType)7 BFloat (org.ballerinalang.model.values.BFloat)6 BInteger (org.ballerinalang.model.values.BInteger)6 BMapType (org.ballerinalang.model.types.BMapType)4 BRefType (org.ballerinalang.model.values.BRefType)4 SQLException (java.sql.SQLException)3 Struct (java.sql.Struct)3 ArrayList (java.util.ArrayList)3 CallableUnitCallback (org.ballerinalang.bre.bvm.CallableUnitCallback)3 BBlob (org.ballerinalang.model.values.BBlob)3 Message (org.ballerinalang.net.grpc.Message)3 StructFieldInfo (org.ballerinalang.util.codegen.StructFieldInfo)3 StructInfo (org.ballerinalang.util.codegen.StructInfo)3