Platform-dependent exit() function for Surveyor
git-svn-id: http://picoc.googlecode.com/svn/trunk@121 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
parent
bf38bf0d5e
commit
6ce1662475
1
TODO
1
TODO
|
@ -1,6 +1,7 @@
|
|||
TODO
|
||||
|
||||
* pointers to array elements and struct elements
|
||||
* setjmp() / longjmp() hooks for error exit
|
||||
* test character array pointers and dereferencing
|
||||
* operator precedence
|
||||
* '->'
|
||||
|
|
3
picoc.c
3
picoc.c
|
@ -21,6 +21,9 @@ int main(int argc, char **argv)
|
|||
ProgramFail(NULL, "Format: picoc <program.c> <args>...\n");
|
||||
|
||||
Initialise();
|
||||
if (PlatformSetExitPoint())
|
||||
return 1;
|
||||
|
||||
PlatformScanFile(argv[1]);
|
||||
|
||||
return 0;
|
||||
|
|
2
picoc.h
2
picoc.h
|
@ -299,5 +299,7 @@ char *PlatformGetLine(char *Buf, int MaxLen);
|
|||
void PlatformPutc(unsigned char OutCh);
|
||||
void PlatformPrintf(const char *Format, ...);
|
||||
void PlatformVPrintf(const char *Format, va_list Args);
|
||||
int PlatformSetExitPoint();
|
||||
void PlatformExit();
|
||||
|
||||
#endif /* PICOC_H */
|
||||
|
|
|
@ -45,6 +45,8 @@
|
|||
# include "../string.h"
|
||||
# include "../print.h"
|
||||
# include "../malloc.h"
|
||||
# include "../setjmp.h"
|
||||
# include "../stdarg.h"
|
||||
# define assert(x)
|
||||
# endif
|
||||
# endif
|
||||
|
|
|
@ -1,32 +1,6 @@
|
|||
#include "picoc.h"
|
||||
|
||||
#ifdef UNIX_HOST
|
||||
/* exit with a message */
|
||||
void ProgramFail(struct ParseState *Parser, const char *Message, ...)
|
||||
{
|
||||
va_list Args;
|
||||
|
||||
if (Parser != NULL)
|
||||
PlatformPrintf("%s:%d: ", Parser->FileName, Parser->Line);
|
||||
|
||||
va_start(Args, Message);
|
||||
PlatformVPrintf(Message, Args);
|
||||
PlatformPrintf("\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* exit lexing with a message */
|
||||
void LexFail(struct LexState *Lexer, const char *Message, ...)
|
||||
{
|
||||
va_list Args;
|
||||
|
||||
PlatformPrintf("%s:%d: ", Lexer->FileName, Lexer->Line);
|
||||
va_start(Args, Message);
|
||||
PlatformVPrintf(Message, Args);
|
||||
PlatformPrintf("\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* get a line of interactive input */
|
||||
char *PlatformGetLine(char *Buf, int MaxLen)
|
||||
{
|
||||
|
@ -73,6 +47,18 @@ void PlatformScanFile(const char *FileName)
|
|||
Parse(FileName, SourceStr, strlen(SourceStr), TRUE);
|
||||
free(SourceStr);
|
||||
}
|
||||
|
||||
/* mark where to end the program for platforms which require this */
|
||||
int PlatformSetExitPoint()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* exit the program */
|
||||
void PlatformExit()
|
||||
{
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SURVEYOR_HOST
|
||||
|
@ -96,8 +82,47 @@ char *PlatformGetLine(char *Buf, int MaxLen)
|
|||
void PlatformPutc(unsigned char OutCh)
|
||||
{
|
||||
}
|
||||
|
||||
/* mark where to end the program for platforms which require this */
|
||||
static jmp_buf ExitPoint;
|
||||
int PlatformSetExitPoint()
|
||||
{
|
||||
return setjmp(ExitPoint);
|
||||
}
|
||||
|
||||
/* exit the program */
|
||||
void PlatformExit()
|
||||
{
|
||||
longjmp(ExitPoint, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* exit with a message */
|
||||
void ProgramFail(struct ParseState *Parser, const char *Message, ...)
|
||||
{
|
||||
va_list Args;
|
||||
|
||||
if (Parser != NULL)
|
||||
PlatformPrintf("%s:%d: ", Parser->FileName, Parser->Line);
|
||||
|
||||
va_start(Args, Message);
|
||||
PlatformVPrintf(Message, Args);
|
||||
PlatformPrintf("\n");
|
||||
PlatformExit(1);
|
||||
}
|
||||
|
||||
/* exit lexing with a message */
|
||||
void LexFail(struct LexState *Lexer, const char *Message, ...)
|
||||
{
|
||||
va_list Args;
|
||||
|
||||
PlatformPrintf("%s:%d: ", Lexer->FileName, Lexer->Line);
|
||||
va_start(Args, Message);
|
||||
PlatformVPrintf(Message, Args);
|
||||
PlatformPrintf("\n");
|
||||
PlatformExit(1);
|
||||
}
|
||||
|
||||
/* printf for compiler error reporting */
|
||||
void PlatformPrintf(const char *Format, ...)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue