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:
zik.saleeba 2011-02-18 02:16:51 +00:00
parent 55e2183bea
commit 9b0bd8c4dc
7 changed files with 47 additions and 16 deletions

View file

@ -375,7 +375,7 @@ int TypeLastAccessibleOffset(struct Value *Val);
int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ, int *IsStatic);
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);
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);
/* heap.c */
@ -444,6 +444,7 @@ void PlatformErrorPrefix(struct ParseState *Parser);
void PlatformPrintf(const char *Format, ...);
void PlatformVPrintf(const char *Format, va_list Args);
void PlatformExit(int ExitVal);
char *PlatformMakeTempName(char *TempNameBuffer);
void PlatformLibraryInit();
/* include.c */

View file

@ -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"
/* platform-dependent code for running programs is in this file */
@ -58,9 +59,11 @@ int main(int argc, char **argv)
#else
# ifdef SURVEYOR_HOST
# define HEAP_SIZE C_HEAPSIZE
# include <setjmp.h>
extern int ExitBuf[];
int picoc(char *SourceStr)
{
char *pos;
@ -78,7 +81,7 @@ int picoc(char *SourceStr)
}
ExitBuf[40] = 0;
PicocPlatformSetExitPoint();
setjmp(ExitBuf);
if (ExitBuf[40]) {
printf("Leaving PicoC\n\r");
PicocCleanup();

12
picoc.h
View file

@ -15,13 +15,23 @@
#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 */
void PicocParse(const char *FileName, const char *Source, int SourceLen, int RunIt, int CleanupNow, int CleanupSource);
void PicocParseInteractive();
/* platform.c */
void PicocCallMain(int argc, char **argv);
int PicocPlatformSetExitPoint();
void PicocInitialise(int StackSize);
void PicocCleanup();
void PicocPlatformScanFile(const char *FileName);

View file

@ -211,3 +211,26 @@ void PlatformVPrintf(const char *Format, va_list Args)
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;
}

View file

@ -9,7 +9,7 @@ struct ValueType *IntArrayType;
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, "neuron", IntArrayType, (union AnyValue *)&NNVect, FALSE);
VariableDefinePlatformVar(NULL, "blobcnt", &IntType, (union AnyValue *)&Blobcnt, FALSE);

View file

@ -9,7 +9,7 @@ void PlatformLibraryInit()
{
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, "neuron", IntArrayType, (union AnyValue *)&NNVect, FALSE);
VariableDefinePlatformVar(NULL, "xbuf", CharArrayType, (union AnyValue *)&xbuff, FALSE);

View file

@ -6,6 +6,9 @@
#include <readline/history.h>
#endif
/* mark where to end the program for platforms which require this */
jmp_buf PicocExitBuf;
void PlatformCleanup()
{
}
@ -90,19 +93,10 @@ void PicocPlatformScanFile(const char *FileName)
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 */
void PlatformExit(int RetVal)
{
PicocExitValue = RetVal;
longjmp(ExitBuf, 1);
longjmp(PicocExitBuf, 1);
}