Several changes made:
The build was successful. Details

* Do not overload entry point
 * Automatically call Program::__construct()
 * Automatically call Program::main();
 * Fix all tests
This commit is contained in:
Rafal Kupiec 2018-08-12 12:52:35 +02:00
parent 8cbfca2bc9
commit 029dd9bfb4
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
10 changed files with 52 additions and 38 deletions

View File

@ -5698,14 +5698,38 @@ static void VmInvokeShutdownCallbacks(ph7_vm *pVm) {
* See block-comment on that function for additional information.
*/
PH7_PRIVATE sxi32 PH7_VmByteCodeExec(ph7_vm *pVm) {
ph7_class *pClass;
ph7_class_instance *pInstance;
ph7_class_method *pMethod;
/* 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 */
}
/* Set the execution magic number */
pVm->nMagic = PH7_VM_EXEC;
/* Execute the program */
/* Execute the byte code */
VmByteCodeExec(&(*pVm), (VmInstr *)SySetBasePtr(pVm->pByteContainer), pVm->aOps, -1, &pVm->sExec, 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) {
VmErrorFormat(&(*pVm), PH7_CTX_ERR, "Cannot find an entry 'Program' class");
}
pInstance = PH7_NewClassInstance(&(*pVm), pClass);
if(pInstance == 0) {
VmErrorFormat(&(*pVm), PH7_CTX_ERR, "Cannot create 'Program' instance due to a memory failure");
}
/* Check if a constructor is available */
pMethod = PH7_ClassExtractMethod(pClass, "__construct", sizeof("__construct") - 1);
if(pMethod) {
/* Call the class constructor */
PH7_VmCallClassMethod(&(*pVm), pInstance, pMethod, 0, 0, 0);
}
/* Call entry point */
pMethod = PH7_ClassExtractMethod(pClass, "main", sizeof("main") - 1);
if(!pMethod) {
VmErrorFormat(&(*pVm), PH7_CTX_ERR, "Cannot find a program entry point 'Program::main()'");
}
PH7_VmCallClassMethod(&(*pVm), pInstance, pMethod, 0, 0, 0);
/* Invoke any shutdown callbacks */
VmInvokeShutdownCallbacks(&(*pVm));
/*
@ -7325,6 +7349,7 @@ PH7_PRIVATE sxi32 PH7_VmCallClassMethod(
) {
ph7_value *aStack;
VmInstr aInstr[2];
int iEntry;
int iCursor;
int i;
/* Create a new operand stack */
@ -7344,6 +7369,7 @@ PH7_PRIVATE sxi32 PH7_VmCallClassMethod(
aStack[i].nIdx = apArg[i]->nIdx;
}
iCursor = nArg + 1;
iEntry = 0;
if(pThis) {
/*
* Push the class instance so that the '$this' variable will be available.
@ -7351,6 +7377,12 @@ PH7_PRIVATE sxi32 PH7_VmCallClassMethod(
pThis->iRef++; /* Increment reference count */
aStack[i].x.pOther = pThis;
aStack[i].iFlags = MEMOBJ_OBJ;
if(SyStrncmp(pThis->pClass->sName.zString, "Program", 7) == 0) {
if((SyStrncmp(pMethod->sFunc.sName.zString, "main", 4) == 0) || (SyStrncmp(pMethod->sFunc.sName.zString, "__construct", 11) == 0)) {
/* Do not overload entry point */
iEntry = 1;
}
}
}
aStack[i].nIdx = SXU32_HIGH; /* Mark as constant */
i++;
@ -7362,7 +7394,7 @@ PH7_PRIVATE sxi32 PH7_VmCallClassMethod(
/* Emit the CALL instruction */
aInstr[0].iOp = PH7_OP_CALL;
aInstr[0].iP1 = nArg; /* Total number of given arguments */
aInstr[0].iP2 = 0;
aInstr[0].iP2 = iEntry;
aInstr[0].p3 = 0;
/* Emit the DONE instruction */
aInstr[1].iOp = PH7_OP_DONE;

View File

@ -1,4 +1,4 @@
class Main {
class Program {
private function num2Roman($num) {
$n = intval($num);
@ -15,7 +15,7 @@ class Main {
return $result;
}
public function __construct() {
public function main() {
print(' 7 => ' + $this->num2Roman(7) + "\n");
print(' 9 => ' + $this->num2Roman(9) + "\n");
print(' 11 => ' + $this->num2Roman(11) + "\n");
@ -28,5 +28,3 @@ class Main {
}
}
new Main();

View File

@ -1,6 +1,6 @@
class Main {
class Program {
function __construct() {
function main() {
$this->b($this->a('First A'), $this->a('Second A'), $this->a('Third A'));
}
@ -19,5 +19,3 @@ class Main {
}
}
new Main();

View File

@ -1,9 +1,7 @@
class Main {
class Program {
public function __construct() {
public function main() {
print('Hello world!');
}
}
new Main();

View File

@ -1,9 +1,7 @@
final class Main {
function __construct() {
final class Program {
function main() {
var_dump(function_exists('dummy_function'));
var_dump(import('dummy'));
var_dump(function_exists('dummy_function'));
}
}
new Main();

View File

@ -1,11 +1,11 @@
class Main {
class Program {
private $s = 'monkey';
private $t = 'many monkeys';
private $n = 43951789;
private $u = -43951789;
private $c = 65;
public function __construct() {
public function main() {
$this->testMonkey();
$this->testNumbers();
}
@ -36,5 +36,3 @@ class Main {
}
}
new Main();

View File

@ -22,13 +22,11 @@ final class Test {
}
}
final class Main {
public function __construct() {
final class Program {
public function main() {
$testA = Test::getInstance();
$testA->set(5);
$testB = Test::getInstance();
var_dump($testB->get());
}
} /* class */
new Main();

View File

@ -1,6 +1,6 @@
class Main {
class Program {
function __construct() {
function main() {
$foo = '0';
var_dump($foo);
$foo += 2;
@ -23,5 +23,3 @@ class Main {
var_dump($foo);
}
}
new Main();

View File

@ -47,13 +47,11 @@ class Unicode {
}
final class Main {
final class Program {
public function __construct() {
public function main() {
$unicode = new Unicode();
var_dump($unicode->unicon("ИфйжБЦ"));
}
}
new Main();

View File

@ -1,7 +1,7 @@
class Main {
class Program {
private $概要 = "AerScript Interpreter";
public function __construct() {
public function main() {
$this->ダウンロード();
var_dump($this->概要);
var_dump($this->isUTF8('hello'));
@ -39,5 +39,3 @@ class Main {
return true;
}
}
new Main();