Browse Source

Save the closure return data type for further use.

pull/50/head
Rafal Kupiec 3 years ago
parent
commit
051bca470e
Signed by: belliash GPG Key ID: 4E829243E0CFE6B4
  1. 32
      engine/compiler.c
  2. 1
      include/ph7int.h

32
engine/compiler.c

@ -994,7 +994,36 @@ PH7_PRIVATE sxi32 PH7_CompileClosure(ph7_gen_state *pGen, sxi32 iCompileFlag) {
sxu32 nIdx;
sxu32 nLen;
sxi32 rc;
pGen->pIn++; /* Jump the 'function' keyword */
sxu32 nType;
sxu32 nKey = (sxu32)(SX_PTR_TO_INT(pGen->pIn->pUserData));
if(nKey & PH7_KEYWORD_BOOL) {
nType = MEMOBJ_BOOL;
} else if(nKey & PH7_KEYWORD_CALLBACK) {
nType = MEMOBJ_CALL;
} else if(nKey & PH7_KEYWORD_CHAR) {
nType = MEMOBJ_CHAR;
} else if(nKey & PH7_KEYWORD_FLOAT) {
nType = MEMOBJ_REAL;
} else if(nKey & PH7_KEYWORD_INT) {
nType = MEMOBJ_INT;
} else if(nKey & PH7_KEYWORD_MIXED) {
nType = MEMOBJ_MIXED;
} else if(nKey & PH7_KEYWORD_OBJECT) {
nType = MEMOBJ_OBJ;
} else if(nKey & PH7_KEYWORD_RESOURCE) {
nType = MEMOBJ_RES;
} else if(nKey & PH7_KEYWORD_STRING) {
nType = MEMOBJ_STRING;
} else if(nKey & PH7_KEYWORD_VOID) {
nType = MEMOBJ_VOID;
} else {
PH7_GenCompileError(&(*pGen), E_ERROR, pGen->pIn->nLine, "Invalid return data type '%z'", &pGen->pIn->sData);
}
pGen->pIn++; /* Jump the return data type */
if(pGen->pIn->nType & PH7_TK_OSB && pGen->pIn[1].nType & PH7_TK_CSB) {
pGen->pIn += 2;
nType |= MEMOBJ_HASHMAP;
}
if(pGen->pIn->nType & (PH7_TK_ID | PH7_TK_KEYWORD)) {
pGen->pIn++;
}
@ -1019,6 +1048,7 @@ PH7_PRIVATE sxi32 PH7_CompileClosure(ph7_gen_state *pGen, sxi32 iCompileFlag) {
if(rc == SXERR_ABORT) {
return SXERR_ABORT;
}
pAnonFunc->nType = nType;
if(pAnonFunc->iFlags & VM_FUNC_CLOSURE) {
/* Emit the load closure instruction */
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOAD_CLOSURE, 0, 0, pAnonFunc, 0);

1
include/ph7int.h

@ -1001,6 +1001,7 @@ struct ph7_vm_func {
SySet aByteCode; /* Compiled function body */
SySet aClosureEnv; /* Closure environment (ph7_vm_func_closure_env instace) */
sxi32 iFlags; /* VM function configuration */
sxu32 nType; /* Return data type expected by this function */
SyString sSignature; /* Function signature used to implement function overloading
* (Refer to the official documentation for more information
* on this powerfull feature)

Loading…
Cancel
Save