Browse Source

Fix method parameters.

pull/50/head
Rafal Kupiec 3 years ago
parent
commit
e6e59d299e
Signed by: belliash GPG Key ID: 4E829243E0CFE6B4
2 changed files with 73 additions and 65 deletions
  1. +39
    -50
      engine/compiler.c
  2. +34
    -15
      engine/vm.c

+ 39
- 50
engine/compiler.c View File

@ -2905,9 +2905,7 @@ static sxi32 PH7_GenStateCollectFuncArgs(ph7_vm_func *pFunc, ph7_gen_state *pGen
if(pIn->nType & (PH7_TK_ID | PH7_TK_KEYWORD)) {
if(pIn->nType & PH7_TK_KEYWORD) {
sxu32 nKey = (sxu32)(SX_PTR_TO_INT(pIn->pUserData));
if(nKey & PH7_KEYWORD_ARRAY) {
sArg.nType = MEMOBJ_HASHMAP;
} else if(nKey & PH7_KEYWORD_BOOL) {
if(nKey & PH7_KEYWORD_BOOL) {
sArg.nType = MEMOBJ_BOOL;
} else if(nKey & PH7_KEYWORD_CALLBACK) {
sArg.nType = MEMOBJ_CALL;
@ -2943,6 +2941,10 @@ static sxi32 PH7_GenStateCollectFuncArgs(ph7_vm_func *pFunc, ph7_gen_state *pGen
}
}
pIn++;
if((pIn->nType & PH7_TK_OSB) && &pIn[1] < pEnd && (pIn[1].nType & PH7_TK_CSB)) {
sArg.nType |= MEMOBJ_HASHMAP;
pIn += 2;
}
}
if(pIn >= pEnd) {
rc = PH7_GenCompileError(&(*pGen), E_ERROR, pGen->pIn->nLine, "Missing argument name");
@ -3014,54 +3016,41 @@ static sxi32 PH7_GenStateCollectFuncArgs(ph7_vm_func *pFunc, ph7_gen_state *pGen
/* Class name */
SyBlobAppend(&sSig, SyStringData(&sArg.sClass), SyStringLength(&sArg.sClass));
} else {
int c;
c = 'n'; /* cc warning */
int c = 'n'; /* cc warning */
/* Type leading character */
switch(sArg.nType) {
case MEMOBJ_HASHMAP:
/* Hashmap aka 'array' */
c = 'h';
break;
case MEMOBJ_BOOL:
/* Bool */
c = 'b';
break;
case MEMOBJ_CALL:
/* Callback */
c = 'a';
break;
case MEMOBJ_CHAR:
/* Callback */
c = 'c';
break;
case MEMOBJ_INT:
/* Integer */
c = 'i';
break;
case MEMOBJ_MIXED:
/* Mixed */
c = 'm';
break;
case MEMOBJ_OBJ:
/* Object */
c = 'o';
break;
case MEMOBJ_REAL:
/* Float */
c = 'f';
break;
case MEMOBJ_RES:
/* Resource */
c = 'r';
break;
case MEMOBJ_STRING:
/* String */
c = 's';
break;
case MEMOBJ_VOID:
/* Void */
c = 'v';
break;
if(sArg.nType & MEMOBJ_BOOL) {
/* Bool */
c = 'b';
} else if(sArg.nType & MEMOBJ_CALL) {
/* Callback */
c = 'a';
} else if(sArg.nType & MEMOBJ_CHAR) {
/* Char */
c = 'c';
} else if(sArg.nType & MEMOBJ_INT) {
/* Integer */
c = 'i';
} else if(sArg.nType & MEMOBJ_MIXED) {
/* Mixed */
c = 'm';
} else if(sArg.nType & MEMOBJ_OBJ) {
/* Object */
c = 'o';
} else if(sArg.nType & MEMOBJ_REAL) {
/* Float */
c = 'f';
} else if(sArg.nType & MEMOBJ_RES) {
/* Resource */
c = 'r';
} else if(sArg.nType & MEMOBJ_STRING) {
/* String */
c = 's';
} else if(sArg.nType & MEMOBJ_VOID) {
/* Void */
c = 'v';
}
if(sArg.nType & MEMOBJ_HASHMAP) {
c = SyToUpper(c);
}
SyBlobAppend(&sSig, (const void *)&c, sizeof(char));
}


+ 34
- 15
engine/vm.c View File

@ -553,27 +553,42 @@ static ph7_vm_func *VmOverload(
SyBlobInit(&sSig, &pVm->sAllocator);
for(j = 0 ; j < nArg ; j++) {
int c = 'n'; /* null */
if(aArg[j].iFlags & MEMOBJ_HASHMAP) {
/* Hashmap */
c = 'h';
} else if(aArg[j].iFlags & MEMOBJ_BOOL) {
/* bool */
if(aArg[j].iFlags & MEMOBJ_BOOL) {
/* Bool */
c = 'b';
} else if(aArg[j].iFlags & MEMOBJ_CALL) {
/* Callback */
c = 'a';
} else if(aArg[j].iFlags & MEMOBJ_CHAR) {
/* Char */
c = 'c';
} else if(aArg[j].iFlags & MEMOBJ_INT) {
/* int */
/* Integer */
c = 'i';
} else if(aArg[j].iFlags & MEMOBJ_STRING) {
/* String */
c = 's';
} else if(aArg[j].iFlags & MEMOBJ_REAL) {
/* Float */
c = 'f';
} else if(aArg[j].iFlags & MEMOBJ_MIXED) {
/* Mixed */
c = 'm';
} else if(aArg[j].iFlags & MEMOBJ_OBJ) {
/* Class instance */
ph7_class *pClass = ((ph7_class_instance *)aArg[j].x.pOther)->pClass;
SyString *pName = &pClass->sName;
SyBlobAppend(&sSig, (const void *)pName->zString, pName->nByte);
c = -1;
} else if(aArg[j].iFlags & MEMOBJ_REAL) {
/* Float */
c = 'f';
} else if(aArg[j].iFlags & MEMOBJ_RES) {
/* Resource */
c = 'r';
} else if(aArg[j].iFlags & MEMOBJ_STRING) {
/* String */
c = 's';
} else if(aArg[j].iFlags & MEMOBJ_VOID) {
/* Void */
c = 'v';
}
if(aArg[j].iFlags & MEMOBJ_HASHMAP && (aArg[j].iFlags & MEMOBJ_OBJ) == 0) {
c = SyToUpper(c);
}
if(c > 0) {
SyBlobAppend(&sSig, (const void *)&c, sizeof(char));
@ -4982,7 +4997,7 @@ static sxi32 VmByteCodeExec(
}
}
}
} else if(aFormalArg[n].nType != MEMOBJ_MIXED && ((pArg->iFlags & aFormalArg[n].nType) == 0)) {
} else if((aFormalArg[n].nType & MEMOBJ_MIXED) == 0 && pArg->iFlags != aFormalArg[n].nType) {
if(aFormalArg[n].nType == MEMOBJ_REAL && (pArg->iFlags & MEMOBJ_INT)) {
/* Silently typecast integer value to float */
ProcMemObjCast xCast = PH7_MemObjCastMethod(aFormalArg[n].nType);
@ -5073,7 +5088,7 @@ static sxi32 VmByteCodeExec(
if(rc == PH7_ABORT) {
goto Abort;
}
if(aFormalArg[n].nType != MEMOBJ_MIXED && aFormalArg[n].nType > 0 && ((pObj->iFlags & aFormalArg[n].nType) == 0)) {
if((aFormalArg[n].nType & MEMOBJ_MIXED) == 0 && aFormalArg[n].nType > 0 && pObj->iFlags != aFormalArg[n].nType) {
if(aFormalArg[n].nType == MEMOBJ_REAL && (pObj->iFlags & MEMOBJ_INT)) {
/* Silently typecast integer value to float */
ProcMemObjCast xCast = PH7_MemObjCastMethod(aFormalArg[n].nType);
@ -5393,12 +5408,16 @@ PH7_PRIVATE sxi32 PH7_VmByteCodeExec(ph7_vm *pVm) {
zParam = SyStrtok(NULL, " ");
}
}
/* Call entry point */
/* Extract script entry point */
pMethod = PH7_ClassExtractMethod(pClass, "main", sizeof("main") - 1);
if(!pMethod) {
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Cannot find a program entry point 'Program::main()'");
}
/* A set of arguments is stored in array of strings */
pArgs->iFlags |= MEMOBJ_STRING;
/* Initialize variable for return value */
PH7_MemObjInit(pVm, &pResult);
/* Call entry point */
PH7_VmCallClassMethod(&(*pVm), pInstance, pMethod, &pResult, 1, &pArgs);
if(!pVm->iExitStatus) {
pVm->iExitStatus = ph7_value_to_int(&pResult);


Loading…
Cancel
Save