Now avoiding structure assignment since it seems to cause problems on blackfin processors. Urk!
git-svn-id: http://picoc.googlecode.com/svn/trunk@515 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
parent
e847dc045c
commit
eb7010d292
20
expression.c
20
expression.c
|
@ -992,8 +992,11 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result)
|
|||
debugf("ExpressionParse():\n");
|
||||
do
|
||||
{
|
||||
struct ParseState PreState = *Parser;
|
||||
enum LexToken Token = LexGetToken(Parser, &LexValue, TRUE);
|
||||
struct ParseState PreState;
|
||||
enum LexToken Token;
|
||||
|
||||
ParserCopy(&PreState, Parser);
|
||||
Token = LexGetToken(Parser, &LexValue, TRUE);
|
||||
if ( ( ( (int)Token > TokenComma && (int)Token <= (int)TokenOpenBracket) ||
|
||||
(Token == TokenCloseBracket && BracketPrecedence != 0)) &&
|
||||
(Token != TokenColon || TernaryDepth > 0) )
|
||||
|
@ -1057,7 +1060,7 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result)
|
|||
if (BracketPrecedence == 0)
|
||||
{
|
||||
/* assume this bracket is after the end of the expression */
|
||||
*Parser = PreState;
|
||||
ParserCopy(Parser, &PreState);
|
||||
Done = TRUE;
|
||||
}
|
||||
else
|
||||
|
@ -1131,9 +1134,10 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result)
|
|||
if (VariableValue->Typ->Base == TypeMacro)
|
||||
{
|
||||
/* evaluate a macro as a kind of simple subroutine */
|
||||
struct ParseState MacroParser = VariableValue->Val->MacroDef.Body;
|
||||
struct ParseState MacroParser;
|
||||
struct Value *MacroResult;
|
||||
|
||||
ParserCopy(&MacroParser, &VariableValue->Val->MacroDef.Body);
|
||||
if (VariableValue->Val->MacroDef.NumParams != 0)
|
||||
ProgramFail(&MacroParser, "macro arguments missing");
|
||||
|
||||
|
@ -1173,7 +1177,7 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result)
|
|||
ProgramFail(Parser, "type not expected here");
|
||||
|
||||
PrefixState = FALSE;
|
||||
*Parser = PreState;
|
||||
ParserCopy(Parser, &PreState);
|
||||
TypeParse(Parser, &Typ, &Identifier);
|
||||
TypeValue = VariableAllocValueFromType(Parser, &TypeType, FALSE, NULL, FALSE);
|
||||
TypeValue->Val->Typ = Typ;
|
||||
|
@ -1182,7 +1186,7 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result)
|
|||
else
|
||||
{
|
||||
/* it isn't a token from an expression */
|
||||
*Parser = PreState;
|
||||
ParserCopy(Parser, &PreState);
|
||||
Done = TRUE;
|
||||
}
|
||||
|
||||
|
@ -1286,7 +1290,7 @@ void ExpressionParseMacroCall(struct ParseState *Parser, struct ExpressionStack
|
|||
if (MDef->Body.Pos == NULL)
|
||||
ProgramFail(Parser, "'%s' is undefined", MacroName);
|
||||
|
||||
memcpy((void *)&MacroParser, (void *)&MDef->Body, sizeof(struct ParseState));
|
||||
ParserCopy(&MacroParser, &MDef->Body);
|
||||
VariableStackFrameAdd(Parser, 0);
|
||||
TopStackFrame->NumParams = ArgCount;
|
||||
TopStackFrame->ReturnValue = ReturnValue;
|
||||
|
@ -1387,7 +1391,7 @@ void ExpressionParseFunctionCall(struct ParseState *Parser, struct ExpressionSta
|
|||
if (FuncValue->Val->FuncDef.Body.Pos == NULL)
|
||||
ProgramFail(Parser, "'%s' is undefined", FuncName);
|
||||
|
||||
memcpy((void *)&FuncParser, (void *)&FuncValue->Val->FuncDef.Body, sizeof(struct ParseState));
|
||||
ParserCopy(&FuncParser, &FuncValue->Val->FuncDef.Body);
|
||||
VariableStackFrameAdd(Parser, FuncValue->Val->FuncDef.Intrinsic ? FuncValue->Val->FuncDef.NumParams : 0);
|
||||
TopStackFrame->NumParams = ArgCount;
|
||||
TopStackFrame->ReturnValue = ReturnValue;
|
||||
|
|
2
lex.c
2
lex.c
|
@ -769,7 +769,7 @@ void LexHashIf(struct ParseState *Parser)
|
|||
if (SavedValue->Typ->Base != TypeMacro)
|
||||
ProgramFail(Parser, "value expected");
|
||||
|
||||
MacroParser = SavedValue->Val->MacroDef.Body;
|
||||
ParserCopy(&MacroParser, &SavedValue->Val->MacroDef.Body);
|
||||
Token = LexGetRawToken(&MacroParser, &IdentValue, TRUE);
|
||||
}
|
||||
|
||||
|
|
6
parse.c
6
parse.c
|
@ -325,6 +325,12 @@ void ParseMacroDefinition(struct ParseState *Parser)
|
|||
ProgramFail(Parser, "'%s' is already defined", MacroNameStr);
|
||||
}
|
||||
|
||||
/* copy the entire parser state */
|
||||
void ParserCopy(struct ParseState *To, struct ParseState *From)
|
||||
{
|
||||
memcpy((void *)To, (void *)From, sizeof(*To));
|
||||
}
|
||||
|
||||
/* copy where we're at in the parsing */
|
||||
void ParserCopyPos(struct ParseState *To, struct ParseState *From)
|
||||
{
|
||||
|
|
1
picoc.h
1
picoc.h
|
@ -346,6 +346,7 @@ void Parse(const char *FileName, const char *Source, int SourceLen, int RunIt, i
|
|||
void ParseInteractive();
|
||||
void ParseCleanup();
|
||||
void ParserCopyPos(struct ParseState *To, struct ParseState *From);
|
||||
void ParserCopy(struct ParseState *To, struct ParseState *From);
|
||||
|
||||
/* expression.c */
|
||||
int ExpressionParse(struct ParseState *Parser, struct Value **Result);
|
||||
|
|
14
type.c
14
type.c
|
@ -316,14 +316,16 @@ void TypeParseEnum(struct ParseState *Parser, struct ValueType **Typ)
|
|||
/* parse a type - just the basic type */
|
||||
int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ)
|
||||
{
|
||||
struct ParseState Before = *Parser;
|
||||
struct ParseState Before;
|
||||
struct Value *LexerValue;
|
||||
enum LexToken Token = LexGetToken(Parser, &LexerValue, TRUE);
|
||||
enum LexToken Token;
|
||||
int Unsigned = FALSE;
|
||||
struct Value *VarValue;
|
||||
*Typ = NULL;
|
||||
|
||||
/* ignore leading type qualifiers */
|
||||
ParserCopy(&Before, Parser);
|
||||
Token = LexGetToken(Parser, &LexerValue, TRUE);
|
||||
while (Token == TokenStaticType || Token == TokenRegisterType || Token == TokenExternType)
|
||||
Token = LexGetToken(Parser, &LexerValue, TRUE);
|
||||
|
||||
|
@ -377,7 +379,7 @@ int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ)
|
|||
*Typ = VarValue->Val->Typ;
|
||||
break;
|
||||
|
||||
default: *Parser = Before; return FALSE;
|
||||
default: ParserCopy(Parser, &Before); return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
@ -395,7 +397,7 @@ void TypeParseIdentPart(struct ParseState *Parser, struct ValueType *BasicTyp, s
|
|||
|
||||
while (!Done)
|
||||
{
|
||||
Before = *Parser;
|
||||
ParserCopy(&Before, Parser);
|
||||
Token = LexGetToken(Parser, &LexValue, TRUE);
|
||||
switch (Token)
|
||||
{
|
||||
|
@ -423,7 +425,7 @@ void TypeParseIdentPart(struct ParseState *Parser, struct ValueType *BasicTyp, s
|
|||
Done = TRUE;
|
||||
break;
|
||||
|
||||
default: *Parser = Before; Done = TRUE; break;
|
||||
default: ParserCopy(Parser, &Before); Done = TRUE; break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -459,7 +461,7 @@ void TypeParseIdentPart(struct ParseState *Parser, struct ValueType *BasicTyp, s
|
|||
break; /* XXX - finish this */
|
||||
#endif
|
||||
|
||||
default: *Parser = Before; Done = TRUE; break;
|
||||
default: ParserCopy(Parser, &Before); Done = TRUE; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -252,7 +252,7 @@ void VariableStackFrameAdd(struct ParseState *Parser, int NumParams)
|
|||
if (NewFrame == NULL)
|
||||
ProgramFail(Parser, "out of memory");
|
||||
|
||||
NewFrame->ReturnParser = *Parser;
|
||||
ParserCopy(&NewFrame->ReturnParser, Parser);
|
||||
NewFrame->Parameter = (NumParams > 0) ? ((void *)((char *)NewFrame + sizeof(struct StackFrame))) : NULL;
|
||||
TableInitTable(&NewFrame->LocalTable, &NewFrame->LocalHashTable[0], LOCAL_TABLE_SIZE, FALSE);
|
||||
NewFrame->PreviousStackFrame = TopStackFrame;
|
||||
|
@ -265,7 +265,7 @@ void VariableStackFramePop(struct ParseState *Parser)
|
|||
if (TopStackFrame == NULL)
|
||||
ProgramFail(Parser, "stack is empty - can't go back");
|
||||
|
||||
*Parser = TopStackFrame->ReturnParser;
|
||||
ParserCopy(Parser, &TopStackFrame->ReturnParser);
|
||||
TopStackFrame = TopStackFrame->PreviousStackFrame;
|
||||
HeapPopStackFrame();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue