Search in sources :

Example 1 with BFloatArray

use of org.ballerinalang.model.values.BFloatArray in project ballerina by ballerina-lang.

the class AbstractSQLAction method createProcessedStatement.

private void createProcessedStatement(Connection conn, PreparedStatement stmt, BRefValueArray params, String dataSourceName) {
    if (params == null) {
        return;
    }
    int paramCount = (int) params.size();
    int currentOrdinal = 0;
    for (int index = 0; index < paramCount; index++) {
        BStruct paramStruct = (BStruct) params.get(index);
        if (paramStruct != null) {
            String sqlType = getSQLType(paramStruct);
            BValue value = paramStruct.getRefField(1);
            int direction = getParameterDirection(paramStruct);
            // If the parameter is an array and sql type is not "array" then treat it as an array of parameters
            if (value != null && value.getType().getTag() == TypeTags.ARRAY_TAG && !Constants.SQLDataTypes.ARRAY.equalsIgnoreCase(sqlType)) {
                int arrayLength = (int) ((BNewArray) value).size();
                int typeTag = ((BArrayType) value.getType()).getElementType().getTag();
                for (int i = 0; i < arrayLength; i++) {
                    BValue paramValue;
                    switch(typeTag) {
                        case TypeTags.INT_TAG:
                            paramValue = new BInteger(((BIntArray) value).get(i));
                            break;
                        case TypeTags.FLOAT_TAG:
                            paramValue = new BFloat(((BFloatArray) value).get(i));
                            break;
                        case TypeTags.STRING_TAG:
                            paramValue = new BString(((BStringArray) value).get(i));
                            break;
                        case TypeTags.BOOLEAN_TAG:
                            paramValue = new BBoolean(((BBooleanArray) value).get(i) > 0);
                            break;
                        case TypeTags.BLOB_TAG:
                            paramValue = new BBlob(((BBlobArray) value).get(i));
                            break;
                        default:
                            throw new BallerinaException("unsupported array type for parameter index " + index);
                    }
                    if (Constants.SQLDataTypes.REFCURSOR.equals(sqlType)) {
                        setParameter(conn, stmt, sqlType, paramValue, direction, currentOrdinal, dataSourceName);
                    } else {
                        setParameter(conn, stmt, sqlType, paramValue, direction, currentOrdinal);
                    }
                    currentOrdinal++;
                }
            } else {
                if (Constants.SQLDataTypes.REFCURSOR.equals(sqlType)) {
                    setParameter(conn, stmt, sqlType, value, direction, currentOrdinal, dataSourceName);
                } else {
                    setParameter(conn, stmt, sqlType, value, direction, currentOrdinal);
                }
                currentOrdinal++;
            }
        } else {
            SQLDatasourceUtils.setNullObject(stmt, index);
            currentOrdinal++;
        }
    }
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) BBoolean(org.ballerinalang.model.values.BBoolean) BString(org.ballerinalang.model.values.BString) BStringArray(org.ballerinalang.model.values.BStringArray) BIntArray(org.ballerinalang.model.values.BIntArray) BBlobArray(org.ballerinalang.model.values.BBlobArray) BFloat(org.ballerinalang.model.values.BFloat) BFloatArray(org.ballerinalang.model.values.BFloatArray) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException) BBlob(org.ballerinalang.model.values.BBlob)

Example 2 with BFloatArray

use of org.ballerinalang.model.values.BFloatArray in project ballerina by ballerina-lang.

the class SQLActionsTest method testArrayInParameters.

