use stdbool.h and convert TRUE/FALSE to true/false
This commit is contained in:
parent
24e1166a55
commit
9293ed0443
|
@ -16,14 +16,14 @@ void LibraryInit(Picoc *pc)
|
||||||
|
|
||||||
/* define the version number macro */
|
/* define the version number macro */
|
||||||
pc->VersionString = TableStrRegister(pc, PICOC_VERSION);
|
pc->VersionString = TableStrRegister(pc, PICOC_VERSION);
|
||||||
VariableDefinePlatformVar(pc, NULL, "PICOC_VERSION", pc->CharPtrType, (union AnyValue *)&pc->VersionString, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "PICOC_VERSION", pc->CharPtrType, (union AnyValue *)&pc->VersionString, false);
|
||||||
|
|
||||||
/* define endian-ness macros */
|
/* define endian-ness macros */
|
||||||
BigEndian = ((*(char*)&__ENDIAN_CHECK__) == 0);
|
BigEndian = ((*(char*)&__ENDIAN_CHECK__) == 0);
|
||||||
LittleEndian = ((*(char*)&__ENDIAN_CHECK__) == 1);
|
LittleEndian = ((*(char*)&__ENDIAN_CHECK__) == 1);
|
||||||
|
|
||||||
VariableDefinePlatformVar(pc, NULL, "BIG_ENDIAN", &pc->IntType, (union AnyValue *)&BigEndian, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "BIG_ENDIAN", &pc->IntType, (union AnyValue *)&BigEndian, false);
|
||||||
VariableDefinePlatformVar(pc, NULL, "LITTLE_ENDIAN", &pc->IntType, (union AnyValue *)&LittleEndian, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "LITTLE_ENDIAN", &pc->IntType, (union AnyValue *)&LittleEndian, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add a library */
|
/* add a library */
|
||||||
|
@ -40,7 +40,7 @@ void LibraryAdd(Picoc *pc, struct Table *GlobalTable, struct LibraryFunction *Fu
|
||||||
/* read all the library definitions */
|
/* read all the library definitions */
|
||||||
for (Count = 0; FuncList[Count].Prototype != NULL; Count++) {
|
for (Count = 0; FuncList[Count].Prototype != NULL; Count++) {
|
||||||
Tokens = LexAnalyse(pc, (const char*)IntrinsicName, FuncList[Count].Prototype, strlen((char*)FuncList[Count].Prototype), NULL);
|
Tokens = LexAnalyse(pc, (const char*)IntrinsicName, FuncList[Count].Prototype, strlen((char*)FuncList[Count].Prototype), NULL);
|
||||||
LexInitParser(&Parser, pc, FuncList[Count].Prototype, Tokens, IntrinsicName, TRUE, FALSE);
|
LexInitParser(&Parser, pc, FuncList[Count].Prototype, Tokens, IntrinsicName, true, false);
|
||||||
TypeParse(&Parser, &ReturnType, &Identifier, NULL);
|
TypeParse(&Parser, &ReturnType, &Identifier, NULL);
|
||||||
NewValue = ParseFunctionDefinition(&Parser, ReturnType, Identifier);
|
NewValue = ParseFunctionDefinition(&Parser, ReturnType, Identifier);
|
||||||
NewValue->Val->FuncDef.Intrinsic = FuncList[Count].Func;
|
NewValue->Val->FuncDef.Intrinsic = FuncList[Count].Func;
|
||||||
|
|
162
cstdlib/errno.c
162
cstdlib/errno.c
|
@ -329,325 +329,325 @@ void StdErrnoSetupFunc(Picoc *pc)
|
||||||
{
|
{
|
||||||
/* defines */
|
/* defines */
|
||||||
#ifdef EACCES
|
#ifdef EACCES
|
||||||
VariableDefinePlatformVar(pc, NULL, "EACCES", &pc->IntType, (union AnyValue *)&EACCESValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EACCES", &pc->IntType, (union AnyValue *)&EACCESValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EADDRINUSE
|
#ifdef EADDRINUSE
|
||||||
VariableDefinePlatformVar(pc, NULL, "EADDRINUSE", &pc->IntType, (union AnyValue *)&EADDRINUSEValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EADDRINUSE", &pc->IntType, (union AnyValue *)&EADDRINUSEValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EADDRNOTAVAIL
|
#ifdef EADDRNOTAVAIL
|
||||||
VariableDefinePlatformVar(pc, NULL, "EADDRNOTAVAIL", &pc->IntType, (union AnyValue *)&EADDRNOTAVAILValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EADDRNOTAVAIL", &pc->IntType, (union AnyValue *)&EADDRNOTAVAILValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EAFNOSUPPORT
|
#ifdef EAFNOSUPPORT
|
||||||
VariableDefinePlatformVar(pc, NULL, "EAFNOSUPPORT", &pc->IntType, (union AnyValue *)&EAFNOSUPPORTValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EAFNOSUPPORT", &pc->IntType, (union AnyValue *)&EAFNOSUPPORTValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EAGAIN
|
#ifdef EAGAIN
|
||||||
VariableDefinePlatformVar(pc, NULL, "EAGAIN", &pc->IntType, (union AnyValue *)&EAGAINValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EAGAIN", &pc->IntType, (union AnyValue *)&EAGAINValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EALREADY
|
#ifdef EALREADY
|
||||||
VariableDefinePlatformVar(pc, NULL, "EALREADY", &pc->IntType, (union AnyValue *)&EALREADYValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EALREADY", &pc->IntType, (union AnyValue *)&EALREADYValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EBADF
|
#ifdef EBADF
|
||||||
VariableDefinePlatformVar(pc, NULL, "EBADF", &pc->IntType, (union AnyValue *)&EBADFValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EBADF", &pc->IntType, (union AnyValue *)&EBADFValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EBADMSG
|
#ifdef EBADMSG
|
||||||
VariableDefinePlatformVar(pc, NULL, "EBADMSG", &pc->IntType, (union AnyValue *)&EBADMSGValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EBADMSG", &pc->IntType, (union AnyValue *)&EBADMSGValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EBUSY
|
#ifdef EBUSY
|
||||||
VariableDefinePlatformVar(pc, NULL, "EBUSY", &pc->IntType, (union AnyValue *)&EBUSYValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EBUSY", &pc->IntType, (union AnyValue *)&EBUSYValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ECANCELED
|
#ifdef ECANCELED
|
||||||
VariableDefinePlatformVar(pc, NULL, "ECANCELED", &pc->IntType, (union AnyValue *)&ECANCELEDValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ECANCELED", &pc->IntType, (union AnyValue *)&ECANCELEDValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ECHILD
|
#ifdef ECHILD
|
||||||
VariableDefinePlatformVar(pc, NULL, "ECHILD", &pc->IntType, (union AnyValue *)&ECHILDValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ECHILD", &pc->IntType, (union AnyValue *)&ECHILDValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ECONNABORTED
|
#ifdef ECONNABORTED
|
||||||
VariableDefinePlatformVar(pc, NULL, "ECONNABORTED", &pc->IntType, (union AnyValue *)&ECONNABORTEDValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ECONNABORTED", &pc->IntType, (union AnyValue *)&ECONNABORTEDValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ECONNREFUSED
|
#ifdef ECONNREFUSED
|
||||||
VariableDefinePlatformVar(pc, NULL, "ECONNREFUSED", &pc->IntType, (union AnyValue *)&ECONNREFUSEDValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ECONNREFUSED", &pc->IntType, (union AnyValue *)&ECONNREFUSEDValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ECONNRESET
|
#ifdef ECONNRESET
|
||||||
VariableDefinePlatformVar(pc, NULL, "ECONNRESET", &pc->IntType, (union AnyValue *)&ECONNRESETValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ECONNRESET", &pc->IntType, (union AnyValue *)&ECONNRESETValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EDEADLK
|
#ifdef EDEADLK
|
||||||
VariableDefinePlatformVar(pc, NULL, "EDEADLK", &pc->IntType, (union AnyValue *)&EDEADLKValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EDEADLK", &pc->IntType, (union AnyValue *)&EDEADLKValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EDESTADDRREQ
|
#ifdef EDESTADDRREQ
|
||||||
VariableDefinePlatformVar(pc, NULL, "EDESTADDRREQ", &pc->IntType, (union AnyValue *)&EDESTADDRREQValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EDESTADDRREQ", &pc->IntType, (union AnyValue *)&EDESTADDRREQValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EDOM
|
#ifdef EDOM
|
||||||
VariableDefinePlatformVar(pc, NULL, "EDOM", &pc->IntType, (union AnyValue *)&EDOMValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EDOM", &pc->IntType, (union AnyValue *)&EDOMValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EDQUOT
|
#ifdef EDQUOT
|
||||||
VariableDefinePlatformVar(pc, NULL, "EDQUOT", &pc->IntType, (union AnyValue *)&EDQUOTValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EDQUOT", &pc->IntType, (union AnyValue *)&EDQUOTValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EEXIST
|
#ifdef EEXIST
|
||||||
VariableDefinePlatformVar(pc, NULL, "EEXIST", &pc->IntType, (union AnyValue *)&EEXISTValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EEXIST", &pc->IntType, (union AnyValue *)&EEXISTValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EFAULT
|
#ifdef EFAULT
|
||||||
VariableDefinePlatformVar(pc, NULL, "EFAULT", &pc->IntType, (union AnyValue *)&EFAULTValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EFAULT", &pc->IntType, (union AnyValue *)&EFAULTValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EFBIG
|
#ifdef EFBIG
|
||||||
VariableDefinePlatformVar(pc, NULL, "EFBIG", &pc->IntType, (union AnyValue *)&EFBIGValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EFBIG", &pc->IntType, (union AnyValue *)&EFBIGValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EHOSTUNREACH
|
#ifdef EHOSTUNREACH
|
||||||
VariableDefinePlatformVar(pc, NULL, "EHOSTUNREACH", &pc->IntType, (union AnyValue *)&EHOSTUNREACHValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EHOSTUNREACH", &pc->IntType, (union AnyValue *)&EHOSTUNREACHValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EIDRM
|
#ifdef EIDRM
|
||||||
VariableDefinePlatformVar(pc, NULL, "EIDRM", &pc->IntType, (union AnyValue *)&EIDRMValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EIDRM", &pc->IntType, (union AnyValue *)&EIDRMValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EILSEQ
|
#ifdef EILSEQ
|
||||||
VariableDefinePlatformVar(pc, NULL, "EILSEQ", &pc->IntType, (union AnyValue *)&EILSEQValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EILSEQ", &pc->IntType, (union AnyValue *)&EILSEQValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EINPROGRESS
|
#ifdef EINPROGRESS
|
||||||
VariableDefinePlatformVar(pc, NULL, "EINPROGRESS", &pc->IntType, (union AnyValue *)&EINPROGRESSValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EINPROGRESS", &pc->IntType, (union AnyValue *)&EINPROGRESSValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EINTR
|
#ifdef EINTR
|
||||||
VariableDefinePlatformVar(pc, NULL, "EINTR", &pc->IntType, (union AnyValue *)&EINTRValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EINTR", &pc->IntType, (union AnyValue *)&EINTRValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EINVAL
|
#ifdef EINVAL
|
||||||
VariableDefinePlatformVar(pc, NULL, "EINVAL", &pc->IntType, (union AnyValue *)&EINVALValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EINVAL", &pc->IntType, (union AnyValue *)&EINVALValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EIO
|
#ifdef EIO
|
||||||
VariableDefinePlatformVar(pc, NULL, "EIO", &pc->IntType, (union AnyValue *)&EIOValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EIO", &pc->IntType, (union AnyValue *)&EIOValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EISCONN
|
#ifdef EISCONN
|
||||||
VariableDefinePlatformVar(pc, NULL, "EISCONN", &pc->IntType, (union AnyValue *)&EISCONNValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EISCONN", &pc->IntType, (union AnyValue *)&EISCONNValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EISDIR
|
#ifdef EISDIR
|
||||||
VariableDefinePlatformVar(pc, NULL, "EISDIR", &pc->IntType, (union AnyValue *)&EISDIRValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EISDIR", &pc->IntType, (union AnyValue *)&EISDIRValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ELOOP
|
#ifdef ELOOP
|
||||||
VariableDefinePlatformVar(pc, NULL, "ELOOP", &pc->IntType, (union AnyValue *)&ELOOPValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ELOOP", &pc->IntType, (union AnyValue *)&ELOOPValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EMFILE
|
#ifdef EMFILE
|
||||||
VariableDefinePlatformVar(pc, NULL, "EMFILE", &pc->IntType, (union AnyValue *)&EMFILEValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EMFILE", &pc->IntType, (union AnyValue *)&EMFILEValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EMLINK
|
#ifdef EMLINK
|
||||||
VariableDefinePlatformVar(pc, NULL, "EMLINK", &pc->IntType, (union AnyValue *)&EMLINKValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EMLINK", &pc->IntType, (union AnyValue *)&EMLINKValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EMSGSIZE
|
#ifdef EMSGSIZE
|
||||||
VariableDefinePlatformVar(pc, NULL, "EMSGSIZE", &pc->IntType, (union AnyValue *)&EMSGSIZEValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EMSGSIZE", &pc->IntType, (union AnyValue *)&EMSGSIZEValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EMULTIHOP
|
#ifdef EMULTIHOP
|
||||||
VariableDefinePlatformVar(pc, NULL, "EMULTIHOP", &pc->IntType, (union AnyValue *)&EMULTIHOPValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EMULTIHOP", &pc->IntType, (union AnyValue *)&EMULTIHOPValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENAMETOOLONG
|
#ifdef ENAMETOOLONG
|
||||||
VariableDefinePlatformVar(pc, NULL, "ENAMETOOLONG", &pc->IntType, (union AnyValue *)&ENAMETOOLONGValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ENAMETOOLONG", &pc->IntType, (union AnyValue *)&ENAMETOOLONGValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENETDOWN
|
#ifdef ENETDOWN
|
||||||
VariableDefinePlatformVar(pc, NULL, "ENETDOWN", &pc->IntType, (union AnyValue *)&ENETDOWNValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ENETDOWN", &pc->IntType, (union AnyValue *)&ENETDOWNValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENETRESET
|
#ifdef ENETRESET
|
||||||
VariableDefinePlatformVar(pc, NULL, "ENETRESET", &pc->IntType, (union AnyValue *)&ENETRESETValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ENETRESET", &pc->IntType, (union AnyValue *)&ENETRESETValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENETUNREACH
|
#ifdef ENETUNREACH
|
||||||
VariableDefinePlatformVar(pc, NULL, "ENETUNREACH", &pc->IntType, (union AnyValue *)&ENETUNREACHValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ENETUNREACH", &pc->IntType, (union AnyValue *)&ENETUNREACHValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENFILE
|
#ifdef ENFILE
|
||||||
VariableDefinePlatformVar(pc, NULL, "ENFILE", &pc->IntType, (union AnyValue *)&ENFILEValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ENFILE", &pc->IntType, (union AnyValue *)&ENFILEValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENOBUFS
|
#ifdef ENOBUFS
|
||||||
VariableDefinePlatformVar(pc, NULL, "ENOBUFS", &pc->IntType, (union AnyValue *)&ENOBUFSValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ENOBUFS", &pc->IntType, (union AnyValue *)&ENOBUFSValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENODATA
|
#ifdef ENODATA
|
||||||
VariableDefinePlatformVar(pc, NULL, "ENODATA", &pc->IntType, (union AnyValue *)&ENODATAValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ENODATA", &pc->IntType, (union AnyValue *)&ENODATAValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENODEV
|
#ifdef ENODEV
|
||||||
VariableDefinePlatformVar(pc, NULL, "ENODEV", &pc->IntType, (union AnyValue *)&ENODEVValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ENODEV", &pc->IntType, (union AnyValue *)&ENODEVValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENOENT
|
#ifdef ENOENT
|
||||||
VariableDefinePlatformVar(pc, NULL, "ENOENT", &pc->IntType, (union AnyValue *)&ENOENTValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ENOENT", &pc->IntType, (union AnyValue *)&ENOENTValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENOEXEC
|
#ifdef ENOEXEC
|
||||||
VariableDefinePlatformVar(pc, NULL, "ENOEXEC", &pc->IntType, (union AnyValue *)&ENOEXECValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ENOEXEC", &pc->IntType, (union AnyValue *)&ENOEXECValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENOLCK
|
#ifdef ENOLCK
|
||||||
VariableDefinePlatformVar(pc, NULL, "ENOLCK", &pc->IntType, (union AnyValue *)&ENOLCKValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ENOLCK", &pc->IntType, (union AnyValue *)&ENOLCKValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENOLINK
|
#ifdef ENOLINK
|
||||||
VariableDefinePlatformVar(pc, NULL, "ENOLINK", &pc->IntType, (union AnyValue *)&ENOLINKValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ENOLINK", &pc->IntType, (union AnyValue *)&ENOLINKValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENOMEM
|
#ifdef ENOMEM
|
||||||
VariableDefinePlatformVar(pc, NULL, "ENOMEM", &pc->IntType, (union AnyValue *)&ENOMEMValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ENOMEM", &pc->IntType, (union AnyValue *)&ENOMEMValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENOMSG
|
#ifdef ENOMSG
|
||||||
VariableDefinePlatformVar(pc, NULL, "ENOMSG", &pc->IntType, (union AnyValue *)&ENOMSGValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ENOMSG", &pc->IntType, (union AnyValue *)&ENOMSGValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENOPROTOOPT
|
#ifdef ENOPROTOOPT
|
||||||
VariableDefinePlatformVar(pc, NULL, "ENOPROTOOPT", &pc->IntType, (union AnyValue *)&ENOPROTOOPTValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ENOPROTOOPT", &pc->IntType, (union AnyValue *)&ENOPROTOOPTValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENOSPC
|
#ifdef ENOSPC
|
||||||
VariableDefinePlatformVar(pc, NULL, "ENOSPC", &pc->IntType, (union AnyValue *)&ENOSPCValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ENOSPC", &pc->IntType, (union AnyValue *)&ENOSPCValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENOSR
|
#ifdef ENOSR
|
||||||
VariableDefinePlatformVar(pc, NULL, "ENOSR", &pc->IntType, (union AnyValue *)&ENOSRValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ENOSR", &pc->IntType, (union AnyValue *)&ENOSRValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENOSTR
|
#ifdef ENOSTR
|
||||||
VariableDefinePlatformVar(pc, NULL, "ENOSTR", &pc->IntType, (union AnyValue *)&ENOSTRValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ENOSTR", &pc->IntType, (union AnyValue *)&ENOSTRValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENOSYS
|
#ifdef ENOSYS
|
||||||
VariableDefinePlatformVar(pc, NULL, "ENOSYS", &pc->IntType, (union AnyValue *)&ENOSYSValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ENOSYS", &pc->IntType, (union AnyValue *)&ENOSYSValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENOTCONN
|
#ifdef ENOTCONN
|
||||||
VariableDefinePlatformVar(pc, NULL, "ENOTCONN", &pc->IntType, (union AnyValue *)&ENOTCONNValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ENOTCONN", &pc->IntType, (union AnyValue *)&ENOTCONNValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENOTDIR
|
#ifdef ENOTDIR
|
||||||
VariableDefinePlatformVar(pc, NULL, "ENOTDIR", &pc->IntType, (union AnyValue *)&ENOTDIRValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ENOTDIR", &pc->IntType, (union AnyValue *)&ENOTDIRValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENOTEMPTY
|
#ifdef ENOTEMPTY
|
||||||
VariableDefinePlatformVar(pc, NULL, "ENOTEMPTY", &pc->IntType, (union AnyValue *)&ENOTEMPTYValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ENOTEMPTY", &pc->IntType, (union AnyValue *)&ENOTEMPTYValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENOTRECOVERABLE
|
#ifdef ENOTRECOVERABLE
|
||||||
VariableDefinePlatformVar(pc, NULL, "ENOTRECOVERABLE", &pc->IntType, (union AnyValue *)&ENOTRECOVERABLEValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ENOTRECOVERABLE", &pc->IntType, (union AnyValue *)&ENOTRECOVERABLEValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENOTSOCK
|
#ifdef ENOTSOCK
|
||||||
VariableDefinePlatformVar(pc, NULL, "ENOTSOCK", &pc->IntType, (union AnyValue *)&ENOTSOCKValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ENOTSOCK", &pc->IntType, (union AnyValue *)&ENOTSOCKValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENOTSUP
|
#ifdef ENOTSUP
|
||||||
VariableDefinePlatformVar(pc, NULL, "ENOTSUP", &pc->IntType, (union AnyValue *)&ENOTSUPValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ENOTSUP", &pc->IntType, (union AnyValue *)&ENOTSUPValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENOTTY
|
#ifdef ENOTTY
|
||||||
VariableDefinePlatformVar(pc, NULL, "ENOTTY", &pc->IntType, (union AnyValue *)&ENOTTYValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ENOTTY", &pc->IntType, (union AnyValue *)&ENOTTYValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENXIO
|
#ifdef ENXIO
|
||||||
VariableDefinePlatformVar(pc, NULL, "ENXIO", &pc->IntType, (union AnyValue *)&ENXIOValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ENXIO", &pc->IntType, (union AnyValue *)&ENXIOValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EOPNOTSUPP
|
#ifdef EOPNOTSUPP
|
||||||
VariableDefinePlatformVar(pc, NULL, "EOPNOTSUPP", &pc->IntType, (union AnyValue *)&EOPNOTSUPPValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EOPNOTSUPP", &pc->IntType, (union AnyValue *)&EOPNOTSUPPValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EOVERFLOW
|
#ifdef EOVERFLOW
|
||||||
VariableDefinePlatformVar(pc, NULL, "EOVERFLOW", &pc->IntType, (union AnyValue *)&EOVERFLOWValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EOVERFLOW", &pc->IntType, (union AnyValue *)&EOVERFLOWValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EOWNERDEAD
|
#ifdef EOWNERDEAD
|
||||||
VariableDefinePlatformVar(pc, NULL, "EOWNERDEAD", &pc->IntType, (union AnyValue *)&EOWNERDEADValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EOWNERDEAD", &pc->IntType, (union AnyValue *)&EOWNERDEADValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EPERM
|
#ifdef EPERM
|
||||||
VariableDefinePlatformVar(pc, NULL, "EPERM", &pc->IntType, (union AnyValue *)&EPERMValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EPERM", &pc->IntType, (union AnyValue *)&EPERMValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EPIPE
|
#ifdef EPIPE
|
||||||
VariableDefinePlatformVar(pc, NULL, "EPIPE", &pc->IntType, (union AnyValue *)&EPIPEValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EPIPE", &pc->IntType, (union AnyValue *)&EPIPEValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EPROTO
|
#ifdef EPROTO
|
||||||
VariableDefinePlatformVar(pc, NULL, "EPROTO", &pc->IntType, (union AnyValue *)&EPROTOValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EPROTO", &pc->IntType, (union AnyValue *)&EPROTOValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EPROTONOSUPPORT
|
#ifdef EPROTONOSUPPORT
|
||||||
VariableDefinePlatformVar(pc, NULL, "EPROTONOSUPPORT", &pc->IntType, (union AnyValue *)&EPROTONOSUPPORTValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EPROTONOSUPPORT", &pc->IntType, (union AnyValue *)&EPROTONOSUPPORTValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EPROTOTYPE
|
#ifdef EPROTOTYPE
|
||||||
VariableDefinePlatformVar(pc, NULL, "EPROTOTYPE", &pc->IntType, (union AnyValue *)&EPROTOTYPEValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EPROTOTYPE", &pc->IntType, (union AnyValue *)&EPROTOTYPEValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ERANGE
|
#ifdef ERANGE
|
||||||
VariableDefinePlatformVar(pc, NULL, "ERANGE", &pc->IntType, (union AnyValue *)&ERANGEValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ERANGE", &pc->IntType, (union AnyValue *)&ERANGEValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EROFS
|
#ifdef EROFS
|
||||||
VariableDefinePlatformVar(pc, NULL, "EROFS", &pc->IntType, (union AnyValue *)&EROFSValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EROFS", &pc->IntType, (union AnyValue *)&EROFSValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ESPIPE
|
#ifdef ESPIPE
|
||||||
VariableDefinePlatformVar(pc, NULL, "ESPIPE", &pc->IntType, (union AnyValue *)&ESPIPEValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ESPIPE", &pc->IntType, (union AnyValue *)&ESPIPEValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ESRCH
|
#ifdef ESRCH
|
||||||
VariableDefinePlatformVar(pc, NULL, "ESRCH", &pc->IntType, (union AnyValue *)&ESRCHValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ESRCH", &pc->IntType, (union AnyValue *)&ESRCHValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ESTALE
|
#ifdef ESTALE
|
||||||
VariableDefinePlatformVar(pc, NULL, "ESTALE", &pc->IntType, (union AnyValue *)&ESTALEValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ESTALE", &pc->IntType, (union AnyValue *)&ESTALEValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ETIME
|
#ifdef ETIME
|
||||||
VariableDefinePlatformVar(pc, NULL, "ETIME", &pc->IntType, (union AnyValue *)&ETIMEValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ETIME", &pc->IntType, (union AnyValue *)&ETIMEValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ETIMEDOUT
|
#ifdef ETIMEDOUT
|
||||||
VariableDefinePlatformVar(pc, NULL, "ETIMEDOUT", &pc->IntType, (union AnyValue *)&ETIMEDOUTValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ETIMEDOUT", &pc->IntType, (union AnyValue *)&ETIMEDOUTValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ETXTBSY
|
#ifdef ETXTBSY
|
||||||
VariableDefinePlatformVar(pc, NULL, "ETXTBSY", &pc->IntType, (union AnyValue *)&ETXTBSYValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "ETXTBSY", &pc->IntType, (union AnyValue *)&ETXTBSYValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EWOULDBLOCK
|
#ifdef EWOULDBLOCK
|
||||||
VariableDefinePlatformVar(pc, NULL, "EWOULDBLOCK", &pc->IntType, (union AnyValue *)&EWOULDBLOCKValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EWOULDBLOCK", &pc->IntType, (union AnyValue *)&EWOULDBLOCKValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EXDEV
|
#ifdef EXDEV
|
||||||
VariableDefinePlatformVar(pc, NULL, "EXDEV", &pc->IntType, (union AnyValue *)&EXDEVValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EXDEV", &pc->IntType, (union AnyValue *)&EXDEVValue, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
VariableDefinePlatformVar(pc, NULL, "errno", &pc->IntType, (union AnyValue *)&errno, TRUE);
|
VariableDefinePlatformVar(pc, NULL, "errno", &pc->IntType, (union AnyValue *)&errno, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -166,17 +166,17 @@ struct LibraryFunction MathFunctions[] =
|
||||||
/* creates various system-dependent definitions */
|
/* creates various system-dependent definitions */
|
||||||
void MathSetupFunc(Picoc *pc)
|
void MathSetupFunc(Picoc *pc)
|
||||||
{
|
{
|
||||||
VariableDefinePlatformVar(pc, NULL, "M_E", &pc->FPType, (union AnyValue *)&M_EValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "M_E", &pc->FPType, (union AnyValue *)&M_EValue, false);
|
||||||
VariableDefinePlatformVar(pc, NULL, "M_LOG2E", &pc->FPType, (union AnyValue *)&M_LOG2EValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "M_LOG2E", &pc->FPType, (union AnyValue *)&M_LOG2EValue, false);
|
||||||
VariableDefinePlatformVar(pc, NULL, "M_LOG10E", &pc->FPType, (union AnyValue *)&M_LOG10EValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "M_LOG10E", &pc->FPType, (union AnyValue *)&M_LOG10EValue, false);
|
||||||
VariableDefinePlatformVar(pc, NULL, "M_LN2", &pc->FPType, (union AnyValue *)&M_LN2Value, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "M_LN2", &pc->FPType, (union AnyValue *)&M_LN2Value, false);
|
||||||
VariableDefinePlatformVar(pc, NULL, "M_LN10", &pc->FPType, (union AnyValue *)&M_LN10Value, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "M_LN10", &pc->FPType, (union AnyValue *)&M_LN10Value, false);
|
||||||
VariableDefinePlatformVar(pc, NULL, "M_PI", &pc->FPType, (union AnyValue *)&M_PIValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "M_PI", &pc->FPType, (union AnyValue *)&M_PIValue, false);
|
||||||
VariableDefinePlatformVar(pc, NULL, "M_PI_2", &pc->FPType, (union AnyValue *)&M_PI_2Value, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "M_PI_2", &pc->FPType, (union AnyValue *)&M_PI_2Value, false);
|
||||||
VariableDefinePlatformVar(pc, NULL, "M_PI_4", &pc->FPType, (union AnyValue *)&M_PI_4Value, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "M_PI_4", &pc->FPType, (union AnyValue *)&M_PI_4Value, false);
|
||||||
VariableDefinePlatformVar(pc, NULL, "M_1_PI", &pc->FPType, (union AnyValue *)&M_1_PIValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "M_1_PI", &pc->FPType, (union AnyValue *)&M_1_PIValue, false);
|
||||||
VariableDefinePlatformVar(pc, NULL, "M_2_PI", &pc->FPType, (union AnyValue *)&M_2_PIValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "M_2_PI", &pc->FPType, (union AnyValue *)&M_2_PIValue, false);
|
||||||
VariableDefinePlatformVar(pc, NULL, "M_2_SQRTPI", &pc->FPType, (union AnyValue *)&M_2_SQRTPIValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "M_2_SQRTPI", &pc->FPType, (union AnyValue *)&M_2_SQRTPIValue, false);
|
||||||
VariableDefinePlatformVar(pc, NULL, "M_SQRT2", &pc->FPType, (union AnyValue *)&M_SQRT2Value, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "M_SQRT2", &pc->FPType, (union AnyValue *)&M_SQRT2Value, false);
|
||||||
VariableDefinePlatformVar(pc, NULL, "M_SQRT1_2", &pc->FPType, (union AnyValue *)&M_SQRT1_2Value, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "M_SQRT1_2", &pc->FPType, (union AnyValue *)&M_SQRT1_2Value, false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ const char StdboolDefs[] = "typedef int bool;";
|
||||||
void StdboolSetupFunc(Picoc *pc)
|
void StdboolSetupFunc(Picoc *pc)
|
||||||
{
|
{
|
||||||
/* defines */
|
/* defines */
|
||||||
VariableDefinePlatformVar(pc, NULL, "true", &pc->IntType, (union AnyValue *)&trueValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "true", &pc->IntType, (union AnyValue *)&trueValue, false);
|
||||||
VariableDefinePlatformVar(pc, NULL, "false", &pc->IntType, (union AnyValue *)&falseValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "false", &pc->IntType, (union AnyValue *)&falseValue, false);
|
||||||
VariableDefinePlatformVar(pc, NULL, "__bool_true_false_are_defined", &pc->IntType, (union AnyValue *)&trueValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "__bool_true_false_are_defined", &pc->IntType, (union AnyValue *)&trueValue, false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -637,32 +637,32 @@ void StdioSetupFunc(Picoc *pc)
|
||||||
StructFileType = TypeCreateOpaqueStruct(pc, NULL, TableStrRegister(pc, "__FILEStruct"), sizeof(FILE));
|
StructFileType = TypeCreateOpaqueStruct(pc, NULL, TableStrRegister(pc, "__FILEStruct"), sizeof(FILE));
|
||||||
|
|
||||||
/* get a FILE * type */
|
/* get a FILE * type */
|
||||||
FilePtrType = TypeGetMatching(pc, NULL, StructFileType, TypePointer, 0, pc->StrEmpty, TRUE);
|
FilePtrType = TypeGetMatching(pc, NULL, StructFileType, TypePointer, 0, pc->StrEmpty, true);
|
||||||
|
|
||||||
/* make a "struct __va_listStruct" which is the same size as our struct StdVararg */
|
/* make a "struct __va_listStruct" which is the same size as our struct StdVararg */
|
||||||
TypeCreateOpaqueStruct(pc, NULL, TableStrRegister(pc, "__va_listStruct"), sizeof(FILE));
|
TypeCreateOpaqueStruct(pc, NULL, TableStrRegister(pc, "__va_listStruct"), sizeof(FILE));
|
||||||
|
|
||||||
/* define EOF equal to the system EOF */
|
/* define EOF equal to the system EOF */
|
||||||
VariableDefinePlatformVar(pc, NULL, "EOF", &pc->IntType, (union AnyValue *)&EOFValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "EOF", &pc->IntType, (union AnyValue *)&EOFValue, false);
|
||||||
VariableDefinePlatformVar(pc, NULL, "SEEK_SET", &pc->IntType, (union AnyValue *)&SEEK_SETValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "SEEK_SET", &pc->IntType, (union AnyValue *)&SEEK_SETValue, false);
|
||||||
VariableDefinePlatformVar(pc, NULL, "SEEK_CUR", &pc->IntType, (union AnyValue *)&SEEK_CURValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "SEEK_CUR", &pc->IntType, (union AnyValue *)&SEEK_CURValue, false);
|
||||||
VariableDefinePlatformVar(pc, NULL, "SEEK_END", &pc->IntType, (union AnyValue *)&SEEK_ENDValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "SEEK_END", &pc->IntType, (union AnyValue *)&SEEK_ENDValue, false);
|
||||||
VariableDefinePlatformVar(pc, NULL, "BUFSIZ", &pc->IntType, (union AnyValue *)&BUFSIZValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "BUFSIZ", &pc->IntType, (union AnyValue *)&BUFSIZValue, false);
|
||||||
VariableDefinePlatformVar(pc, NULL, "FILENAME_MAX", &pc->IntType, (union AnyValue *)&FILENAME_MAXValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "FILENAME_MAX", &pc->IntType, (union AnyValue *)&FILENAME_MAXValue, false);
|
||||||
VariableDefinePlatformVar(pc, NULL, "_IOFBF", &pc->IntType, (union AnyValue *)&_IOFBFValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "_IOFBF", &pc->IntType, (union AnyValue *)&_IOFBFValue, false);
|
||||||
VariableDefinePlatformVar(pc, NULL, "_IOLBF", &pc->IntType, (union AnyValue *)&_IOLBFValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "_IOLBF", &pc->IntType, (union AnyValue *)&_IOLBFValue, false);
|
||||||
VariableDefinePlatformVar(pc, NULL, "_IONBF", &pc->IntType, (union AnyValue *)&_IONBFValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "_IONBF", &pc->IntType, (union AnyValue *)&_IONBFValue, false);
|
||||||
VariableDefinePlatformVar(pc, NULL, "L_tmpnam", &pc->IntType, (union AnyValue *)&L_tmpnamValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "L_tmpnam", &pc->IntType, (union AnyValue *)&L_tmpnamValue, false);
|
||||||
VariableDefinePlatformVar(pc, NULL, "GETS_MAX", &pc->IntType, (union AnyValue *)&GETS_MAXValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "GETS_MAX", &pc->IntType, (union AnyValue *)&GETS_MAXValue, false);
|
||||||
|
|
||||||
/* define stdin, stdout and stderr */
|
/* define stdin, stdout and stderr */
|
||||||
VariableDefinePlatformVar(pc, NULL, "stdin", FilePtrType, (union AnyValue *)&stdinValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "stdin", FilePtrType, (union AnyValue *)&stdinValue, false);
|
||||||
VariableDefinePlatformVar(pc, NULL, "stdout", FilePtrType, (union AnyValue *)&stdoutValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "stdout", FilePtrType, (union AnyValue *)&stdoutValue, false);
|
||||||
VariableDefinePlatformVar(pc, NULL, "stderr", FilePtrType, (union AnyValue *)&stderrValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "stderr", FilePtrType, (union AnyValue *)&stderrValue, false);
|
||||||
|
|
||||||
/* define NULL, TRUE and FALSE */
|
/* define NULL, true and false */
|
||||||
if (!VariableDefined(pc, TableStrRegister(pc, "NULL")))
|
if (!VariableDefined(pc, TableStrRegister(pc, "NULL")))
|
||||||
VariableDefinePlatformVar(pc, NULL, "NULL", &pc->IntType, (union AnyValue *)&Stdio_ZeroValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "NULL", &pc->IntType, (union AnyValue *)&Stdio_ZeroValue, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* portability-related I/O calls */
|
/* portability-related I/O calls */
|
||||||
|
|
|
@ -162,6 +162,6 @@ void StdlibSetupFunc(Picoc *pc)
|
||||||
{
|
{
|
||||||
/* define NULL, TRUE and FALSE */
|
/* define NULL, TRUE and FALSE */
|
||||||
if (!VariableDefined(pc, TableStrRegister(pc, "NULL")))
|
if (!VariableDefined(pc, TableStrRegister(pc, "NULL")))
|
||||||
VariableDefinePlatformVar(pc, NULL, "NULL", &pc->IntType, (union AnyValue *)&Stdlib_ZeroValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "NULL", &pc->IntType, (union AnyValue *)&Stdlib_ZeroValue, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -179,6 +179,6 @@ void StringSetupFunc(Picoc *pc)
|
||||||
{
|
{
|
||||||
/* define NULL */
|
/* define NULL */
|
||||||
if (!VariableDefined(pc, TableStrRegister(pc, "NULL")))
|
if (!VariableDefined(pc, TableStrRegister(pc, "NULL")))
|
||||||
VariableDefinePlatformVar(pc, NULL, "NULL", &pc->IntType, (union AnyValue *)&String_ZeroValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "NULL", &pc->IntType, (union AnyValue *)&String_ZeroValue, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,12 +111,12 @@ void StdTimeSetupFunc(Picoc *pc)
|
||||||
TypeCreateOpaqueStruct(pc, NULL, TableStrRegister(pc, "tm"), sizeof(struct tm));
|
TypeCreateOpaqueStruct(pc, NULL, TableStrRegister(pc, "tm"), sizeof(struct tm));
|
||||||
|
|
||||||
/* define CLK_PER_SEC etc. */
|
/* define CLK_PER_SEC etc. */
|
||||||
VariableDefinePlatformVar(pc, NULL, "CLOCKS_PER_SEC", &pc->IntType, (union AnyValue *)&CLOCKS_PER_SECValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "CLOCKS_PER_SEC", &pc->IntType, (union AnyValue *)&CLOCKS_PER_SECValue, false);
|
||||||
#ifdef CLK_PER_SEC
|
#ifdef CLK_PER_SEC
|
||||||
VariableDefinePlatformVar(pc, NULL, "CLK_PER_SEC", &pc->IntType, (union AnyValue *)&CLK_PER_SECValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "CLK_PER_SEC", &pc->IntType, (union AnyValue *)&CLK_PER_SECValue, false);
|
||||||
#endif
|
#endif
|
||||||
#ifdef CLK_TCK
|
#ifdef CLK_TCK
|
||||||
VariableDefinePlatformVar(pc, NULL, "CLK_TCK", &pc->IntType, (union AnyValue *)&CLK_TCKValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "CLK_TCK", &pc->IntType, (union AnyValue *)&CLK_TCKValue, false);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -493,12 +493,12 @@ void UnistdSetupFunc(Picoc *pc)
|
||||||
{
|
{
|
||||||
/* define NULL */
|
/* define NULL */
|
||||||
if (!VariableDefined(pc, TableStrRegister(pc, "NULL")))
|
if (!VariableDefined(pc, TableStrRegister(pc, "NULL")))
|
||||||
VariableDefinePlatformVar(pc, NULL, "NULL", &pc->IntType, (union AnyValue *)&ZeroValue, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "NULL", &pc->IntType, (union AnyValue *)&ZeroValue, false);
|
||||||
|
|
||||||
/* define optarg and friends */
|
/* define optarg and friends */
|
||||||
VariableDefinePlatformVar(pc, NULL, "optarg", pc->CharPtrType, (union AnyValue *)&optarg, TRUE);
|
VariableDefinePlatformVar(pc, NULL, "optarg", pc->CharPtrType, (union AnyValue *)&optarg, true);
|
||||||
VariableDefinePlatformVar(pc, NULL, "optind", &pc->IntType, (union AnyValue *)&optind, TRUE);
|
VariableDefinePlatformVar(pc, NULL, "optind", &pc->IntType, (union AnyValue *)&optind, true);
|
||||||
VariableDefinePlatformVar(pc, NULL, "opterr", &pc->IntType, (union AnyValue *)&opterr, TRUE);
|
VariableDefinePlatformVar(pc, NULL, "opterr", &pc->IntType, (union AnyValue *)&opterr, true);
|
||||||
VariableDefinePlatformVar(pc, NULL, "optopt", &pc->IntType, (union AnyValue *)&optopt, TRUE);
|
VariableDefinePlatformVar(pc, NULL, "optopt", &pc->IntType, (union AnyValue *)&optopt, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
debug.c
16
debug.c
|
@ -7,7 +7,7 @@
|
||||||
/* initialise the debugger by clearing the breakpoint table */
|
/* initialise the debugger by clearing the breakpoint table */
|
||||||
void DebugInit(Picoc *pc)
|
void DebugInit(Picoc *pc)
|
||||||
{
|
{
|
||||||
TableInitTable(&pc->BreakpointTable, &pc->BreakpointHashTable[0], BREAKPOINT_TABLE_SIZE, TRUE);
|
TableInitTable(&pc->BreakpointTable, &pc->BreakpointHashTable[0], BREAKPOINT_TABLE_SIZE, true);
|
||||||
pc->BreakpointCount = 0;
|
pc->BreakpointCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,35 +78,35 @@ int DebugClearBreakpoint(struct ParseState *Parser)
|
||||||
HeapFreeMem(pc, DeleteEntry);
|
HeapFreeMem(pc, DeleteEntry);
|
||||||
pc->BreakpointCount--;
|
pc->BreakpointCount--;
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* before we run a statement, check if there's anything we have to do with the debugger here */
|
/* before we run a statement, check if there's anything we have to do with the debugger here */
|
||||||
void DebugCheckStatement(struct ParseState *Parser)
|
void DebugCheckStatement(struct ParseState *Parser)
|
||||||
{
|
{
|
||||||
int DoBreak = FALSE;
|
int DoBreak = false;
|
||||||
int AddAt;
|
int AddAt;
|
||||||
Picoc *pc = Parser->pc;
|
Picoc *pc = Parser->pc;
|
||||||
|
|
||||||
/* has the user manually pressed break? */
|
/* has the user manually pressed break? */
|
||||||
if (pc->DebugManualBreak) {
|
if (pc->DebugManualBreak) {
|
||||||
PlatformPrintf(pc->CStdOut, "break\n");
|
PlatformPrintf(pc->CStdOut, "break\n");
|
||||||
DoBreak = TRUE;
|
DoBreak = true;
|
||||||
pc->DebugManualBreak = FALSE;
|
pc->DebugManualBreak = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* is this a breakpoint location? */
|
/* is this a breakpoint location? */
|
||||||
if (Parser->pc->BreakpointCount != 0 && DebugTableSearchBreakpoint(Parser, &AddAt) != NULL)
|
if (Parser->pc->BreakpointCount != 0 && DebugTableSearchBreakpoint(Parser, &AddAt) != NULL)
|
||||||
DoBreak = TRUE;
|
DoBreak = true;
|
||||||
|
|
||||||
/* handle a break */
|
/* handle a break */
|
||||||
if (DoBreak) {
|
if (DoBreak) {
|
||||||
PlatformPrintf(pc->CStdOut, "Handling a break\n");
|
PlatformPrintf(pc->CStdOut, "Handling a break\n");
|
||||||
PicocParseInteractiveNoStartPrompt(pc, FALSE);
|
PicocParseInteractiveNoStartPrompt(pc, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
152
expression.c
152
expression.c
|
@ -10,7 +10,7 @@
|
||||||
/* If the destination is not float, we can't assign a floating value to it, we need to convert it to integer instead */
|
/* If the destination is not float, we can't assign a floating value to it, we need to convert it to integer instead */
|
||||||
#define ASSIGN_FP_OR_INT(value) \
|
#define ASSIGN_FP_OR_INT(value) \
|
||||||
if (IS_FP(BottomValue)) { ResultFP = ExpressionAssignFP(Parser, BottomValue, value); } \
|
if (IS_FP(BottomValue)) { ResultFP = ExpressionAssignFP(Parser, BottomValue, value); } \
|
||||||
else { ResultInt = ExpressionAssignInt(Parser, BottomValue, (long)(value), FALSE); ResultIsInt = TRUE; } \
|
else { ResultInt = ExpressionAssignInt(Parser, BottomValue, (long)(value), false); ResultIsInt = true; } \
|
||||||
|
|
||||||
#define DEEP_PRECEDENCE (BRACKET_PRECEDENCE*1000)
|
#define DEEP_PRECEDENCE (BRACKET_PRECEDENCE*1000)
|
||||||
|
|
||||||
|
@ -264,7 +264,7 @@ double ExpressionAssignFP(struct ParseState *Parser, struct Value *DestValue, do
|
||||||
/* push a node on to the expression stack */
|
/* push a node on to the expression stack */
|
||||||
void ExpressionStackPushValueNode(struct ParseState *Parser, struct ExpressionStack **StackTop, struct Value *ValueLoc)
|
void ExpressionStackPushValueNode(struct ParseState *Parser, struct ExpressionStack **StackTop, struct Value *ValueLoc)
|
||||||
{
|
{
|
||||||
struct ExpressionStack *StackNode = VariableAlloc(Parser->pc, Parser, sizeof(struct ExpressionStack), FALSE);
|
struct ExpressionStack *StackNode = VariableAlloc(Parser->pc, Parser, sizeof(struct ExpressionStack), false);
|
||||||
StackNode->Next = *StackTop;
|
StackNode->Next = *StackTop;
|
||||||
StackNode->Val = ValueLoc;
|
StackNode->Val = ValueLoc;
|
||||||
*StackTop = StackNode;
|
*StackTop = StackNode;
|
||||||
|
@ -280,7 +280,7 @@ void ExpressionStackPushValueNode(struct ParseState *Parser, struct ExpressionSt
|
||||||
/* push a blank value on to the expression stack by type */
|
/* push a blank value on to the expression stack by type */
|
||||||
struct Value *ExpressionStackPushValueByType(struct ParseState *Parser, struct ExpressionStack **StackTop, struct ValueType *PushType)
|
struct Value *ExpressionStackPushValueByType(struct ParseState *Parser, struct ExpressionStack **StackTop, struct ValueType *PushType)
|
||||||
{
|
{
|
||||||
struct Value *ValueLoc = VariableAllocValueFromType(Parser->pc, Parser, PushType, FALSE, NULL, FALSE);
|
struct Value *ValueLoc = VariableAllocValueFromType(Parser->pc, Parser, PushType, false, NULL, false);
|
||||||
ExpressionStackPushValueNode(Parser, StackTop, ValueLoc);
|
ExpressionStackPushValueNode(Parser, StackTop, ValueLoc);
|
||||||
|
|
||||||
return ValueLoc;
|
return ValueLoc;
|
||||||
|
@ -289,7 +289,7 @@ struct Value *ExpressionStackPushValueByType(struct ParseState *Parser, struct E
|
||||||
/* push a value on to the expression stack */
|
/* push a value on to the expression stack */
|
||||||
void ExpressionStackPushValue(struct ParseState *Parser, struct ExpressionStack **StackTop, struct Value *PushValue)
|
void ExpressionStackPushValue(struct ParseState *Parser, struct ExpressionStack **StackTop, struct Value *PushValue)
|
||||||
{
|
{
|
||||||
struct Value *ValueLoc = VariableAllocValueAndCopy(Parser->pc, Parser, PushValue, FALSE);
|
struct Value *ValueLoc = VariableAllocValueAndCopy(Parser->pc, Parser, PushValue, false);
|
||||||
ExpressionStackPushValueNode(Parser, StackTop, ValueLoc);
|
ExpressionStackPushValueNode(Parser, StackTop, ValueLoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,14 +317,14 @@ void ExpressionStackPushDereference(struct ParseState *Parser, struct Expression
|
||||||
|
|
||||||
void ExpressionPushInt(struct ParseState *Parser, struct ExpressionStack **StackTop, long IntValue)
|
void ExpressionPushInt(struct ParseState *Parser, struct ExpressionStack **StackTop, long IntValue)
|
||||||
{
|
{
|
||||||
struct Value *ValueLoc = VariableAllocValueFromType(Parser->pc, Parser, &Parser->pc->IntType, FALSE, NULL, FALSE);
|
struct Value *ValueLoc = VariableAllocValueFromType(Parser->pc, Parser, &Parser->pc->IntType, false, NULL, false);
|
||||||
ValueLoc->Val->Integer = IntValue;
|
ValueLoc->Val->Integer = IntValue;
|
||||||
ExpressionStackPushValueNode(Parser, StackTop, ValueLoc);
|
ExpressionStackPushValueNode(Parser, StackTop, ValueLoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExpressionPushFP(struct ParseState *Parser, struct ExpressionStack **StackTop, double FPValue)
|
void ExpressionPushFP(struct ParseState *Parser, struct ExpressionStack **StackTop, double FPValue)
|
||||||
{
|
{
|
||||||
struct Value *ValueLoc = VariableAllocValueFromType(Parser->pc, Parser, &Parser->pc->FPType, FALSE, NULL, FALSE);
|
struct Value *ValueLoc = VariableAllocValueFromType(Parser->pc, Parser, &Parser->pc->FPType, false, NULL, false);
|
||||||
ValueLoc->Val->FP = FPValue;
|
ValueLoc->Val->FP = FPValue;
|
||||||
ExpressionStackPushValueNode(Parser, StackTop, ValueLoc);
|
ExpressionStackPushValueNode(Parser, StackTop, ValueLoc);
|
||||||
}
|
}
|
||||||
|
@ -388,7 +388,7 @@ void ExpressionAssign(struct ParseState *Parser, struct Value *DestValue, struct
|
||||||
if (SourceValue->Typ->Base == TypeArray && DestValue->Typ->FromType == DestValue->Typ->FromType && DestValue->Typ->ArraySize == 0) {
|
if (SourceValue->Typ->Base == TypeArray && DestValue->Typ->FromType == DestValue->Typ->FromType && DestValue->Typ->ArraySize == 0) {
|
||||||
/* destination array is unsized - need to resize the destination array to the same size as the source array */
|
/* destination array is unsized - need to resize the destination array to the same size as the source array */
|
||||||
DestValue->Typ = SourceValue->Typ;
|
DestValue->Typ = SourceValue->Typ;
|
||||||
VariableRealloc(Parser, DestValue, TypeSizeValue(DestValue, FALSE));
|
VariableRealloc(Parser, DestValue, TypeSizeValue(DestValue, false));
|
||||||
|
|
||||||
if (DestValue->LValueFrom != NULL) {
|
if (DestValue->LValueFrom != NULL) {
|
||||||
/* copy the resized value back to the LValue */
|
/* copy the resized value back to the LValue */
|
||||||
|
@ -405,8 +405,8 @@ void ExpressionAssign(struct ParseState *Parser, struct Value *DestValue, struct
|
||||||
PRINT_SOURCE_POS();
|
PRINT_SOURCE_POS();
|
||||||
fprintf(stderr, "str size: %d\n", Size);
|
fprintf(stderr, "str size: %d\n", Size);
|
||||||
#endif
|
#endif
|
||||||
DestValue->Typ = TypeGetMatching(Parser->pc, Parser, DestValue->Typ->FromType, DestValue->Typ->Base, Size, DestValue->Typ->Identifier, TRUE);
|
DestValue->Typ = TypeGetMatching(Parser->pc, Parser, DestValue->Typ->FromType, DestValue->Typ->Base, Size, DestValue->Typ->Identifier, true);
|
||||||
VariableRealloc(Parser, DestValue, TypeSizeValue(DestValue, FALSE));
|
VariableRealloc(Parser, DestValue, TypeSizeValue(DestValue, false));
|
||||||
}
|
}
|
||||||
/* else, it's char x[10] = "abcd" */
|
/* else, it's char x[10] = "abcd" */
|
||||||
|
|
||||||
|
@ -414,7 +414,7 @@ void ExpressionAssign(struct ParseState *Parser, struct Value *DestValue, struct
|
||||||
PRINT_SOURCE_POS();
|
PRINT_SOURCE_POS();
|
||||||
fprintf(stderr, "char[%d] from char* (len=%d)\n", DestValue->Typ->ArraySize, strlen(SourceValue->Val->Pointer));
|
fprintf(stderr, "char[%d] from char* (len=%d)\n", DestValue->Typ->ArraySize, strlen(SourceValue->Val->Pointer));
|
||||||
#endif
|
#endif
|
||||||
memcpy((void *)DestValue->Val, SourceValue->Val->Pointer, TypeSizeValue(DestValue, FALSE));
|
memcpy((void *)DestValue->Val, SourceValue->Val->Pointer, TypeSizeValue(DestValue, false));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -424,7 +424,7 @@ void ExpressionAssign(struct ParseState *Parser, struct Value *DestValue, struct
|
||||||
if (DestValue->Typ->ArraySize != SourceValue->Typ->ArraySize)
|
if (DestValue->Typ->ArraySize != SourceValue->Typ->ArraySize)
|
||||||
AssignFail(Parser, "from an array of size %d to one of size %d", NULL, NULL, DestValue->Typ->ArraySize, SourceValue->Typ->ArraySize, FuncName, ParamNo);
|
AssignFail(Parser, "from an array of size %d to one of size %d", NULL, NULL, DestValue->Typ->ArraySize, SourceValue->Typ->ArraySize, FuncName, ParamNo);
|
||||||
|
|
||||||
memcpy((void *)DestValue->Val, (void *)SourceValue->Val, TypeSizeValue(DestValue, FALSE));
|
memcpy((void *)DestValue->Val, (void *)SourceValue->Val, TypeSizeValue(DestValue, false));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TypeStruct:
|
case TypeStruct:
|
||||||
|
@ -432,7 +432,7 @@ void ExpressionAssign(struct ParseState *Parser, struct Value *DestValue, struct
|
||||||
if (DestValue->Typ != SourceValue->Typ)
|
if (DestValue->Typ != SourceValue->Typ)
|
||||||
AssignFail(Parser, "%t from %t", DestValue->Typ, SourceValue->Typ, 0, 0, FuncName, ParamNo);
|
AssignFail(Parser, "%t from %t", DestValue->Typ, SourceValue->Typ, 0, 0, FuncName, ParamNo);
|
||||||
|
|
||||||
memcpy((void *)DestValue->Val, (void *)SourceValue->Val, TypeSizeValue(SourceValue, FALSE));
|
memcpy((void *)DestValue->Val, (void *)SourceValue->Val, TypeSizeValue(SourceValue, false));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -484,7 +484,7 @@ void ExpressionPrefixOperator(struct ParseState *Parser, struct ExpressionStack
|
||||||
ProgramFail(Parser, "can't get the address of this");
|
ProgramFail(Parser, "can't get the address of this");
|
||||||
|
|
||||||
ValPtr = TopValue->Val;
|
ValPtr = TopValue->Val;
|
||||||
Result = VariableAllocValueFromType(Parser->pc, Parser, TypeGetMatching(Parser->pc, Parser, TopValue->Typ, TypePointer, 0, Parser->pc->StrEmpty, TRUE), FALSE, NULL, FALSE);
|
Result = VariableAllocValueFromType(Parser->pc, Parser, TypeGetMatching(Parser->pc, Parser, TopValue->Typ, TypePointer, 0, Parser->pc->StrEmpty, true), false, NULL, false);
|
||||||
Result->Val->Pointer = (void *)ValPtr;
|
Result->Val->Pointer = (void *)ValPtr;
|
||||||
ExpressionStackPushValueNode(Parser, StackTop, Result);
|
ExpressionStackPushValueNode(Parser, StackTop, Result);
|
||||||
break;
|
break;
|
||||||
|
@ -496,9 +496,9 @@ void ExpressionPrefixOperator(struct ParseState *Parser, struct ExpressionStack
|
||||||
case TokenSizeof:
|
case TokenSizeof:
|
||||||
/* return the size of the argument */
|
/* return the size of the argument */
|
||||||
if (TopValue->Typ == &Parser->pc->TypeType)
|
if (TopValue->Typ == &Parser->pc->TypeType)
|
||||||
ExpressionPushInt(Parser, StackTop, TypeSize(TopValue->Val->Typ, TopValue->Val->Typ->ArraySize, TRUE));
|
ExpressionPushInt(Parser, StackTop, TypeSize(TopValue->Val->Typ, TopValue->Val->Typ->ArraySize, true));
|
||||||
else
|
else
|
||||||
ExpressionPushInt(Parser, StackTop, TypeSize(TopValue->Typ, TopValue->Typ->ArraySize, TRUE));
|
ExpressionPushInt(Parser, StackTop, TypeSize(TopValue->Typ, TopValue->Typ->ArraySize, true));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -524,8 +524,8 @@ void ExpressionPrefixOperator(struct ParseState *Parser, struct ExpressionStack
|
||||||
switch (Op) {
|
switch (Op) {
|
||||||
case TokenPlus: ResultInt = TopInt; break;
|
case TokenPlus: ResultInt = TopInt; break;
|
||||||
case TokenMinus: ResultInt = -TopInt; break;
|
case TokenMinus: ResultInt = -TopInt; break;
|
||||||
case TokenIncrement: ResultInt = ExpressionAssignInt(Parser, TopValue, TopInt+1, FALSE); break;
|
case TokenIncrement: ResultInt = ExpressionAssignInt(Parser, TopValue, TopInt+1, false); break;
|
||||||
case TokenDecrement: ResultInt = ExpressionAssignInt(Parser, TopValue, TopInt-1, FALSE); break;
|
case TokenDecrement: ResultInt = ExpressionAssignInt(Parser, TopValue, TopInt-1, false); break;
|
||||||
case TokenUnaryNot: ResultInt = !TopInt; break;
|
case TokenUnaryNot: ResultInt = !TopInt; break;
|
||||||
case TokenUnaryExor: ResultInt = ~TopInt; break;
|
case TokenUnaryExor: ResultInt = ~TopInt; break;
|
||||||
default: ProgramFail(Parser, "invalid operation"); break;
|
default: ProgramFail(Parser, "invalid operation"); break;
|
||||||
|
@ -534,7 +534,7 @@ void ExpressionPrefixOperator(struct ParseState *Parser, struct ExpressionStack
|
||||||
ExpressionPushInt(Parser, StackTop, ResultInt);
|
ExpressionPushInt(Parser, StackTop, ResultInt);
|
||||||
} else if (TopValue->Typ->Base == TypePointer) {
|
} else if (TopValue->Typ->Base == TypePointer) {
|
||||||
/* pointer prefix arithmetic */
|
/* pointer prefix arithmetic */
|
||||||
int Size = TypeSize(TopValue->Typ->FromType, 0, TRUE);
|
int Size = TypeSize(TopValue->Typ->FromType, 0, true);
|
||||||
struct Value *StackValue;
|
struct Value *StackValue;
|
||||||
void *ResultPtr;
|
void *ResultPtr;
|
||||||
|
|
||||||
|
@ -582,8 +582,8 @@ void ExpressionPostfixOperator(struct ParseState *Parser, struct ExpressionStack
|
||||||
long ResultInt = 0;
|
long ResultInt = 0;
|
||||||
long TopInt = ExpressionCoerceInteger(TopValue);
|
long TopInt = ExpressionCoerceInteger(TopValue);
|
||||||
switch (Op) {
|
switch (Op) {
|
||||||
case TokenIncrement: ResultInt = ExpressionAssignInt(Parser, TopValue, TopInt+1, TRUE); break;
|
case TokenIncrement: ResultInt = ExpressionAssignInt(Parser, TopValue, TopInt+1, true); break;
|
||||||
case TokenDecrement: ResultInt = ExpressionAssignInt(Parser, TopValue, TopInt-1, TRUE); break;
|
case TokenDecrement: ResultInt = ExpressionAssignInt(Parser, TopValue, TopInt-1, true); break;
|
||||||
case TokenRightSquareBracket: ProgramFail(Parser, "not supported"); break; /* XXX */
|
case TokenRightSquareBracket: ProgramFail(Parser, "not supported"); break; /* XXX */
|
||||||
case TokenCloseBracket: ProgramFail(Parser, "not supported"); break; /* XXX */
|
case TokenCloseBracket: ProgramFail(Parser, "not supported"); break; /* XXX */
|
||||||
default: ProgramFail(Parser, "invalid operation"); break;
|
default: ProgramFail(Parser, "invalid operation"); break;
|
||||||
|
@ -592,7 +592,7 @@ void ExpressionPostfixOperator(struct ParseState *Parser, struct ExpressionStack
|
||||||
ExpressionPushInt(Parser, StackTop, ResultInt);
|
ExpressionPushInt(Parser, StackTop, ResultInt);
|
||||||
} else if (TopValue->Typ->Base == TypePointer) {
|
} else if (TopValue->Typ->Base == TypePointer) {
|
||||||
/* pointer postfix arithmetic */
|
/* pointer postfix arithmetic */
|
||||||
int Size = TypeSize(TopValue->Typ->FromType, 0, TRUE);
|
int Size = TypeSize(TopValue->Typ->FromType, 0, true);
|
||||||
struct Value *StackValue;
|
struct Value *StackValue;
|
||||||
void *OrigPointer = TopValue->Val->Pointer;
|
void *OrigPointer = TopValue->Val->Pointer;
|
||||||
|
|
||||||
|
@ -641,8 +641,8 @@ void ExpressionInfixOperator(struct ParseState *Parser, struct ExpressionStack *
|
||||||
|
|
||||||
/* make the array element result */
|
/* make the array element result */
|
||||||
switch (BottomValue->Typ->Base) {
|
switch (BottomValue->Typ->Base) {
|
||||||
case TypeArray: Result = VariableAllocValueFromExistingData(Parser, BottomValue->Typ->FromType, (union AnyValue *)(&BottomValue->Val->ArrayMem[0] + TypeSize(BottomValue->Typ, ArrayIndex, TRUE)), BottomValue->IsLValue, BottomValue->LValueFrom); break;
|
case TypeArray: Result = VariableAllocValueFromExistingData(Parser, BottomValue->Typ->FromType, (union AnyValue *)(&BottomValue->Val->ArrayMem[0] + TypeSize(BottomValue->Typ, ArrayIndex, true)), BottomValue->IsLValue, BottomValue->LValueFrom); break;
|
||||||
case TypePointer: Result = VariableAllocValueFromExistingData(Parser, BottomValue->Typ->FromType, (union AnyValue *)((char *)BottomValue->Val->Pointer + TypeSize(BottomValue->Typ->FromType, 0, TRUE) * ArrayIndex), BottomValue->IsLValue, BottomValue->LValueFrom); break;
|
case TypePointer: Result = VariableAllocValueFromExistingData(Parser, BottomValue->Typ->FromType, (union AnyValue *)((char *)BottomValue->Val->Pointer + TypeSize(BottomValue->Typ->FromType, 0, true) * ArrayIndex), BottomValue->IsLValue, BottomValue->LValueFrom); break;
|
||||||
default: ProgramFail(Parser, "this %t is not an array", BottomValue->Typ);
|
default: ProgramFail(Parser, "this %t is not an array", BottomValue->Typ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -655,7 +655,7 @@ void ExpressionInfixOperator(struct ParseState *Parser, struct ExpressionStack *
|
||||||
(TopValue->Typ == &Parser->pc->FPType && IS_NUMERIC_COERCIBLE(BottomValue)) ||
|
(TopValue->Typ == &Parser->pc->FPType && IS_NUMERIC_COERCIBLE(BottomValue)) ||
|
||||||
(IS_NUMERIC_COERCIBLE(TopValue) && BottomValue->Typ == &Parser->pc->FPType) ) {
|
(IS_NUMERIC_COERCIBLE(TopValue) && BottomValue->Typ == &Parser->pc->FPType) ) {
|
||||||
/* floating point infix arithmetic */
|
/* floating point infix arithmetic */
|
||||||
int ResultIsInt = FALSE;
|
int ResultIsInt = false;
|
||||||
double ResultFP = 0.0;
|
double ResultFP = 0.0;
|
||||||
double TopFP = (TopValue->Typ == &Parser->pc->FPType) ? TopValue->Val->FP : (double)ExpressionCoerceInteger(TopValue);
|
double TopFP = (TopValue->Typ == &Parser->pc->FPType) ? TopValue->Val->FP : (double)ExpressionCoerceInteger(TopValue);
|
||||||
double BottomFP = (BottomValue->Typ == &Parser->pc->FPType) ? BottomValue->Val->FP : (double)ExpressionCoerceInteger(BottomValue);
|
double BottomFP = (BottomValue->Typ == &Parser->pc->FPType) ? BottomValue->Val->FP : (double)ExpressionCoerceInteger(BottomValue);
|
||||||
|
@ -666,12 +666,12 @@ void ExpressionInfixOperator(struct ParseState *Parser, struct ExpressionStack *
|
||||||
case TokenSubtractAssign: ASSIGN_FP_OR_INT(BottomFP - TopFP); break;
|
case TokenSubtractAssign: ASSIGN_FP_OR_INT(BottomFP - TopFP); break;
|
||||||
case TokenMultiplyAssign: ASSIGN_FP_OR_INT(BottomFP * TopFP); break;
|
case TokenMultiplyAssign: ASSIGN_FP_OR_INT(BottomFP * TopFP); break;
|
||||||
case TokenDivideAssign: ASSIGN_FP_OR_INT(BottomFP / TopFP); break;
|
case TokenDivideAssign: ASSIGN_FP_OR_INT(BottomFP / TopFP); break;
|
||||||
case TokenEqual: ResultInt = BottomFP == TopFP; ResultIsInt = TRUE; break;
|
case TokenEqual: ResultInt = BottomFP == TopFP; ResultIsInt = true; break;
|
||||||
case TokenNotEqual: ResultInt = BottomFP != TopFP; ResultIsInt = TRUE; break;
|
case TokenNotEqual: ResultInt = BottomFP != TopFP; ResultIsInt = true; break;
|
||||||
case TokenLessThan: ResultInt = BottomFP < TopFP; ResultIsInt = TRUE; break;
|
case TokenLessThan: ResultInt = BottomFP < TopFP; ResultIsInt = true; break;
|
||||||
case TokenGreaterThan: ResultInt = BottomFP > TopFP; ResultIsInt = TRUE; break;
|
case TokenGreaterThan: ResultInt = BottomFP > TopFP; ResultIsInt = true; break;
|
||||||
case TokenLessEqual: ResultInt = BottomFP <= TopFP; ResultIsInt = TRUE; break;
|
case TokenLessEqual: ResultInt = BottomFP <= TopFP; ResultIsInt = true; break;
|
||||||
case TokenGreaterEqual: ResultInt = BottomFP >= TopFP; ResultIsInt = TRUE; break;
|
case TokenGreaterEqual: ResultInt = BottomFP >= TopFP; ResultIsInt = true; break;
|
||||||
case TokenPlus: ResultFP = BottomFP + TopFP; break;
|
case TokenPlus: ResultFP = BottomFP + TopFP; break;
|
||||||
case TokenMinus: ResultFP = BottomFP - TopFP; break;
|
case TokenMinus: ResultFP = BottomFP - TopFP; break;
|
||||||
case TokenAsterisk: ResultFP = BottomFP * TopFP; break;
|
case TokenAsterisk: ResultFP = BottomFP * TopFP; break;
|
||||||
|
@ -688,17 +688,17 @@ void ExpressionInfixOperator(struct ParseState *Parser, struct ExpressionStack *
|
||||||
long TopInt = ExpressionCoerceInteger(TopValue);
|
long TopInt = ExpressionCoerceInteger(TopValue);
|
||||||
long BottomInt = ExpressionCoerceInteger(BottomValue);
|
long BottomInt = ExpressionCoerceInteger(BottomValue);
|
||||||
switch (Op) {
|
switch (Op) {
|
||||||
case TokenAssign: ResultInt = ExpressionAssignInt(Parser, BottomValue, TopInt, FALSE); break;
|
case TokenAssign: ResultInt = ExpressionAssignInt(Parser, BottomValue, TopInt, false); break;
|
||||||
case TokenAddAssign: ResultInt = ExpressionAssignInt(Parser, BottomValue, BottomInt + TopInt, FALSE); break;
|
case TokenAddAssign: ResultInt = ExpressionAssignInt(Parser, BottomValue, BottomInt + TopInt, false); break;
|
||||||
case TokenSubtractAssign: ResultInt = ExpressionAssignInt(Parser, BottomValue, BottomInt - TopInt, FALSE); break;
|
case TokenSubtractAssign: ResultInt = ExpressionAssignInt(Parser, BottomValue, BottomInt - TopInt, false); break;
|
||||||
case TokenMultiplyAssign: ResultInt = ExpressionAssignInt(Parser, BottomValue, BottomInt * TopInt, FALSE); break;
|
case TokenMultiplyAssign: ResultInt = ExpressionAssignInt(Parser, BottomValue, BottomInt * TopInt, false); break;
|
||||||
case TokenDivideAssign: ResultInt = ExpressionAssignInt(Parser, BottomValue, BottomInt / TopInt, FALSE); break;
|
case TokenDivideAssign: ResultInt = ExpressionAssignInt(Parser, BottomValue, BottomInt / TopInt, false); break;
|
||||||
case TokenModulusAssign: ResultInt = ExpressionAssignInt(Parser, BottomValue, BottomInt % TopInt, FALSE); break;
|
case TokenModulusAssign: ResultInt = ExpressionAssignInt(Parser, BottomValue, BottomInt % TopInt, false); break;
|
||||||
case TokenShiftLeftAssign: ResultInt = ExpressionAssignInt(Parser, BottomValue, BottomInt << TopInt, FALSE); break;
|
case TokenShiftLeftAssign: ResultInt = ExpressionAssignInt(Parser, BottomValue, BottomInt << TopInt, false); break;
|
||||||
case TokenShiftRightAssign: ResultInt = ExpressionAssignInt(Parser, BottomValue, BottomInt >> TopInt, FALSE); break;
|
case TokenShiftRightAssign: ResultInt = ExpressionAssignInt(Parser, BottomValue, BottomInt >> TopInt, false); break;
|
||||||
case TokenArithmeticAndAssign: ResultInt = ExpressionAssignInt(Parser, BottomValue, BottomInt & TopInt, FALSE); break;
|
case TokenArithmeticAndAssign: ResultInt = ExpressionAssignInt(Parser, BottomValue, BottomInt & TopInt, false); break;
|
||||||
case TokenArithmeticOrAssign: ResultInt = ExpressionAssignInt(Parser, BottomValue, BottomInt | TopInt, FALSE); break;
|
case TokenArithmeticOrAssign: ResultInt = ExpressionAssignInt(Parser, BottomValue, BottomInt | TopInt, false); break;
|
||||||
case TokenArithmeticExorAssign: ResultInt = ExpressionAssignInt(Parser, BottomValue, BottomInt ^ TopInt, FALSE); break;
|
case TokenArithmeticExorAssign: ResultInt = ExpressionAssignInt(Parser, BottomValue, BottomInt ^ TopInt, false); break;
|
||||||
case TokenLogicalOr: ResultInt = BottomInt || TopInt; break;
|
case TokenLogicalOr: ResultInt = BottomInt || TopInt; break;
|
||||||
case TokenLogicalAnd: ResultInt = BottomInt && TopInt; break;
|
case TokenLogicalAnd: ResultInt = BottomInt && TopInt; break;
|
||||||
case TokenArithmeticOr: ResultInt = BottomInt | TopInt; break;
|
case TokenArithmeticOr: ResultInt = BottomInt | TopInt; break;
|
||||||
|
@ -736,7 +736,7 @@ void ExpressionInfixOperator(struct ParseState *Parser, struct ExpressionStack *
|
||||||
ExpressionPushInt(Parser, StackTop, BottomValue->Val->Pointer != NULL);
|
ExpressionPushInt(Parser, StackTop, BottomValue->Val->Pointer != NULL);
|
||||||
} else if (Op == TokenPlus || Op == TokenMinus) {
|
} else if (Op == TokenPlus || Op == TokenMinus) {
|
||||||
/* pointer arithmetic */
|
/* pointer arithmetic */
|
||||||
int Size = TypeSize(BottomValue->Typ->FromType, 0, TRUE);
|
int Size = TypeSize(BottomValue->Typ->FromType, 0, true);
|
||||||
|
|
||||||
Pointer = BottomValue->Val->Pointer;
|
Pointer = BottomValue->Val->Pointer;
|
||||||
if (Pointer == NULL)
|
if (Pointer == NULL)
|
||||||
|
@ -752,11 +752,11 @@ void ExpressionInfixOperator(struct ParseState *Parser, struct ExpressionStack *
|
||||||
} else if (Op == TokenAssign && TopInt == 0) {
|
} else if (Op == TokenAssign && TopInt == 0) {
|
||||||
/* assign a NULL pointer */
|
/* assign a NULL pointer */
|
||||||
HeapUnpopStack(Parser->pc, sizeof(struct Value));
|
HeapUnpopStack(Parser->pc, sizeof(struct Value));
|
||||||
ExpressionAssign(Parser, BottomValue, TopValue, FALSE, NULL, 0, FALSE);
|
ExpressionAssign(Parser, BottomValue, TopValue, false, NULL, 0, false);
|
||||||
ExpressionStackPushValueNode(Parser, StackTop, BottomValue);
|
ExpressionStackPushValueNode(Parser, StackTop, BottomValue);
|
||||||
} else if (Op == TokenAddAssign || Op == TokenSubtractAssign) {
|
} else if (Op == TokenAddAssign || Op == TokenSubtractAssign) {
|
||||||
/* pointer arithmetic */
|
/* pointer arithmetic */
|
||||||
int Size = TypeSize(BottomValue->Typ->FromType, 0, TRUE);
|
int Size = TypeSize(BottomValue->Typ->FromType, 0, true);
|
||||||
|
|
||||||
Pointer = BottomValue->Val->Pointer;
|
Pointer = BottomValue->Val->Pointer;
|
||||||
if (Pointer == NULL)
|
if (Pointer == NULL)
|
||||||
|
@ -786,12 +786,12 @@ void ExpressionInfixOperator(struct ParseState *Parser, struct ExpressionStack *
|
||||||
} else if (Op == TokenAssign) {
|
} else if (Op == TokenAssign) {
|
||||||
/* assign a non-numeric type */
|
/* assign a non-numeric type */
|
||||||
HeapUnpopStack(Parser->pc, sizeof(struct Value)); /* XXX - possible bug if lvalue is a temp value and takes more than sizeof(struct Value) */
|
HeapUnpopStack(Parser->pc, sizeof(struct Value)); /* XXX - possible bug if lvalue is a temp value and takes more than sizeof(struct Value) */
|
||||||
ExpressionAssign(Parser, BottomValue, TopValue, FALSE, NULL, 0, FALSE);
|
ExpressionAssign(Parser, BottomValue, TopValue, false, NULL, 0, false);
|
||||||
ExpressionStackPushValueNode(Parser, StackTop, BottomValue);
|
ExpressionStackPushValueNode(Parser, StackTop, BottomValue);
|
||||||
} else if (Op == TokenCast) {
|
} else if (Op == TokenCast) {
|
||||||
/* cast a value to a different type */ /* XXX - possible bug if the destination type takes more than sizeof(struct Value) + sizeof(struct ValueType *) */
|
/* cast a value to a different type */ /* XXX - possible bug if the destination type takes more than sizeof(struct Value) + sizeof(struct ValueType *) */
|
||||||
struct Value *ValueLoc = ExpressionStackPushValueByType(Parser, StackTop, BottomValue->Val->Typ);
|
struct Value *ValueLoc = ExpressionStackPushValueByType(Parser, StackTop, BottomValue->Val->Typ);
|
||||||
ExpressionAssign(Parser, ValueLoc, TopValue, TRUE, NULL, 0, TRUE);
|
ExpressionAssign(Parser, ValueLoc, TopValue, true, NULL, 0, true);
|
||||||
} else
|
} else
|
||||||
ProgramFail(Parser, "invalid operation");
|
ProgramFail(Parser, "invalid operation");
|
||||||
}
|
}
|
||||||
|
@ -918,7 +918,7 @@ void ExpressionStackCollapse(struct ParseState *Parser, struct ExpressionStack *
|
||||||
/* push an operator on to the expression stack */
|
/* push an operator on to the expression stack */
|
||||||
void ExpressionStackPushOperator(struct ParseState *Parser, struct ExpressionStack **StackTop, enum OperatorOrder Order, enum LexToken Token, int Precedence)
|
void ExpressionStackPushOperator(struct ParseState *Parser, struct ExpressionStack **StackTop, enum OperatorOrder Order, enum LexToken Token, int Precedence)
|
||||||
{
|
{
|
||||||
struct ExpressionStack *StackNode = VariableAlloc(Parser->pc, Parser, sizeof(struct ExpressionStack), FALSE);
|
struct ExpressionStack *StackNode = VariableAlloc(Parser->pc, Parser, sizeof(struct ExpressionStack), false);
|
||||||
StackNode->Next = *StackTop;
|
StackNode->Next = *StackTop;
|
||||||
StackNode->Order = Order;
|
StackNode->Order = Order;
|
||||||
StackNode->Op = Token;
|
StackNode->Op = Token;
|
||||||
|
@ -942,7 +942,7 @@ void ExpressionGetStructElement(struct ParseState *Parser, struct ExpressionStac
|
||||||
struct Value *Ident;
|
struct Value *Ident;
|
||||||
|
|
||||||
/* get the identifier following the '.' or '->' */
|
/* get the identifier following the '.' or '->' */
|
||||||
if (LexGetToken(Parser, &Ident, TRUE) != TokenIdentifier)
|
if (LexGetToken(Parser, &Ident, true) != TokenIdentifier)
|
||||||
ProgramFail(Parser, "need an structure or union member after '%s'", (Token == TokenDot) ? "." : "->");
|
ProgramFail(Parser, "need an structure or union member after '%s'", (Token == TokenDot) ? "." : "->");
|
||||||
|
|
||||||
if (Parser->Mode == RunModeRun) {
|
if (Parser->Mode == RunModeRun) {
|
||||||
|
@ -969,7 +969,7 @@ void ExpressionGetStructElement(struct ParseState *Parser, struct ExpressionStac
|
||||||
*StackTop = (*StackTop)->Next;
|
*StackTop = (*StackTop)->Next;
|
||||||
|
|
||||||
/* make the result value for this member only */
|
/* make the result value for this member only */
|
||||||
Result = VariableAllocValueFromExistingData(Parser, MemberValue->Typ, (void *)(DerefDataLoc + MemberValue->Val->Integer), TRUE, (StructVal != NULL) ? StructVal->LValueFrom : NULL);
|
Result = VariableAllocValueFromExistingData(Parser, MemberValue->Typ, (void *)(DerefDataLoc + MemberValue->Val->Integer), true, (StructVal != NULL) ? StructVal->LValueFrom : NULL);
|
||||||
ExpressionStackPushValueNode(Parser, StackTop, Result);
|
ExpressionStackPushValueNode(Parser, StackTop, Result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -977,8 +977,8 @@ void ExpressionGetStructElement(struct ParseState *Parser, struct ExpressionStac
|
||||||
/* parse an expression with operator precedence */
|
/* parse an expression with operator precedence */
|
||||||
int ExpressionParse(struct ParseState *Parser, struct Value **Result)
|
int ExpressionParse(struct ParseState *Parser, struct Value **Result)
|
||||||
{
|
{
|
||||||
int PrefixState = TRUE;
|
int PrefixState = true;
|
||||||
int Done = FALSE;
|
int Done = false;
|
||||||
int BracketPrecedence = 0;
|
int BracketPrecedence = 0;
|
||||||
int LocalPrecedence;
|
int LocalPrecedence;
|
||||||
int Precedence = 0;
|
int Precedence = 0;
|
||||||
|
@ -996,7 +996,7 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result)
|
||||||
enum LexToken Token;
|
enum LexToken Token;
|
||||||
|
|
||||||
ParserCopy(&PreState, Parser);
|
ParserCopy(&PreState, Parser);
|
||||||
Token = LexGetToken(Parser, &LexValue, TRUE);
|
Token = LexGetToken(Parser, &LexValue, true);
|
||||||
if ( ( ( (int)Token > TokenComma && (int)Token <= (int)TokenOpenBracket) ||
|
if ( ( ( (int)Token > TokenComma && (int)Token <= (int)TokenOpenBracket) ||
|
||||||
(Token == TokenCloseBracket && BracketPrecedence != 0)) &&
|
(Token == TokenCloseBracket && BracketPrecedence != 0)) &&
|
||||||
(Token != TokenColon || TernaryDepth > 0) ) {
|
(Token != TokenColon || TernaryDepth > 0) ) {
|
||||||
|
@ -1011,7 +1011,7 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result)
|
||||||
|
|
||||||
if (Token == TokenOpenBracket) {
|
if (Token == TokenOpenBracket) {
|
||||||
/* it's either a new bracket level or a cast */
|
/* it's either a new bracket level or a cast */
|
||||||
enum LexToken BracketToken = LexGetToken(Parser, &LexValue, FALSE);
|
enum LexToken BracketToken = LexGetToken(Parser, &LexValue, false);
|
||||||
if (IsTypeToken(Parser, BracketToken, LexValue) && (StackTop == NULL || StackTop->Op != TokenSizeof)) {
|
if (IsTypeToken(Parser, BracketToken, LexValue) && (StackTop == NULL || StackTop->Op != TokenSizeof)) {
|
||||||
/* it's a cast - get the new type */
|
/* it's a cast - get the new type */
|
||||||
struct ValueType *CastType;
|
struct ValueType *CastType;
|
||||||
|
@ -1019,14 +1019,14 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result)
|
||||||
struct Value *CastTypeValue;
|
struct Value *CastTypeValue;
|
||||||
|
|
||||||
TypeParse(Parser, &CastType, &CastIdentifier, NULL);
|
TypeParse(Parser, &CastType, &CastIdentifier, NULL);
|
||||||
if (LexGetToken(Parser, &LexValue, TRUE) != TokenCloseBracket)
|
if (LexGetToken(Parser, &LexValue, true) != TokenCloseBracket)
|
||||||
ProgramFail(Parser, "brackets not closed");
|
ProgramFail(Parser, "brackets not closed");
|
||||||
|
|
||||||
/* scan and collapse the stack to the precedence of this infix cast operator, then push */
|
/* scan and collapse the stack to the precedence of this infix cast operator, then push */
|
||||||
Precedence = BracketPrecedence + OperatorPrecedence[(int)TokenCast].PrefixPrecedence;
|
Precedence = BracketPrecedence + OperatorPrecedence[(int)TokenCast].PrefixPrecedence;
|
||||||
|
|
||||||
ExpressionStackCollapse(Parser, &StackTop, Precedence+1, &IgnorePrecedence);
|
ExpressionStackCollapse(Parser, &StackTop, Precedence+1, &IgnorePrecedence);
|
||||||
CastTypeValue = VariableAllocValueFromType(Parser->pc, Parser, &Parser->pc->TypeType, FALSE, NULL, FALSE);
|
CastTypeValue = VariableAllocValueFromType(Parser->pc, Parser, &Parser->pc->TypeType, false, NULL, false);
|
||||||
CastTypeValue->Val->Typ = CastType;
|
CastTypeValue->Val->Typ = CastType;
|
||||||
ExpressionStackPushValueNode(Parser, &StackTop, CastTypeValue);
|
ExpressionStackPushValueNode(Parser, &StackTop, CastTypeValue);
|
||||||
ExpressionStackPushOperator(Parser, &StackTop, OrderInfix, TokenCast, Precedence);
|
ExpressionStackPushOperator(Parser, &StackTop, OrderInfix, TokenCast, Precedence);
|
||||||
|
@ -1038,7 +1038,7 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result)
|
||||||
/* scan and collapse the stack to the precedence of this operator, then push */
|
/* scan and collapse the stack to the precedence of this operator, then push */
|
||||||
|
|
||||||
/* take some extra care for double prefix operators, e.g. x = - -5, or x = **y */
|
/* take some extra care for double prefix operators, e.g. x = - -5, or x = **y */
|
||||||
int NextToken = LexGetToken(Parser, NULL, FALSE);
|
int NextToken = LexGetToken(Parser, NULL, false);
|
||||||
int TempPrecedenceBoost = 0;
|
int TempPrecedenceBoost = 0;
|
||||||
if (NextToken > TokenComma && NextToken < TokenOpenBracket) {
|
if (NextToken > TokenComma && NextToken < TokenOpenBracket) {
|
||||||
int NextPrecedence = OperatorPrecedence[(int)NextToken].PrefixPrecedence;
|
int NextPrecedence = OperatorPrecedence[(int)NextToken].PrefixPrecedence;
|
||||||
|
@ -1061,7 +1061,7 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result)
|
||||||
if (BracketPrecedence == 0) {
|
if (BracketPrecedence == 0) {
|
||||||
/* assume this bracket is after the end of the expression */
|
/* assume this bracket is after the end of the expression */
|
||||||
ParserCopy(Parser, &PreState);
|
ParserCopy(Parser, &PreState);
|
||||||
Done = TRUE;
|
Done = true;
|
||||||
} else {
|
} else {
|
||||||
/* collapse to the bracket precedence */
|
/* collapse to the bracket precedence */
|
||||||
ExpressionStackCollapse(Parser, &StackTop, BracketPrecedence, &IgnorePrecedence);
|
ExpressionStackCollapse(Parser, &StackTop, BracketPrecedence, &IgnorePrecedence);
|
||||||
|
@ -1099,7 +1099,7 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result)
|
||||||
|
|
||||||
/* push the operator on the stack */
|
/* push the operator on the stack */
|
||||||
ExpressionStackPushOperator(Parser, &StackTop, OrderInfix, Token, Precedence);
|
ExpressionStackPushOperator(Parser, &StackTop, OrderInfix, Token, Precedence);
|
||||||
PrefixState = TRUE;
|
PrefixState = true;
|
||||||
|
|
||||||
switch (Token) {
|
switch (Token) {
|
||||||
case TokenQuestionMark: TernaryDepth++; break;
|
case TokenQuestionMark: TernaryDepth++; break;
|
||||||
|
@ -1121,7 +1121,7 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result)
|
||||||
if (!PrefixState)
|
if (!PrefixState)
|
||||||
ProgramFail(Parser, "identifier not expected here");
|
ProgramFail(Parser, "identifier not expected here");
|
||||||
|
|
||||||
if (LexGetToken(Parser, NULL, FALSE) == TokenOpenBracket) {
|
if (LexGetToken(Parser, NULL, false) == TokenOpenBracket) {
|
||||||
ExpressionParseFunctionCall(Parser, &StackTop, LexValue->Val->Identifier, Parser->Mode == RunModeRun && Precedence < IgnorePrecedence);
|
ExpressionParseFunctionCall(Parser, &StackTop, LexValue->Val->Identifier, Parser->Mode == RunModeRun && Precedence < IgnorePrecedence);
|
||||||
} else {
|
} else {
|
||||||
if (Parser->Mode == RunModeRun /* && Precedence < IgnorePrecedence */) {
|
if (Parser->Mode == RunModeRun /* && Precedence < IgnorePrecedence */) {
|
||||||
|
@ -1138,7 +1138,7 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result)
|
||||||
if (VariableValue->Val->MacroDef.NumParams != 0)
|
if (VariableValue->Val->MacroDef.NumParams != 0)
|
||||||
ProgramFail(&MacroParser, "macro arguments missing");
|
ProgramFail(&MacroParser, "macro arguments missing");
|
||||||
|
|
||||||
if (!ExpressionParse(&MacroParser, &MacroResult) || LexGetToken(&MacroParser, NULL, FALSE) != TokenEndOfFunction)
|
if (!ExpressionParse(&MacroParser, &MacroResult) || LexGetToken(&MacroParser, NULL, false) != TokenEndOfFunction)
|
||||||
ProgramFail(&MacroParser, "expression expected");
|
ProgramFail(&MacroParser, "expression expected");
|
||||||
|
|
||||||
ExpressionStackPushValueNode(Parser, &StackTop, MacroResult);
|
ExpressionStackPushValueNode(Parser, &StackTop, MacroResult);
|
||||||
|
@ -1155,13 +1155,13 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result)
|
||||||
if (Precedence <= IgnorePrecedence)
|
if (Precedence <= IgnorePrecedence)
|
||||||
IgnorePrecedence = DEEP_PRECEDENCE;
|
IgnorePrecedence = DEEP_PRECEDENCE;
|
||||||
|
|
||||||
PrefixState = FALSE;
|
PrefixState = false;
|
||||||
} else if ((int)Token > TokenCloseBracket && (int)Token <= TokenCharacterConstant) {
|
} else if ((int)Token > TokenCloseBracket && (int)Token <= TokenCharacterConstant) {
|
||||||
/* it's a value of some sort, push it */
|
/* it's a value of some sort, push it */
|
||||||
if (!PrefixState)
|
if (!PrefixState)
|
||||||
ProgramFail(Parser, "value not expected here");
|
ProgramFail(Parser, "value not expected here");
|
||||||
|
|
||||||
PrefixState = FALSE;
|
PrefixState = false;
|
||||||
ExpressionStackPushValue(Parser, &StackTop, LexValue);
|
ExpressionStackPushValue(Parser, &StackTop, LexValue);
|
||||||
} else if (IsTypeToken(Parser, Token, LexValue)) {
|
} else if (IsTypeToken(Parser, Token, LexValue)) {
|
||||||
/* it's a type. push it on the stack like a value. this is used in sizeof() */
|
/* it's a type. push it on the stack like a value. this is used in sizeof() */
|
||||||
|
@ -1172,16 +1172,16 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result)
|
||||||
if (!PrefixState)
|
if (!PrefixState)
|
||||||
ProgramFail(Parser, "type not expected here");
|
ProgramFail(Parser, "type not expected here");
|
||||||
|
|
||||||
PrefixState = FALSE;
|
PrefixState = false;
|
||||||
ParserCopy(Parser, &PreState);
|
ParserCopy(Parser, &PreState);
|
||||||
TypeParse(Parser, &Typ, &Identifier, NULL);
|
TypeParse(Parser, &Typ, &Identifier, NULL);
|
||||||
TypeValue = VariableAllocValueFromType(Parser->pc, Parser, &Parser->pc->TypeType, FALSE, NULL, FALSE);
|
TypeValue = VariableAllocValueFromType(Parser->pc, Parser, &Parser->pc->TypeType, false, NULL, false);
|
||||||
TypeValue->Val->Typ = Typ;
|
TypeValue->Val->Typ = Typ;
|
||||||
ExpressionStackPushValueNode(Parser, &StackTop, TypeValue);
|
ExpressionStackPushValueNode(Parser, &StackTop, TypeValue);
|
||||||
} else {
|
} else {
|
||||||
/* it isn't a token from an expression */
|
/* it isn't a token from an expression */
|
||||||
ParserCopy(Parser, &PreState);
|
ParserCopy(Parser, &PreState);
|
||||||
Done = TRUE;
|
Done = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (!Done);
|
} while (!Done);
|
||||||
|
@ -1246,12 +1246,12 @@ void ExpressionParseMacroCall(struct ParseState *Parser, struct ExpressionStack
|
||||||
}
|
}
|
||||||
|
|
||||||
ArgCount++;
|
ArgCount++;
|
||||||
Token = LexGetToken(Parser, NULL, TRUE);
|
Token = LexGetToken(Parser, NULL, true);
|
||||||
if (Token != TokenComma && Token != TokenCloseBracket)
|
if (Token != TokenComma && Token != TokenCloseBracket)
|
||||||
ProgramFail(Parser, "comma expected");
|
ProgramFail(Parser, "comma expected");
|
||||||
} else {
|
} else {
|
||||||
/* end of argument list? */
|
/* end of argument list? */
|
||||||
Token = LexGetToken(Parser, NULL, TRUE);
|
Token = LexGetToken(Parser, NULL, true);
|
||||||
if (!TokenCloseBracket)
|
if (!TokenCloseBracket)
|
||||||
ProgramFail(Parser, "bad argument");
|
ProgramFail(Parser, "bad argument");
|
||||||
}
|
}
|
||||||
|
@ -1276,10 +1276,10 @@ void ExpressionParseMacroCall(struct ParseState *Parser, struct ExpressionStack
|
||||||
Parser->pc->TopStackFrame->NumParams = ArgCount;
|
Parser->pc->TopStackFrame->NumParams = ArgCount;
|
||||||
Parser->pc->TopStackFrame->ReturnValue = ReturnValue;
|
Parser->pc->TopStackFrame->ReturnValue = ReturnValue;
|
||||||
for (Count = 0; Count < MDef->NumParams; Count++)
|
for (Count = 0; Count < MDef->NumParams; Count++)
|
||||||
VariableDefine(Parser->pc, Parser, MDef->ParamName[Count], ParamArray[Count], NULL, TRUE);
|
VariableDefine(Parser->pc, Parser, MDef->ParamName[Count], ParamArray[Count], NULL, true);
|
||||||
|
|
||||||
ExpressionParse(&MacroParser, &EvalValue);
|
ExpressionParse(&MacroParser, &EvalValue);
|
||||||
ExpressionAssign(Parser, ReturnValue, EvalValue, TRUE, MacroName, 0, FALSE);
|
ExpressionAssign(Parser, ReturnValue, EvalValue, true, MacroName, 0, false);
|
||||||
VariableStackFramePop(Parser);
|
VariableStackFramePop(Parser);
|
||||||
HeapPopStackFrame(Parser->pc);
|
HeapPopStackFrame(Parser->pc);
|
||||||
}
|
}
|
||||||
|
@ -1289,7 +1289,7 @@ void ExpressionParseMacroCall(struct ParseState *Parser, struct ExpressionStack
|
||||||
void ExpressionParseFunctionCall(struct ParseState *Parser, struct ExpressionStack **StackTop, const char *FuncName, int RunIt)
|
void ExpressionParseFunctionCall(struct ParseState *Parser, struct ExpressionStack **StackTop, const char *FuncName, int RunIt)
|
||||||
{
|
{
|
||||||
int ArgCount;
|
int ArgCount;
|
||||||
enum LexToken Token = LexGetToken(Parser, NULL, TRUE); /* open bracket */
|
enum LexToken Token = LexGetToken(Parser, NULL, true); /* open bracket */
|
||||||
enum RunMode OldMode = Parser->Mode;
|
enum RunMode OldMode = Parser->Mode;
|
||||||
struct Value *ReturnValue = NULL;
|
struct Value *ReturnValue = NULL;
|
||||||
struct Value *FuncValue = NULL;
|
struct Value *FuncValue = NULL;
|
||||||
|
@ -1324,12 +1324,12 @@ void ExpressionParseFunctionCall(struct ParseState *Parser, struct ExpressionSta
|
||||||
ArgCount = 0;
|
ArgCount = 0;
|
||||||
do {
|
do {
|
||||||
if (RunIt && ArgCount < FuncValue->Val->FuncDef.NumParams)
|
if (RunIt && ArgCount < FuncValue->Val->FuncDef.NumParams)
|
||||||
ParamArray[ArgCount] = VariableAllocValueFromType(Parser->pc, Parser, FuncValue->Val->FuncDef.ParamType[ArgCount], FALSE, NULL, FALSE);
|
ParamArray[ArgCount] = VariableAllocValueFromType(Parser->pc, Parser, FuncValue->Val->FuncDef.ParamType[ArgCount], false, NULL, false);
|
||||||
|
|
||||||
if (ExpressionParse(Parser, &Param)) {
|
if (ExpressionParse(Parser, &Param)) {
|
||||||
if (RunIt) {
|
if (RunIt) {
|
||||||
if (ArgCount < FuncValue->Val->FuncDef.NumParams) {
|
if (ArgCount < FuncValue->Val->FuncDef.NumParams) {
|
||||||
ExpressionAssign(Parser, ParamArray[ArgCount], Param, TRUE, FuncName, ArgCount+1, FALSE);
|
ExpressionAssign(Parser, ParamArray[ArgCount], Param, true, FuncName, ArgCount+1, false);
|
||||||
VariableStackPop(Parser, Param);
|
VariableStackPop(Parser, Param);
|
||||||
} else {
|
} else {
|
||||||
if (!FuncValue->Val->FuncDef.VarArgs)
|
if (!FuncValue->Val->FuncDef.VarArgs)
|
||||||
|
@ -1338,12 +1338,12 @@ void ExpressionParseFunctionCall(struct ParseState *Parser, struct ExpressionSta
|
||||||
}
|
}
|
||||||
|
|
||||||
ArgCount++;
|
ArgCount++;
|
||||||
Token = LexGetToken(Parser, NULL, TRUE);
|
Token = LexGetToken(Parser, NULL, true);
|
||||||
if (Token != TokenComma && Token != TokenCloseBracket)
|
if (Token != TokenComma && Token != TokenCloseBracket)
|
||||||
ProgramFail(Parser, "comma expected");
|
ProgramFail(Parser, "comma expected");
|
||||||
} else {
|
} else {
|
||||||
/* end of argument list? */
|
/* end of argument list? */
|
||||||
Token = LexGetToken(Parser, NULL, TRUE);
|
Token = LexGetToken(Parser, NULL, true);
|
||||||
if (!TokenCloseBracket)
|
if (!TokenCloseBracket)
|
||||||
ProgramFail(Parser, "bad argument");
|
ProgramFail(Parser, "bad argument");
|
||||||
}
|
}
|
||||||
|
@ -1373,11 +1373,11 @@ void ExpressionParseFunctionCall(struct ParseState *Parser, struct ExpressionSta
|
||||||
Parser->ScopeID = -1;
|
Parser->ScopeID = -1;
|
||||||
|
|
||||||
for (Count = 0; Count < FuncValue->Val->FuncDef.NumParams; Count++)
|
for (Count = 0; Count < FuncValue->Val->FuncDef.NumParams; Count++)
|
||||||
VariableDefine(Parser->pc, Parser, FuncValue->Val->FuncDef.ParamName[Count], ParamArray[Count], NULL, TRUE);
|
VariableDefine(Parser->pc, Parser, FuncValue->Val->FuncDef.ParamName[Count], ParamArray[Count], NULL, true);
|
||||||
|
|
||||||
Parser->ScopeID = OldScopeID;
|
Parser->ScopeID = OldScopeID;
|
||||||
|
|
||||||
if (ParseStatement(&FuncParser, TRUE) != ParseResultOk)
|
if (ParseStatement(&FuncParser, true) != ParseResultOk)
|
||||||
ProgramFail(&FuncParser, "function body expected");
|
ProgramFail(&FuncParser, "function body expected");
|
||||||
|
|
||||||
if (RunIt) {
|
if (RunIt) {
|
||||||
|
|
8
heap.c
8
heap.c
|
@ -76,7 +76,7 @@ int HeapPopStack(Picoc *pc, void *Addr, int Size)
|
||||||
{
|
{
|
||||||
int ToLose = MEM_ALIGN(Size);
|
int ToLose = MEM_ALIGN(Size);
|
||||||
if (ToLose > ((char*)pc->HeapStackTop - (char*)&(pc->HeapMemory)[0]))
|
if (ToLose > ((char*)pc->HeapStackTop - (char*)&(pc->HeapMemory)[0]))
|
||||||
return FALSE;
|
return false;
|
||||||
|
|
||||||
#ifdef DEBUG_HEAP
|
#ifdef DEBUG_HEAP
|
||||||
printf("HeapPopStack(0x%lx, %ld) back to 0x%lx\n", (unsigned long)Addr,
|
printf("HeapPopStack(0x%lx, %ld) back to 0x%lx\n", (unsigned long)Addr,
|
||||||
|
@ -85,7 +85,7 @@ int HeapPopStack(Picoc *pc, void *Addr, int Size)
|
||||||
pc->HeapStackTop = (void*)((char*)pc->HeapStackTop - ToLose);
|
pc->HeapStackTop = (void*)((char*)pc->HeapStackTop - ToLose);
|
||||||
assert(Addr == NULL || pc->HeapStackTop == Addr);
|
assert(Addr == NULL || pc->HeapStackTop == Addr);
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* push a new stack frame on to the stack */
|
/* push a new stack frame on to the stack */
|
||||||
|
@ -108,9 +108,9 @@ int HeapPopStackFrame(Picoc *pc)
|
||||||
#ifdef DEBUG_HEAP
|
#ifdef DEBUG_HEAP
|
||||||
printf("Popping stack frame back to 0x%lx\n", (unsigned long)pc->HeapStackTop);
|
printf("Popping stack frame back to 0x%lx\n", (unsigned long)pc->HeapStackTop);
|
||||||
#endif
|
#endif
|
||||||
return TRUE;
|
return true;
|
||||||
} else
|
} else
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allocate some dynamically allocated memory. memory is cleared. can return NULL if out of memory */
|
/* allocate some dynamically allocated memory. memory is cleared. can return NULL if out of memory */
|
||||||
|
|
|
@ -69,7 +69,7 @@ void IncludeFile(Picoc *pc, char *FileName)
|
||||||
if (strcmp(LInclude->IncludeName, FileName) == 0) {
|
if (strcmp(LInclude->IncludeName, FileName) == 0) {
|
||||||
/* found it - protect against multiple inclusion */
|
/* found it - protect against multiple inclusion */
|
||||||
if (!VariableDefined(pc, FileName)) {
|
if (!VariableDefined(pc, FileName)) {
|
||||||
VariableDefine(pc, NULL, FileName, NULL, &pc->VoidType, FALSE);
|
VariableDefine(pc, NULL, FileName, NULL, &pc->VoidType, false);
|
||||||
|
|
||||||
/* run an extra startup function if there is one */
|
/* run an extra startup function if there is one */
|
||||||
if (LInclude->SetupFunction != NULL)
|
if (LInclude->SetupFunction != NULL)
|
||||||
|
@ -77,7 +77,7 @@ void IncludeFile(Picoc *pc, char *FileName)
|
||||||
|
|
||||||
/* parse the setup C source code - may define types etc. */
|
/* parse the setup C source code - may define types etc. */
|
||||||
if (LInclude->SetupCSource != NULL)
|
if (LInclude->SetupCSource != NULL)
|
||||||
PicocParse(pc, FileName, LInclude->SetupCSource, strlen(LInclude->SetupCSource), TRUE, TRUE, FALSE, FALSE);
|
PicocParse(pc, FileName, LInclude->SetupCSource, strlen(LInclude->SetupCSource), true, true, false, false);
|
||||||
|
|
||||||
/* set up the library functions */
|
/* set up the library functions */
|
||||||
if (LInclude->FuncList != NULL)
|
if (LInclude->FuncList != NULL)
|
||||||
|
|
|
@ -7,13 +7,6 @@
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
|
||||||
|
|
||||||
/* handy definitions */
|
|
||||||
#ifndef TRUE
|
|
||||||
#define TRUE 1
|
|
||||||
#define FALSE 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef NULL
|
#ifndef NULL
|
||||||
#define NULL 0
|
#define NULL 0
|
||||||
#endif
|
#endif
|
||||||
|
@ -24,8 +17,6 @@
|
||||||
|
|
||||||
#define MEM_ALIGN(x) (((x) + sizeof(ALIGN_TYPE) - 1) & ~(sizeof(ALIGN_TYPE)-1))
|
#define MEM_ALIGN(x) (((x) + sizeof(ALIGN_TYPE) - 1) & ~(sizeof(ALIGN_TYPE)-1))
|
||||||
|
|
||||||
#define GETS_BUF_MAX (256)
|
|
||||||
|
|
||||||
/* for debugging */
|
/* for debugging */
|
||||||
#define PRINT_SOURCE_POS() { \
|
#define PRINT_SOURCE_POS() { \
|
||||||
PrintSourceTextErrorLine(Parser->pc->CStdOut, \
|
PrintSourceTextErrorLine(Parser->pc->CStdOut, \
|
||||||
|
|
62
lex.c
62
lex.c
|
@ -7,7 +7,7 @@
|
||||||
#define isCident(c) (isalnum(c) || (c)=='_')
|
#define isCident(c) (isalnum(c) || (c)=='_')
|
||||||
|
|
||||||
#define IS_HEX_ALPHA_DIGIT(c) (((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
|
#define IS_HEX_ALPHA_DIGIT(c) (((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
|
||||||
#define IS_BASE_DIGIT(c,b) (((c) >= '0' && (c) < '0' + (((b)<10)?(b):10)) || (((b) > 10) ? IS_HEX_ALPHA_DIGIT(c) : FALSE))
|
#define IS_BASE_DIGIT(c,b) (((c) >= '0' && (c) < '0' + (((b)<10)?(b):10)) || (((b) > 10) ? IS_HEX_ALPHA_DIGIT(c) : false))
|
||||||
#define GET_BASE_DIGIT(c) (((c) <= '9') ? ((c) - '0') : (((c) <= 'F') ? ((c) - 'A' + 10) : ((c) - 'a' + 10)))
|
#define GET_BASE_DIGIT(c) (((c) <= '9') ? ((c) - '0') : (((c) <= 'F') ? ((c) - 'A' + 10) : ((c) - 'a' + 10)))
|
||||||
|
|
||||||
#define NEXTIS(c,x,y) { if (NextChar == (c)) { LEXER_INC(Lexer); GotToken = (x); } else GotToken = (y); }
|
#define NEXTIS(c,x,y) { if (NextChar == (c)) { LEXER_INC(Lexer); GotToken = (x); } else GotToken = (y); }
|
||||||
|
@ -80,7 +80,7 @@ void LexInit(Picoc *pc)
|
||||||
{
|
{
|
||||||
int Count;
|
int Count;
|
||||||
|
|
||||||
TableInitTable(&pc->ReservedWordTable, &pc->ReservedWordHashTable[0], sizeof(ReservedWords) / sizeof(struct ReservedWord) * 2, TRUE);
|
TableInitTable(&pc->ReservedWordTable, &pc->ReservedWordHashTable[0], sizeof(ReservedWords) / sizeof(struct ReservedWord) * 2, true);
|
||||||
|
|
||||||
for (Count = 0; Count < sizeof(ReservedWords) / sizeof(struct ReservedWord); Count++) {
|
for (Count = 0; Count < sizeof(ReservedWords) / sizeof(struct ReservedWord); Count++) {
|
||||||
TableSet(pc, &pc->ReservedWordTable, TableStrRegister(pc, ReservedWords[Count].Word), (struct Value *)&ReservedWords[Count], NULL, 0, 0);
|
TableSet(pc, &pc->ReservedWordTable, TableStrRegister(pc, ReservedWords[Count].Word), (struct Value *)&ReservedWords[Count], NULL, 0, 0);
|
||||||
|
@ -88,11 +88,11 @@ void LexInit(Picoc *pc)
|
||||||
|
|
||||||
pc->LexValue.Typ = NULL;
|
pc->LexValue.Typ = NULL;
|
||||||
pc->LexValue.Val = &pc->LexAnyValue;
|
pc->LexValue.Val = &pc->LexAnyValue;
|
||||||
pc->LexValue.LValueFrom = FALSE;
|
pc->LexValue.LValueFrom = false;
|
||||||
pc->LexValue.ValOnHeap = FALSE;
|
pc->LexValue.ValOnHeap = false;
|
||||||
pc->LexValue.ValOnStack = FALSE;
|
pc->LexValue.ValOnStack = false;
|
||||||
pc->LexValue.AnyValOnHeap = FALSE;
|
pc->LexValue.AnyValOnHeap = false;
|
||||||
pc->LexValue.IsLValue = FALSE;
|
pc->LexValue.IsLValue = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* deallocate */
|
/* deallocate */
|
||||||
|
@ -295,7 +295,7 @@ unsigned char LexUnEscapeCharacter(const char **From, const char *End)
|
||||||
/* get a string constant - used while scanning */
|
/* get a string constant - used while scanning */
|
||||||
enum LexToken LexGetStringConstant(Picoc *pc, struct LexState *Lexer, struct Value *Value, char EndChar)
|
enum LexToken LexGetStringConstant(Picoc *pc, struct LexState *Lexer, struct Value *Value, char EndChar)
|
||||||
{
|
{
|
||||||
int Escape = FALSE;
|
int Escape = false;
|
||||||
const char *StartPos = Lexer->Pos;
|
const char *StartPos = Lexer->Pos;
|
||||||
const char *EndPos;
|
const char *EndPos;
|
||||||
char *EscBuf;
|
char *EscBuf;
|
||||||
|
@ -316,9 +316,9 @@ enum LexToken LexGetStringConstant(Picoc *pc, struct LexState *Lexer, struct Val
|
||||||
Lexer->EmitExtraNewlines++;
|
Lexer->EmitExtraNewlines++;
|
||||||
}
|
}
|
||||||
|
|
||||||
Escape = FALSE;
|
Escape = false;
|
||||||
} else if (*Lexer->Pos == '\\')
|
} else if (*Lexer->Pos == '\\')
|
||||||
Escape = TRUE;
|
Escape = true;
|
||||||
|
|
||||||
LEXER_INC(Lexer);
|
LEXER_INC(Lexer);
|
||||||
}
|
}
|
||||||
|
@ -337,7 +337,7 @@ enum LexToken LexGetStringConstant(Picoc *pc, struct LexState *Lexer, struct Val
|
||||||
ArrayValue = VariableStringLiteralGet(pc, RegString);
|
ArrayValue = VariableStringLiteralGet(pc, RegString);
|
||||||
if (ArrayValue == NULL) {
|
if (ArrayValue == NULL) {
|
||||||
/* create and store this string literal */
|
/* create and store this string literal */
|
||||||
ArrayValue = VariableAllocValueAndData(pc, NULL, 0, FALSE, NULL, TRUE);
|
ArrayValue = VariableAllocValueAndData(pc, NULL, 0, false, NULL, true);
|
||||||
ArrayValue->Typ = pc->CharArrayType;
|
ArrayValue->Typ = pc->CharArrayType;
|
||||||
ArrayValue->Val = (union AnyValue *)RegString;
|
ArrayValue->Val = (union AnyValue *)RegString;
|
||||||
VariableStringLiteralDefine(pc, RegString, ArrayValue);
|
VariableStringLiteralDefine(pc, RegString, ArrayValue);
|
||||||
|
@ -606,7 +606,7 @@ enum LexToken LexGetRawToken(struct ParseState *Parser, struct Value **Value, in
|
||||||
/* get interactive input */
|
/* get interactive input */
|
||||||
if (pc->LexUseStatementPrompt) {
|
if (pc->LexUseStatementPrompt) {
|
||||||
Prompt = INTERACTIVE_PROMPT_STATEMENT;
|
Prompt = INTERACTIVE_PROMPT_STATEMENT;
|
||||||
pc->LexUseStatementPrompt = FALSE;
|
pc->LexUseStatementPrompt = false;
|
||||||
} else
|
} else
|
||||||
Prompt = INTERACTIVE_PROMPT_LINE;
|
Prompt = INTERACTIVE_PROMPT_LINE;
|
||||||
|
|
||||||
|
@ -615,7 +615,7 @@ enum LexToken LexGetRawToken(struct ParseState *Parser, struct Value **Value, in
|
||||||
|
|
||||||
/* put the new line at the end of the linked list of interactive lines */
|
/* put the new line at the end of the linked list of interactive lines */
|
||||||
LineTokens = LexAnalyse(pc, pc->StrEmpty, &LineBuffer[0], strlen(LineBuffer), &LineBytes);
|
LineTokens = LexAnalyse(pc, pc->StrEmpty, &LineBuffer[0], strlen(LineBuffer), &LineBytes);
|
||||||
LineNode = VariableAlloc(pc, Parser, sizeof(struct TokenLine), TRUE);
|
LineNode = VariableAlloc(pc, Parser, sizeof(struct TokenLine), true);
|
||||||
LineNode->Tokens = LineTokens;
|
LineNode->Tokens = LineTokens;
|
||||||
LineNode->NumBytes = LineBytes;
|
LineNode->NumBytes = LineBytes;
|
||||||
if (pc->InteractiveHead == NULL) {
|
if (pc->InteractiveHead == NULL) {
|
||||||
|
@ -663,9 +663,9 @@ enum LexToken LexGetRawToken(struct ParseState *Parser, struct Value **Value, in
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy((void *)pc->LexValue.Val, (void *)((char *)Parser->Pos + TOKEN_DATA_OFFSET), ValueSize);
|
memcpy((void *)pc->LexValue.Val, (void *)((char *)Parser->Pos + TOKEN_DATA_OFFSET), ValueSize);
|
||||||
pc->LexValue.ValOnHeap = FALSE;
|
pc->LexValue.ValOnHeap = false;
|
||||||
pc->LexValue.ValOnStack = FALSE;
|
pc->LexValue.ValOnStack = false;
|
||||||
pc->LexValue.IsLValue = FALSE;
|
pc->LexValue.IsLValue = false;
|
||||||
pc->LexValue.LValueFrom = NULL;
|
pc->LexValue.LValueFrom = NULL;
|
||||||
*Value = &pc->LexValue;
|
*Value = &pc->LexValue;
|
||||||
}
|
}
|
||||||
|
@ -688,7 +688,7 @@ enum LexToken LexGetRawToken(struct ParseState *Parser, struct Value **Value, in
|
||||||
void LexHashIncPos(struct ParseState *Parser, int IncPos)
|
void LexHashIncPos(struct ParseState *Parser, int IncPos)
|
||||||
{
|
{
|
||||||
if (!IncPos)
|
if (!IncPos)
|
||||||
LexGetRawToken(Parser, NULL, TRUE);
|
LexGetRawToken(Parser, NULL, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* handle a #ifdef directive */
|
/* handle a #ifdef directive */
|
||||||
|
@ -698,7 +698,7 @@ void LexHashIfdef(struct ParseState *Parser, int IfNot)
|
||||||
int IsDefined;
|
int IsDefined;
|
||||||
struct Value *IdentValue;
|
struct Value *IdentValue;
|
||||||
struct Value *SavedValue;
|
struct Value *SavedValue;
|
||||||
enum LexToken Token = LexGetRawToken(Parser, &IdentValue, TRUE);
|
enum LexToken Token = LexGetRawToken(Parser, &IdentValue, true);
|
||||||
|
|
||||||
if (Token != TokenIdentifier)
|
if (Token != TokenIdentifier)
|
||||||
ProgramFail(Parser, "identifier expected");
|
ProgramFail(Parser, "identifier expected");
|
||||||
|
@ -720,7 +720,7 @@ void LexHashIf(struct ParseState *Parser)
|
||||||
struct Value *IdentValue;
|
struct Value *IdentValue;
|
||||||
struct Value *SavedValue = NULL;
|
struct Value *SavedValue = NULL;
|
||||||
struct ParseState MacroParser;
|
struct ParseState MacroParser;
|
||||||
enum LexToken Token = LexGetRawToken(Parser, &IdentValue, TRUE);
|
enum LexToken Token = LexGetRawToken(Parser, &IdentValue, true);
|
||||||
|
|
||||||
if (Token == TokenIdentifier) {
|
if (Token == TokenIdentifier) {
|
||||||
/* look up a value from a macro definition */
|
/* look up a value from a macro definition */
|
||||||
|
@ -731,7 +731,7 @@ void LexHashIf(struct ParseState *Parser)
|
||||||
ProgramFail(Parser, "value expected");
|
ProgramFail(Parser, "value expected");
|
||||||
|
|
||||||
ParserCopy(&MacroParser, &SavedValue->Val->MacroDef.Body);
|
ParserCopy(&MacroParser, &SavedValue->Val->MacroDef.Body);
|
||||||
Token = LexGetRawToken(&MacroParser, &IdentValue, TRUE);
|
Token = LexGetRawToken(&MacroParser, &IdentValue, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Token != TokenCharacterConstant && Token != TokenIntegerConstant)
|
if (Token != TokenCharacterConstant && Token != TokenIntegerConstant)
|
||||||
|
@ -816,22 +816,22 @@ enum LexToken LexGetToken(struct ParseState *Parser, struct Value **Value, int I
|
||||||
|
|
||||||
/* implements the pre-processor #if commands */
|
/* implements the pre-processor #if commands */
|
||||||
do {
|
do {
|
||||||
int WasPreProcToken = TRUE;
|
int WasPreProcToken = true;
|
||||||
|
|
||||||
Token = LexGetRawToken(Parser, Value, IncPos);
|
Token = LexGetRawToken(Parser, Value, IncPos);
|
||||||
switch (Token) {
|
switch (Token) {
|
||||||
case TokenHashIfdef: LexHashIncPos(Parser, IncPos); LexHashIfdef(Parser, FALSE); break;
|
case TokenHashIfdef: LexHashIncPos(Parser, IncPos); LexHashIfdef(Parser, false); break;
|
||||||
case TokenHashIfndef: LexHashIncPos(Parser, IncPos); LexHashIfdef(Parser, TRUE); break;
|
case TokenHashIfndef: LexHashIncPos(Parser, IncPos); LexHashIfdef(Parser, true); break;
|
||||||
case TokenHashIf: LexHashIncPos(Parser, IncPos); LexHashIf(Parser); break;
|
case TokenHashIf: LexHashIncPos(Parser, IncPos); LexHashIf(Parser); break;
|
||||||
case TokenHashElse: LexHashIncPos(Parser, IncPos); LexHashElse(Parser); break;
|
case TokenHashElse: LexHashIncPos(Parser, IncPos); LexHashElse(Parser); break;
|
||||||
case TokenHashEndif: LexHashIncPos(Parser, IncPos); LexHashEndif(Parser); break;
|
case TokenHashEndif: LexHashIncPos(Parser, IncPos); LexHashEndif(Parser); break;
|
||||||
default: WasPreProcToken = FALSE; break;
|
default: WasPreProcToken = false; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if we're going to reject this token, increment the token pointer to the next one */
|
/* if we're going to reject this token, increment the token pointer to the next one */
|
||||||
TryNextToken = (Parser->HashIfEvaluateToLevel < Parser->HashIfLevel && Token != TokenEOF) || WasPreProcToken;
|
TryNextToken = (Parser->HashIfEvaluateToLevel < Parser->HashIfLevel && Token != TokenEOF) || WasPreProcToken;
|
||||||
if (!IncPos && TryNextToken)
|
if (!IncPos && TryNextToken)
|
||||||
LexGetRawToken(Parser, NULL, TRUE);
|
LexGetRawToken(Parser, NULL, true);
|
||||||
|
|
||||||
} while (TryNextToken);
|
} while (TryNextToken);
|
||||||
|
|
||||||
|
@ -847,12 +847,12 @@ enum LexToken LexRawPeekToken(struct ParseState *Parser)
|
||||||
/* find the end of the line */
|
/* find the end of the line */
|
||||||
void LexToEndOfLine(struct ParseState *Parser)
|
void LexToEndOfLine(struct ParseState *Parser)
|
||||||
{
|
{
|
||||||
while (TRUE) {
|
while (true) {
|
||||||
enum LexToken Token = (enum LexToken)*(unsigned char *)Parser->Pos;
|
enum LexToken Token = (enum LexToken)*(unsigned char *)Parser->Pos;
|
||||||
if (Token == TokenEndOfLine || Token == TokenEOF)
|
if (Token == TokenEndOfLine || Token == TokenEOF)
|
||||||
return;
|
return;
|
||||||
else
|
else
|
||||||
LexGetRawToken(Parser, NULL, TRUE);
|
LexGetRawToken(Parser, NULL, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -870,7 +870,7 @@ void *LexCopyTokens(struct ParseState *StartParser, struct ParseState *EndParser
|
||||||
if (pc->InteractiveHead == NULL) {
|
if (pc->InteractiveHead == NULL) {
|
||||||
/* non-interactive mode - copy the tokens */
|
/* non-interactive mode - copy the tokens */
|
||||||
MemSize = EndParser->Pos - StartParser->Pos;
|
MemSize = EndParser->Pos - StartParser->Pos;
|
||||||
NewTokens = VariableAlloc(pc, StartParser, MemSize + TOKEN_DATA_OFFSET, TRUE);
|
NewTokens = VariableAlloc(pc, StartParser, MemSize + TOKEN_DATA_OFFSET, true);
|
||||||
memcpy(NewTokens, (void *)StartParser->Pos, MemSize);
|
memcpy(NewTokens, (void *)StartParser->Pos, MemSize);
|
||||||
} else {
|
} else {
|
||||||
/* we're in interactive mode - add up line by line */
|
/* we're in interactive mode - add up line by line */
|
||||||
|
@ -880,7 +880,7 @@ void *LexCopyTokens(struct ParseState *StartParser, struct ParseState *EndParser
|
||||||
if (EndParser->Pos >= StartParser->Pos && EndParser->Pos < &pc->InteractiveCurrentLine->Tokens[pc->InteractiveCurrentLine->NumBytes]) {
|
if (EndParser->Pos >= StartParser->Pos && EndParser->Pos < &pc->InteractiveCurrentLine->Tokens[pc->InteractiveCurrentLine->NumBytes]) {
|
||||||
/* all on a single line */
|
/* all on a single line */
|
||||||
MemSize = EndParser->Pos - StartParser->Pos;
|
MemSize = EndParser->Pos - StartParser->Pos;
|
||||||
NewTokens = VariableAlloc(pc, StartParser, MemSize + TOKEN_DATA_OFFSET, TRUE);
|
NewTokens = VariableAlloc(pc, StartParser, MemSize + TOKEN_DATA_OFFSET, true);
|
||||||
memcpy(NewTokens, (void *)StartParser->Pos, MemSize);
|
memcpy(NewTokens, (void *)StartParser->Pos, MemSize);
|
||||||
} else {
|
} else {
|
||||||
/* it's spread across multiple lines */
|
/* it's spread across multiple lines */
|
||||||
|
@ -891,7 +891,7 @@ void *LexCopyTokens(struct ParseState *StartParser, struct ParseState *EndParser
|
||||||
|
|
||||||
assert(ILine != NULL);
|
assert(ILine != NULL);
|
||||||
MemSize += EndParser->Pos - &ILine->Tokens[0];
|
MemSize += EndParser->Pos - &ILine->Tokens[0];
|
||||||
NewTokens = VariableAlloc(pc, StartParser, MemSize + TOKEN_DATA_OFFSET, TRUE);
|
NewTokens = VariableAlloc(pc, StartParser, MemSize + TOKEN_DATA_OFFSET, true);
|
||||||
|
|
||||||
CopySize = &pc->InteractiveCurrentLine->Tokens[pc->InteractiveCurrentLine->NumBytes-TOKEN_DATA_OFFSET] - Pos;
|
CopySize = &pc->InteractiveCurrentLine->Tokens[pc->InteractiveCurrentLine->NumBytes-TOKEN_DATA_OFFSET] - Pos;
|
||||||
memcpy(NewTokens, Pos, CopySize);
|
memcpy(NewTokens, Pos, CopySize);
|
||||||
|
@ -949,5 +949,5 @@ void LexInteractiveCompleted(Picoc *pc, struct ParseState *Parser)
|
||||||
/* the next time we prompt, make it the full statement prompt */
|
/* the next time we prompt, make it the full statement prompt */
|
||||||
void LexInteractiveStatementPrompt(Picoc *pc)
|
void LexInteractiveStatementPrompt(Picoc *pc)
|
||||||
{
|
{
|
||||||
pc->LexUseStatementPrompt = TRUE;
|
pc->LexUseStatementPrompt = true;
|
||||||
}
|
}
|
||||||
|
|
218
parse.c
218
parse.c
|
@ -4,9 +4,9 @@
|
||||||
#include "interpreter.h"
|
#include "interpreter.h"
|
||||||
|
|
||||||
#ifdef DEBUGGER
|
#ifdef DEBUGGER
|
||||||
static int gEnableDebugger = TRUE;
|
static int gEnableDebugger = true;
|
||||||
#else
|
#else
|
||||||
static int gEnableDebugger = FALSE;
|
static int gEnableDebugger = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ void ParseCleanup(Picoc *pc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* parse a statement, but only run it if Condition is TRUE */
|
/* parse a statement, but only run it if Condition is true */
|
||||||
enum ParseResult ParseStatementMaybeRun(struct ParseState *Parser, int Condition, int CheckTrailingSemicolon)
|
enum ParseResult ParseStatementMaybeRun(struct ParseState *Parser, int Condition, int CheckTrailingSemicolon)
|
||||||
{
|
{
|
||||||
if (Parser->Mode != RunModeSkip && !Condition) {
|
if (Parser->Mode != RunModeSkip && !Condition) {
|
||||||
|
@ -44,11 +44,11 @@ int ParseCountParams(struct ParseState *Parser)
|
||||||
{
|
{
|
||||||
int ParamCount = 0;
|
int ParamCount = 0;
|
||||||
|
|
||||||
enum LexToken Token = LexGetToken(Parser, NULL, TRUE);
|
enum LexToken Token = LexGetToken(Parser, NULL, true);
|
||||||
if (Token != TokenCloseBracket && Token != TokenEOF) {
|
if (Token != TokenCloseBracket && Token != TokenEOF) {
|
||||||
/* count the number of parameters */
|
/* count the number of parameters */
|
||||||
ParamCount++;
|
ParamCount++;
|
||||||
while ((Token = LexGetToken(Parser, NULL, TRUE)) != TokenCloseBracket && Token != TokenEOF) {
|
while ((Token = LexGetToken(Parser, NULL, true)) != TokenCloseBracket && Token != TokenEOF) {
|
||||||
if (Token == TokenComma)
|
if (Token == TokenComma)
|
||||||
ParamCount++;
|
ParamCount++;
|
||||||
}
|
}
|
||||||
|
@ -73,26 +73,26 @@ struct Value *ParseFunctionDefinition(struct ParseState *Parser, struct ValueTyp
|
||||||
if (pc->TopStackFrame != NULL)
|
if (pc->TopStackFrame != NULL)
|
||||||
ProgramFail(Parser, "nested function definitions are not allowed");
|
ProgramFail(Parser, "nested function definitions are not allowed");
|
||||||
|
|
||||||
LexGetToken(Parser, NULL, TRUE); /* open bracket */
|
LexGetToken(Parser, NULL, true); /* open bracket */
|
||||||
ParserCopy(&ParamParser, Parser);
|
ParserCopy(&ParamParser, Parser);
|
||||||
ParamCount = ParseCountParams(Parser);
|
ParamCount = ParseCountParams(Parser);
|
||||||
if (ParamCount > PARAMETER_MAX)
|
if (ParamCount > PARAMETER_MAX)
|
||||||
ProgramFail(Parser, "too many parameters (%d allowed)", PARAMETER_MAX);
|
ProgramFail(Parser, "too many parameters (%d allowed)", PARAMETER_MAX);
|
||||||
|
|
||||||
FuncValue = VariableAllocValueAndData(pc, Parser, sizeof(struct FuncDef) + sizeof(struct ValueType *) * ParamCount + sizeof(const char *) * ParamCount, FALSE, NULL, TRUE);
|
FuncValue = VariableAllocValueAndData(pc, Parser, sizeof(struct FuncDef) + sizeof(struct ValueType *) * ParamCount + sizeof(const char *) * ParamCount, false, NULL, true);
|
||||||
FuncValue->Typ = &pc->FunctionType;
|
FuncValue->Typ = &pc->FunctionType;
|
||||||
FuncValue->Val->FuncDef.ReturnType = ReturnType;
|
FuncValue->Val->FuncDef.ReturnType = ReturnType;
|
||||||
FuncValue->Val->FuncDef.NumParams = ParamCount;
|
FuncValue->Val->FuncDef.NumParams = ParamCount;
|
||||||
FuncValue->Val->FuncDef.VarArgs = FALSE;
|
FuncValue->Val->FuncDef.VarArgs = false;
|
||||||
FuncValue->Val->FuncDef.ParamType = (struct ValueType **)((char *)FuncValue->Val + sizeof(struct FuncDef));
|
FuncValue->Val->FuncDef.ParamType = (struct ValueType **)((char *)FuncValue->Val + sizeof(struct FuncDef));
|
||||||
FuncValue->Val->FuncDef.ParamName = (char **)((char *)FuncValue->Val->FuncDef.ParamType + sizeof(struct ValueType *) * ParamCount);
|
FuncValue->Val->FuncDef.ParamName = (char **)((char *)FuncValue->Val->FuncDef.ParamType + sizeof(struct ValueType *) * ParamCount);
|
||||||
|
|
||||||
for (ParamCount = 0; ParamCount < FuncValue->Val->FuncDef.NumParams; ParamCount++) {
|
for (ParamCount = 0; ParamCount < FuncValue->Val->FuncDef.NumParams; ParamCount++) {
|
||||||
/* harvest the parameters into the function definition */
|
/* harvest the parameters into the function definition */
|
||||||
if (ParamCount == FuncValue->Val->FuncDef.NumParams-1 && LexGetToken(&ParamParser, NULL, FALSE) == TokenEllipsis) {
|
if (ParamCount == FuncValue->Val->FuncDef.NumParams-1 && LexGetToken(&ParamParser, NULL, false) == TokenEllipsis) {
|
||||||
/* ellipsis at end */
|
/* ellipsis at end */
|
||||||
FuncValue->Val->FuncDef.NumParams--;
|
FuncValue->Val->FuncDef.NumParams--;
|
||||||
FuncValue->Val->FuncDef.VarArgs = TRUE;
|
FuncValue->Val->FuncDef.VarArgs = true;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
/* add a parameter */
|
/* add a parameter */
|
||||||
|
@ -107,7 +107,7 @@ struct Value *ParseFunctionDefinition(struct ParseState *Parser, struct ValueTyp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Token = LexGetToken(&ParamParser, NULL, TRUE);
|
Token = LexGetToken(&ParamParser, NULL, true);
|
||||||
if (Token != TokenComma && ParamCount < FuncValue->Val->FuncDef.NumParams-1)
|
if (Token != TokenComma && ParamCount < FuncValue->Val->FuncDef.NumParams-1)
|
||||||
ProgramFail(&ParamParser, "comma expected");
|
ProgramFail(&ParamParser, "comma expected");
|
||||||
}
|
}
|
||||||
|
@ -127,16 +127,16 @@ struct Value *ParseFunctionDefinition(struct ParseState *Parser, struct ValueTyp
|
||||||
}
|
}
|
||||||
|
|
||||||
/* look for a function body */
|
/* look for a function body */
|
||||||
Token = LexGetToken(Parser, NULL, FALSE);
|
Token = LexGetToken(Parser, NULL, false);
|
||||||
if (Token == TokenSemicolon)
|
if (Token == TokenSemicolon)
|
||||||
LexGetToken(Parser, NULL, TRUE); /* it's a prototype, absorb the trailing semicolon */
|
LexGetToken(Parser, NULL, true); /* it's a prototype, absorb the trailing semicolon */
|
||||||
else {
|
else {
|
||||||
/* it's a full function definition with a body */
|
/* it's a full function definition with a body */
|
||||||
if (Token != TokenLeftBrace)
|
if (Token != TokenLeftBrace)
|
||||||
ProgramFail(Parser, "bad function definition");
|
ProgramFail(Parser, "bad function definition");
|
||||||
|
|
||||||
ParserCopy(&FuncBody, Parser);
|
ParserCopy(&FuncBody, Parser);
|
||||||
if (ParseStatementMaybeRun(Parser, FALSE, TRUE) != ParseResultOk)
|
if (ParseStatementMaybeRun(Parser, false, true) != ParseResultOk)
|
||||||
ProgramFail(Parser, "function definition expected");
|
ProgramFail(Parser, "function definition expected");
|
||||||
|
|
||||||
FuncValue->Val->FuncDef.Body = FuncBody;
|
FuncValue->Val->FuncDef.Body = FuncBody;
|
||||||
|
@ -171,14 +171,14 @@ int ParseArrayInitialiser(struct ParseState *Parser, struct Value *NewVariable,
|
||||||
int NumElements;
|
int NumElements;
|
||||||
|
|
||||||
ParserCopy(&CountParser, Parser);
|
ParserCopy(&CountParser, Parser);
|
||||||
NumElements = ParseArrayInitialiser(&CountParser, NewVariable, FALSE);
|
NumElements = ParseArrayInitialiser(&CountParser, NewVariable, false);
|
||||||
|
|
||||||
if (NewVariable->Typ->Base != TypeArray)
|
if (NewVariable->Typ->Base != TypeArray)
|
||||||
AssignFail(Parser, "%t from array initializer", NewVariable->Typ, NULL, 0, 0, NULL, 0);
|
AssignFail(Parser, "%t from array initializer", NewVariable->Typ, NULL, 0, 0, NULL, 0);
|
||||||
|
|
||||||
if (NewVariable->Typ->ArraySize == 0) {
|
if (NewVariable->Typ->ArraySize == 0) {
|
||||||
NewVariable->Typ = TypeGetMatching(Parser->pc, Parser, NewVariable->Typ->FromType, NewVariable->Typ->Base, NumElements, NewVariable->Typ->Identifier, TRUE);
|
NewVariable->Typ = TypeGetMatching(Parser->pc, Parser, NewVariable->Typ->FromType, NewVariable->Typ->Base, NumElements, NewVariable->Typ->Identifier, true);
|
||||||
VariableRealloc(Parser, NewVariable, TypeSizeValue(NewVariable, FALSE));
|
VariableRealloc(Parser, NewVariable, TypeSizeValue(NewVariable, false));
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_ARRAY_INITIALIZER
|
#ifdef DEBUG_ARRAY_INITIALIZER
|
||||||
PRINT_SOURCE_POS();
|
PRINT_SOURCE_POS();
|
||||||
|
@ -187,17 +187,17 @@ int ParseArrayInitialiser(struct ParseState *Parser, struct Value *NewVariable,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* parse the array initialiser */
|
/* parse the array initialiser */
|
||||||
Token = LexGetToken(Parser, NULL, FALSE);
|
Token = LexGetToken(Parser, NULL, false);
|
||||||
while (Token != TokenRightBrace) {
|
while (Token != TokenRightBrace) {
|
||||||
if (LexGetToken(Parser, NULL, FALSE) == TokenLeftBrace) {
|
if (LexGetToken(Parser, NULL, false) == TokenLeftBrace) {
|
||||||
/* this is a sub-array initialiser */
|
/* this is a sub-array initialiser */
|
||||||
int SubArraySize = 0;
|
int SubArraySize = 0;
|
||||||
struct Value *SubArray = NewVariable;
|
struct Value *SubArray = NewVariable;
|
||||||
if (Parser->Mode == RunModeRun && DoAssignment) {
|
if (Parser->Mode == RunModeRun && DoAssignment) {
|
||||||
SubArraySize = TypeSize(NewVariable->Typ->FromType, NewVariable->Typ->FromType->ArraySize, TRUE);
|
SubArraySize = TypeSize(NewVariable->Typ->FromType, NewVariable->Typ->FromType->ArraySize, true);
|
||||||
SubArray = VariableAllocValueFromExistingData(Parser, NewVariable->Typ->FromType, (union AnyValue *)(&NewVariable->Val->ArrayMem[0] + SubArraySize * ArrayIndex), TRUE, NewVariable);
|
SubArray = VariableAllocValueFromExistingData(Parser, NewVariable->Typ->FromType, (union AnyValue *)(&NewVariable->Val->ArrayMem[0] + SubArraySize * ArrayIndex), true, NewVariable);
|
||||||
#ifdef DEBUG_ARRAY_INITIALIZER
|
#ifdef DEBUG_ARRAY_INITIALIZER
|
||||||
int FullArraySize = TypeSize(NewVariable->Typ, NewVariable->Typ->ArraySize, TRUE);
|
int FullArraySize = TypeSize(NewVariable->Typ, NewVariable->Typ->ArraySize, true);
|
||||||
PRINT_SOURCE_POS();
|
PRINT_SOURCE_POS();
|
||||||
PRINT_TYPE(NewVariable->Typ)
|
PRINT_TYPE(NewVariable->Typ)
|
||||||
printf("[%d] subarray size: %d (full: %d,%d) \n", ArrayIndex, SubArraySize, FullArraySize, NewVariable->Typ->ArraySize);
|
printf("[%d] subarray size: %d (full: %d,%d) \n", ArrayIndex, SubArraySize, FullArraySize, NewVariable->Typ->ArraySize);
|
||||||
|
@ -205,7 +205,7 @@ int ParseArrayInitialiser(struct ParseState *Parser, struct Value *NewVariable,
|
||||||
if (ArrayIndex >= NewVariable->Typ->ArraySize)
|
if (ArrayIndex >= NewVariable->Typ->ArraySize)
|
||||||
ProgramFail(Parser, "too many array elements");
|
ProgramFail(Parser, "too many array elements");
|
||||||
}
|
}
|
||||||
LexGetToken(Parser, NULL, TRUE);
|
LexGetToken(Parser, NULL, true);
|
||||||
ParseArrayInitialiser(Parser, SubArray, DoAssignment);
|
ParseArrayInitialiser(Parser, SubArray, DoAssignment);
|
||||||
} else {
|
} else {
|
||||||
struct Value *ArrayElement = NULL;
|
struct Value *ArrayElement = NULL;
|
||||||
|
@ -221,17 +221,17 @@ int ParseArrayInitialiser(struct ParseState *Parser, struct Value *NewVariable,
|
||||||
ElementType = ElementType->FromType;
|
ElementType = ElementType->FromType;
|
||||||
|
|
||||||
/* char x[10][10] = {"abc", "def"} => assign "abc" to x[0], "def" to x[1] etc */
|
/* char x[10][10] = {"abc", "def"} => assign "abc" to x[0], "def" to x[1] etc */
|
||||||
if (LexGetToken(Parser, NULL, FALSE) == TokenStringConstant && ElementType->FromType->Base == TypeChar)
|
if (LexGetToken(Parser, NULL, false) == TokenStringConstant && ElementType->FromType->Base == TypeChar)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ElementSize = TypeSize(ElementType, ElementType->ArraySize, TRUE);
|
ElementSize = TypeSize(ElementType, ElementType->ArraySize, true);
|
||||||
#ifdef DEBUG_ARRAY_INITIALIZER
|
#ifdef DEBUG_ARRAY_INITIALIZER
|
||||||
PRINT_SOURCE_POS();
|
PRINT_SOURCE_POS();
|
||||||
printf("[%d/%d] element size: %d (x%d) \n", ArrayIndex, TotalSize, ElementSize, ElementType->ArraySize);
|
printf("[%d/%d] element size: %d (x%d) \n", ArrayIndex, TotalSize, ElementSize, ElementType->ArraySize);
|
||||||
#endif
|
#endif
|
||||||
if (ArrayIndex >= TotalSize)
|
if (ArrayIndex >= TotalSize)
|
||||||
ProgramFail(Parser, "too many array elements");
|
ProgramFail(Parser, "too many array elements");
|
||||||
ArrayElement = VariableAllocValueFromExistingData(Parser, ElementType, (union AnyValue *)(&NewVariable->Val->ArrayMem[0] + ElementSize * ArrayIndex), TRUE, NewVariable);
|
ArrayElement = VariableAllocValueFromExistingData(Parser, ElementType, (union AnyValue *)(&NewVariable->Val->ArrayMem[0] + ElementSize * ArrayIndex), true, NewVariable);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this is a normal expression initialiser */
|
/* this is a normal expression initialiser */
|
||||||
|
@ -239,7 +239,7 @@ int ParseArrayInitialiser(struct ParseState *Parser, struct Value *NewVariable,
|
||||||
ProgramFail(Parser, "expression expected");
|
ProgramFail(Parser, "expression expected");
|
||||||
|
|
||||||
if (Parser->Mode == RunModeRun && DoAssignment) {
|
if (Parser->Mode == RunModeRun && DoAssignment) {
|
||||||
ExpressionAssign(Parser, ArrayElement, CValue, FALSE, NULL, 0, FALSE);
|
ExpressionAssign(Parser, ArrayElement, CValue, false, NULL, 0, false);
|
||||||
VariableStackPop(Parser, CValue);
|
VariableStackPop(Parser, CValue);
|
||||||
VariableStackPop(Parser, ArrayElement);
|
VariableStackPop(Parser, ArrayElement);
|
||||||
}
|
}
|
||||||
|
@ -247,16 +247,16 @@ int ParseArrayInitialiser(struct ParseState *Parser, struct Value *NewVariable,
|
||||||
|
|
||||||
ArrayIndex++;
|
ArrayIndex++;
|
||||||
|
|
||||||
Token = LexGetToken(Parser, NULL, FALSE);
|
Token = LexGetToken(Parser, NULL, false);
|
||||||
if (Token == TokenComma) {
|
if (Token == TokenComma) {
|
||||||
LexGetToken(Parser, NULL, TRUE);
|
LexGetToken(Parser, NULL, true);
|
||||||
Token = LexGetToken(Parser, NULL, FALSE);
|
Token = LexGetToken(Parser, NULL, false);
|
||||||
} else if (Token != TokenRightBrace)
|
} else if (Token != TokenRightBrace)
|
||||||
ProgramFail(Parser, "comma expected");
|
ProgramFail(Parser, "comma expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Token == TokenRightBrace)
|
if (Token == TokenRightBrace)
|
||||||
LexGetToken(Parser, NULL, TRUE);
|
LexGetToken(Parser, NULL, true);
|
||||||
else
|
else
|
||||||
ProgramFail(Parser, "'}' expected");
|
ProgramFail(Parser, "'}' expected");
|
||||||
|
|
||||||
|
@ -268,9 +268,9 @@ void ParseDeclarationAssignment(struct ParseState *Parser, struct Value *NewVari
|
||||||
{
|
{
|
||||||
struct Value *CValue;
|
struct Value *CValue;
|
||||||
|
|
||||||
if (LexGetToken(Parser, NULL, FALSE) == TokenLeftBrace) {
|
if (LexGetToken(Parser, NULL, false) == TokenLeftBrace) {
|
||||||
/* this is an array initialiser */
|
/* this is an array initialiser */
|
||||||
LexGetToken(Parser, NULL, TRUE);
|
LexGetToken(Parser, NULL, true);
|
||||||
ParseArrayInitialiser(Parser, NewVariable, DoAssignment);
|
ParseArrayInitialiser(Parser, NewVariable, DoAssignment);
|
||||||
} else {
|
} else {
|
||||||
/* this is a normal expression initialiser */
|
/* this is a normal expression initialiser */
|
||||||
|
@ -278,7 +278,7 @@ void ParseDeclarationAssignment(struct ParseState *Parser, struct Value *NewVari
|
||||||
ProgramFail(Parser, "expression expected");
|
ProgramFail(Parser, "expression expected");
|
||||||
|
|
||||||
if (Parser->Mode == RunModeRun && DoAssignment) {
|
if (Parser->Mode == RunModeRun && DoAssignment) {
|
||||||
ExpressionAssign(Parser, NewVariable, CValue, FALSE, NULL, 0, FALSE);
|
ExpressionAssign(Parser, NewVariable, CValue, false, NULL, 0, false);
|
||||||
VariableStackPop(Parser, CValue);
|
VariableStackPop(Parser, CValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -287,8 +287,8 @@ void ParseDeclarationAssignment(struct ParseState *Parser, struct Value *NewVari
|
||||||
/* declare a variable or function */
|
/* declare a variable or function */
|
||||||
int ParseDeclaration(struct ParseState *Parser, enum LexToken Token)
|
int ParseDeclaration(struct ParseState *Parser, enum LexToken Token)
|
||||||
{
|
{
|
||||||
int IsStatic = FALSE;
|
int IsStatic = false;
|
||||||
int FirstVisit = FALSE;
|
int FirstVisit = false;
|
||||||
char *Identifier;
|
char *Identifier;
|
||||||
struct ValueType *BasicType;
|
struct ValueType *BasicType;
|
||||||
struct ValueType *Typ;
|
struct ValueType *Typ;
|
||||||
|
@ -303,10 +303,10 @@ int ParseDeclaration(struct ParseState *Parser, enum LexToken Token)
|
||||||
|
|
||||||
if (Identifier != pc->StrEmpty) {
|
if (Identifier != pc->StrEmpty) {
|
||||||
/* handle function definitions */
|
/* handle function definitions */
|
||||||
if (LexGetToken(Parser, NULL, FALSE) == TokenOpenBracket)
|
if (LexGetToken(Parser, NULL, false) == TokenOpenBracket)
|
||||||
{
|
{
|
||||||
ParseFunctionDefinition(Parser, Typ, Identifier);
|
ParseFunctionDefinition(Parser, Typ, Identifier);
|
||||||
return FALSE;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
if (Typ == &pc->VoidType && Identifier != pc->StrEmpty)
|
if (Typ == &pc->VoidType && Identifier != pc->StrEmpty)
|
||||||
ProgramFail(Parser, "can't define a void variable");
|
ProgramFail(Parser, "can't define a void variable");
|
||||||
|
@ -314,21 +314,21 @@ int ParseDeclaration(struct ParseState *Parser, enum LexToken Token)
|
||||||
if (Parser->Mode == RunModeRun || Parser->Mode == RunModeGoto)
|
if (Parser->Mode == RunModeRun || Parser->Mode == RunModeGoto)
|
||||||
NewVariable = VariableDefineButIgnoreIdentical(Parser, Identifier, Typ, IsStatic, &FirstVisit);
|
NewVariable = VariableDefineButIgnoreIdentical(Parser, Identifier, Typ, IsStatic, &FirstVisit);
|
||||||
|
|
||||||
if (LexGetToken(Parser, NULL, FALSE) == TokenAssign) {
|
if (LexGetToken(Parser, NULL, false) == TokenAssign) {
|
||||||
/* we're assigning an initial value */
|
/* we're assigning an initial value */
|
||||||
LexGetToken(Parser, NULL, TRUE);
|
LexGetToken(Parser, NULL, true);
|
||||||
ParseDeclarationAssignment(Parser, NewVariable, !IsStatic || FirstVisit);
|
ParseDeclarationAssignment(Parser, NewVariable, !IsStatic || FirstVisit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Token = LexGetToken(Parser, NULL, FALSE);
|
Token = LexGetToken(Parser, NULL, false);
|
||||||
if (Token == TokenComma)
|
if (Token == TokenComma)
|
||||||
LexGetToken(Parser, NULL, TRUE);
|
LexGetToken(Parser, NULL, true);
|
||||||
|
|
||||||
} while (Token == TokenComma);
|
} while (Token == TokenComma);
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* parse a #define macro definition and store it for later */
|
/* parse a #define macro definition and store it for later */
|
||||||
|
@ -339,34 +339,34 @@ void ParseMacroDefinition(struct ParseState *Parser)
|
||||||
struct Value *ParamName;
|
struct Value *ParamName;
|
||||||
struct Value *MacroValue;
|
struct Value *MacroValue;
|
||||||
|
|
||||||
if (LexGetToken(Parser, &MacroName, TRUE) != TokenIdentifier)
|
if (LexGetToken(Parser, &MacroName, true) != TokenIdentifier)
|
||||||
ProgramFail(Parser, "identifier expected");
|
ProgramFail(Parser, "identifier expected");
|
||||||
|
|
||||||
MacroNameStr = MacroName->Val->Identifier;
|
MacroNameStr = MacroName->Val->Identifier;
|
||||||
|
|
||||||
if (LexRawPeekToken(Parser) == TokenOpenMacroBracket) {
|
if (LexRawPeekToken(Parser) == TokenOpenMacroBracket) {
|
||||||
/* it's a parameterised macro, read the parameters */
|
/* it's a parameterised macro, read the parameters */
|
||||||
enum LexToken Token = LexGetToken(Parser, NULL, TRUE);
|
enum LexToken Token = LexGetToken(Parser, NULL, true);
|
||||||
struct ParseState ParamParser;
|
struct ParseState ParamParser;
|
||||||
int NumParams;
|
int NumParams;
|
||||||
int ParamCount = 0;
|
int ParamCount = 0;
|
||||||
|
|
||||||
ParserCopy(&ParamParser, Parser);
|
ParserCopy(&ParamParser, Parser);
|
||||||
NumParams = ParseCountParams(&ParamParser);
|
NumParams = ParseCountParams(&ParamParser);
|
||||||
MacroValue = VariableAllocValueAndData(Parser->pc, Parser, sizeof(struct MacroDef) + sizeof(const char *) * NumParams, FALSE, NULL, TRUE);
|
MacroValue = VariableAllocValueAndData(Parser->pc, Parser, sizeof(struct MacroDef) + sizeof(const char *) * NumParams, false, NULL, true);
|
||||||
MacroValue->Val->MacroDef.NumParams = NumParams;
|
MacroValue->Val->MacroDef.NumParams = NumParams;
|
||||||
MacroValue->Val->MacroDef.ParamName = (char **)((char *)MacroValue->Val + sizeof(struct MacroDef));
|
MacroValue->Val->MacroDef.ParamName = (char **)((char *)MacroValue->Val + sizeof(struct MacroDef));
|
||||||
|
|
||||||
Token = LexGetToken(Parser, &ParamName, TRUE);
|
Token = LexGetToken(Parser, &ParamName, true);
|
||||||
|
|
||||||
while (Token == TokenIdentifier) {
|
while (Token == TokenIdentifier) {
|
||||||
/* store a parameter name */
|
/* store a parameter name */
|
||||||
MacroValue->Val->MacroDef.ParamName[ParamCount++] = ParamName->Val->Identifier;
|
MacroValue->Val->MacroDef.ParamName[ParamCount++] = ParamName->Val->Identifier;
|
||||||
|
|
||||||
/* get the trailing comma */
|
/* get the trailing comma */
|
||||||
Token = LexGetToken(Parser, NULL, TRUE);
|
Token = LexGetToken(Parser, NULL, true);
|
||||||
if (Token == TokenComma)
|
if (Token == TokenComma)
|
||||||
Token = LexGetToken(Parser, &ParamName, TRUE);
|
Token = LexGetToken(Parser, &ParamName, true);
|
||||||
|
|
||||||
else if (Token != TokenCloseBracket)
|
else if (Token != TokenCloseBracket)
|
||||||
ProgramFail(Parser, "comma expected");
|
ProgramFail(Parser, "comma expected");
|
||||||
|
@ -376,7 +376,7 @@ void ParseMacroDefinition(struct ParseState *Parser)
|
||||||
ProgramFail(Parser, "close bracket expected");
|
ProgramFail(Parser, "close bracket expected");
|
||||||
} else {
|
} else {
|
||||||
/* allocate a simple unparameterised macro */
|
/* allocate a simple unparameterised macro */
|
||||||
MacroValue = VariableAllocValueAndData(Parser->pc, Parser, sizeof(struct MacroDef), FALSE, NULL, TRUE);
|
MacroValue = VariableAllocValueAndData(Parser->pc, Parser, sizeof(struct MacroDef), false, NULL, true);
|
||||||
MacroValue->Val->MacroDef.NumParams = 0;
|
MacroValue->Val->MacroDef.NumParams = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,29 +420,29 @@ void ParseFor(struct ParseState *Parser)
|
||||||
int PrevScopeID = 0;
|
int PrevScopeID = 0;
|
||||||
int ScopeID = VariableScopeBegin(Parser, &PrevScopeID);
|
int ScopeID = VariableScopeBegin(Parser, &PrevScopeID);
|
||||||
|
|
||||||
if (LexGetToken(Parser, NULL, TRUE) != TokenOpenBracket)
|
if (LexGetToken(Parser, NULL, true) != TokenOpenBracket)
|
||||||
ProgramFail(Parser, "'(' expected");
|
ProgramFail(Parser, "'(' expected");
|
||||||
|
|
||||||
if (ParseStatement(Parser, TRUE) != ParseResultOk)
|
if (ParseStatement(Parser, true) != ParseResultOk)
|
||||||
ProgramFail(Parser, "statement expected");
|
ProgramFail(Parser, "statement expected");
|
||||||
|
|
||||||
ParserCopyPos(&PreConditional, Parser);
|
ParserCopyPos(&PreConditional, Parser);
|
||||||
if (LexGetToken(Parser, NULL, FALSE) == TokenSemicolon)
|
if (LexGetToken(Parser, NULL, false) == TokenSemicolon)
|
||||||
Condition = TRUE;
|
Condition = true;
|
||||||
else
|
else
|
||||||
Condition = ExpressionParseInt(Parser);
|
Condition = ExpressionParseInt(Parser);
|
||||||
|
|
||||||
if (LexGetToken(Parser, NULL, TRUE) != TokenSemicolon)
|
if (LexGetToken(Parser, NULL, true) != TokenSemicolon)
|
||||||
ProgramFail(Parser, "';' expected");
|
ProgramFail(Parser, "';' expected");
|
||||||
|
|
||||||
ParserCopyPos(&PreIncrement, Parser);
|
ParserCopyPos(&PreIncrement, Parser);
|
||||||
ParseStatementMaybeRun(Parser, FALSE, FALSE);
|
ParseStatementMaybeRun(Parser, false, false);
|
||||||
|
|
||||||
if (LexGetToken(Parser, NULL, TRUE) != TokenCloseBracket)
|
if (LexGetToken(Parser, NULL, true) != TokenCloseBracket)
|
||||||
ProgramFail(Parser, "')' expected");
|
ProgramFail(Parser, "')' expected");
|
||||||
|
|
||||||
ParserCopyPos(&PreStatement, Parser);
|
ParserCopyPos(&PreStatement, Parser);
|
||||||
if (ParseStatementMaybeRun(Parser, Condition, TRUE) != ParseResultOk)
|
if (ParseStatementMaybeRun(Parser, Condition, true) != ParseResultOk)
|
||||||
ProgramFail(Parser, "statement expected");
|
ProgramFail(Parser, "statement expected");
|
||||||
|
|
||||||
if (Parser->Mode == RunModeContinue && OldMode == RunModeRun)
|
if (Parser->Mode == RunModeContinue && OldMode == RunModeRun)
|
||||||
|
@ -452,17 +452,17 @@ void ParseFor(struct ParseState *Parser)
|
||||||
|
|
||||||
while (Condition && Parser->Mode == RunModeRun) {
|
while (Condition && Parser->Mode == RunModeRun) {
|
||||||
ParserCopyPos(Parser, &PreIncrement);
|
ParserCopyPos(Parser, &PreIncrement);
|
||||||
ParseStatement(Parser, FALSE);
|
ParseStatement(Parser, false);
|
||||||
|
|
||||||
ParserCopyPos(Parser, &PreConditional);
|
ParserCopyPos(Parser, &PreConditional);
|
||||||
if (LexGetToken(Parser, NULL, FALSE) == TokenSemicolon)
|
if (LexGetToken(Parser, NULL, false) == TokenSemicolon)
|
||||||
Condition = TRUE;
|
Condition = true;
|
||||||
else
|
else
|
||||||
Condition = ExpressionParseInt(Parser);
|
Condition = ExpressionParseInt(Parser);
|
||||||
|
|
||||||
if (Condition) {
|
if (Condition) {
|
||||||
ParserCopyPos(Parser, &PreStatement);
|
ParserCopyPos(Parser, &PreStatement);
|
||||||
ParseStatement(Parser, TRUE);
|
ParseStatement(Parser, true);
|
||||||
|
|
||||||
if (Parser->Mode == RunModeContinue)
|
if (Parser->Mode == RunModeContinue)
|
||||||
Parser->Mode = RunModeRun;
|
Parser->Mode = RunModeRun;
|
||||||
|
@ -483,23 +483,23 @@ enum RunMode ParseBlock(struct ParseState *Parser, int AbsorbOpenBrace, int Cond
|
||||||
int PrevScopeID = 0;
|
int PrevScopeID = 0;
|
||||||
int ScopeID = VariableScopeBegin(Parser, &PrevScopeID);
|
int ScopeID = VariableScopeBegin(Parser, &PrevScopeID);
|
||||||
|
|
||||||
if (AbsorbOpenBrace && LexGetToken(Parser, NULL, TRUE) != TokenLeftBrace)
|
if (AbsorbOpenBrace && LexGetToken(Parser, NULL, true) != TokenLeftBrace)
|
||||||
ProgramFail(Parser, "'{' expected");
|
ProgramFail(Parser, "'{' expected");
|
||||||
|
|
||||||
if (Parser->Mode == RunModeSkip || !Condition) {
|
if (Parser->Mode == RunModeSkip || !Condition) {
|
||||||
/* condition failed - skip this block instead */
|
/* condition failed - skip this block instead */
|
||||||
enum RunMode OldMode = Parser->Mode;
|
enum RunMode OldMode = Parser->Mode;
|
||||||
Parser->Mode = RunModeSkip;
|
Parser->Mode = RunModeSkip;
|
||||||
while (ParseStatement(Parser, TRUE) == ParseResultOk) {
|
while (ParseStatement(Parser, true) == ParseResultOk) {
|
||||||
}
|
}
|
||||||
Parser->Mode = OldMode;
|
Parser->Mode = OldMode;
|
||||||
} else {
|
} else {
|
||||||
/* just run it in its current mode */
|
/* just run it in its current mode */
|
||||||
while (ParseStatement(Parser, TRUE) == ParseResultOk) {
|
while (ParseStatement(Parser, true) == ParseResultOk) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LexGetToken(Parser, NULL, TRUE) != TokenRightBrace)
|
if (LexGetToken(Parser, NULL, true) != TokenRightBrace)
|
||||||
ProgramFail(Parser, "'}' expected");
|
ProgramFail(Parser, "'}' expected");
|
||||||
|
|
||||||
VariableScopeEnd(Parser, ScopeID, PrevScopeID);
|
VariableScopeEnd(Parser, ScopeID, PrevScopeID);
|
||||||
|
@ -521,7 +521,7 @@ void ParseTypedef(struct ParseState *Parser)
|
||||||
TypPtr = &Typ;
|
TypPtr = &Typ;
|
||||||
InitValue.Typ = &Parser->pc->TypeType;
|
InitValue.Typ = &Parser->pc->TypeType;
|
||||||
InitValue.Val = (union AnyValue *)TypPtr;
|
InitValue.Val = (union AnyValue *)TypPtr;
|
||||||
VariableDefine(Parser->pc, Parser, TypeName, &InitValue, NULL, FALSE);
|
VariableDefine(Parser->pc, Parser, TypeName, &InitValue, NULL, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -545,7 +545,7 @@ enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemi
|
||||||
|
|
||||||
/* take note of where we are and then grab a token to see what statement we have */
|
/* take note of where we are and then grab a token to see what statement we have */
|
||||||
ParserCopy(&PreState, Parser);
|
ParserCopy(&PreState, Parser);
|
||||||
Token = LexGetToken(Parser, &LexerValue, TRUE);
|
Token = LexGetToken(Parser, &LexerValue, true);
|
||||||
|
|
||||||
switch (Token) {
|
switch (Token) {
|
||||||
case TokenEOF:
|
case TokenEOF:
|
||||||
|
@ -561,13 +561,13 @@ enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemi
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* it might be a goto label */
|
/* it might be a goto label */
|
||||||
enum LexToken NextToken = LexGetToken(Parser, NULL, FALSE);
|
enum LexToken NextToken = LexGetToken(Parser, NULL, false);
|
||||||
if (NextToken == TokenColon) {
|
if (NextToken == TokenColon) {
|
||||||
/* declare the identifier as a goto label */
|
/* declare the identifier as a goto label */
|
||||||
LexGetToken(Parser, NULL, TRUE);
|
LexGetToken(Parser, NULL, true);
|
||||||
if (Parser->Mode == RunModeGoto && LexerValue->Val->Identifier == Parser->SearchGotoLabel)
|
if (Parser->Mode == RunModeGoto && LexerValue->Val->Identifier == Parser->SearchGotoLabel)
|
||||||
Parser->Mode = RunModeRun;
|
Parser->Mode = RunModeRun;
|
||||||
CheckTrailingSemicolon = FALSE;
|
CheckTrailingSemicolon = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -584,44 +584,44 @@ enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemi
|
||||||
VariableStackPop(Parser, CValue);
|
VariableStackPop(Parser, CValue);
|
||||||
break;
|
break;
|
||||||
case TokenLeftBrace:
|
case TokenLeftBrace:
|
||||||
ParseBlock(Parser, FALSE, TRUE);
|
ParseBlock(Parser, false, true);
|
||||||
CheckTrailingSemicolon = FALSE;
|
CheckTrailingSemicolon = false;
|
||||||
break;
|
break;
|
||||||
case TokenIf:
|
case TokenIf:
|
||||||
if (LexGetToken(Parser, NULL, TRUE) != TokenOpenBracket)
|
if (LexGetToken(Parser, NULL, true) != TokenOpenBracket)
|
||||||
ProgramFail(Parser, "'(' expected");
|
ProgramFail(Parser, "'(' expected");
|
||||||
Condition = ExpressionParseInt(Parser);
|
Condition = ExpressionParseInt(Parser);
|
||||||
if (LexGetToken(Parser, NULL, TRUE) != TokenCloseBracket)
|
if (LexGetToken(Parser, NULL, true) != TokenCloseBracket)
|
||||||
ProgramFail(Parser, "')' expected");
|
ProgramFail(Parser, "')' expected");
|
||||||
if (ParseStatementMaybeRun(Parser, Condition, TRUE) != ParseResultOk)
|
if (ParseStatementMaybeRun(Parser, Condition, true) != ParseResultOk)
|
||||||
ProgramFail(Parser, "statement expected");
|
ProgramFail(Parser, "statement expected");
|
||||||
if (LexGetToken(Parser, NULL, FALSE) == TokenElse) {
|
if (LexGetToken(Parser, NULL, false) == TokenElse) {
|
||||||
LexGetToken(Parser, NULL, TRUE);
|
LexGetToken(Parser, NULL, true);
|
||||||
if (ParseStatementMaybeRun(Parser, !Condition, TRUE) != ParseResultOk)
|
if (ParseStatementMaybeRun(Parser, !Condition, true) != ParseResultOk)
|
||||||
ProgramFail(Parser, "statement expected");
|
ProgramFail(Parser, "statement expected");
|
||||||
}
|
}
|
||||||
CheckTrailingSemicolon = FALSE;
|
CheckTrailingSemicolon = false;
|
||||||
break;
|
break;
|
||||||
case TokenWhile:
|
case TokenWhile:
|
||||||
{
|
{
|
||||||
struct ParseState PreConditional;
|
struct ParseState PreConditional;
|
||||||
enum RunMode PreMode = Parser->Mode;
|
enum RunMode PreMode = Parser->Mode;
|
||||||
if (LexGetToken(Parser, NULL, TRUE) != TokenOpenBracket)
|
if (LexGetToken(Parser, NULL, true) != TokenOpenBracket)
|
||||||
ProgramFail(Parser, "'(' expected");
|
ProgramFail(Parser, "'(' expected");
|
||||||
ParserCopyPos(&PreConditional, Parser);
|
ParserCopyPos(&PreConditional, Parser);
|
||||||
do {
|
do {
|
||||||
ParserCopyPos(Parser, &PreConditional);
|
ParserCopyPos(Parser, &PreConditional);
|
||||||
Condition = ExpressionParseInt(Parser);
|
Condition = ExpressionParseInt(Parser);
|
||||||
if (LexGetToken(Parser, NULL, TRUE) != TokenCloseBracket)
|
if (LexGetToken(Parser, NULL, true) != TokenCloseBracket)
|
||||||
ProgramFail(Parser, "')' expected");
|
ProgramFail(Parser, "')' expected");
|
||||||
if (ParseStatementMaybeRun(Parser, Condition, TRUE) != ParseResultOk)
|
if (ParseStatementMaybeRun(Parser, Condition, true) != ParseResultOk)
|
||||||
ProgramFail(Parser, "statement expected");
|
ProgramFail(Parser, "statement expected");
|
||||||
if (Parser->Mode == RunModeContinue)
|
if (Parser->Mode == RunModeContinue)
|
||||||
Parser->Mode = PreMode;
|
Parser->Mode = PreMode;
|
||||||
} while (Parser->Mode == RunModeRun && Condition);
|
} while (Parser->Mode == RunModeRun && Condition);
|
||||||
if (Parser->Mode == RunModeBreak)
|
if (Parser->Mode == RunModeBreak)
|
||||||
Parser->Mode = PreMode;
|
Parser->Mode = PreMode;
|
||||||
CheckTrailingSemicolon = FALSE;
|
CheckTrailingSemicolon = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TokenDo:
|
case TokenDo:
|
||||||
|
@ -631,16 +631,16 @@ enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemi
|
||||||
ParserCopyPos(&PreStatement, Parser);
|
ParserCopyPos(&PreStatement, Parser);
|
||||||
do {
|
do {
|
||||||
ParserCopyPos(Parser, &PreStatement);
|
ParserCopyPos(Parser, &PreStatement);
|
||||||
if (ParseStatement(Parser, TRUE) != ParseResultOk)
|
if (ParseStatement(Parser, true) != ParseResultOk)
|
||||||
ProgramFail(Parser, "statement expected");
|
ProgramFail(Parser, "statement expected");
|
||||||
if (Parser->Mode == RunModeContinue)
|
if (Parser->Mode == RunModeContinue)
|
||||||
Parser->Mode = PreMode;
|
Parser->Mode = PreMode;
|
||||||
if (LexGetToken(Parser, NULL, TRUE) != TokenWhile)
|
if (LexGetToken(Parser, NULL, true) != TokenWhile)
|
||||||
ProgramFail(Parser, "'while' expected");
|
ProgramFail(Parser, "'while' expected");
|
||||||
if (LexGetToken(Parser, NULL, TRUE) != TokenOpenBracket)
|
if (LexGetToken(Parser, NULL, true) != TokenOpenBracket)
|
||||||
ProgramFail(Parser, "'(' expected");
|
ProgramFail(Parser, "'(' expected");
|
||||||
Condition = ExpressionParseInt(Parser);
|
Condition = ExpressionParseInt(Parser);
|
||||||
if (LexGetToken(Parser, NULL, TRUE) != TokenCloseBracket)
|
if (LexGetToken(Parser, NULL, true) != TokenCloseBracket)
|
||||||
ProgramFail(Parser, "')' expected");
|
ProgramFail(Parser, "')' expected");
|
||||||
} while (Condition && Parser->Mode == RunModeRun);
|
} while (Condition && Parser->Mode == RunModeRun);
|
||||||
if (Parser->Mode == RunModeBreak)
|
if (Parser->Mode == RunModeBreak)
|
||||||
|
@ -649,10 +649,10 @@ enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemi
|
||||||
break;
|
break;
|
||||||
case TokenFor:
|
case TokenFor:
|
||||||
ParseFor(Parser);
|
ParseFor(Parser);
|
||||||
CheckTrailingSemicolon = FALSE;
|
CheckTrailingSemicolon = false;
|
||||||
break;
|
break;
|
||||||
case TokenSemicolon:
|
case TokenSemicolon:
|
||||||
CheckTrailingSemicolon = FALSE;
|
CheckTrailingSemicolon = false;
|
||||||
break;
|
break;
|
||||||
case TokenIntType:
|
case TokenIntType:
|
||||||
case TokenShortType:
|
case TokenShortType:
|
||||||
|
@ -675,21 +675,21 @@ enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemi
|
||||||
break;
|
break;
|
||||||
case TokenHashDefine:
|
case TokenHashDefine:
|
||||||
ParseMacroDefinition(Parser);
|
ParseMacroDefinition(Parser);
|
||||||
CheckTrailingSemicolon = FALSE;
|
CheckTrailingSemicolon = false;
|
||||||
break;
|
break;
|
||||||
case TokenHashInclude:
|
case TokenHashInclude:
|
||||||
if (LexGetToken(Parser, &LexerValue, TRUE) != TokenStringConstant)
|
if (LexGetToken(Parser, &LexerValue, true) != TokenStringConstant)
|
||||||
ProgramFail(Parser, "\"filename.h\" expected");
|
ProgramFail(Parser, "\"filename.h\" expected");
|
||||||
IncludeFile(Parser->pc, (char *)LexerValue->Val->Pointer);
|
IncludeFile(Parser->pc, (char *)LexerValue->Val->Pointer);
|
||||||
CheckTrailingSemicolon = FALSE;
|
CheckTrailingSemicolon = false;
|
||||||
break;
|
break;
|
||||||
case TokenSwitch:
|
case TokenSwitch:
|
||||||
if (LexGetToken(Parser, NULL, TRUE) != TokenOpenBracket)
|
if (LexGetToken(Parser, NULL, true) != TokenOpenBracket)
|
||||||
ProgramFail(Parser, "'(' expected");
|
ProgramFail(Parser, "'(' expected");
|
||||||
Condition = ExpressionParseInt(Parser);
|
Condition = ExpressionParseInt(Parser);
|
||||||
if (LexGetToken(Parser, NULL, TRUE) != TokenCloseBracket)
|
if (LexGetToken(Parser, NULL, true) != TokenCloseBracket)
|
||||||
ProgramFail(Parser, "')' expected");
|
ProgramFail(Parser, "')' expected");
|
||||||
if (LexGetToken(Parser, NULL, FALSE) != TokenLeftBrace)
|
if (LexGetToken(Parser, NULL, false) != TokenLeftBrace)
|
||||||
ProgramFail(Parser, "'{' expected");
|
ProgramFail(Parser, "'{' expected");
|
||||||
{
|
{
|
||||||
/* new block so we can store parser state */
|
/* new block so we can store parser state */
|
||||||
|
@ -697,12 +697,12 @@ enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemi
|
||||||
int OldSearchLabel = Parser->SearchLabel;
|
int OldSearchLabel = Parser->SearchLabel;
|
||||||
Parser->Mode = RunModeCaseSearch;
|
Parser->Mode = RunModeCaseSearch;
|
||||||
Parser->SearchLabel = Condition;
|
Parser->SearchLabel = Condition;
|
||||||
ParseBlock(Parser, TRUE, (OldMode != RunModeSkip) && (OldMode != RunModeReturn));
|
ParseBlock(Parser, true, (OldMode != RunModeSkip) && (OldMode != RunModeReturn));
|
||||||
if (Parser->Mode != RunModeReturn)
|
if (Parser->Mode != RunModeReturn)
|
||||||
Parser->Mode = OldMode;
|
Parser->Mode = OldMode;
|
||||||
Parser->SearchLabel = OldSearchLabel;
|
Parser->SearchLabel = OldSearchLabel;
|
||||||
}
|
}
|
||||||
CheckTrailingSemicolon = FALSE;
|
CheckTrailingSemicolon = false;
|
||||||
break;
|
break;
|
||||||
case TokenCase:
|
case TokenCase:
|
||||||
if (Parser->Mode == RunModeCaseSearch) {
|
if (Parser->Mode == RunModeCaseSearch) {
|
||||||
|
@ -711,18 +711,18 @@ enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemi
|
||||||
Parser->Mode = RunModeCaseSearch;
|
Parser->Mode = RunModeCaseSearch;
|
||||||
} else
|
} else
|
||||||
Condition = ExpressionParseInt(Parser);
|
Condition = ExpressionParseInt(Parser);
|
||||||
if (LexGetToken(Parser, NULL, TRUE) != TokenColon)
|
if (LexGetToken(Parser, NULL, true) != TokenColon)
|
||||||
ProgramFail(Parser, "':' expected");
|
ProgramFail(Parser, "':' expected");
|
||||||
if (Parser->Mode == RunModeCaseSearch && Condition == Parser->SearchLabel)
|
if (Parser->Mode == RunModeCaseSearch && Condition == Parser->SearchLabel)
|
||||||
Parser->Mode = RunModeRun;
|
Parser->Mode = RunModeRun;
|
||||||
CheckTrailingSemicolon = FALSE;
|
CheckTrailingSemicolon = false;
|
||||||
break;
|
break;
|
||||||
case TokenDefault:
|
case TokenDefault:
|
||||||
if (LexGetToken(Parser, NULL, TRUE) != TokenColon)
|
if (LexGetToken(Parser, NULL, true) != TokenColon)
|
||||||
ProgramFail(Parser, "':' expected");
|
ProgramFail(Parser, "':' expected");
|
||||||
if (Parser->Mode == RunModeCaseSearch)
|
if (Parser->Mode == RunModeCaseSearch)
|
||||||
Parser->Mode = RunModeRun;
|
Parser->Mode = RunModeRun;
|
||||||
CheckTrailingSemicolon = FALSE;
|
CheckTrailingSemicolon = false;
|
||||||
break;
|
break;
|
||||||
case TokenBreak:
|
case TokenBreak:
|
||||||
if (Parser->Mode == RunModeRun)
|
if (Parser->Mode == RunModeRun)
|
||||||
|
@ -740,7 +740,7 @@ enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemi
|
||||||
if (!Parser->pc->TopStackFrame) /* return from top-level program? */
|
if (!Parser->pc->TopStackFrame) /* return from top-level program? */
|
||||||
PlatformExit(Parser->pc, ExpressionCoerceInteger(CValue));
|
PlatformExit(Parser->pc, ExpressionCoerceInteger(CValue));
|
||||||
else
|
else
|
||||||
ExpressionAssign(Parser, Parser->pc->TopStackFrame->ReturnValue, CValue, TRUE, NULL, 0, FALSE);
|
ExpressionAssign(Parser, Parser->pc->TopStackFrame->ReturnValue, CValue, true, NULL, 0, false);
|
||||||
VariableStackPop(Parser, CValue);
|
VariableStackPop(Parser, CValue);
|
||||||
} else {
|
} else {
|
||||||
if (ExpressionParse(Parser, &CValue))
|
if (ExpressionParse(Parser, &CValue))
|
||||||
|
@ -755,7 +755,7 @@ enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemi
|
||||||
ParseTypedef(Parser);
|
ParseTypedef(Parser);
|
||||||
break;
|
break;
|
||||||
case TokenGoto:
|
case TokenGoto:
|
||||||
if (LexGetToken(Parser, &LexerValue, TRUE) != TokenIdentifier)
|
if (LexGetToken(Parser, &LexerValue, true) != TokenIdentifier)
|
||||||
ProgramFail(Parser, "identifier expected");
|
ProgramFail(Parser, "identifier expected");
|
||||||
if (Parser->Mode == RunModeRun) {
|
if (Parser->Mode == RunModeRun) {
|
||||||
/* start scanning for the goto label */
|
/* start scanning for the goto label */
|
||||||
|
@ -766,7 +766,7 @@ enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemi
|
||||||
case TokenDelete:
|
case TokenDelete:
|
||||||
{
|
{
|
||||||
/* try it as a function or variable name to delete */
|
/* try it as a function or variable name to delete */
|
||||||
if (LexGetToken(Parser, &LexerValue, TRUE) != TokenIdentifier)
|
if (LexGetToken(Parser, &LexerValue, true) != TokenIdentifier)
|
||||||
ProgramFail(Parser, "identifier expected");
|
ProgramFail(Parser, "identifier expected");
|
||||||
if (Parser->Mode == RunModeRun) {
|
if (Parser->Mode == RunModeRun) {
|
||||||
/* delete this variable or function */
|
/* delete this variable or function */
|
||||||
|
@ -784,7 +784,7 @@ enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemi
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CheckTrailingSemicolon) {
|
if (CheckTrailingSemicolon) {
|
||||||
if (LexGetToken(Parser, NULL, TRUE) != TokenSemicolon)
|
if (LexGetToken(Parser, NULL, true) != TokenSemicolon)
|
||||||
ProgramFail(Parser, "';' expected");
|
ProgramFail(Parser, "';' expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -821,7 +821,7 @@ void PicocParse(Picoc *pc, const char *FileName, const char *Source, int SourceL
|
||||||
LexInitParser(&Parser, pc, Source, Tokens, RegFileName, RunIt, EnableDebugger);
|
LexInitParser(&Parser, pc, Source, Tokens, RegFileName, RunIt, EnableDebugger);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
Ok = ParseStatement(&Parser, TRUE);
|
Ok = ParseStatement(&Parser, true);
|
||||||
} while (Ok == ParseResultOk);
|
} while (Ok == ParseResultOk);
|
||||||
|
|
||||||
if (Ok == ParseResultError)
|
if (Ok == ParseResultError)
|
||||||
|
@ -838,13 +838,13 @@ void PicocParseInteractiveNoStartPrompt(Picoc *pc, int EnableDebugger)
|
||||||
enum ParseResult Ok;
|
enum ParseResult Ok;
|
||||||
struct ParseState Parser;
|
struct ParseState Parser;
|
||||||
|
|
||||||
LexInitParser(&Parser, pc, NULL, NULL, pc->StrEmpty, TRUE, EnableDebugger);
|
LexInitParser(&Parser, pc, NULL, NULL, pc->StrEmpty, true, EnableDebugger);
|
||||||
PicocPlatformSetExitPoint(pc);
|
PicocPlatformSetExitPoint(pc);
|
||||||
LexInteractiveClear(pc, &Parser);
|
LexInteractiveClear(pc, &Parser);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
LexInteractiveStatementPrompt(pc);
|
LexInteractiveStatementPrompt(pc);
|
||||||
Ok = ParseStatement(&Parser, TRUE);
|
Ok = ParseStatement(&Parser, true);
|
||||||
LexInteractiveCompleted(pc, &Parser);
|
LexInteractiveCompleted(pc, &Parser);
|
||||||
|
|
||||||
} while (Ok == ParseResultOk);
|
} while (Ok == ParseResultOk);
|
||||||
|
|
4
picoc.c
4
picoc.c
|
@ -17,7 +17,7 @@
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int ParamCount = 1;
|
int ParamCount = 1;
|
||||||
int DontRunMain = FALSE;
|
int DontRunMain = false;
|
||||||
int StackSize = getenv("STACKSIZE") ? atoi(getenv("STACKSIZE")) : PICOC_STACK_SIZE;
|
int StackSize = getenv("STACKSIZE") ? atoi(getenv("STACKSIZE")) : PICOC_STACK_SIZE;
|
||||||
Picoc pc;
|
Picoc pc;
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ int main(int argc, char **argv)
|
||||||
PicocInitialise(&pc, StackSize);
|
PicocInitialise(&pc, StackSize);
|
||||||
|
|
||||||
if (strcmp(argv[ParamCount], "-s") == 0 || strcmp(argv[ParamCount], "-m") == 0) {
|
if (strcmp(argv[ParamCount], "-s") == 0 || strcmp(argv[ParamCount], "-m") == 0) {
|
||||||
DontRunMain = TRUE;
|
DontRunMain = true;
|
||||||
PicocIncludeAllSystemHeaders(&pc);
|
PicocIncludeAllSystemHeaders(&pc);
|
||||||
ParamCount++;
|
ParamCount++;
|
||||||
}
|
}
|
||||||
|
|
6
picoc.h
6
picoc.h
|
@ -10,12 +10,6 @@
|
||||||
#define PICOC_VERSION "v2.2"
|
#define PICOC_VERSION "v2.2"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* handy definitions */
|
|
||||||
#ifndef TRUE
|
|
||||||
#define TRUE 1
|
|
||||||
#define FALSE 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "interpreter.h"
|
#include "interpreter.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
18
platform.c
18
platform.c
|
@ -5,9 +5,9 @@
|
||||||
#include "interpreter.h"
|
#include "interpreter.h"
|
||||||
|
|
||||||
#ifdef DEBUGGER
|
#ifdef DEBUGGER
|
||||||
static int gEnableDebugger = TRUE;
|
static int gEnableDebugger = true;
|
||||||
#else
|
#else
|
||||||
static int gEnableDebugger = FALSE;
|
static int gEnableDebugger = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,22 +68,22 @@ void PicocCallMain(Picoc *pc, int argc, char **argv)
|
||||||
|
|
||||||
if (FuncValue->Val->FuncDef.NumParams != 0) {
|
if (FuncValue->Val->FuncDef.NumParams != 0) {
|
||||||
/* define the arguments */
|
/* define the arguments */
|
||||||
VariableDefinePlatformVar(pc, NULL, "__argc", &pc->IntType, (union AnyValue *)&argc, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "__argc", &pc->IntType, (union AnyValue *)&argc, false);
|
||||||
VariableDefinePlatformVar(pc, NULL, "__argv", pc->CharPtrPtrType, (union AnyValue *)&argv, FALSE);
|
VariableDefinePlatformVar(pc, NULL, "__argv", pc->CharPtrPtrType, (union AnyValue *)&argv, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FuncValue->Val->FuncDef.ReturnType == &pc->VoidType) {
|
if (FuncValue->Val->FuncDef.ReturnType == &pc->VoidType) {
|
||||||
if (FuncValue->Val->FuncDef.NumParams == 0)
|
if (FuncValue->Val->FuncDef.NumParams == 0)
|
||||||
PicocParse(pc, "startup", CALL_MAIN_NO_ARGS_RETURN_VOID, strlen(CALL_MAIN_NO_ARGS_RETURN_VOID), TRUE, TRUE, FALSE, gEnableDebugger);
|
PicocParse(pc, "startup", CALL_MAIN_NO_ARGS_RETURN_VOID, strlen(CALL_MAIN_NO_ARGS_RETURN_VOID), true, true, false, gEnableDebugger);
|
||||||
else
|
else
|
||||||
PicocParse(pc, "startup", CALL_MAIN_WITH_ARGS_RETURN_VOID, strlen(CALL_MAIN_WITH_ARGS_RETURN_VOID), TRUE, TRUE, FALSE, gEnableDebugger);
|
PicocParse(pc, "startup", CALL_MAIN_WITH_ARGS_RETURN_VOID, strlen(CALL_MAIN_WITH_ARGS_RETURN_VOID), true, true, false, gEnableDebugger);
|
||||||
} else {
|
} else {
|
||||||
VariableDefinePlatformVar(pc, NULL, "__exit_value", &pc->IntType, (union AnyValue *)&pc->PicocExitValue, TRUE);
|
VariableDefinePlatformVar(pc, NULL, "__exit_value", &pc->IntType, (union AnyValue *)&pc->PicocExitValue, true);
|
||||||
|
|
||||||
if (FuncValue->Val->FuncDef.NumParams == 0)
|
if (FuncValue->Val->FuncDef.NumParams == 0)
|
||||||
PicocParse(pc, "startup", CALL_MAIN_NO_ARGS_RETURN_INT, strlen(CALL_MAIN_NO_ARGS_RETURN_INT), TRUE, TRUE, FALSE, gEnableDebugger);
|
PicocParse(pc, "startup", CALL_MAIN_NO_ARGS_RETURN_INT, strlen(CALL_MAIN_NO_ARGS_RETURN_INT), true, true, false, gEnableDebugger);
|
||||||
else
|
else
|
||||||
PicocParse(pc, "startup", CALL_MAIN_WITH_ARGS_RETURN_INT, strlen(CALL_MAIN_WITH_ARGS_RETURN_INT), TRUE, TRUE, FALSE, gEnableDebugger);
|
PicocParse(pc, "startup", CALL_MAIN_WITH_ARGS_RETURN_INT, strlen(CALL_MAIN_WITH_ARGS_RETURN_INT), true, true, false, gEnableDebugger);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
/* configurable options */
|
/* configurable options */
|
||||||
/* select your host type (or do it in the Makefile):
|
/* select your host type (or do it in the Makefile):
|
||||||
|
@ -38,9 +39,9 @@
|
||||||
#define ALIGN_TYPE void * /* the default data type to use for alignment */
|
#define ALIGN_TYPE void * /* the default data type to use for alignment */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
# if defined(__powerpc__) || defined(__hppa__) || defined(__sparc__)
|
#if defined(__powerpc__) || defined(__hppa__) || defined(__sparc__)
|
||||||
# define BIG_ENDIAN
|
#define BIG_ENDIAN
|
||||||
# endif
|
#endif
|
||||||
|
|
||||||
#define GLOBAL_TABLE_SIZE (97) /* global variable table */
|
#define GLOBAL_TABLE_SIZE (97) /* global variable table */
|
||||||
#define STRING_TABLE_SIZE (97) /* shared string table size */
|
#define STRING_TABLE_SIZE (97) /* shared string table size */
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
#include "../interpreter.h"
|
#include "../interpreter.h"
|
||||||
|
|
||||||
#ifdef DEBUGGER
|
#ifdef DEBUGGER
|
||||||
static int gEnableDebugger = TRUE;
|
static int gEnableDebugger = true;
|
||||||
#else
|
#else
|
||||||
static int gEnableDebugger = FALSE;
|
static int gEnableDebugger = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* mark where to end the program for platforms which require this */
|
/* mark where to end the program for platforms which require this */
|
||||||
|
@ -81,7 +81,7 @@ char *PlatformReadFile(Picoc *pc, const char *FileName)
|
||||||
void PicocPlatformScanFile(Picoc *pc, const char *FileName)
|
void PicocPlatformScanFile(Picoc *pc, const char *FileName)
|
||||||
{
|
{
|
||||||
char *SourceStr = PlatformReadFile(pc, FileName);
|
char *SourceStr = PlatformReadFile(pc, FileName);
|
||||||
PicocParse(pc, FileName, SourceStr, strlen(SourceStr), TRUE, FALSE, TRUE, gEnableDebugger);
|
PicocParse(pc, FileName, SourceStr, strlen(SourceStr), true, false, true, gEnableDebugger);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* exit the program */
|
/* exit the program */
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DEBUGGER
|
#ifdef DEBUGGER
|
||||||
static int gEnableDebugger = TRUE;
|
static int gEnableDebugger = true;
|
||||||
#else
|
#else
|
||||||
static int gEnableDebugger = FALSE;
|
static int gEnableDebugger = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* mark where to end the program for platforms which require this */
|
/* mark where to end the program for platforms which require this */
|
||||||
|
@ -22,7 +22,7 @@ Picoc *break_pc = NULL;
|
||||||
|
|
||||||
static void BreakHandler(int Signal)
|
static void BreakHandler(int Signal)
|
||||||
{
|
{
|
||||||
break_pc->DebugManualBreak = TRUE;
|
break_pc->DebugManualBreak = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlatformInit(Picoc *pc)
|
void PlatformInit(Picoc *pc)
|
||||||
|
@ -126,7 +126,7 @@ void PicocPlatformScanFile(Picoc *pc, const char *FileName)
|
||||||
SourceStr[1] = '/';
|
SourceStr[1] = '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
PicocParse(pc, FileName, SourceStr, strlen(SourceStr), TRUE, FALSE, TRUE, gEnableDebugger);
|
PicocParse(pc, FileName, SourceStr, strlen(SourceStr), true, false, true, gEnableDebugger);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* exit the program */
|
/* exit the program */
|
||||||
|
|
10
table.c
10
table.c
|
@ -6,7 +6,7 @@
|
||||||
/* initialise the shared string system */
|
/* initialise the shared string system */
|
||||||
void TableInit(Picoc *pc)
|
void TableInit(Picoc *pc)
|
||||||
{
|
{
|
||||||
TableInitTable(&pc->StringTable, &pc->StringHashTable[0], STRING_TABLE_SIZE, TRUE);
|
TableInitTable(&pc->StringTable, &pc->StringHashTable[0], STRING_TABLE_SIZE, true);
|
||||||
pc->StrEmpty = TableStrRegister(pc, "");
|
pc->StrEmpty = TableStrRegister(pc, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,10 +67,10 @@ int TableSet(Picoc *pc, struct Table *Tbl, char *Key, struct Value *Val, const c
|
||||||
NewEntry->p.v.Val = Val;
|
NewEntry->p.v.Val = Val;
|
||||||
NewEntry->Next = Tbl->HashTable[AddAt];
|
NewEntry->Next = Tbl->HashTable[AddAt];
|
||||||
Tbl->HashTable[AddAt] = NewEntry;
|
Tbl->HashTable[AddAt] = NewEntry;
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* find a value in a table. returns FALSE if not found.
|
/* find a value in a table. returns FALSE if not found.
|
||||||
|
@ -80,7 +80,7 @@ int TableGet(struct Table *Tbl, const char *Key, struct Value **Val, const char
|
||||||
int AddAt;
|
int AddAt;
|
||||||
struct TableEntry *FoundEntry = TableSearch(Tbl, Key, &AddAt);
|
struct TableEntry *FoundEntry = TableSearch(Tbl, Key, &AddAt);
|
||||||
if (FoundEntry == NULL)
|
if (FoundEntry == NULL)
|
||||||
return FALSE;
|
return false;
|
||||||
|
|
||||||
*Val = FoundEntry->p.v.Val;
|
*Val = FoundEntry->p.v.Val;
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ int TableGet(struct Table *Tbl, const char *Key, struct Value **Val, const char
|
||||||
*DeclColumn = FoundEntry->DeclColumn;
|
*DeclColumn = FoundEntry->DeclColumn;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* remove an entry from the table */
|
/* remove an entry from the table */
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
/* By Terry R. McConnell (12/2/97) */
|
/* By Terry R. McConnell (12/2/97) */
|
||||||
/* Compile: cc -o hanoi hanoi.c */
|
/* Compile: cc -o hanoi hanoi.c */
|
||||||
|
|
||||||
/* This program does no error checking. But then, if it's right,
|
/* This program does no error checking. But then, if it's right,
|
||||||
it's right ... right ? */
|
it's right ... right ? */
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ of a smaller one. When the disks have been transferred entirely to another
|
||||||
spike the Universe will come to an end in a large thunderclap.
|
spike the Universe will come to an end in a large thunderclap.
|
||||||
|
|
||||||
This paraphrases the original legend due to DeParville, La Nature, Paris 1884,
|
This paraphrases the original legend due to DeParville, La Nature, Paris 1884,
|
||||||
Part I, 285-286. For this and further information see: Mathematical
|
Part I, 285-286. For this and further information see: Mathematical
|
||||||
Recreations & Essays, W.W. Rouse Ball, MacMillan, NewYork, 11th Ed. 1967,
|
Recreations & Essays, W.W. Rouse Ball, MacMillan, NewYork, 11th Ed. 1967,
|
||||||
303-305.
|
303-305.
|
||||||
*
|
*
|
||||||
|
@ -29,11 +29,8 @@ Recreations & Essays, W.W. Rouse Ball, MacMillan, NewYork, 11th Ed. 1967,
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define TRUE 1
|
|
||||||
#define FALSE 0
|
|
||||||
|
|
||||||
#define N 4 /* This is the number of "disks" on tower A initially. */
|
#define N 4 /* This is the number of "disks" on tower A initially. */
|
||||||
/* Taken to be 64 in the legend. The number of moves
|
/* Taken to be 64 in the legend. The number of moves
|
||||||
required, in general, is 2^N - 1. For N = 64, this is
|
required, in general, is 2^N - 1. For N = 64, this is
|
||||||
18,446,744,073,709,551,615 */
|
18,446,744,073,709,551,615 */
|
||||||
|
|
||||||
|
@ -64,7 +61,7 @@ PrintAll()
|
||||||
printf("------------------------------------------\n");
|
printf("------------------------------------------\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Move the leftmost nonzero element of source to dest, leave behind 0. */
|
/* Move the leftmost nonzero element of source to dest, leave behind 0. */
|
||||||
/* Returns the value moved (not used.) */
|
/* Returns the value moved (not used.) */
|
||||||
|
|
||||||
|
@ -97,7 +94,7 @@ Hanoi(int n,int *source, int *dest, int *spare)
|
||||||
|
|
||||||
Hanoi(n-1,source,spare,dest);
|
Hanoi(n-1,source,spare,dest);
|
||||||
Move(source,dest);
|
Move(source,dest);
|
||||||
Hanoi(n-1,spare,dest,source);
|
Hanoi(n-1,spare,dest,source);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +108,7 @@ main()
|
||||||
for(i=0;i<N;i++)A[i]=i+1;
|
for(i=0;i<N;i++)A[i]=i+1;
|
||||||
for(i=0;i<N;i++)B[i]=0;
|
for(i=0;i<N;i++)B[i]=0;
|
||||||
for(i=0;i<N;i++)C[i]=0;
|
for(i=0;i<N;i++)C[i]=0;
|
||||||
|
|
||||||
printf("Solution of Tower of Hanoi Problem with %d Disks\n\n",N);
|
printf("Solution of Tower of Hanoi Problem with %d Disks\n\n",N);
|
||||||
|
|
||||||
/* Print the starting state */
|
/* Print the starting state */
|
||||||
|
|
108
type.c
108
type.c
|
@ -11,7 +11,7 @@ static int IntAlignBytes;
|
||||||
/* add a new type to the set of types we know about */
|
/* add a new type to the set of types we know about */
|
||||||
struct ValueType *TypeAdd(Picoc *pc, struct ParseState *Parser, struct ValueType *ParentType, enum BaseType Base, int ArraySize, const char *Identifier, int Sizeof, int AlignBytes)
|
struct ValueType *TypeAdd(Picoc *pc, struct ParseState *Parser, struct ValueType *ParentType, enum BaseType Base, int ArraySize, const char *Identifier, int Sizeof, int AlignBytes)
|
||||||
{
|
{
|
||||||
struct ValueType *NewType = VariableAlloc(pc, Parser, sizeof(struct ValueType), TRUE);
|
struct ValueType *NewType = VariableAlloc(pc, Parser, sizeof(struct ValueType), true);
|
||||||
NewType->Base = Base;
|
NewType->Base = Base;
|
||||||
NewType->ArraySize = ArraySize;
|
NewType->ArraySize = ArraySize;
|
||||||
NewType->Sizeof = Sizeof;
|
NewType->Sizeof = Sizeof;
|
||||||
|
@ -20,7 +20,7 @@ struct ValueType *TypeAdd(Picoc *pc, struct ParseState *Parser, struct ValueType
|
||||||
NewType->Members = NULL;
|
NewType->Members = NULL;
|
||||||
NewType->FromType = ParentType;
|
NewType->FromType = ParentType;
|
||||||
NewType->DerivedTypeList = NULL;
|
NewType->DerivedTypeList = NULL;
|
||||||
NewType->OnHeap = TRUE;
|
NewType->OnHeap = true;
|
||||||
NewType->Next = ParentType->DerivedTypeList;
|
NewType->Next = ParentType->DerivedTypeList;
|
||||||
ParentType->DerivedTypeList = NewType;
|
ParentType->DerivedTypeList = NewType;
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ struct ValueType *TypeGetMatching(Picoc *pc, struct ParseState *Parser, struct V
|
||||||
int TypeStackSizeValue(struct Value *Val)
|
int TypeStackSizeValue(struct Value *Val)
|
||||||
{
|
{
|
||||||
if (Val != NULL && Val->ValOnStack)
|
if (Val != NULL && Val->ValOnStack)
|
||||||
return TypeSizeValue(Val, FALSE);
|
return TypeSizeValue(Val, false);
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ void TypeAddBaseType(Picoc *pc, struct ValueType *TypeNode, enum BaseType Base,
|
||||||
TypeNode->Members = NULL;
|
TypeNode->Members = NULL;
|
||||||
TypeNode->FromType = NULL;
|
TypeNode->FromType = NULL;
|
||||||
TypeNode->DerivedTypeList = NULL;
|
TypeNode->DerivedTypeList = NULL;
|
||||||
TypeNode->OnHeap = FALSE;
|
TypeNode->OnHeap = false;
|
||||||
TypeNode->Next = pc->UberType.DerivedTypeList;
|
TypeNode->Next = pc->UberType.DerivedTypeList;
|
||||||
pc->UberType.DerivedTypeList = TypeNode;
|
pc->UberType.DerivedTypeList = TypeNode;
|
||||||
}
|
}
|
||||||
|
@ -175,21 +175,21 @@ void TypeParseStruct(struct ParseState *Parser, struct ValueType **Typ, int IsSt
|
||||||
struct Value *LexValue;
|
struct Value *LexValue;
|
||||||
struct ValueType *MemberType;
|
struct ValueType *MemberType;
|
||||||
|
|
||||||
Token = LexGetToken(Parser, &LexValue, FALSE);
|
Token = LexGetToken(Parser, &LexValue, false);
|
||||||
if (Token == TokenIdentifier) {
|
if (Token == TokenIdentifier) {
|
||||||
LexGetToken(Parser, &LexValue, TRUE);
|
LexGetToken(Parser, &LexValue, true);
|
||||||
StructIdentifier = LexValue->Val->Identifier;
|
StructIdentifier = LexValue->Val->Identifier;
|
||||||
Token = LexGetToken(Parser, NULL, FALSE);
|
Token = LexGetToken(Parser, NULL, false);
|
||||||
} else {
|
} else {
|
||||||
static char TempNameBuf[7] = "^s0000";
|
static char TempNameBuf[7] = "^s0000";
|
||||||
StructIdentifier = PlatformMakeTempName(pc, TempNameBuf);
|
StructIdentifier = PlatformMakeTempName(pc, TempNameBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
*Typ = TypeGetMatching(pc, Parser, &Parser->pc->UberType, IsStruct ? TypeStruct : TypeUnion, 0, StructIdentifier, TRUE);
|
*Typ = TypeGetMatching(pc, Parser, &Parser->pc->UberType, IsStruct ? TypeStruct : TypeUnion, 0, StructIdentifier, true);
|
||||||
if (Token == TokenLeftBrace && (*Typ)->Members != NULL)
|
if (Token == TokenLeftBrace && (*Typ)->Members != NULL)
|
||||||
ProgramFail(Parser, "data type '%t' is already defined", *Typ);
|
ProgramFail(Parser, "data type '%t' is already defined", *Typ);
|
||||||
|
|
||||||
Token = LexGetToken(Parser, NULL, FALSE);
|
Token = LexGetToken(Parser, NULL, false);
|
||||||
if (Token != TokenLeftBrace) {
|
if (Token != TokenLeftBrace) {
|
||||||
/* use the already defined structure */
|
/* use the already defined structure */
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -202,17 +202,17 @@ void TypeParseStruct(struct ParseState *Parser, struct ValueType **Typ, int IsSt
|
||||||
if (pc->TopStackFrame != NULL)
|
if (pc->TopStackFrame != NULL)
|
||||||
ProgramFail(Parser, "struct/union definitions can only be globals");
|
ProgramFail(Parser, "struct/union definitions can only be globals");
|
||||||
|
|
||||||
LexGetToken(Parser, NULL, TRUE);
|
LexGetToken(Parser, NULL, true);
|
||||||
(*Typ)->Members = VariableAlloc(pc, Parser, sizeof(struct Table) + STRUCT_TABLE_SIZE * sizeof(struct TableEntry), TRUE);
|
(*Typ)->Members = VariableAlloc(pc, Parser, sizeof(struct Table) + STRUCT_TABLE_SIZE * sizeof(struct TableEntry), true);
|
||||||
(*Typ)->Members->HashTable = (struct TableEntry**)((char*)(*Typ)->Members + sizeof(struct Table));
|
(*Typ)->Members->HashTable = (struct TableEntry**)((char*)(*Typ)->Members + sizeof(struct Table));
|
||||||
TableInitTable((*Typ)->Members, (struct TableEntry**)((char*)(*Typ)->Members + sizeof(struct Table)), STRUCT_TABLE_SIZE, TRUE);
|
TableInitTable((*Typ)->Members, (struct TableEntry**)((char*)(*Typ)->Members + sizeof(struct Table)), STRUCT_TABLE_SIZE, true);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
TypeParse(Parser, &MemberType, &MemberIdentifier, NULL);
|
TypeParse(Parser, &MemberType, &MemberIdentifier, NULL);
|
||||||
if (MemberType == NULL || MemberIdentifier == NULL)
|
if (MemberType == NULL || MemberIdentifier == NULL)
|
||||||
ProgramFail(Parser, "invalid type in struct");
|
ProgramFail(Parser, "invalid type in struct");
|
||||||
|
|
||||||
MemberValue = VariableAllocValueAndData(pc, Parser, sizeof(int), FALSE, NULL, TRUE);
|
MemberValue = VariableAllocValueAndData(pc, Parser, sizeof(int), false, NULL, true);
|
||||||
MemberValue->Typ = MemberType;
|
MemberValue->Typ = MemberType;
|
||||||
if (IsStruct) {
|
if (IsStruct) {
|
||||||
/* allocate this member's location in the struct */
|
/* allocate this member's location in the struct */
|
||||||
|
@ -221,12 +221,12 @@ void TypeParseStruct(struct ParseState *Parser, struct ValueType **Typ, int IsSt
|
||||||
(*Typ)->Sizeof += AlignBoundary - ((*Typ)->Sizeof & (AlignBoundary-1));
|
(*Typ)->Sizeof += AlignBoundary - ((*Typ)->Sizeof & (AlignBoundary-1));
|
||||||
|
|
||||||
MemberValue->Val->Integer = (*Typ)->Sizeof;
|
MemberValue->Val->Integer = (*Typ)->Sizeof;
|
||||||
(*Typ)->Sizeof += TypeSizeValue(MemberValue, TRUE);
|
(*Typ)->Sizeof += TypeSizeValue(MemberValue, true);
|
||||||
} else {
|
} else {
|
||||||
/* union members always start at 0, make sure it's big enough to hold the largest member */
|
/* union members always start at 0, make sure it's big enough to hold the largest member */
|
||||||
MemberValue->Val->Integer = 0;
|
MemberValue->Val->Integer = 0;
|
||||||
if (MemberValue->Typ->Sizeof > (*Typ)->Sizeof)
|
if (MemberValue->Typ->Sizeof > (*Typ)->Sizeof)
|
||||||
(*Typ)->Sizeof = TypeSizeValue(MemberValue, TRUE);
|
(*Typ)->Sizeof = TypeSizeValue(MemberValue, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* make sure to align to the size of the largest member's alignment */
|
/* make sure to align to the size of the largest member's alignment */
|
||||||
|
@ -237,28 +237,28 @@ void TypeParseStruct(struct ParseState *Parser, struct ValueType **Typ, int IsSt
|
||||||
if (!TableSet(pc, (*Typ)->Members, MemberIdentifier, MemberValue, Parser->FileName, Parser->Line, Parser->CharacterPos))
|
if (!TableSet(pc, (*Typ)->Members, MemberIdentifier, MemberValue, Parser->FileName, Parser->Line, Parser->CharacterPos))
|
||||||
ProgramFail(Parser, "member '%s' already defined", &MemberIdentifier);
|
ProgramFail(Parser, "member '%s' already defined", &MemberIdentifier);
|
||||||
|
|
||||||
if (LexGetToken(Parser, NULL, TRUE) != TokenSemicolon)
|
if (LexGetToken(Parser, NULL, true) != TokenSemicolon)
|
||||||
ProgramFail(Parser, "semicolon expected");
|
ProgramFail(Parser, "semicolon expected");
|
||||||
|
|
||||||
} while (LexGetToken(Parser, NULL, FALSE) != TokenRightBrace);
|
} while (LexGetToken(Parser, NULL, false) != TokenRightBrace);
|
||||||
|
|
||||||
/* now align the structure to the size of its largest member's alignment */
|
/* now align the structure to the size of its largest member's alignment */
|
||||||
AlignBoundary = (*Typ)->AlignBytes;
|
AlignBoundary = (*Typ)->AlignBytes;
|
||||||
if (((*Typ)->Sizeof & (AlignBoundary-1)) != 0)
|
if (((*Typ)->Sizeof & (AlignBoundary-1)) != 0)
|
||||||
(*Typ)->Sizeof += AlignBoundary - ((*Typ)->Sizeof & (AlignBoundary-1));
|
(*Typ)->Sizeof += AlignBoundary - ((*Typ)->Sizeof & (AlignBoundary-1));
|
||||||
|
|
||||||
LexGetToken(Parser, NULL, TRUE);
|
LexGetToken(Parser, NULL, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create a system struct which has no user-visible members */
|
/* create a system struct which has no user-visible members */
|
||||||
struct ValueType *TypeCreateOpaqueStruct(Picoc *pc, struct ParseState *Parser, const char *StructName, int Size)
|
struct ValueType *TypeCreateOpaqueStruct(Picoc *pc, struct ParseState *Parser, const char *StructName, int Size)
|
||||||
{
|
{
|
||||||
struct ValueType *Typ = TypeGetMatching(pc, Parser, &pc->UberType, TypeStruct, 0, StructName, FALSE);
|
struct ValueType *Typ = TypeGetMatching(pc, Parser, &pc->UberType, TypeStruct, 0, StructName, false);
|
||||||
|
|
||||||
/* create the (empty) table */
|
/* create the (empty) table */
|
||||||
Typ->Members = VariableAlloc(pc, Parser, sizeof(struct Table) + STRUCT_TABLE_SIZE * sizeof(struct TableEntry), TRUE);
|
Typ->Members = VariableAlloc(pc, Parser, sizeof(struct Table) + STRUCT_TABLE_SIZE * sizeof(struct TableEntry), true);
|
||||||
Typ->Members->HashTable = (struct TableEntry**)((char*)Typ->Members + sizeof(struct Table));
|
Typ->Members->HashTable = (struct TableEntry**)((char*)Typ->Members + sizeof(struct Table));
|
||||||
TableInitTable(Typ->Members, (struct TableEntry**)((char*)Typ->Members + sizeof(struct Table)), STRUCT_TABLE_SIZE, TRUE);
|
TableInitTable(Typ->Members, (struct TableEntry**)((char*)Typ->Members + sizeof(struct Table)), STRUCT_TABLE_SIZE, true);
|
||||||
Typ->Sizeof = Size;
|
Typ->Sizeof = Size;
|
||||||
|
|
||||||
return Typ;
|
return Typ;
|
||||||
|
@ -274,11 +274,11 @@ void TypeParseEnum(struct ParseState *Parser, struct ValueType **Typ)
|
||||||
struct Value InitValue;
|
struct Value InitValue;
|
||||||
Picoc *pc = Parser->pc;
|
Picoc *pc = Parser->pc;
|
||||||
|
|
||||||
Token = LexGetToken(Parser, &LexValue, FALSE);
|
Token = LexGetToken(Parser, &LexValue, false);
|
||||||
if (Token == TokenIdentifier) {
|
if (Token == TokenIdentifier) {
|
||||||
LexGetToken(Parser, &LexValue, TRUE);
|
LexGetToken(Parser, &LexValue, true);
|
||||||
EnumIdentifier = LexValue->Val->Identifier;
|
EnumIdentifier = LexValue->Val->Identifier;
|
||||||
Token = LexGetToken(Parser, NULL, FALSE);
|
Token = LexGetToken(Parser, NULL, false);
|
||||||
} else {
|
} else {
|
||||||
static char TempNameBuf[7] = "^e0000";
|
static char TempNameBuf[7] = "^e0000";
|
||||||
EnumIdentifier = PlatformMakeTempName(pc, TempNameBuf);
|
EnumIdentifier = PlatformMakeTempName(pc, TempNameBuf);
|
||||||
|
@ -297,24 +297,24 @@ void TypeParseEnum(struct ParseState *Parser, struct ValueType **Typ)
|
||||||
if (pc->TopStackFrame != NULL)
|
if (pc->TopStackFrame != NULL)
|
||||||
ProgramFail(Parser, "enum definitions can only be globals");
|
ProgramFail(Parser, "enum definitions can only be globals");
|
||||||
|
|
||||||
LexGetToken(Parser, NULL, TRUE);
|
LexGetToken(Parser, NULL, true);
|
||||||
(*Typ)->Members = &pc->GlobalTable;
|
(*Typ)->Members = &pc->GlobalTable;
|
||||||
memset((void *)&InitValue, '\0', sizeof(struct Value));
|
memset((void *)&InitValue, '\0', sizeof(struct Value));
|
||||||
InitValue.Typ = &pc->IntType;
|
InitValue.Typ = &pc->IntType;
|
||||||
InitValue.Val = (union AnyValue *)&EnumValue;
|
InitValue.Val = (union AnyValue *)&EnumValue;
|
||||||
do {
|
do {
|
||||||
if (LexGetToken(Parser, &LexValue, TRUE) != TokenIdentifier)
|
if (LexGetToken(Parser, &LexValue, true) != TokenIdentifier)
|
||||||
ProgramFail(Parser, "identifier expected");
|
ProgramFail(Parser, "identifier expected");
|
||||||
|
|
||||||
EnumIdentifier = LexValue->Val->Identifier;
|
EnumIdentifier = LexValue->Val->Identifier;
|
||||||
if (LexGetToken(Parser, NULL, FALSE) == TokenAssign) {
|
if (LexGetToken(Parser, NULL, false) == TokenAssign) {
|
||||||
LexGetToken(Parser, NULL, TRUE);
|
LexGetToken(Parser, NULL, true);
|
||||||
EnumValue = ExpressionParseInt(Parser);
|
EnumValue = ExpressionParseInt(Parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
VariableDefine(pc, Parser, EnumIdentifier, &InitValue, NULL, FALSE);
|
VariableDefine(pc, Parser, EnumIdentifier, &InitValue, NULL, false);
|
||||||
|
|
||||||
Token = LexGetToken(Parser, NULL, TRUE);
|
Token = LexGetToken(Parser, NULL, true);
|
||||||
if (Token != TokenComma && Token != TokenRightBrace)
|
if (Token != TokenComma && Token != TokenRightBrace)
|
||||||
ProgramFail(Parser, "comma expected");
|
ProgramFail(Parser, "comma expected");
|
||||||
|
|
||||||
|
@ -325,8 +325,8 @@ void TypeParseEnum(struct ParseState *Parser, struct ValueType **Typ)
|
||||||
/* parse a type - just the basic type */
|
/* parse a type - just the basic type */
|
||||||
int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ, int *IsStatic)
|
int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ, int *IsStatic)
|
||||||
{
|
{
|
||||||
int Unsigned = FALSE;
|
int Unsigned = false;
|
||||||
int StaticQualifier = FALSE;
|
int StaticQualifier = false;
|
||||||
enum LexToken Token;
|
enum LexToken Token;
|
||||||
struct ParseState Before;
|
struct ParseState Before;
|
||||||
struct Value *LexerValue;
|
struct Value *LexerValue;
|
||||||
|
@ -336,12 +336,12 @@ int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ, int *IsSta
|
||||||
|
|
||||||
/* ignore leading type qualifiers */
|
/* ignore leading type qualifiers */
|
||||||
ParserCopy(&Before, Parser);
|
ParserCopy(&Before, Parser);
|
||||||
Token = LexGetToken(Parser, &LexerValue, TRUE);
|
Token = LexGetToken(Parser, &LexerValue, true);
|
||||||
while (Token == TokenStaticType || Token == TokenAutoType || Token == TokenRegisterType || Token == TokenExternType) {
|
while (Token == TokenStaticType || Token == TokenAutoType || Token == TokenRegisterType || Token == TokenExternType) {
|
||||||
if (Token == TokenStaticType)
|
if (Token == TokenStaticType)
|
||||||
StaticQualifier = TRUE;
|
StaticQualifier = true;
|
||||||
|
|
||||||
Token = LexGetToken(Parser, &LexerValue, TRUE);
|
Token = LexGetToken(Parser, &LexerValue, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsStatic != NULL)
|
if (IsStatic != NULL)
|
||||||
|
@ -349,7 +349,7 @@ int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ, int *IsSta
|
||||||
|
|
||||||
/* handle signed/unsigned with no trailing type */
|
/* handle signed/unsigned with no trailing type */
|
||||||
if (Token == TokenSignedType || Token == TokenUnsignedType) {
|
if (Token == TokenSignedType || Token == TokenUnsignedType) {
|
||||||
enum LexToken FollowToken = LexGetToken(Parser, &LexerValue, FALSE);
|
enum LexToken FollowToken = LexGetToken(Parser, &LexerValue, false);
|
||||||
Unsigned = (Token == TokenUnsignedType);
|
Unsigned = (Token == TokenUnsignedType);
|
||||||
|
|
||||||
if (FollowToken != TokenIntType && FollowToken != TokenLongType && FollowToken != TokenShortType && FollowToken != TokenCharType) {
|
if (FollowToken != TokenIntType && FollowToken != TokenLongType && FollowToken != TokenShortType && FollowToken != TokenCharType) {
|
||||||
|
@ -358,10 +358,10 @@ int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ, int *IsSta
|
||||||
else
|
else
|
||||||
*Typ = &pc->IntType;
|
*Typ = &pc->IntType;
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Token = LexGetToken(Parser, &LexerValue, TRUE);
|
Token = LexGetToken(Parser, &LexerValue, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (Token) {
|
switch (Token) {
|
||||||
|
@ -391,10 +391,10 @@ int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ, int *IsSta
|
||||||
*Typ = VarValue->Val->Typ;
|
*Typ = VarValue->Val->Typ;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: ParserCopy(Parser, &Before); return FALSE;
|
default: ParserCopy(Parser, &Before); return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* parse a type - the part at the end after the identifier. eg. array specifications etc. */
|
/* parse a type - the part at the end after the identifier. eg. array specifications etc. */
|
||||||
|
@ -404,13 +404,13 @@ struct ValueType *TypeParseBack(struct ParseState *Parser, struct ValueType *Fro
|
||||||
struct ParseState Before;
|
struct ParseState Before;
|
||||||
|
|
||||||
ParserCopy(&Before, Parser);
|
ParserCopy(&Before, Parser);
|
||||||
Token = LexGetToken(Parser, NULL, TRUE);
|
Token = LexGetToken(Parser, NULL, true);
|
||||||
if (Token == TokenLeftSquareBracket) {
|
if (Token == TokenLeftSquareBracket) {
|
||||||
/* add another array bound */
|
/* add another array bound */
|
||||||
if (LexGetToken(Parser, NULL, FALSE) == TokenRightSquareBracket) {
|
if (LexGetToken(Parser, NULL, false) == TokenRightSquareBracket) {
|
||||||
/* an unsized array */
|
/* an unsized array */
|
||||||
LexGetToken(Parser, NULL, TRUE);
|
LexGetToken(Parser, NULL, true);
|
||||||
return TypeGetMatching(Parser->pc, Parser, TypeParseBack(Parser, FromType), TypeArray, 0, Parser->pc->StrEmpty, TRUE);
|
return TypeGetMatching(Parser->pc, Parser, TypeParseBack(Parser, FromType), TypeArray, 0, Parser->pc->StrEmpty, true);
|
||||||
} else {
|
} else {
|
||||||
/* get a numeric array size */
|
/* get a numeric array size */
|
||||||
enum RunMode OldMode = Parser->Mode;
|
enum RunMode OldMode = Parser->Mode;
|
||||||
|
@ -419,10 +419,10 @@ struct ValueType *TypeParseBack(struct ParseState *Parser, struct ValueType *Fro
|
||||||
ArraySize = ExpressionParseInt(Parser);
|
ArraySize = ExpressionParseInt(Parser);
|
||||||
Parser->Mode = OldMode;
|
Parser->Mode = OldMode;
|
||||||
|
|
||||||
if (LexGetToken(Parser, NULL, TRUE) != TokenRightSquareBracket)
|
if (LexGetToken(Parser, NULL, true) != TokenRightSquareBracket)
|
||||||
ProgramFail(Parser, "']' expected");
|
ProgramFail(Parser, "']' expected");
|
||||||
|
|
||||||
return TypeGetMatching(Parser->pc, Parser, TypeParseBack(Parser, FromType), TypeArray, ArraySize, Parser->pc->StrEmpty, TRUE);
|
return TypeGetMatching(Parser->pc, Parser, TypeParseBack(Parser, FromType), TypeArray, ArraySize, Parser->pc->StrEmpty, true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* the type specification has finished */
|
/* the type specification has finished */
|
||||||
|
@ -434,7 +434,7 @@ struct ValueType *TypeParseBack(struct ParseState *Parser, struct ValueType *Fro
|
||||||
/* parse a type - the part which is repeated with each identifier in a declaration list */
|
/* parse a type - the part which is repeated with each identifier in a declaration list */
|
||||||
void TypeParseIdentPart(struct ParseState *Parser, struct ValueType *BasicTyp, struct ValueType **Typ, char **Identifier)
|
void TypeParseIdentPart(struct ParseState *Parser, struct ValueType *BasicTyp, struct ValueType **Typ, char **Identifier)
|
||||||
{
|
{
|
||||||
int Done = FALSE;
|
int Done = false;
|
||||||
enum LexToken Token;
|
enum LexToken Token;
|
||||||
struct Value *LexValue;
|
struct Value *LexValue;
|
||||||
struct ParseState Before;
|
struct ParseState Before;
|
||||||
|
@ -443,14 +443,14 @@ void TypeParseIdentPart(struct ParseState *Parser, struct ValueType *BasicTyp, s
|
||||||
|
|
||||||
while (!Done) {
|
while (!Done) {
|
||||||
ParserCopy(&Before, Parser);
|
ParserCopy(&Before, Parser);
|
||||||
Token = LexGetToken(Parser, &LexValue, TRUE);
|
Token = LexGetToken(Parser, &LexValue, true);
|
||||||
switch (Token) {
|
switch (Token) {
|
||||||
case TokenOpenBracket:
|
case TokenOpenBracket:
|
||||||
if (*Typ != NULL)
|
if (*Typ != NULL)
|
||||||
ProgramFail(Parser, "bad type declaration");
|
ProgramFail(Parser, "bad type declaration");
|
||||||
|
|
||||||
TypeParse(Parser, Typ, Identifier, NULL);
|
TypeParse(Parser, Typ, Identifier, NULL);
|
||||||
if (LexGetToken(Parser, NULL, TRUE) != TokenCloseBracket)
|
if (LexGetToken(Parser, NULL, true) != TokenCloseBracket)
|
||||||
ProgramFail(Parser, "')' expected");
|
ProgramFail(Parser, "')' expected");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -458,7 +458,7 @@ void TypeParseIdentPart(struct ParseState *Parser, struct ValueType *BasicTyp, s
|
||||||
if (*Typ == NULL)
|
if (*Typ == NULL)
|
||||||
ProgramFail(Parser, "bad type declaration");
|
ProgramFail(Parser, "bad type declaration");
|
||||||
|
|
||||||
*Typ = TypeGetMatching(Parser->pc, Parser, *Typ, TypePointer, 0, Parser->pc->StrEmpty, TRUE);
|
*Typ = TypeGetMatching(Parser->pc, Parser, *Typ, TypePointer, 0, Parser->pc->StrEmpty, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TokenIdentifier:
|
case TokenIdentifier:
|
||||||
|
@ -466,10 +466,10 @@ void TypeParseIdentPart(struct ParseState *Parser, struct ValueType *BasicTyp, s
|
||||||
ProgramFail(Parser, "bad type declaration");
|
ProgramFail(Parser, "bad type declaration");
|
||||||
|
|
||||||
*Identifier = LexValue->Val->Identifier;
|
*Identifier = LexValue->Val->Identifier;
|
||||||
Done = TRUE;
|
Done = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: ParserCopy(Parser, &Before); Done = TRUE; break;
|
default: ParserCopy(Parser, &Before); Done = true; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -498,7 +498,7 @@ int TypeIsForwardDeclared(struct ParseState *Parser, struct ValueType *Typ)
|
||||||
return TypeIsForwardDeclared(Parser, Typ->FromType);
|
return TypeIsForwardDeclared(Parser, Typ->FromType);
|
||||||
|
|
||||||
if ( (Typ->Base == TypeStruct || Typ->Base == TypeUnion) && Typ->Members == NULL)
|
if ( (Typ->Base == TypeStruct || Typ->Base == TypeUnion) && Typ->Members == NULL)
|
||||||
return TRUE;
|
return true;
|
||||||
|
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
62
variable.c
62
variable.c
|
@ -10,8 +10,8 @@
|
||||||
/* initialise the variable system */
|
/* initialise the variable system */
|
||||||
void VariableInit(Picoc *pc)
|
void VariableInit(Picoc *pc)
|
||||||
{
|
{
|
||||||
TableInitTable(&(pc->GlobalTable), &(pc->GlobalHashTable)[0], GLOBAL_TABLE_SIZE, TRUE);
|
TableInitTable(&(pc->GlobalTable), &(pc->GlobalHashTable)[0], GLOBAL_TABLE_SIZE, true);
|
||||||
TableInitTable(&pc->StringLiteralTable, &pc->StringLiteralHashTable[0], STRING_LITERAL_TABLE_SIZE, TRUE);
|
TableInitTable(&pc->StringLiteralTable, &pc->StringLiteralHashTable[0], STRING_LITERAL_TABLE_SIZE, true);
|
||||||
pc->TopStackFrame = NULL;
|
pc->TopStackFrame = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,14 +88,14 @@ struct Value *VariableAllocValueAndData(Picoc *pc, struct ParseState *Parser, in
|
||||||
struct Value *NewValue = VariableAlloc(pc, Parser, MEM_ALIGN(sizeof(struct Value)) + DataSize, OnHeap);
|
struct Value *NewValue = VariableAlloc(pc, Parser, MEM_ALIGN(sizeof(struct Value)) + DataSize, OnHeap);
|
||||||
NewValue->Val = (union AnyValue*)((char*)NewValue + MEM_ALIGN(sizeof(struct Value)));
|
NewValue->Val = (union AnyValue*)((char*)NewValue + MEM_ALIGN(sizeof(struct Value)));
|
||||||
NewValue->ValOnHeap = OnHeap;
|
NewValue->ValOnHeap = OnHeap;
|
||||||
NewValue->AnyValOnHeap = FALSE;
|
NewValue->AnyValOnHeap = false;
|
||||||
NewValue->ValOnStack = !OnHeap;
|
NewValue->ValOnStack = !OnHeap;
|
||||||
NewValue->IsLValue = IsLValue;
|
NewValue->IsLValue = IsLValue;
|
||||||
NewValue->LValueFrom = LValueFrom;
|
NewValue->LValueFrom = LValueFrom;
|
||||||
if (Parser)
|
if (Parser)
|
||||||
NewValue->ScopeID = Parser->ScopeID;
|
NewValue->ScopeID = Parser->ScopeID;
|
||||||
|
|
||||||
NewValue->OutOfScope = FALSE;
|
NewValue->OutOfScope = false;
|
||||||
|
|
||||||
return NewValue;
|
return NewValue;
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ struct Value *VariableAllocValueAndData(Picoc *pc, struct ParseState *Parser, in
|
||||||
/* allocate a value given its type */
|
/* allocate a value given its type */
|
||||||
struct Value *VariableAllocValueFromType(Picoc *pc, struct ParseState *Parser, struct ValueType *Typ, int IsLValue, struct Value *LValueFrom, int OnHeap)
|
struct Value *VariableAllocValueFromType(Picoc *pc, struct ParseState *Parser, struct ValueType *Typ, int IsLValue, struct Value *LValueFrom, int OnHeap)
|
||||||
{
|
{
|
||||||
int Size = TypeSize(Typ, Typ->ArraySize, FALSE);
|
int Size = TypeSize(Typ, Typ->ArraySize, false);
|
||||||
struct Value *NewValue = VariableAllocValueAndData(pc, Parser, Size, IsLValue, LValueFrom, OnHeap);
|
struct Value *NewValue = VariableAllocValueAndData(pc, Parser, Size, IsLValue, LValueFrom, OnHeap);
|
||||||
assert(Size >= 0 || Typ == &pc->VoidType);
|
assert(Size >= 0 || Typ == &pc->VoidType);
|
||||||
NewValue->Typ = Typ;
|
NewValue->Typ = Typ;
|
||||||
|
@ -114,7 +114,7 @@ struct Value *VariableAllocValueFromType(Picoc *pc, struct ParseState *Parser, s
|
||||||
/* allocate a value either on the heap or the stack and copy its value. handles overlapping data */
|
/* allocate a value either on the heap or the stack and copy its value. handles overlapping data */
|
||||||
struct Value *VariableAllocValueAndCopy(Picoc *pc, struct ParseState *Parser, struct Value *FromValue, int OnHeap)
|
struct Value *VariableAllocValueAndCopy(Picoc *pc, struct ParseState *Parser, struct Value *FromValue, int OnHeap)
|
||||||
{
|
{
|
||||||
int CopySize = TypeSizeValue(FromValue, TRUE);
|
int CopySize = TypeSizeValue(FromValue, true);
|
||||||
char TmpBuf[MAX_TMP_COPY_BUF];
|
char TmpBuf[MAX_TMP_COPY_BUF];
|
||||||
struct ValueType *DType = FromValue->Typ;
|
struct ValueType *DType = FromValue->Typ;
|
||||||
struct Value *NewValue;
|
struct Value *NewValue;
|
||||||
|
@ -131,12 +131,12 @@ struct Value *VariableAllocValueAndCopy(Picoc *pc, struct ParseState *Parser, st
|
||||||
/* allocate a value either on the heap or the stack from an existing AnyValue and type */
|
/* allocate a value either on the heap or the stack from an existing AnyValue and type */
|
||||||
struct Value *VariableAllocValueFromExistingData(struct ParseState *Parser, struct ValueType *Typ, union AnyValue *FromValue, int IsLValue, struct Value *LValueFrom)
|
struct Value *VariableAllocValueFromExistingData(struct ParseState *Parser, struct ValueType *Typ, union AnyValue *FromValue, int IsLValue, struct Value *LValueFrom)
|
||||||
{
|
{
|
||||||
struct Value *NewValue = VariableAlloc(Parser->pc, Parser, sizeof(struct Value), FALSE);
|
struct Value *NewValue = VariableAlloc(Parser->pc, Parser, sizeof(struct Value), false);
|
||||||
NewValue->Typ = Typ;
|
NewValue->Typ = Typ;
|
||||||
NewValue->Val = FromValue;
|
NewValue->Val = FromValue;
|
||||||
NewValue->ValOnHeap = FALSE;
|
NewValue->ValOnHeap = false;
|
||||||
NewValue->AnyValOnHeap = FALSE;
|
NewValue->AnyValOnHeap = false;
|
||||||
NewValue->ValOnStack = FALSE;
|
NewValue->ValOnStack = false;
|
||||||
NewValue->IsLValue = IsLValue;
|
NewValue->IsLValue = IsLValue;
|
||||||
NewValue->LValueFrom = LValueFrom;
|
NewValue->LValueFrom = LValueFrom;
|
||||||
|
|
||||||
|
@ -155,8 +155,8 @@ void VariableRealloc(struct ParseState *Parser, struct Value *FromValue, int New
|
||||||
if (FromValue->AnyValOnHeap)
|
if (FromValue->AnyValOnHeap)
|
||||||
HeapFreeMem(Parser->pc, FromValue->Val);
|
HeapFreeMem(Parser->pc, FromValue->Val);
|
||||||
|
|
||||||
FromValue->Val = VariableAlloc(Parser->pc, Parser, NewSize, TRUE);
|
FromValue->Val = VariableAlloc(Parser->pc, Parser, NewSize, true);
|
||||||
FromValue->AnyValOnHeap = TRUE;
|
FromValue->AnyValOnHeap = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int VariableScopeBegin(struct ParseState *Parser, int* OldScopeID)
|
int VariableScopeBegin(struct ParseState *Parser, int* OldScopeID)
|
||||||
|
@ -182,8 +182,8 @@ int VariableScopeBegin(struct ParseState *Parser, int* OldScopeID)
|
||||||
for (Count = 0; Count < HashTable->Size; Count++) {
|
for (Count = 0; Count < HashTable->Size; Count++) {
|
||||||
for (Entry = HashTable->HashTable[Count]; Entry != NULL; Entry = NextEntry) {
|
for (Entry = HashTable->HashTable[Count]; Entry != NULL; Entry = NextEntry) {
|
||||||
NextEntry = Entry->Next;
|
NextEntry = Entry->Next;
|
||||||
if (Entry->p.v.Val->ScopeID == Parser->ScopeID && Entry->p.v.Val->OutOfScope == TRUE) {
|
if (Entry->p.v.Val->ScopeID == Parser->ScopeID && Entry->p.v.Val->OutOfScope == true) {
|
||||||
Entry->p.v.Val->OutOfScope = FALSE;
|
Entry->p.v.Val->OutOfScope = false;
|
||||||
Entry->p.v.Key = (char*)((intptr_t)Entry->p.v.Key & ~1);
|
Entry->p.v.Key = (char*)((intptr_t)Entry->p.v.Key & ~1);
|
||||||
#ifdef DEBUG_VAR_SCOPE
|
#ifdef DEBUG_VAR_SCOPE
|
||||||
if (!FirstPrint) PRINT_SOURCE_POS();
|
if (!FirstPrint) PRINT_SOURCE_POS();
|
||||||
|
@ -214,13 +214,13 @@ void VariableScopeEnd(struct ParseState *Parser, int ScopeID, int PrevScopeID)
|
||||||
for (Count = 0; Count < HashTable->Size; Count++) {
|
for (Count = 0; Count < HashTable->Size; Count++) {
|
||||||
for (Entry = HashTable->HashTable[Count]; Entry != NULL; Entry = NextEntry) {
|
for (Entry = HashTable->HashTable[Count]; Entry != NULL; Entry = NextEntry) {
|
||||||
NextEntry = Entry->Next;
|
NextEntry = Entry->Next;
|
||||||
if ((Entry->p.v.Val->ScopeID == ScopeID) && (Entry->p.v.Val->OutOfScope == FALSE)) {
|
if ((Entry->p.v.Val->ScopeID == ScopeID) && (Entry->p.v.Val->OutOfScope == false)) {
|
||||||
#ifdef DEBUG_VAR_SCOPE
|
#ifdef DEBUG_VAR_SCOPE
|
||||||
if (!FirstPrint) PRINT_SOURCE_POS();
|
if (!FirstPrint) PRINT_SOURCE_POS();
|
||||||
FirstPrint = 1;
|
FirstPrint = 1;
|
||||||
printf(">>> out of scope: %s %x %d\n", Entry->p.v.Key, Entry->p.v.Val->ScopeID, Entry->p.v.Val->Val->Integer);
|
printf(">>> out of scope: %s %x %d\n", Entry->p.v.Key, Entry->p.v.Val->ScopeID, Entry->p.v.Val->Val->Integer);
|
||||||
#endif
|
#endif
|
||||||
Entry->p.v.Val->OutOfScope = TRUE;
|
Entry->p.v.Val->OutOfScope = true;
|
||||||
Entry->p.v.Key = (char*)((intptr_t)Entry->p.v.Key | 1); /* alter the key so it won't be found by normal searches */
|
Entry->p.v.Key = (char*)((intptr_t)Entry->p.v.Key | 1); /* alter the key so it won't be found by normal searches */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,11 +237,11 @@ int VariableDefinedAndOutOfScope(Picoc * pc, const char* Ident)
|
||||||
struct Table * HashTable = (pc->TopStackFrame == NULL) ? &(pc->GlobalTable) : &(pc->TopStackFrame)->LocalTable;
|
struct Table * HashTable = (pc->TopStackFrame == NULL) ? &(pc->GlobalTable) : &(pc->TopStackFrame)->LocalTable;
|
||||||
for (Count = 0; Count < HashTable->Size; Count++) {
|
for (Count = 0; Count < HashTable->Size; Count++) {
|
||||||
for (Entry = HashTable->HashTable[Count]; Entry != NULL; Entry = Entry->Next) {
|
for (Entry = HashTable->HashTable[Count]; Entry != NULL; Entry = Entry->Next) {
|
||||||
if (Entry->p.v.Val->OutOfScope == TRUE && (char*)((intptr_t)Entry->p.v.Key & ~1) == Ident)
|
if (Entry->p.v.Val->OutOfScope == true && (char*)((intptr_t)Entry->p.v.Key & ~1) == Ident)
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* define a variable. Ident must be registered */
|
/* define a variable. Ident must be registered */
|
||||||
|
@ -262,7 +262,7 @@ struct Value *VariableDefine(Picoc *pc, struct ParseState *Parser, char *Ident,
|
||||||
|
|
||||||
AssignValue->IsLValue = MakeWritable;
|
AssignValue->IsLValue = MakeWritable;
|
||||||
AssignValue->ScopeID = ScopeID;
|
AssignValue->ScopeID = ScopeID;
|
||||||
AssignValue->OutOfScope = FALSE;
|
AssignValue->OutOfScope = false;
|
||||||
|
|
||||||
if (!TableSet(pc, currentTable, Ident, AssignValue, Parser ? ((char*)Parser->FileName) : NULL, Parser ? Parser->Line : 0, Parser ? Parser->CharacterPos : 0))
|
if (!TableSet(pc, currentTable, Ident, AssignValue, Parser ? ((char*)Parser->FileName) : NULL, Parser ? Parser->Line : 0, Parser ? Parser->CharacterPos : 0))
|
||||||
ProgramFail(Parser, "'%s' is already defined", Ident);
|
ProgramFail(Parser, "'%s' is already defined", Ident);
|
||||||
|
@ -309,20 +309,20 @@ struct Value *VariableDefineButIgnoreIdentical(struct ParseState *Parser, char *
|
||||||
/* is this static already defined? */
|
/* is this static already defined? */
|
||||||
if (!TableGet(&pc->GlobalTable, RegisteredMangledName, &ExistingValue, &DeclFileName, &DeclLine, &DeclColumn)) {
|
if (!TableGet(&pc->GlobalTable, RegisteredMangledName, &ExistingValue, &DeclFileName, &DeclLine, &DeclColumn)) {
|
||||||
/* define the mangled-named static variable store in the global scope */
|
/* define the mangled-named static variable store in the global scope */
|
||||||
ExistingValue = VariableAllocValueFromType(Parser->pc, Parser, Typ, TRUE, NULL, TRUE);
|
ExistingValue = VariableAllocValueFromType(Parser->pc, Parser, Typ, true, NULL, true);
|
||||||
TableSet(pc, &pc->GlobalTable, (char*)RegisteredMangledName, ExistingValue, (char *)Parser->FileName, Parser->Line, Parser->CharacterPos);
|
TableSet(pc, &pc->GlobalTable, (char*)RegisteredMangledName, ExistingValue, (char *)Parser->FileName, Parser->Line, Parser->CharacterPos);
|
||||||
*FirstVisit = TRUE;
|
*FirstVisit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static variable exists in the global scope - now make a mirroring variable in our own scope with the short name */
|
/* static variable exists in the global scope - now make a mirroring variable in our own scope with the short name */
|
||||||
VariableDefinePlatformVar(Parser->pc, Parser, Ident, ExistingValue->Typ, ExistingValue->Val, TRUE);
|
VariableDefinePlatformVar(Parser->pc, Parser, Ident, ExistingValue->Typ, ExistingValue->Val, true);
|
||||||
return ExistingValue;
|
return ExistingValue;
|
||||||
} else {
|
} else {
|
||||||
if (Parser->Line != 0 && TableGet((pc->TopStackFrame == NULL) ? &pc->GlobalTable : &pc->TopStackFrame->LocalTable, Ident, &ExistingValue, &DeclFileName, &DeclLine, &DeclColumn)
|
if (Parser->Line != 0 && TableGet((pc->TopStackFrame == NULL) ? &pc->GlobalTable : &pc->TopStackFrame->LocalTable, Ident, &ExistingValue, &DeclFileName, &DeclLine, &DeclColumn)
|
||||||
&& DeclFileName == Parser->FileName && DeclLine == Parser->Line && DeclColumn == Parser->CharacterPos)
|
&& DeclFileName == Parser->FileName && DeclLine == Parser->Line && DeclColumn == Parser->CharacterPos)
|
||||||
return ExistingValue;
|
return ExistingValue;
|
||||||
else
|
else
|
||||||
return VariableDefine(Parser->pc, Parser, Ident, NULL, Typ, TRUE);
|
return VariableDefine(Parser->pc, Parser, Ident, NULL, Typ, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,10 +333,10 @@ int VariableDefined(Picoc *pc, const char *Ident)
|
||||||
|
|
||||||
if (pc->TopStackFrame == NULL || !TableGet(&pc->TopStackFrame->LocalTable, Ident, &FoundValue, NULL, NULL, NULL)) {
|
if (pc->TopStackFrame == NULL || !TableGet(&pc->TopStackFrame->LocalTable, Ident, &FoundValue, NULL, NULL, NULL)) {
|
||||||
if (!TableGet(&pc->GlobalTable, Ident, &FoundValue, NULL, NULL, NULL))
|
if (!TableGet(&pc->GlobalTable, Ident, &FoundValue, NULL, NULL, NULL))
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get the value of a variable. must be defined. Ident must be registered */
|
/* get the value of a variable. must be defined. Ident must be registered */
|
||||||
|
@ -355,7 +355,7 @@ void VariableGet(Picoc *pc, struct ParseState *Parser, const char *Ident, struct
|
||||||
/* define a global variable shared with a platform global. Ident will be registered */
|
/* define a global variable shared with a platform global. Ident will be registered */
|
||||||
void VariableDefinePlatformVar(Picoc *pc, struct ParseState *Parser, char *Ident, struct ValueType *Typ, union AnyValue *FromValue, int IsWritable)
|
void VariableDefinePlatformVar(Picoc *pc, struct ParseState *Parser, char *Ident, struct ValueType *Typ, union AnyValue *FromValue, int IsWritable)
|
||||||
{
|
{
|
||||||
struct Value *SomeValue = VariableAllocValueAndData(pc, NULL, 0, IsWritable, NULL, TRUE);
|
struct Value *SomeValue = VariableAllocValueAndData(pc, NULL, 0, IsWritable, NULL, true);
|
||||||
SomeValue->Typ = Typ;
|
SomeValue->Typ = Typ;
|
||||||
SomeValue->Val = FromValue;
|
SomeValue->Val = FromValue;
|
||||||
|
|
||||||
|
@ -370,7 +370,7 @@ void VariableStackPop(struct ParseState *Parser, struct Value *Var)
|
||||||
|
|
||||||
#ifdef DEBUG_HEAP
|
#ifdef DEBUG_HEAP
|
||||||
if (Var->ValOnStack)
|
if (Var->ValOnStack)
|
||||||
printf("popping %ld at 0x%lx\n", (unsigned long)(sizeof(struct Value) + TypeSizeValue(Var, FALSE)), (unsigned long)Var);
|
printf("popping %ld at 0x%lx\n", (unsigned long)(sizeof(struct Value) + TypeSizeValue(Var, false)), (unsigned long)Var);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (Var->ValOnHeap) {
|
if (Var->ValOnHeap) {
|
||||||
|
@ -379,7 +379,7 @@ void VariableStackPop(struct ParseState *Parser, struct Value *Var)
|
||||||
|
|
||||||
Success = HeapPopStack(Parser->pc, Var, sizeof(struct Value)); /* free from heap */
|
Success = HeapPopStack(Parser->pc, Var, sizeof(struct Value)); /* free from heap */
|
||||||
} else if (Var->ValOnStack)
|
} else if (Var->ValOnStack)
|
||||||
Success = HeapPopStack(Parser->pc, Var, sizeof(struct Value) + TypeSizeValue(Var, FALSE)); /* free from stack */
|
Success = HeapPopStack(Parser->pc, Var, sizeof(struct Value) + TypeSizeValue(Var, false)); /* free from stack */
|
||||||
else
|
else
|
||||||
Success = HeapPopStack(Parser->pc, Var, sizeof(struct Value)); /* value isn't our problem */
|
Success = HeapPopStack(Parser->pc, Var, sizeof(struct Value)); /* value isn't our problem */
|
||||||
|
|
||||||
|
@ -400,7 +400,7 @@ void VariableStackFrameAdd(struct ParseState *Parser, const char *FuncName, int
|
||||||
ParserCopy(&NewFrame->ReturnParser, Parser);
|
ParserCopy(&NewFrame->ReturnParser, Parser);
|
||||||
NewFrame->FuncName = FuncName;
|
NewFrame->FuncName = FuncName;
|
||||||
NewFrame->Parameter = (NumParams > 0) ? ((void*)((char *)NewFrame + sizeof(struct StackFrame))) : NULL;
|
NewFrame->Parameter = (NumParams > 0) ? ((void*)((char *)NewFrame + sizeof(struct StackFrame))) : NULL;
|
||||||
TableInitTable(&NewFrame->LocalTable, &NewFrame->LocalHashTable[0], LOCAL_TABLE_SIZE, FALSE);
|
TableInitTable(&NewFrame->LocalTable, &NewFrame->LocalHashTable[0], LOCAL_TABLE_SIZE, false);
|
||||||
NewFrame->PreviousStackFrame = Parser->pc->TopStackFrame;
|
NewFrame->PreviousStackFrame = Parser->pc->TopStackFrame;
|
||||||
Parser->pc->TopStackFrame = NewFrame;
|
Parser->pc->TopStackFrame = NewFrame;
|
||||||
}
|
}
|
||||||
|
@ -446,7 +446,7 @@ void *VariableDereferencePointer(struct ParseState *Parser, struct Value *Pointe
|
||||||
*DerefOffset = 0;
|
*DerefOffset = 0;
|
||||||
|
|
||||||
if (DerefIsLValue != NULL)
|
if (DerefIsLValue != NULL)
|
||||||
*DerefIsLValue = TRUE;
|
*DerefIsLValue = true;
|
||||||
|
|
||||||
return PointerValue->Val->Pointer;
|
return PointerValue->Val->Pointer;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue