Search in sources :

Example 1 with FunctionInfo

use of org.ballerinalang.util.codegen.FunctionInfo in project ballerina by ballerina-lang.

the class CPU method invokeVirtualFunction.

private static WorkerExecutionContext invokeVirtualFunction(WorkerExecutionContext ctx, int receiver, FunctionInfo virtualFuncInfo, int[] argRegs, int[] retRegs, int flags) {
    BStruct structVal = (BStruct) ctx.workerLocal.refRegs[receiver];
    if (structVal == null) {
        ctx.setError(BLangVMErrors.createNullRefException(ctx));
        handleError(ctx);
        return null;
    }
    StructInfo structInfo = structVal.getType().structInfo;
    AttachedFunctionInfo attachedFuncInfo = structInfo.funcInfoEntries.get(virtualFuncInfo.getName());
    FunctionInfo concreteFuncInfo = attachedFuncInfo.functionInfo;
    return BLangFunctions.invokeCallable(concreteFuncInfo, ctx, argRegs, retRegs, false, flags);
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) AttachedFunctionInfo(org.ballerinalang.util.codegen.AttachedFunctionInfo) StructInfo(org.ballerinalang.util.codegen.StructInfo) FunctionInfo(org.ballerinalang.util.codegen.FunctionInfo) AttachedFunctionInfo(org.ballerinalang.util.codegen.AttachedFunctionInfo)

Example 2 with FunctionInfo

use of org.ballerinalang.util.codegen.FunctionInfo in project ballerina by ballerina-lang.

the class BLangProgramRunner method getMainFunction.

public static FunctionInfo getMainFunction(PackageInfo mainPkgInfo) {
    String errorMsg = "main function not found in  '" + mainPkgInfo.getProgramFile().getProgramFilePath() + "'";
    FunctionInfo mainFuncInfo = mainPkgInfo.getFunctionInfo("main");
    if (mainFuncInfo == null) {
        throw new BallerinaException(errorMsg);
    }
    BType[] paramTypes = mainFuncInfo.getParamTypes();
    BType[] retParamTypes = mainFuncInfo.getRetParamTypes();
    BArrayType argsType = new BArrayType(BTypes.typeString);
    if (paramTypes.length != 1 || !paramTypes[0].equals(argsType) || retParamTypes.length != 0) {
        throw new BallerinaException(errorMsg);
    }
    return mainFuncInfo;
}
Also used : BArrayType(org.ballerinalang.model.types.BArrayType) BType(org.ballerinalang.model.types.BType) FunctionInfo(org.ballerinalang.util.codegen.FunctionInfo) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException)

Example 3 with FunctionInfo

use of org.ballerinalang.util.codegen.FunctionInfo in project ballerina by ballerina-lang.

the class BLangProgramRunner method runMain.

public static void runMain(ProgramFile programFile, String[] args) {
    if (!programFile.isMainEPAvailable()) {
        throw new BallerinaException("main function not found in  '" + programFile.getProgramFilePath() + "'");
    }
    PackageInfo mainPkgInfo = programFile.getEntryPackage();
    if (mainPkgInfo == null) {
        throw new BallerinaException("main function not found in  '" + programFile.getProgramFilePath() + "'");
    }
    Debugger debugger = new Debugger(programFile);
    initDebugger(programFile, debugger);
    boolean distributedTxEnabled = CompilerUtils.isDistributedTransactionsEnabled();
    programFile.setDistributedTransactionEnabled(distributedTxEnabled);
    FunctionInfo mainFuncInfo = getMainFunction(mainPkgInfo);
    try {
        BLangFunctions.invokeEntrypointCallable(programFile, mainPkgInfo, mainFuncInfo, extractMainArgs(args));
    } finally {
        if (debugger.isDebugEnabled()) {
            debugger.notifyExit();
        }
        BLangFunctions.invokeVMUtilFunction(mainPkgInfo.getStopFunctionInfo());
    }
}
Also used : Debugger(org.ballerinalang.util.debugger.Debugger) PackageInfo(org.ballerinalang.util.codegen.PackageInfo) FunctionInfo(org.ballerinalang.util.codegen.FunctionInfo) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException)

Example 4 with FunctionInfo

use of org.ballerinalang.util.codegen.FunctionInfo in project ballerina by ballerina-lang.

the class TransactionUtils method invokeCoordinatorFunction.

private static BValue[] invokeCoordinatorFunction(WorkerExecutionContext ctx, String functionName, BValue[] args) {
    PackageInfo packageInfo = ctx.programFile.getPackageInfo(TransactionConstants.COORDINATOR_PACKAGE);
    FunctionInfo functionInfo = packageInfo.getFunctionInfo(functionName);
    return BLangFunctions.invokeCallable(functionInfo, args);
}
Also used : PackageInfo(org.ballerinalang.util.codegen.PackageInfo) FunctionInfo(org.ballerinalang.util.codegen.FunctionInfo)

Example 5 with FunctionInfo

use of org.ballerinalang.util.codegen.FunctionInfo in project ballerina by ballerina-lang.

the class DebuggerExecutor method run.

@Override
public void run() {
    ProgramFile programFile = result.getProgFile();
    programFile.setDebugger(debugger);
    debugger.init();
    debugger.addDebugPoints(breakPoints);
    debugger.releaseLock();
    debugger.waitTillDebuggeeResponds();
    // Prepare main function arguments
    BStringArray arrayArgs = new BStringArray();
    for (int i = 0; i < args.length; i++) {
        arrayArgs.add(i, args[i]);
    }
    // Invoke package init function
    FunctionInfo mainFuncInfo = BLangProgramRunner.getMainFunction(mainPkgInfo);
    try {
        BLangFunctions.invokeEntrypointCallable(programFile, mainPkgInfo, mainFuncInfo, new BValue[] { arrayArgs });
    } catch (Exception e) {
        log.debug("error occurred, invoking the function - " + e.getMessage(), e);
    } finally {
        BLangFunctions.invokeVMUtilFunction(mainPkgInfo.getStopFunctionInfo());
    }
    debugger.notifyExit();
}
Also used : FunctionInfo(org.ballerinalang.util.codegen.FunctionInfo) BStringArray(org.ballerinalang.model.values.BStringArray) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException) ProgramFile(org.ballerinalang.util.codegen.ProgramFile)

Aggregations

FunctionInfo (org.ballerinalang.util.codegen.FunctionInfo)9 PackageInfo (org.ballerinalang.util.codegen.PackageInfo)5 ProgramFile (org.ballerinalang.util.codegen.ProgramFile)3 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)3 BStringArray (org.ballerinalang.model.values.BStringArray)2 BStruct (org.ballerinalang.model.values.BStruct)2 BValue (org.ballerinalang.model.values.BValue)2 AttachedFunctionInfo (org.ballerinalang.util.codegen.AttachedFunctionInfo)2 Instruction (org.ballerinalang.util.codegen.Instruction)2 Debugger (org.ballerinalang.util.debugger.Debugger)2 StringJoiner (java.util.StringJoiner)1 BArrayType (org.ballerinalang.model.types.BArrayType)1 BMapType (org.ballerinalang.model.types.BMapType)1 BType (org.ballerinalang.model.types.BType)1 BBlobArray (org.ballerinalang.model.values.BBlobArray)1 BBooleanArray (org.ballerinalang.model.values.BBooleanArray)1 BFloatArray (org.ballerinalang.model.values.BFloatArray)1 BFunctionPointer (org.ballerinalang.model.values.BFunctionPointer)1 BIntArray (org.ballerinalang.model.values.BIntArray)1 BJSON (org.ballerinalang.model.values.BJSON)1