@Test(groups = "ConnectorTest")
public void testArrayInParameters() {
    BValue[] returns = BRunUtil.invoke(result, "testArrayInParameters");
    BInteger retValue = (BInteger) returns[0];
    Assert.assertEquals(retValue.intValue(), 1);
    Assert.assertTrue(returns[1] instanceof BIntArray);
    BIntArray intArray = (BIntArray) returns[1];
    Assert.assertEquals(intArray.get(0), 1);
    Assert.assertTrue(returns[2] instanceof BIntArray);
    BIntArray longArray = (BIntArray) returns[2];
    Assert.assertEquals(longArray.get(0), 1503383034226L);
    Assert.assertEquals(longArray.get(1), 1503383034224L);
    Assert.assertEquals(longArray.get(2), 1503383034225L);
    Assert.assertTrue(returns[3] instanceof BFloatArray);
    BFloatArray doubleArray = (BFloatArray) returns[3];
    Assert.assertEquals(doubleArray.get(0), 1503383034226.23D);
    Assert.assertEquals(doubleArray.get(1), 1503383034224.43D);
    Assert.assertEquals(doubleArray.get(2), 1503383034225.123D);
    Assert.assertTrue(returns[4] instanceof BStringArray);
    BStringArray stringArray = (BStringArray) returns[4];
    Assert.assertEquals(stringArray.get(0), "Hello");
    Assert.assertEquals(stringArray.get(1), "Ballerina");
    Assert.assertTrue(returns[5] instanceof BBooleanArray);
    BBooleanArray booleanArray = (BBooleanArray) returns[5];
    Assert.assertEquals(booleanArray.get(0), 1);
    Assert.assertEquals(booleanArray.get(1), 0);
    Assert.assertEquals(booleanArray.get(2), 1);
    Assert.assertTrue(returns[6] instanceof BFloatArray);
    BFloatArray floatArray = (BFloatArray) returns[6];
    Assert.assertEquals(floatArray.get(0), 245.23);
    Assert.assertEquals(floatArray.get(1), 5559.49);
    Assert.assertEquals(floatArray.get(2), 8796.123);
}
Also used : BBooleanArray(org.ballerinalang.model.values.BBooleanArray) BValue(org.ballerinalang.model.values.BValue) BInteger(org.ballerinalang.model.values.BInteger) BFloatArray(org.ballerinalang.model.values.BFloatArray) BStringArray(org.ballerinalang.model.values.BStringArray) BIntArray(org.ballerinalang.model.values.BIntArray) Test(org.testng.annotations.Test)

Example 3 with BFloatArray

use of org.ballerinalang.model.values.BFloatArray in project ballerina by ballerina-lang.

