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);
}
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;
}
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());
}
}
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);
}
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();
}
Aggregations