Search in sources :

Example 41 with RegIndex

use of org.wso2.ballerinalang.programfile.Instruction.RegIndex in project ballerina by ballerina-lang.

the class CodeGenerator method visit.

public void visit(BLangCatch bLangCatch) {
    // Define local variable index for Error.
    BLangVariable variable = bLangCatch.param;
    RegIndex lvIndex = getLVIndex(variable.symbol.type.tag);
    variable.symbol.varIndex = lvIndex;
    emit(InstructionFactory.get(InstructionCodes.ERRSTORE, lvIndex));
    // Visit Catch Block.
    genNode(bLangCatch.body, env);
}
Also used : BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 42 with RegIndex

use of org.wso2.ballerinalang.programfile.Instruction.RegIndex in project ballerina by ballerina-lang.

the class CodeGenerator method visit.

// Expressions
@Override
public void visit(BLangLiteral literalExpr) {
    int opcode;
    Operand regIndex = calcAndGetExprRegIndex(literalExpr);
    int typeTag = literalExpr.type.tag;
    switch(typeTag) {
        case TypeTags.INT:
            long longVal = (Long) literalExpr.value;
            if (longVal >= 0 && longVal <= 5) {
                opcode = InstructionCodes.ICONST_0 + (int) longVal;
                emit(opcode, regIndex);
            } else {
                int intCPEntryIndex = currentPkgInfo.addCPEntry(new IntegerCPEntry(longVal));
                emit(InstructionCodes.ICONST, getOperand(intCPEntryIndex), regIndex);
            }
            break;
        case TypeTags.FLOAT:
            double doubleVal = (Double) literalExpr.value;
            if (doubleVal == 0 || doubleVal == 1 || doubleVal == 2 || doubleVal == 3 || doubleVal == 4 || doubleVal == 5) {
                opcode = InstructionCodes.FCONST_0 + (int) doubleVal;
                emit(opcode, regIndex);
            } else {
                int floatCPEntryIndex = currentPkgInfo.addCPEntry(new FloatCPEntry(doubleVal));
                emit(InstructionCodes.FCONST, getOperand(floatCPEntryIndex), regIndex);
            }
            break;
        case TypeTags.STRING:
            String strValue = (String) literalExpr.value;
            StringCPEntry stringCPEntry = new StringCPEntry(addUTF8CPEntry(currentPkgInfo, strValue), strValue);
            int strCPIndex = currentPkgInfo.addCPEntry(stringCPEntry);
            emit(InstructionCodes.SCONST, getOperand(strCPIndex), regIndex);
            break;
        case TypeTags.BOOLEAN:
            boolean booleanVal = (Boolean) literalExpr.value;
            if (!booleanVal) {
                opcode = InstructionCodes.BCONST_0;
            } else {
                opcode = InstructionCodes.BCONST_1;
            }
            emit(opcode, regIndex);
            break;
        case TypeTags.NULL:
            emit(InstructionCodes.RCONST_NULL, regIndex);
    }
}
Also used : StringCPEntry(org.wso2.ballerinalang.programfile.cpentries.StringCPEntry) Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) IntegerCPEntry(org.wso2.ballerinalang.programfile.cpentries.IntegerCPEntry) FloatCPEntry(org.wso2.ballerinalang.programfile.cpentries.FloatCPEntry) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Aggregations

RegIndex (org.wso2.ballerinalang.programfile.Instruction.RegIndex)37 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)22 Operand (org.wso2.ballerinalang.programfile.Instruction.Operand)20 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)13 UTF8CPEntry (org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry)6 BLangXMLQuotedString (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)5 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)4 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)4 BXMLNSSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol)3 BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)3 Stack (java.util.Stack)2 Name (org.ballerinalang.model.Name)2 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)2 BTypeSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol)2 BMapType (org.wso2.ballerinalang.compiler.semantics.model.types.BMapType)2 BLangEnumerator (org.wso2.ballerinalang.compiler.tree.BLangEnum.BLangEnumerator)2 BLangIdentifier (org.wso2.ballerinalang.compiler.tree.BLangIdentifier)2 BLangLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral)2 BLangRecordKeyValue (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangRecordKeyValue)2 EnumInfo (org.wso2.ballerinalang.programfile.EnumInfo)2