the class CPU method execLoadOpcodes.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static void execLoadOpcodes(WorkerExecutionContext ctx, WorkerData sf, int opcode, int[] operands) {
    int i;
    int j;
    int k;
    // Index of the local variable
    int lvIndex;
    int fieldIndex;
    BIntArray bIntArray;
    BFloatArray bFloatArray;
    BStringArray bStringArray;
    BBooleanArray bBooleanArray;
    BBlobArray bBlobArray;
    BRefValueArray bArray;
    StructureType structureType;
    BMap<String, BRefType> bMap;
    BJSON jsonVal;
    switch(opcode) {
        case InstructionCodes.IMOVE:
            lvIndex = operands[0];
            i = operands[1];
            sf.longRegs[i] = sf.longRegs[lvIndex];
            break;
        case InstructionCodes.FMOVE:
            lvIndex = operands[0];
            i = operands[1];
            sf.doubleRegs[i] = sf.doubleRegs[lvIndex];
            break;
        case InstructionCodes.SMOVE:
            lvIndex = operands[0];
            i = operands[1];
            sf.stringRegs[i] = sf.stringRegs[lvIndex];
            break;
        case InstructionCodes.BMOVE:
            lvIndex = operands[0];
            i = operands[1];
            sf.intRegs[i] = sf.intRegs[lvIndex];
            break;
        case InstructionCodes.LMOVE:
            lvIndex = operands[0];
            i = operands[1];
            sf.byteRegs[i] = sf.byteRegs[lvIndex];
            break;
        case InstructionCodes.RMOVE:
            lvIndex = operands[0];
            i = operands[1];
            sf.refRegs[i] = sf.refRegs[lvIndex];
            break;
        case InstructionCodes.IALOAD:
            i = operands[0];
            j = operands[1];
            k = operands[2];
            bIntArray = (BIntArray) sf.refRegs[i];
            if (bIntArray == null) {
                handleNullRefError(ctx);
                break;
            }
            try {
                sf.longRegs[k] = bIntArray.get(sf.longRegs[j]);
            } catch (Exception e) {
                ctx.setError(BLangVMErrors.createError(ctx, e.getMessage()));
                handleError(ctx);
            }
            break;
        case InstructionCodes.FALOAD:
            i = operands[0];
            j = operands[1];
            k = operands[2];
            bFloatArray = (BFloatArray) sf.refRegs[i];
            if (bFloatArray == null) {
                handleNullRefError(ctx);
                break;
            }
            try {
                sf.doubleRegs[k] = bFloatArray.get(sf.longRegs[j]);
            } catch (Exception e) {
                ctx.setError(BLangVMErrors.createError(ctx, e.getMessage()));
                handleError(ctx);
            }
            break;
        case InstructionCodes.SALOAD:
            i = operands[0];
            j = operands[1];
            k = operands[2];
            bStringArray = (BStringArray) sf.refRegs[i];
            if (bStringArray == null) {
                handleNullRefError(ctx);
                break;
            }
            try {
                sf.stringRegs[k] = bStringArray.get(sf.longRegs[j]);
            } catch (Exception e) {
                ctx.setError(BLangVMErrors.createError(ctx, e.getMessage()));
                handleError(ctx);
            }
            break;
        case InstructionCodes.BALOAD:
            i = operands[0];
            j = operands[1];
            k = operands[2];
            bBooleanArray = (BBooleanArray) sf.refRegs[i];
            if (bBooleanArray == null) {
                handleNullRefError(ctx);
                break;
            }
            try {
                sf.intRegs[k] = bBooleanArray.get(sf.longRegs[j]);
            } catch (Exception e) {
                ctx.setError(BLangVMErrors.createError(ctx, e.getMessage()));
                handleError(ctx);
            }
            break;
        case InstructionCodes.LALOAD:
            i = operands[0];
            j = operands[1];
            k = operands[2];
            bBlobArray = (BBlobArray) sf.refRegs[i];
            if (bBlobArray == null) {
                handleNullRefError(ctx);
                break;
            }
            try {
                sf.byteRegs[k] = bBlobArray.get(sf.longRegs[j]);
            } catch (Exception e) {
                ctx.setError(BLangVMErrors.createError(ctx, e.getMessage()));
                handleError(ctx);
            }
            break;
        case InstructionCodes.RALOAD:
            i = operands[0];
            j = operands[1];
            k = operands[2];
            bArray = (BRefValueArray) sf.refRegs[i];
            if (bArray == null) {
                handleNullRefError(ctx);
                break;
            }
            try {
                sf.refRegs[k] = bArray.get(sf.longRegs[j]);
            } catch (Exception e) {
                ctx.setError(BLangVMErrors.createError(ctx, e.getMessage()));
                handleError(ctx);
            }
            break;
        case InstructionCodes.JSONALOAD:
            i = operands[0];
            j = operands[1];
            k = operands[2];
            jsonVal = (BJSON) sf.refRegs[i];
            if (jsonVal == null) {
                handleNullRefError(ctx);
                break;
            }
            try {
                sf.refRegs[k] = JSONUtils.getArrayElement(jsonVal, sf.longRegs[j]);
            } catch (Exception e) {
                ctx.setError(BLangVMErrors.createError(ctx, e.getMessage()));
                handleError(ctx);
            }
            break;
        case InstructionCodes.IGLOAD:
            // Global variable index
            i = operands[0];
            // Stack registry index
            j = operands[1];
            sf.longRegs[j] = ctx.programFile.getGlobalMemoryBlock().getIntField(i);
            break;
        case InstructionCodes.FGLOAD:
            i = operands[0];
            j = operands[1];
            sf.doubleRegs[j] = ctx.programFile.getGlobalMemoryBlock().getFloatField(i);
            break;
        case InstructionCodes.SGLOAD:
            i = operands[0];
            j = operands[1];
            sf.stringRegs[j] = ctx.programFile.getGlobalMemoryBlock().getStringField(i);
            break;
        case InstructionCodes.BGLOAD:
            i = operands[0];
            j = operands[1];
            sf.intRegs[j] = ctx.programFile.getGlobalMemoryBlock().getBooleanField(i);
            break;
        case InstructionCodes.LGLOAD:
            i = operands[0];
            j = operands[1];
            sf.byteRegs[j] = ctx.programFile.getGlobalMemoryBlock().getBlobField(i);
            break;
        case InstructionCodes.RGLOAD:
            i = operands[0];
            j = operands[1];
            sf.refRegs[j] = ctx.programFile.getGlobalMemoryBlock().getRefField(i);
            break;
        case InstructionCodes.IFIELDLOAD:
            i = operands[0];
            fieldIndex = operands[1];
            j = operands[2];
            structureType = (StructureType) sf.refRegs[i];
            if (structureType == null) {
                handleNullRefError(ctx);
                break;
            }
            sf.longRegs[j] = structureType.getIntField(fieldIndex);
            break;
        case InstructionCodes.FFIELDLOAD:
            i = operands[0];
            fieldIndex = operands[1];
            j = operands[2];
            structureType = (StructureType) sf.refRegs[i];
            if (structureType == null) {
                handleNullRefError(ctx);
                break;
            }
            sf.doubleRegs[j] = structureType.getFloatField(fieldIndex);
            break;
        case InstructionCodes.SFIELDLOAD:
            i = operands[0];
            fieldIndex = operands[1];
            j = operands[2];
            structureType = (StructureType) sf.refRegs[i];
            if (structureType == null) {
                handleNullRefError(ctx);
                break;
            }
            sf.stringRegs[j] = structureType.getStringField(fieldIndex);
            break;
        case InstructionCodes.BFIELDLOAD:
            i = operands[0];
            fieldIndex = operands[1];
            j = operands[2];
            structureType = (StructureType) sf.refRegs[i];
            if (structureType == null) {
                handleNullRefError(ctx);
                break;
            }
            sf.intRegs[j] = structureType.getBooleanField(fieldIndex);
            break;
        case InstructionCodes.LFIELDLOAD:
            i = operands[0];
            fieldIndex = operands[1];
            j = operands[2];
            structureType = (StructureType) sf.refRegs[i];
            if (structureType == null) {
                handleNullRefError(ctx);
                break;
            }
            sf.byteRegs[j] = structureType.getBlobField(fieldIndex);
            break;
        case InstructionCodes.RFIELDLOAD:
            i = operands[0];
            fieldIndex = operands[1];
            j = operands[2];
            structureType = (StructureType) sf.refRegs[i];
            if (structureType == null) {
                handleNullRefError(ctx);
                break;
            }
            sf.refRegs[j] = structureType.getRefField(fieldIndex);
            break;
        case InstructionCodes.MAPLOAD:
            i = operands[0];
            j = operands[1];
            k = operands[2];
            bMap = (BMap<String, BRefType>) sf.refRegs[i];
            if (bMap == null) {
                handleNullRefError(ctx);
                break;
            }
            sf.refRegs[k] = bMap.get(sf.stringRegs[j]);
            break;
        case InstructionCodes.JSONLOAD:
            i = operands[0];
            j = operands[1];
            k = operands[2];
            jsonVal = (BJSON) sf.refRegs[i];
            if (jsonVal == null) {
                handleNullRefError(ctx);
                break;
            }
            sf.refRegs[k] = JSONUtils.getElement(jsonVal, sf.stringRegs[j]);
            break;
        case InstructionCodes.ENUMERATORLOAD:
            i = operands[0];
            j = operands[1];
            k = operands[2];
            TypeRefCPEntry typeRefCPEntry = (TypeRefCPEntry) ctx.constPool[i];
            BEnumType enumType = (BEnumType) typeRefCPEntry.getType();
            sf.refRegs[k] = enumType.getEnumerator(j);
            break;
        default:
            throw new UnsupportedOperationException();
    }
}
Also used : BRefType(org.ballerinalang.model.values.BRefType) TypeRefCPEntry(org.ballerinalang.util.codegen.cpentries.TypeRefCPEntry) BRefValueArray(org.ballerinalang.model.values.BRefValueArray) BString(org.ballerinalang.model.values.BString) BStringArray(org.ballerinalang.model.values.BStringArray) BJSON(org.ballerinalang.model.values.BJSON) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException) BIntArray(org.ballerinalang.model.values.BIntArray) BEnumType(org.ballerinalang.model.types.BEnumType) BBlobArray(org.ballerinalang.model.values.BBlobArray) BBooleanArray(org.ballerinalang.model.values.BBooleanArray) StructureType(org.ballerinalang.model.values.StructureType) BFloatArray(org.ballerinalang.model.values.BFloatArray)

