Trying to make PicocPlatformSetExitPoint() work correctly.
git-svn-id: http://picoc.googlecode.com/svn/trunk@551 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
parent
55e2183bea
commit
9b0bd8c4dc
|
@ -375,7 +375,7 @@ int TypeLastAccessibleOffset(struct Value *Val);
|
||||||
int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ, int *IsStatic);
|
int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ, int *IsStatic);
|
||||||
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);
|
||||||
void TypeParse(struct ParseState *Parser, struct ValueType **Typ, char **Identifier, int *IsStatic);
|
void TypeParse(struct ParseState *Parser, struct ValueType **Typ, char **Identifier, int *IsStatic);
|
||||||
struct ValueType *TypeGetMatching(struct ParseState *Parser, struct ValueType *ParentType, enum BaseType Base, int ArraySize, const char *Identifier);
|
struct ValueType *TypeGetMatching(struct ParseState *Parser, struct ValueType *ParentType, enum BaseType Base, int ArraySize, const char *Identifier, int AllowDuplicates);
|
||||||
struct ValueType *TypeCreateOpaqueStruct(struct ParseState *Parser, const char *StructName, int Size);
|
struct ValueType *TypeCreateOpaqueStruct(struct ParseState *Parser, const char *StructName, int Size);
|
||||||
|
|
||||||
/* heap.c */
|
/* heap.c */
|
||||||
|
@ -444,6 +444,7 @@ void PlatformErrorPrefix(struct ParseState *Parser);
|
||||||
void PlatformPrintf(const char *Format, ...);
|
void PlatformPrintf(const char *Format, ...);
|
||||||
void PlatformVPrintf(const char *Format, va_list Args);
|
void PlatformVPrintf(const char *Format, va_list Args);
|
||||||
void PlatformExit(int ExitVal);
|
void PlatformExit(int ExitVal);
|
||||||
|
char *PlatformMakeTempName(char *TempNameBuffer);
|
||||||
void PlatformLibraryInit();
|
void PlatformLibraryInit();
|
||||||
|
|
||||||
/* include.c */
|
/* include.c */
|
||||||
|
|
7
picoc.c
7
picoc.c
|
@ -1,3 +1,4 @@
|
||||||
|
/* include only picoc.h here - should be able to use it with only the external interfaces, no internals from interpreter.h */
|
||||||
#include "picoc.h"
|
#include "picoc.h"
|
||||||
|
|
||||||
/* platform-dependent code for running programs is in this file */
|
/* platform-dependent code for running programs is in this file */
|
||||||
|
@ -58,9 +59,11 @@ int main(int argc, char **argv)
|
||||||
#else
|
#else
|
||||||
# ifdef SURVEYOR_HOST
|
# ifdef SURVEYOR_HOST
|
||||||
# define HEAP_SIZE C_HEAPSIZE
|
# define HEAP_SIZE C_HEAPSIZE
|
||||||
|
# include <setjmp.h>
|
||||||
|
|
||||||
|
extern int ExitBuf[];
|
||||||
|
|
||||||
int picoc(char *SourceStr)
|
int picoc(char *SourceStr)
|
||||||
|
|
||||||
{
|
{
|
||||||
char *pos;
|
char *pos;
|
||||||
|
|
||||||
|
@ -78,7 +81,7 @@ int picoc(char *SourceStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
ExitBuf[40] = 0;
|
ExitBuf[40] = 0;
|
||||||
PicocPlatformSetExitPoint();
|
setjmp(ExitBuf);
|
||||||
if (ExitBuf[40]) {
|
if (ExitBuf[40]) {
|
||||||
printf("Leaving PicoC\n\r");
|
printf("Leaving PicoC\n\r");
|
||||||
PicocCleanup();
|
PicocCleanup();
|
||||||
|
|
12
picoc.h
12
picoc.h
|
@ -15,13 +15,23 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef UNIX_HOST
|
||||||
|
#include <setjmp.h>
|
||||||
|
|
||||||
|
/* mark where to end the program for platforms which require this */
|
||||||
|
extern jmp_buf PicocExitBuf;
|
||||||
|
|
||||||
|
/* this has to be a macro, otherwise errors will occur due to the stack being corrupt */
|
||||||
|
#define PicocPlatformSetExitPoint() setjmp(PicocExitBuf)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* parse.c */
|
/* parse.c */
|
||||||
void PicocParse(const char *FileName, const char *Source, int SourceLen, int RunIt, int CleanupNow, int CleanupSource);
|
void PicocParse(const char *FileName, const char *Source, int SourceLen, int RunIt, int CleanupNow, int CleanupSource);
|
||||||
void PicocParseInteractive();
|
void PicocParseInteractive();
|
||||||
|
|
||||||
/* platform.c */
|
/* platform.c */
|
||||||
void PicocCallMain(int argc, char **argv);
|
void PicocCallMain(int argc, char **argv);
|
||||||
int PicocPlatformSetExitPoint();
|
|
||||||
void PicocInitialise(int StackSize);
|
void PicocInitialise(int StackSize);
|
||||||
void PicocCleanup();
|
void PicocCleanup();
|
||||||
void PicocPlatformScanFile(const char *FileName);
|
void PicocPlatformScanFile(const char *FileName);
|
||||||
|
|
23
platform.c
23
platform.c
|
@ -211,3 +211,26 @@ void PlatformVPrintf(const char *Format, va_list Args)
|
||||||
PrintCh(*FPos, CStdOut);
|
PrintCh(*FPos, CStdOut);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* make a new temporary name. takes a static buffer of char [7] as a parameter. should be initialised to "XX0000"
|
||||||
|
* where XX can be any characters */
|
||||||
|
char *PlatformMakeTempName(char *TempNameBuffer)
|
||||||
|
{
|
||||||
|
int CPos = 5;
|
||||||
|
|
||||||
|
while (CPos > 1)
|
||||||
|
{
|
||||||
|
if (TempNameBuffer[CPos] < '9')
|
||||||
|
{
|
||||||
|
TempNameBuffer[CPos]++;
|
||||||
|
return TempNameBuffer;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TempNameBuffer[CPos] = 0;
|
||||||
|
CPos--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return TempNameBuffer;
|
||||||
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ struct ValueType *IntArrayType;
|
||||||
|
|
||||||
void SRV1SetupFunc()
|
void SRV1SetupFunc()
|
||||||
{
|
{
|
||||||
IntArrayType = TypeGetMatching(NULL, &IntType, TypeArray, 16, StrEmpty);
|
IntArrayType = TypeGetMatching(NULL, &IntType, TypeArray, 16, StrEmpty, TRUE);
|
||||||
VariableDefinePlatformVar(NULL, "scanvect", IntArrayType, (union AnyValue *)&ScanVect, FALSE);
|
VariableDefinePlatformVar(NULL, "scanvect", IntArrayType, (union AnyValue *)&ScanVect, FALSE);
|
||||||
VariableDefinePlatformVar(NULL, "neuron", IntArrayType, (union AnyValue *)&NNVect, FALSE);
|
VariableDefinePlatformVar(NULL, "neuron", IntArrayType, (union AnyValue *)&NNVect, FALSE);
|
||||||
VariableDefinePlatformVar(NULL, "blobcnt", &IntType, (union AnyValue *)&Blobcnt, FALSE);
|
VariableDefinePlatformVar(NULL, "blobcnt", &IntType, (union AnyValue *)&Blobcnt, FALSE);
|
||||||
|
|
|
@ -9,7 +9,7 @@ void PlatformLibraryInit()
|
||||||
{
|
{
|
||||||
struct ValueType *IntArrayType;
|
struct ValueType *IntArrayType;
|
||||||
|
|
||||||
IntArrayType = TypeGetMatching(NULL, &IntType, TypeArray, 16, NULL);
|
IntArrayType = TypeGetMatching(NULL, &IntType, TypeArray, 16, StrEmpty, TRUE);
|
||||||
VariableDefinePlatformVar(NULL, "scanvect", IntArrayType, (union AnyValue *)&ScanVect, FALSE);
|
VariableDefinePlatformVar(NULL, "scanvect", IntArrayType, (union AnyValue *)&ScanVect, FALSE);
|
||||||
VariableDefinePlatformVar(NULL, "neuron", IntArrayType, (union AnyValue *)&NNVect, FALSE);
|
VariableDefinePlatformVar(NULL, "neuron", IntArrayType, (union AnyValue *)&NNVect, FALSE);
|
||||||
VariableDefinePlatformVar(NULL, "xbuf", CharArrayType, (union AnyValue *)&xbuff, FALSE);
|
VariableDefinePlatformVar(NULL, "xbuf", CharArrayType, (union AnyValue *)&xbuff, FALSE);
|
||||||
|
|
|
@ -6,6 +6,9 @@
|
||||||
#include <readline/history.h>
|
#include <readline/history.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* mark where to end the program for platforms which require this */
|
||||||
|
jmp_buf PicocExitBuf;
|
||||||
|
|
||||||
void PlatformCleanup()
|
void PlatformCleanup()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -90,19 +93,10 @@ void PicocPlatformScanFile(const char *FileName)
|
||||||
PicocParse(FileName, SourceStr, strlen(SourceStr), TRUE, FALSE, TRUE);
|
PicocParse(FileName, SourceStr, strlen(SourceStr), TRUE, FALSE, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* mark where to end the program for platforms which require this */
|
|
||||||
jmp_buf ExitBuf;
|
|
||||||
|
|
||||||
/* set the point we'll return to when we exit through an error */
|
|
||||||
int PicocPlatformSetExitPoint()
|
|
||||||
{
|
|
||||||
return setjmp(ExitBuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* exit the program */
|
/* exit the program */
|
||||||
void PlatformExit(int RetVal)
|
void PlatformExit(int RetVal)
|
||||||
{
|
{
|
||||||
PicocExitValue = RetVal;
|
PicocExitValue = RetVal;
|
||||||
longjmp(ExitBuf, 1);
|
longjmp(PicocExitBuf, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue