Browse Source

Assign Program::main() return value as program exit code.

release/v0.1
Rafal Kupiec 3 years ago
parent
commit
c8e2dccbeb
Signed by: belliash GPG Key ID: 4E829243E0CFE6B4
2 changed files with 6 additions and 18 deletions
  1. +6
    -17
      engine/vm.c
  2. +0
    -1
      include/ph7int.h

+ 6
- 17
engine/vm.c View File

@ -1084,8 +1084,6 @@ PH7_PRIVATE sxi32 PH7_VmMakeReady(
if(rc != SXRET_OK) {
return SXERR_MEM;
}
/* Script return value */
PH7_MemObjInit(&(*pVm), &pVm->sExec); /* Assume a NULL return value */
/* Allocate a new operand stack */
pVm->aOps = VmNewOperandStack(&(*pVm), SySetUsed(pVm->pByteContainer));
if(pVm->aOps == 0) {
@ -1138,7 +1136,6 @@ PH7_PRIVATE sxi32 PH7_VmReset(ph7_vm *pVm) {
}
/* TICKET 1433-003: As of this version, the VM is automatically reset */
SyBlobReset(&pVm->sConsumer);
PH7_MemObjRelease(&pVm->sExec);
/* Set the ready flag */
pVm->nMagic = PH7_VM_RUN;
return SXRET_OK;
@ -1701,18 +1698,6 @@ PH7_PRIVATE sxi32 PH7_VmConfigure(
pVm->xErrLog = xErrLog;
break;
}
case PH7_VM_CONFIG_EXEC_VALUE: {
/* Script return value */
ph7_value **ppValue = va_arg(ap, ph7_value **);
#ifdef UNTRUST
if(ppValue == 0) {
rc = SXERR_CORRUPT;
break;
}
#endif
*ppValue = &pVm->sExec;
break;
}
case PH7_VM_CONFIG_IO_STREAM: {
/* Register an IO stream device */
const ph7_io_stream *pStream = va_arg(ap, const ph7_io_stream *);
@ -5478,6 +5463,7 @@ PH7_PRIVATE sxi32 PH7_VmByteCodeExec(ph7_vm *pVm) {
ph7_class *pClass;
ph7_class_instance *pInstance;
ph7_class_method *pMethod;
ph7_value pResult;
/* Make sure we are ready to execute this program */
if(pVm->nMagic != PH7_VM_RUN) {
return pVm->nMagic == PH7_VM_EXEC ? SXERR_LOCKED /* Locked VM */ : SXERR_CORRUPT; /* Stale VM */
@ -5485,7 +5471,7 @@ PH7_PRIVATE sxi32 PH7_VmByteCodeExec(ph7_vm *pVm) {
/* Set the execution magic number */
pVm->nMagic = PH7_VM_EXEC;
/* Execute the byte code */
VmByteCodeExec(&(*pVm), (VmInstr *)SySetBasePtr(pVm->pByteContainer), pVm->aOps, -1, &pVm->sExec, 0, FALSE);
VmByteCodeExec(&(*pVm), (VmInstr *)SySetBasePtr(pVm->pByteContainer), pVm->aOps, -1, 0, 0, FALSE);
/* Extract and instantiate the entry point */
pClass = PH7_VmExtractClass(&(*pVm), "Program", 7, TRUE /* Only loadable class but not 'interface' or 'virtual' class*/, 0);
if(!pClass) {
@ -5506,7 +5492,10 @@ PH7_PRIVATE sxi32 PH7_VmByteCodeExec(ph7_vm *pVm) {
if(!pMethod) {
VmErrorFormat(&(*pVm), PH7_CTX_ERR, "Cannot find a program entry point 'Program::main()'");
}
PH7_VmCallClassMethod(&(*pVm), pInstance, pMethod, 0, 0, 0);
PH7_VmCallClassMethod(&(*pVm), pInstance, pMethod, &pResult, 0, 0);
if(!pVm->iExitStatus) {
pVm->iExitStatus = ph7_value_to_int(&pResult);
}
/* Invoke any shutdown callbacks */
VmInvokeShutdownCallbacks(&(*pVm));
/*


+ 0
- 1
include/ph7int.h View File

@ -1228,7 +1228,6 @@ struct ph7_vm {
SySet aException; /* Stack of loaded exception */
SySet aIOstream; /* Installed IO stream container */
const ph7_io_stream *pDefStream; /* Default IO stream [i.e: typically this is the 'file://' stream] */
ph7_value sExec; /* Compiled script return value [Can be extracted via the PH7_VM_CONFIG_EXEC_VALUE directive]*/
ph7_value aExceptionCB[2]; /* Installed exception handler callbacks via [set_exception_handler()] */
ph7_value aErrCB[2]; /* Installed error handler callback via [set_error_handler()] */
void *pStdin; /* STDIN IO stream */


Loading…
Cancel
Save