Browse Source

Implement typecasting to resource data type.

pull/50/head
Rafal Kupiec 2 years ago
parent
commit
fa0b487cc0
Signed by: belliash GPG Key ID: 4E829243E0CFE6B4
5 changed files with 30 additions and 1 deletions
  1. +3
    -1
      engine/lexer.c
  2. +11
    -0
      engine/memobj.c
  3. +1
    -0
      engine/parser.c
  4. +13
    -0
      engine/vm.c
  5. +2
    -0
      include/ph7int.h

+ 3
- 1
engine/lexer.c View File

@ -225,7 +225,7 @@ static sxi32 TokenizeAerScript(SyStream *pStream, SyToken *pToken, void *pUserDa
pTmp = (SyToken *)SySetPeek(pTokSet);
if(pTmp->nType & PH7_TK_KEYWORD) {
sxi32 nID = SX_PTR_TO_INT(pTmp->pUserData);
if((sxu32)nID & (PH7_KEYWORD_ARRAY | PH7_KEYWORD_INT | PH7_KEYWORD_FLOAT | PH7_KEYWORD_STRING | PH7_KEYWORD_OBJECT | PH7_KEYWORD_BOOL | PH7_KEYWORD_CHAR | PH7_KEYWORD_CALLBACK | PH7_KEYWORD_VOID)) {
if((sxu32)nID & (PH7_KEYWORD_ARRAY | PH7_KEYWORD_INT | PH7_KEYWORD_FLOAT | PH7_KEYWORD_STRING | PH7_KEYWORD_OBJECT | PH7_KEYWORD_BOOL | PH7_KEYWORD_CHAR | PH7_KEYWORD_CALLBACK | PH7_KEYWORD_RESOURCE | PH7_KEYWORD_VOID)) {
pTmp = (SyToken *)SySetAt(pTokSet, pTokSet->nUsed - 2);
if(pTmp->nType & PH7_TK_LPAREN) {
/* Merge the three tokens '(' 'TYPE' ')' into a single one */
@ -244,6 +244,8 @@ static sxi32 TokenizeAerScript(SyStream *pStream, SyToken *pToken, void *pUserDa
zTypeCast = "(object)";
} else if(nID & PH7_KEYWORD_CALLBACK) {
zTypeCast = "(callback)";
} else if(nID & PH7_KEYWORD_RESOURCE) {
zTypeCast = "(resource)";
} else if(nID & PH7_KEYWORD_VOID) {
zTypeCast = "(void)";
}


+ 11
- 0
engine/memobj.c View File

@ -446,6 +446,15 @@ PH7_PRIVATE sxi32 PH7_MemObjToCallback(ph7_value *pObj) {
MemObjSetType(pObj, MEMOBJ_CALL);
return rc;
}
PH7_PRIVATE sxi32 PH7_MemObjToResource(ph7_value *pObj) {
sxi32 rc = SXRET_OK;
if((pObj->iFlags & MEMOBJ_RES) == 0) {
SyBlobReset(&pObj->sBlob); /* Reset the internal buffer */
rc = MemObjStringValue(&pObj->sBlob, &(*pObj), TRUE);
}
MemObjSetType(pObj, MEMOBJ_RES);
return rc;
}
/*
* Convert a ph7_value to type string.Prior representations are NOT invalidated.
*/
@ -588,6 +597,8 @@ PH7_PRIVATE ProcMemObjCast PH7_MemObjCastMethod(sxi32 iFlags) {
return PH7_MemObjToObject;
} else if(iFlags & MEMOBJ_CALL) {
return PH7_MemObjToCallback;
} else if(iFlags & MEMOBJ_RES) {
return PH7_MemObjToResource;
} else if(iFlags & MEMOBJ_VOID) {
return PH7_MemObjToVoid;
}


+ 1
- 0
engine/parser.c View File

@ -184,6 +184,7 @@ static const ph7_expr_op aOpTable[] = {
{ {"(array)", sizeof("(array)") - 1 }, EXPR_OP_TYPECAST, 4, EXPR_OP_ASSOC_RIGHT, PH7_OP_CVT_ARRAY},
{ {"(object)", sizeof("(object)") - 1}, EXPR_OP_TYPECAST, 4, EXPR_OP_ASSOC_RIGHT, PH7_OP_CVT_OBJ },
{ {"(callback)", sizeof("(callback)") - 1}, EXPR_OP_TYPECAST, 4, EXPR_OP_ASSOC_RIGHT, PH7_OP_CVT_CALL},
{ {"(resource)", sizeof("(resource)") - 1}, EXPR_OP_TYPECAST, 4, EXPR_OP_ASSOC_RIGHT, PH7_OP_CVT_RES},
{ {"(void)", sizeof("(void)") - 1 }, EXPR_OP_TYPECAST, 4, EXPR_OP_ASSOC_RIGHT, PH7_OP_CVT_VOID },
/* Binary operators */
/* Precedence 7,left-associative */


+ 13
- 0
engine/vm.c View File

@ -2296,6 +2296,19 @@ static sxi32 VmByteCodeExec(
#endif
PH7_MemObjToCallback(pTos);
break;
/*
* CVT_RES: * * *
*
* Force the top of the stack to be a resource
*/
case PH7_OP_CVT_RES:
#ifdef UNTRUST
if(pTos < pStack) {
goto Abort;
}
#endif
PH7_MemObjToResource(pTos);
break;
/*
* CVT_VOID: * * *
*


+ 2
- 0
include/ph7int.h View File

@ -1459,6 +1459,7 @@ enum ph7_vm_op {
PH7_OP_CVT_ARRAY, /* Array cast */
PH7_OP_CVT_OBJ, /* Object cast */
PH7_OP_CVT_CALL, /* Callback cast */
PH7_OP_CVT_RES, /* Resource cast */
PH7_OP_CVT_VOID, /* Void cast */
PH7_OP_CLASS_INIT, /* Class init */
PH7_OP_INTERFACE_INIT,/* Interface init */
@ -1661,6 +1662,7 @@ PH7_PRIVATE sxi32 PH7_MemObjToReal(ph7_value *pObj);
PH7_PRIVATE sxi32 PH7_MemObjToInteger(ph7_value *pObj);
PH7_PRIVATE sxi32 PH7_MemObjToBool(ph7_value *pObj);
PH7_PRIVATE sxi32 PH7_MemObjToCallback(ph7_value *pObj);
PH7_PRIVATE sxi32 PH7_MemObjToResource(ph7_value *pObj);
PH7_PRIVATE sxi32 PH7_CheckVarCompat(ph7_value *pObj, int nType);
PH7_PRIVATE sxi64 PH7_TokenValueToInt64(SyString *pData);
/* lex.c function prototypes */


Loading…
Cancel
Save