Search in sources :

Example 11 with PackageInfo

use of org.ballerinalang.util.codegen.PackageInfo 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 12 with PackageInfo

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

the class BLangProgramRunner method runService.

public static void runService(ProgramFile programFile) {
    if (!programFile.isServiceEPAvailable()) {
        throw new BallerinaException("no services found in '" + programFile.getProgramFilePath() + "'");
    }
    // Get the service package
    PackageInfo servicesPackage = programFile.getEntryPackage();
    if (servicesPackage == null) {
        throw new BallerinaException("no services found in '" + programFile.getProgramFilePath() + "'");
    }
    Debugger debugger = new Debugger(programFile);
    initDebugger(programFile, debugger);
    boolean distributedTxEnabled = CompilerUtils.isDistributedTransactionsEnabled();
    programFile.setDistributedTransactionEnabled(distributedTxEnabled);
    // Invoke package init function
    BLangFunctions.invokePackageInitFunction(servicesPackage.getInitFunctionInfo());
    BLangFunctions.invokeVMUtilFunction(servicesPackage.getStartFunctionInfo());
}
Also used : Debugger(org.ballerinalang.util.debugger.Debugger) PackageInfo(org.ballerinalang.util.codegen.PackageInfo) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException)

Example 13 with PackageInfo

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

the class BLangConnectorSPIUtil method getPackageEndpoint.

public static BStruct getPackageEndpoint(ProgramFile programFile, String pkgName, String endpointName) {
    final PackageInfo packageInfo = programFile.getPackageInfo(pkgName);
    if (packageInfo == null) {
        throw new BallerinaConnectorException("Incorrect package name");
    }
    final PackageVarInfo packageVarInfo = packageInfo.getPackageVarInfo(endpointName);
    if (packageVarInfo == null) {
        throw new BallerinaConnectorException("Can't locate " + endpointName + " endpoint variable");
    }
    return (BStruct) programFile.getGlobalMemoryBlock().getRefField(packageVarInfo.getGlobalMemIndex());
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) PackageInfo(org.ballerinalang.util.codegen.PackageInfo) PackageVarInfo(org.ballerinalang.util.codegen.PackageVarInfo)

Example 14 with PackageInfo

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

the class BLangConnectorSPIUtil method createBStruct.

public static BStruct createBStruct(ProgramFile programFile, String pkgPath, String structName, Object... values) {
    PackageInfo packageInfo = programFile.getPackageInfo(pkgPath);
    if (packageInfo == null) {
        throw new BallerinaConnectorException("package - " + pkgPath + " does not exist");
    }
    StructInfo structInfo = packageInfo.getStructInfo(structName);
    if (structInfo == null) {
        throw new BallerinaConnectorException("struct - " + structName + " does not exist");
    }
    return BLangVMStructs.createBStruct(structInfo, values);
}
Also used : StructInfo(org.ballerinalang.util.codegen.StructInfo) PackageInfo(org.ballerinalang.util.codegen.PackageInfo)

Example 15 with PackageInfo

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

the class BCompileUtil method createAndGetStruct.

public static BStruct createAndGetStruct(ProgramFile programFile, String packagePath, String structName) {
    PackageInfo structPackageInfo = programFile.getPackageInfo(packagePath);
    StructInfo structInfo = structPackageInfo.getStructInfo(structName);
    BStructType structType = structInfo.getType();
    return new BStruct(structType);
}
Also used : BStructType(org.ballerinalang.model.types.BStructType) BStruct(org.ballerinalang.model.values.BStruct) StructInfo(org.ballerinalang.util.codegen.StructInfo) PackageInfo(org.ballerinalang.util.codegen.PackageInfo)

Aggregations

PackageInfo (org.ballerinalang.util.codegen.PackageInfo)48 StructInfo (org.ballerinalang.util.codegen.StructInfo)35 BStruct (org.ballerinalang.model.values.BStruct)17 ProgramFile (org.ballerinalang.util.codegen.ProgramFile)10 BValue (org.ballerinalang.model.values.BValue)6 BStructType (org.ballerinalang.model.types.BStructType)5 FunctionInfo (org.ballerinalang.util.codegen.FunctionInfo)5 Debugger (org.ballerinalang.util.debugger.Debugger)5 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)5 BInteger (org.ballerinalang.model.values.BInteger)2 BMap (org.ballerinalang.model.values.BMap)2 BString (org.ballerinalang.model.values.BString)2 SocketIOChannel (org.ballerinalang.nativeimpl.io.channels.SocketIOChannel)2 Channel (org.ballerinalang.nativeimpl.io.channels.base.Channel)2 TesterinaFunction (org.ballerinalang.testerina.core.entity.TesterinaFunction)2 Instruction (org.ballerinalang.util.codegen.Instruction)2 PackageVarInfo (org.ballerinalang.util.codegen.PackageVarInfo)2 BLangRuntimeException (org.ballerinalang.util.exceptions.BLangRuntimeException)2 Test (org.testng.annotations.Test)2 PrintStream (java.io.PrintStream)1