Example 4 with BFloatArray

use of org.ballerinalang.model.values.BFloatArray in project ballerina by ballerina-lang.

the class CPU method execStoreOpcodes.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static void execStoreOpcodes(WorkerExecutionContext ctx, WorkerData sf, int opcode, int[] operands) {
    int i;
    int j;
    int k;
    int fieldIndex;
    BIntArray bIntArray;
    BFloatArray bFloatArray;
    BStringArray bStringArray;
    BBooleanArray bBooleanArray;
    BBlobArray bBlobArray;
    BRefValueArray bArray;
    StructureType structureType;
    BMap<String, BRefType> bMap;
    BJSON jsonVal;
    switch(opcode) {
        case InstructionCodes.IASTORE:
            i = operands[0];
            j = operands[1];
            k = operands[2];
            bIntArray = (BIntArray) sf.refRegs[i];
            if (bIntArray == null) {
                handleNullRefError(ctx);
                break;
            }
            try {
                bIntArray.add(sf.longRegs[j], sf.longRegs[k]);
            } catch (Exception e) {
                ctx.setError(BLangVMErrors.createError(ctx, e.getMessage()));
                handleError(ctx);
            }
            break;
        case InstructionCodes.FASTORE:
            i = operands[0];
            j = operands[1];
            k = operands[2];
            bFloatArray = (BFloatArray) sf.refRegs[i];
            if (bFloatArray == null) {
                handleNullRefError(ctx);
                break;
            }
            try {
                bFloatArray.add(sf.longRegs[j], sf.doubleRegs[k]);
            } catch (Exception e) {
                ctx.setError(BLangVMErrors.createError(ctx, e.getMessage()));
                handleError(ctx);
            }
            break;
        case InstructionCodes.SASTORE:
            i = operands[0];
            j = operands[1];
            k = operands[2];
            bStringArray = (BStringArray) sf.refRegs[i];
            if (bStringArray == null) {
                handleNullRefError(ctx);
                break;
            }
            try {
                bStringArray.add(sf.longRegs[j], sf.stringRegs[k]);
            } catch (Exception e) {
                ctx.setError(BLangVMErrors.createError(ctx, e.getMessage()));
                handleError(ctx);
            }
            break;
        case InstructionCodes.BASTORE:
            i = operands[0];
            j = operands[1];
            k = operands[2];
            bBooleanArray = (BBooleanArray) sf.refRegs[i];
            if (bBooleanArray == null) {
                handleNullRefError(ctx);
                break;
            }
            try {
                bBooleanArray.add(sf.longRegs[j], sf.intRegs[k]);
            } catch (Exception e) {
                ctx.setError(BLangVMErrors.createError(ctx, e.getMessage()));
                handleError(ctx);
            }
            break;
        case InstructionCodes.LASTORE:
            i = operands[0];
            j = operands[1];
            k = operands[2];
            bBlobArray = (BBlobArray) sf.refRegs[i];
            if (bBlobArray == null) {
                handleNullRefError(ctx);
                break;
            }
            try {
                bBlobArray.add(sf.longRegs[j], sf.byteRegs[k]);
            } catch (Exception e) {
                ctx.setError(BLangVMErrors.createError(ctx, e.getMessage()));
                handleError(ctx);
            }
            break;
        case InstructionCodes.RASTORE:
            i = operands[0];
            j = operands[1];
            k = operands[2];
            bArray = (BRefValueArray) sf.refRegs[i];
            if (bArray == null) {
                handleNullRefError(ctx);
                break;
            }
            try {
                bArray.add(sf.longRegs[j], sf.refRegs[k]);
            } catch (Exception e) {
                ctx.setError(BLangVMErrors.createError(ctx, e.getMessage()));
                handleError(ctx);
            }
            break;
        case InstructionCodes.JSONASTORE:
            i = operands[0];
            j = operands[1];
            k = operands[2];
            jsonVal = (BJSON) sf.refRegs[i];
            if (jsonVal == null) {
                handleNullRefError(ctx);
                break;
            }
            try {
                JSONUtils.setArrayElement(jsonVal, sf.longRegs[j], (BJSON) sf.refRegs[k]);
            } catch (Exception e) {
                ctx.setError(BLangVMErrors.createError(ctx, e.getMessage()));
                handleError(ctx);
            }
            break;
        case InstructionCodes.IGSTORE:
            // Stack reg index
            i = operands[0];
            // Global var index
            j = operands[1];
            ctx.programFile.getGlobalMemoryBlock().setIntField(j, sf.longRegs[i]);
            break;
        case InstructionCodes.FGSTORE:
            i = operands[0];
            j = operands[1];
            ctx.programFile.getGlobalMemoryBlock().setFloatField(j, sf.doubleRegs[i]);
            break;
        case InstructionCodes.SGSTORE:
            i = operands[0];
            j = operands[1];
            ctx.programFile.getGlobalMemoryBlock().setStringField(j, sf.stringRegs[i]);
            break;
        case InstructionCodes.BGSTORE:
            i = operands[0];
            j = operands[1];
            ctx.programFile.getGlobalMemoryBlock().setBooleanField(j, sf.intRegs[i]);
            break;
        case InstructionCodes.LGSTORE:
            i = operands[0];
            j = operands[1];
            ctx.programFile.getGlobalMemoryBlock().setBlobField(j, sf.byteRegs[i]);
            break;
        case InstructionCodes.RGSTORE:
            i = operands[0];
            j = operands[1];
            ctx.programFile.getGlobalMemoryBlock().setRefField(j, sf.refRegs[i]);
            break;
        case InstructionCodes.IFIELDSTORE:
            i = operands[0];
            fieldIndex = operands[1];
            j = operands[2];
            structureType = (StructureType) sf.refRegs[i];
            if (structureType == null) {
                handleNullRefError(ctx);
                break;
            }
            structureType.setIntField(fieldIndex, sf.longRegs[j]);
            break;
        case InstructionCodes.FFIELDSTORE:
            i = operands[0];
            fieldIndex = operands[1];
            j = operands[2];
            structureType = (StructureType) sf.refRegs[i];
            if (structureType == null) {
                handleNullRefError(ctx);
                break;
            }
            structureType.setFloatField(fieldIndex, sf.doubleRegs[j]);
            break;
        case InstructionCodes.SFIELDSTORE:
            i = operands[0];
            fieldIndex = operands[1];
            j = operands[2];
            structureType = (StructureType) sf.refRegs[i];
            if (structureType == null) {
                handleNullRefError(ctx);
                break;
            }
            structureType.setStringField(fieldIndex, sf.stringRegs[j]);
            break;
        case InstructionCodes.BFIELDSTORE:
            i = operands[0];
            fieldIndex = operands[1];
            j = operands[2];
            structureType = (StructureType) sf.refRegs[i];
            if (structureType == null) {
                handleNullRefError(ctx);
                break;
            }
            structureType.setBooleanField(fieldIndex, sf.intRegs[j]);
            break;
        case InstructionCodes.LFIELDSTORE:
            i = operands[0];
            fieldIndex = operands[1];
            j = operands[2];
            structureType = (StructureType) sf.refRegs[i];
            if (structureType == null) {
                handleNullRefError(ctx);
                break;
            }
            structureType.setBlobField(fieldIndex, sf.byteRegs[j]);
            break;
        case InstructionCodes.RFIELDSTORE:
            i = operands[0];
            fieldIndex = operands[1];
            j = operands[2];
            structureType = (StructureType) sf.refRegs[i];
            if (structureType == null) {
                handleNullRefError(ctx);
                break;
            }
            structureType.setRefField(fieldIndex, sf.refRegs[j]);
            break;
        case InstructionCodes.MAPSTORE:
            i = operands[0];
            j = operands[1];
            k = operands[2];
            bMap = (BMap<String, BRefType>) sf.refRegs[i];
            if (bMap == null) {
                handleNullRefError(ctx);
                break;
            }
            BMapType mapType = (BMapType) bMap.getType();
            if (sf.refRegs[k] == null) {
                bMap.put(sf.stringRegs[j], sf.refRegs[k]);
            } else if (mapType.getConstrainedType() == BTypes.typeAny || mapType.getConstrainedType().equals(sf.refRegs[k].getType())) {
                bMap.put(sf.stringRegs[j], sf.refRegs[k]);
            } else if (sf.refRegs[k].getType().getTag() == TypeTags.STRUCT_TAG && mapType.getConstrainedType().getTag() == TypeTags.STRUCT_TAG && checkStructEquivalency((BStructType) sf.refRegs[k].getType(), (BStructType) mapType.getConstrainedType())) {
                bMap.put(sf.stringRegs[j], sf.refRegs[k]);
            } else {
                ctx.setError(BLangVMErrors.createError(ctx, BLangExceptionHelper.getErrorMessage(RuntimeErrors.INVALID_MAP_INSERTION, mapType.getConstrainedType(), sf.refRegs[k].getType())));
                handleError(ctx);
                break;
            }
            break;
        case InstructionCodes.JSONSTORE:
            i = operands[0];
            j = operands[1];
            k = operands[2];
            jsonVal = (BJSON) sf.refRegs[i];
            if (jsonVal == null) {
                handleNullRefError(ctx);
                break;
            }
            JSONUtils.setElement(jsonVal, sf.stringRegs[j], (BJSON) sf.refRegs[k]);
            break;
        default:
            throw new UnsupportedOperationException();
    }
}
Also used : BRefType(org.ballerinalang.model.values.BRefType) BRefValueArray(org.ballerinalang.model.values.BRefValueArray) BString(org.ballerinalang.model.values.BString) BStringArray(org.ballerinalang.model.values.BStringArray) BJSON(org.ballerinalang.model.values.BJSON) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException) BIntArray(org.ballerinalang.model.values.BIntArray) BBlobArray(org.ballerinalang.model.values.BBlobArray) BStructType(org.ballerinalang.model.types.BStructType) BMapType(org.ballerinalang.model.types.BMapType) BBooleanArray(org.ballerinalang.model.values.BBooleanArray) StructureType(org.ballerinalang.model.values.StructureType) BFloatArray(org.ballerinalang.model.values.BFloatArray)

