Search in sources :

Example 11 with Operand

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

the class CodeGenerator method visit.

@Override
public void visit(BLangIsAssignableExpr assignableExpr) {
    genNode(assignableExpr.lhsExpr, this.env);
    RegIndex regIndex = calcAndGetExprRegIndex(assignableExpr);
    Operand typeCPIndex = getTypeCPIndex(assignableExpr.targetType);
    emit(assignableExpr.opSymbol.opcode, assignableExpr.lhsExpr.regIndex, typeCPIndex, regIndex);
}
Also used : Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 12 with Operand

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

the class CodeGenerator method visit.

public void visit(BLangTypeConversionExpr convExpr) {
    int opcode = convExpr.conversionSymbol.opcode;
    // Figure out the reg index of the result value
    BType castExprType = convExpr.type;
    RegIndex convExprRegIndex = calcAndGetExprRegIndex(convExpr.regIndex, castExprType.tag);
    convExpr.regIndex = convExprRegIndex;
    if (opcode == InstructionCodes.NOP) {
        convExpr.expr.regIndex = createLHSRegIndex(convExprRegIndex);
        genNode(convExpr.expr, this.env);
        return;
    }
    genNode(convExpr.expr, this.env);
    if (opcode == InstructionCodes.MAP2T || opcode == InstructionCodes.JSON2T || opcode == InstructionCodes.ANY2T || opcode == InstructionCodes.ANY2C || opcode == InstructionCodes.ANY2E || opcode == InstructionCodes.ANY2M || opcode == InstructionCodes.CHECKCAST) {
        Operand typeCPIndex = getTypeCPIndex(convExpr.targetType);
        emit(opcode, convExpr.expr.regIndex, typeCPIndex, convExprRegIndex);
    } else {
        emit(opcode, convExpr.expr.regIndex, convExprRegIndex);
    }
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 13 with Operand

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

the class CodeGenerator method visit.

public void visit(BLangUnaryExpr unaryExpr) {
    RegIndex exprIndex = calcAndGetExprRegIndex(unaryExpr);
    if (OperatorKind.ADD.equals(unaryExpr.operator) || OperatorKind.UNTAINT.equals(unaryExpr.operator)) {
        unaryExpr.expr.regIndex = createLHSRegIndex(unaryExpr.regIndex);
        genNode(unaryExpr.expr, this.env);
        return;
    }
    int opcode;
    genNode(unaryExpr.expr, this.env);
    if (OperatorKind.TYPEOF.equals(unaryExpr.operator)) {
        opcode = unaryExpr.opSymbol.opcode;
        if (opcode == InstructionCodes.TYPEOF) {
            emit(opcode, unaryExpr.expr.regIndex, exprIndex);
        } else {
            Operand typeCPIndex = getTypeCPIndex(unaryExpr.expr.type);
            emit(opcode, typeCPIndex, exprIndex);
        }
    } else if (OperatorKind.LENGTHOF.equals(unaryExpr.operator)) {
        Operand typeCPIndex = getTypeCPIndex(unaryExpr.expr.type);
        opcode = unaryExpr.opSymbol.opcode;
        emit(opcode, unaryExpr.expr.regIndex, typeCPIndex, exprIndex);
    } else {
        opcode = unaryExpr.opSymbol.opcode;
        emit(opcode, unaryExpr.expr.regIndex, exprIndex);
    }
}
Also used : Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 14 with Operand

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

the class CodeGenerator method visit.

@Override
public void visit(BLangTableLiteral tableLiteral) {
    tableLiteral.regIndex = calcAndGetExprRegIndex(tableLiteral);
    Operand typeCPIndex = getTypeCPIndex(tableLiteral.type);
    emit(InstructionCodes.NEWTABLE, tableLiteral.regIndex, typeCPIndex);
}
Also used : Operand(org.wso2.ballerinalang.programfile.Instruction.Operand)

Example 15 with Operand

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

the class CodeGenerator method generateURILookupInstructions.

private void generateURILookupInstructions(Map<Name, BXMLNSSymbol> namespaces, RegIndex localNameRegIndex, RegIndex uriRegIndex, RegIndex targetQNameRegIndex, DiagnosticPos pos, SymbolEnv symbolEnv) {
    if (namespaces.isEmpty()) {
        createQNameWithoutPrefix(localNameRegIndex, uriRegIndex, targetQNameRegIndex);
        return;
    }
    Stack<Operand> endJumpInstrStack = new Stack<>();
    String prefix;
    for (Entry<Name, BXMLNSSymbol> keyValues : namespaces.entrySet()) {
        prefix = keyValues.getKey().getValue();
        // skip the default namespace
        if (prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) {
            continue;
        }
        // Below section creates the condition to compare the namespace URIs
        // store the comparing uri as string
        BXMLNSSymbol nsSymbol = keyValues.getValue();
        int opcode = getOpcode(TypeTags.STRING, InstructionCodes.IEQ);
        RegIndex conditionExprIndex = getRegIndex(TypeTags.BOOLEAN);
        emit(opcode, uriRegIndex, getNamespaceURIIndex(nsSymbol, symbolEnv), conditionExprIndex);
        Operand ifCondJumpAddr = getOperand(-1);
        emit(InstructionCodes.BR_FALSE, conditionExprIndex, ifCondJumpAddr);
        // Below section creates instructions to be executed, if the above condition succeeds (then body)
        // create the prefix literal
        RegIndex prefixIndex = createStringLiteral(prefix, null, env);
        // create a qname
        emit(InstructionCodes.NEWQNAME, localNameRegIndex, uriRegIndex, prefixIndex, targetQNameRegIndex);
        Operand endJumpAddr = getOperand(-1);
        emit(InstructionCodes.GOTO, endJumpAddr);
        endJumpInstrStack.add(endJumpAddr);
        ifCondJumpAddr.value = nextIP();
    }
    // else part. create a qname with empty prefix
    createQNameWithoutPrefix(localNameRegIndex, uriRegIndex, targetQNameRegIndex);
    while (!endJumpInstrStack.isEmpty()) {
        endJumpInstrStack.pop().value = nextIP();
    }
}
Also used : BXMLNSSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol) Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) Stack(java.util.Stack) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) Name(org.ballerinalang.model.Name) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Aggregations

Operand (org.wso2.ballerinalang.programfile.Instruction.Operand)42 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)28 RegIndex (org.wso2.ballerinalang.programfile.Instruction.RegIndex)18 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)10 Instruction (org.wso2.ballerinalang.programfile.Instruction)6 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)5 UTF8CPEntry (org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry)5 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)4 BLangRecordKeyValue (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangRecordKeyValue)4 BLangXMLQuotedString (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)4 StructureRefCPEntry (org.wso2.ballerinalang.programfile.cpentries.StructureRefCPEntry)4 BXMLNSSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol)3 BMapType (org.wso2.ballerinalang.compiler.semantics.model.types.BMapType)3 BLangLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral)3 ErrorTableEntry (org.wso2.ballerinalang.programfile.ErrorTableEntry)3 WorkerDataChannelInfo (org.wso2.ballerinalang.programfile.WorkerDataChannelInfo)3 ErrorTableAttributeInfo (org.wso2.ballerinalang.programfile.attributes.ErrorTableAttributeInfo)3 StringCPEntry (org.wso2.ballerinalang.programfile.cpentries.StringCPEntry)3 TypeRefCPEntry (org.wso2.ballerinalang.programfile.cpentries.TypeRefCPEntry)3 WorkerDataChannelRefCPEntry (org.wso2.ballerinalang.programfile.cpentries.WorkerDataChannelRefCPEntry)3