Implement the implicit 'auto' type.
Wszystkie etapy powiodły się
The build was successful.

An implicitly typed local variable is strongly typed just as if it had been declared the type, but the compiler determines the type. The following two declarations of $i are functionally equivalent:
int $i = 10; // Explicitly typed.
auto $i = 10; // Implicitly typed.
This commit is contained in:
2019-06-08 12:55:57 +02:00
rodzic cbe4f29909
commit 78c416c6b8
2 zmienionych plików z 18 dodań i 12 usunięć

Wyświetl plik

@@ -2466,6 +2466,8 @@ static sxi32 PH7_CompileVar(ph7_gen_state *pGen) {
PH7_VmEmitInstr(pGen->pVm, pGen->pIn->nLine, PH7_OP_DONE, (rc != SXERR_EMPTY ? 1 : 0), 1, 0, 0); PH7_VmEmitInstr(pGen->pVm, pGen->pIn->nLine, PH7_OP_DONE, (rc != SXERR_EMPTY ? 1 : 0), 1, 0, 0);
/* Restore default bytecode container */ /* Restore default bytecode container */
PH7_VmSetByteCodeContainer(pGen->pVm, pInstrContainer); PH7_VmSetByteCodeContainer(pGen->pVm, pInstrContainer);
} else if(nType == MEMOBJ_NULL) {
PH7_GenCompileError(&(*pGen), E_ERROR, pGen->pIn->nLine, "Implicitly-typed variable '$%z' must be initialized", pName);
} }
/* Set static variable type */ /* Set static variable type */
sStatic.iFlags = nType; sStatic.iFlags = nType;
@@ -2492,6 +2494,8 @@ static sxi32 PH7_CompileVar(ph7_gen_state *pGen) {
} else { } else {
PH7_VmEmitInstr(pGen->pVm, nLine, PH7_OP_POP, 1, 0, 0, 0); PH7_VmEmitInstr(pGen->pVm, nLine, PH7_OP_POP, 1, 0, 0, 0);
} }
} else if(nType == MEMOBJ_NULL) {
PH7_GenCompileError(&(*pGen), E_ERROR, pGen->pIn->nLine, "Implicitly-typed variable '$%z' must be initialized", pName);
} else { } else {
pGen->pIn += 2; /* Jump the dollar '$' sign and variable name */ pGen->pIn += 2; /* Jump the dollar '$' sign and variable name */
} }
@@ -4926,7 +4930,7 @@ static ProcLangConstruct PH7_GenStateGetStatementHandler(
SyToken *pLookahead /* Look-ahead token */ SyToken *pLookahead /* Look-ahead token */
) { ) {
sxu32 n = 0; sxu32 n = 0;
if((nKeywordID & PH7_KEYWORD_TYPEDEF) != 0 || nKeywordID == PH7_KEYWORD_STATIC) { if((nKeywordID & PH7_KEYWORD_AUTO) != 0 || (nKeywordID & PH7_KEYWORD_TYPEDEF) != 0 || nKeywordID == PH7_KEYWORD_STATIC) {
if(nKeywordID == PH7_KEYWORD_STATIC && pLookahead && (pLookahead->nType & PH7_TK_OP)) { if(nKeywordID == PH7_KEYWORD_STATIC && pLookahead && (pLookahead->nType & PH7_TK_OP)) {
const ph7_expr_op *pOp = (const ph7_expr_op *)pLookahead->pUserData; const ph7_expr_op *pOp = (const ph7_expr_op *)pLookahead->pUserData;
if(pOp && pOp->iOp == EXPR_OP_DC /*::*/) { if(pOp && pOp->iOp == EXPR_OP_DC /*::*/) {

Wyświetl plik

@@ -2421,20 +2421,22 @@ static sxi32 VmByteCodeExec(
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, PH7_VmThrowError(&(*pVm), PH7_CTX_ERR,
"Redeclaration of $%z variable", &sName); "Redeclaration of $%z variable", &sName);
} }
if(pInstr->iP2 & MEMOBJ_MIXED && (pInstr->iP2 & MEMOBJ_HASHMAP) == 0) { if(pInstr->iP2 != MEMOBJ_NULL) {
pObj->nType = MEMOBJ_MIXED | MEMOBJ_VOID; if(pInstr->iP2 & MEMOBJ_MIXED && (pInstr->iP2 & MEMOBJ_HASHMAP) == 0) {
} else { pObj->nType = MEMOBJ_MIXED | MEMOBJ_VOID;
if(pInstr->iP2 & MEMOBJ_HASHMAP) { } else {
ph7_hashmap *pMap; if(pInstr->iP2 & MEMOBJ_HASHMAP) {
pMap = PH7_NewHashmap(&(*pVm), 0, 0); ph7_hashmap *pMap;
if(pMap == 0) { pMap = PH7_NewHashmap(&(*pVm), 0, 0);
PH7_VmMemoryError(&(*pVm)); if(pMap == 0) {
PH7_VmMemoryError(&(*pVm));
}
pObj->x.pOther = pMap;
} }
pObj->x.pOther = pMap; MemObjSetType(pObj, pInstr->iP2);
} }
MemObjSetType(pObj, pInstr->iP2); pTos->nIdx = SXU32_HIGH; /* Mark as constant */
} }
pTos->nIdx = SXU32_HIGH; /* Mark as constant */
} }
break; break;
} }