Example 5 with BFloatArray

use of org.ballerinalang.model.values.BFloatArray in project ballerina by ballerina-lang.

the class JSONUtils method jsonNodeToBFloatArray.

private static BFloatArray jsonNodeToBFloatArray(JsonNode arrayNode) {
    BFloatArray floatArray = new BFloatArray();
    for (int i = 0; i < arrayNode.size(); i++) {
        JsonNode jsonValue = arrayNode.get(i);
        floatArray.add(i, jsonNodeToFloat(jsonValue));
    }
    return floatArray;
}
Also used : BFloatArray(org.ballerinalang.model.values.BFloatArray)

Aggregations

BFloatArray (org.ballerinalang.model.values.BFloatArray)14 BValue (org.ballerinalang.model.values.BValue)9 BIntArray (org.ballerinalang.model.values.BIntArray)8 BStringArray (org.ballerinalang.model.values.BStringArray)8 Test (org.testng.annotations.Test)8 BBooleanArray (org.ballerinalang.model.values.BBooleanArray)7 BBlobArray (org.ballerinalang.model.values.BBlobArray)4 BRefValueArray (org.ballerinalang.model.values.BRefValueArray)4 BString (org.ballerinalang.model.values.BString)4 BJSON (org.ballerinalang.model.values.BJSON)3 BRefType (org.ballerinalang.model.values.BRefType)3 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)3 BMapType (org.ballerinalang.model.types.BMapType)2 BInteger (org.ballerinalang.model.values.BInteger)2 BStruct (org.ballerinalang.model.values.BStruct)2 StructureType (org.ballerinalang.model.values.StructureType)2 TypeRefCPEntry (org.ballerinalang.util.codegen.cpentries.TypeRefCPEntry)2 StringJoiner (java.util.StringJoiner)1 BEnumType (org.ballerinalang.model.types.BEnumType)1 BStructType (org.ballerinalang.model.types.BStructType)1