reorder types

This commit is contained in:
Joseph Poirier 2015-06-10 13:07:58 -05:00
parent f26b78f29f
commit c063462464
7 changed files with 57 additions and 57 deletions

View file

@ -325,11 +325,11 @@ void ExpressionStackPushLValue(struct ParseState *Parser, struct ExpressionStack
void ExpressionStackPushDereference(struct ParseState *Parser, struct ExpressionStack **StackTop, struct Value *DereferenceValue) void ExpressionStackPushDereference(struct ParseState *Parser, struct ExpressionStack **StackTop, struct Value *DereferenceValue)
{ {
int Offset;
int DerefIsLValue;
struct Value *DerefVal; struct Value *DerefVal;
struct Value *ValueLoc; struct Value *ValueLoc;
int Offset;
struct ValueType *DerefType; struct ValueType *DerefType;
int DerefIsLValue;
void *DerefDataLoc = VariableDereferencePointer(Parser, DereferenceValue, &DerefVal, &Offset, &DerefType, &DerefIsLValue); void *DerefDataLoc = VariableDereferencePointer(Parser, DereferenceValue, &DerefVal, &Offset, &DerefType, &DerefIsLValue);
if (DerefDataLoc == NULL) if (DerefDataLoc == NULL)
ProgramFail(Parser, "NULL pointer dereference"); ProgramFail(Parser, "NULL pointer dereference");
@ -1018,15 +1018,15 @@ 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)
{ {
struct Value *LexValue;
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;
int IgnorePrecedence = DEEP_PRECEDENCE; int IgnorePrecedence = DEEP_PRECEDENCE;
struct ExpressionStack *StackTop = NULL;
int TernaryDepth = 0; int TernaryDepth = 0;
struct Value *LexValue;
struct ExpressionStack *StackTop = NULL;
#ifdef DEBUG_EXPRESSIONS #ifdef DEBUG_EXPRESSIONS
printf("ExpressionParse():\n"); printf("ExpressionParse():\n");
@ -1258,11 +1258,11 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result)
/* do a parameterised macro call */ /* do a parameterised macro call */
void ExpressionParseMacroCall(struct ParseState *Parser, struct ExpressionStack **StackTop, const char *MacroName, struct MacroDef *MDef) void ExpressionParseMacroCall(struct ParseState *Parser, struct ExpressionStack **StackTop, const char *MacroName, struct MacroDef *MDef)
{ {
int ArgCount;
enum LexToken Token;
struct Value *ReturnValue = NULL; struct Value *ReturnValue = NULL;
struct Value *Param; struct Value *Param;
struct Value **ParamArray = NULL; struct Value **ParamArray = NULL;
int ArgCount;
enum LexToken Token;
if (Parser->Mode == RunModeRun) { if (Parser->Mode == RunModeRun) {
/* create a stack frame for this macro */ /* create a stack frame for this macro */
@ -1333,13 +1333,13 @@ void ExpressionParseMacroCall(struct ParseState *Parser, struct ExpressionStack
/* do a function call */ /* do a function call */
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;
enum LexToken Token = LexGetToken(Parser, NULL, TRUE); /* open bracket */
enum RunMode OldMode = Parser->Mode;
struct Value *ReturnValue = NULL; struct Value *ReturnValue = NULL;
struct Value *FuncValue = NULL; struct Value *FuncValue = NULL;
struct Value *Param; struct Value *Param;
struct Value **ParamArray = NULL; struct Value **ParamArray = NULL;
int ArgCount;
enum LexToken Token = LexGetToken(Parser, NULL, TRUE); /* open bracket */
enum RunMode OldMode = Parser->Mode;
if (RunIt) { if (RunIt) {
/* get the function definition */ /* get the function definition */
@ -1446,8 +1446,8 @@ void ExpressionParseFunctionCall(struct ParseState *Parser, struct ExpressionSta
/* parse an expression */ /* parse an expression */
long ExpressionParseInt(struct ParseState *Parser) long ExpressionParseInt(struct ParseState *Parser)
{ {
struct Value *Val;
long Result = 0; long Result = 0;
struct Value *Val;
if (!ExpressionParse(Parser, &Val)) if (!ExpressionParse(Parser, &Val))
ProgramFail(Parser, "expression expected"); ProgramFail(Parser, "expression expected");

20
lex.c
View file

@ -251,8 +251,8 @@ enum LexToken LexGetWord(Picoc *pc, struct LexState *Lexer, struct Value *Value)
/* unescape a character from an octal character constant */ /* unescape a character from an octal character constant */
unsigned char LexUnEscapeCharacterConstant(const char **From, const char *End, unsigned char FirstChar, int Base) unsigned char LexUnEscapeCharacterConstant(const char **From, const char *End, unsigned char FirstChar, int Base)
{ {
unsigned char Total = GET_BASE_DIGIT(FirstChar);
int CCount; int CCount;
unsigned char Total = GET_BASE_DIGIT(FirstChar);
for (CCount = 0; IS_BASE_DIGIT(**From, Base) && CCount < 2; CCount++, (*From)++) for (CCount = 0; IS_BASE_DIGIT(**From, Base) && CCount < 2; CCount++, (*From)++)
Total = Total * Base + GET_BASE_DIGIT(**From); Total = Total * Base + GET_BASE_DIGIT(**From);
@ -489,15 +489,15 @@ int LexTokenSize(enum LexToken Token)
/* produce tokens from the lexer and return a heap buffer with the result - used for scanning */ /* produce tokens from the lexer and return a heap buffer with the result - used for scanning */
void *LexTokenise(Picoc *pc, struct LexState *Lexer, int *TokenLen) void *LexTokenise(Picoc *pc, struct LexState *Lexer, int *TokenLen)
{ {
enum LexToken Token;
void *HeapMem;
struct Value *GotValue;
int MemUsed = 0; int MemUsed = 0;
int ValueSize; int ValueSize;
int ReserveSpace = (Lexer->End - Lexer->Pos) * 4 + 16;
void *TokenSpace = HeapAllocStack(pc, ReserveSpace);
char *TokenPos = (char *)TokenSpace;
int LastCharacterPos = 0; int LastCharacterPos = 0;
int ReserveSpace = (Lexer->End - Lexer->Pos) * 4 + 16;
void *HeapMem;
void *TokenSpace = HeapAllocStack(pc, ReserveSpace);
enum LexToken Token;
struct Value *GotValue;
char *TokenPos = (char*)TokenSpace;
if (TokenSpace == NULL) if (TokenSpace == NULL)
LexFail(pc, Lexer, "(LexTokenise TokenSpace == NULL) out of memory"); LexFail(pc, Lexer, "(LexTokenise TokenSpace == NULL) out of memory");
@ -587,9 +587,9 @@ void LexInitParser(struct ParseState *Parser, Picoc *pc, const char *SourceText,
/* get the next token, without pre-processing */ /* get the next token, without pre-processing */
enum LexToken LexGetRawToken(struct ParseState *Parser, struct Value **Value, int IncPos) enum LexToken LexGetRawToken(struct ParseState *Parser, struct Value **Value, int IncPos)
{ {
enum LexToken Token = TokenNone;
int ValueSize; int ValueSize;
char *Prompt = NULL; char *Prompt = NULL;
enum LexToken Token = TokenNone;
Picoc *pc = Parser->pc; Picoc *pc = Parser->pc;
do { do {
@ -707,9 +707,9 @@ void LexHashIncPos(struct ParseState *Parser, int IncPos)
void LexHashIfdef(struct ParseState *Parser, int IfNot) void LexHashIfdef(struct ParseState *Parser, int IfNot)
{ {
/* get symbol to check */ /* get symbol to check */
int IsDefined;
struct Value *IdentValue; struct Value *IdentValue;
struct Value *SavedValue; struct Value *SavedValue;
int IsDefined;
enum LexToken Token = LexGetRawToken(Parser, &IdentValue, TRUE); enum LexToken Token = LexGetRawToken(Parser, &IdentValue, TRUE);
if (Token != TokenIdentifier) if (Token != TokenIdentifier)
@ -823,8 +823,8 @@ void LexPrintToken(enum LexToken Token)
/* get the next token given a parser state, pre-processing as we go */ /* get the next token given a parser state, pre-processing as we go */
enum LexToken LexGetToken(struct ParseState *Parser, struct Value **Value, int IncPos) enum LexToken LexGetToken(struct ParseState *Parser, struct Value **Value, int IncPos)
{ {
enum LexToken Token;
int TryNextToken; int TryNextToken;
enum LexToken Token;
/* implements the pre-processor #if commands */ /* implements the pre-processor #if commands */
do { do {

24
parse.c
View file

@ -60,14 +60,14 @@ int ParseCountParams(struct ParseState *Parser)
/* parse a function definition and store it for later */ /* parse a function definition and store it for later */
struct Value *ParseFunctionDefinition(struct ParseState *Parser, struct ValueType *ReturnType, char *Identifier) struct Value *ParseFunctionDefinition(struct ParseState *Parser, struct ValueType *ReturnType, char *Identifier)
{ {
struct ValueType *ParamType; int ParamCount = 0;
char *ParamIdentifier; char *ParamIdentifier;
enum LexToken Token = TokenNone; enum LexToken Token = TokenNone;
struct ValueType *ParamType;
struct ParseState ParamParser; struct ParseState ParamParser;
struct Value *FuncValue; struct Value *FuncValue;
struct Value *OldFuncValue; struct Value *OldFuncValue;
struct ParseState FuncBody; struct ParseState FuncBody;
int ParamCount = 0;
Picoc *pc = Parser->pc; Picoc *pc = Parser->pc;
if (pc->TopStackFrame != NULL) if (pc->TopStackFrame != NULL)
@ -287,12 +287,12 @@ 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 FirstVisit = FALSE;
char *Identifier; char *Identifier;
struct ValueType *BasicType; struct ValueType *BasicType;
struct ValueType *Typ; struct ValueType *Typ;
struct Value *NewVariable = NULL; struct Value *NewVariable = NULL;
int IsStatic = FALSE;
int FirstVisit = FALSE;
Picoc *pc = Parser->pc; Picoc *pc = Parser->pc;
TypeParseFront(Parser, &BasicType, &IsStatic); TypeParseFront(Parser, &BasicType, &IsStatic);
@ -334,8 +334,8 @@ int ParseDeclaration(struct ParseState *Parser, enum LexToken Token)
/* parse a #define macro definition and store it for later */ /* parse a #define macro definition and store it for later */
void ParseMacroDefinition(struct ParseState *Parser) void ParseMacroDefinition(struct ParseState *Parser)
{ {
struct Value *MacroName;
char *MacroNameStr; char *MacroNameStr;
struct Value *MacroName;
struct Value *ParamName; struct Value *ParamName;
struct Value *MacroValue; struct Value *MacroValue;
@ -510,9 +510,9 @@ enum RunMode ParseBlock(struct ParseState *Parser, int AbsorbOpenBrace, int Cond
/* parse a typedef declaration */ /* parse a typedef declaration */
void ParseTypedef(struct ParseState *Parser) void ParseTypedef(struct ParseState *Parser)
{ {
char *TypeName;
struct ValueType *Typ; struct ValueType *Typ;
struct ValueType **TypPtr; struct ValueType **TypPtr;
char *TypeName;
struct Value InitValue; struct Value InitValue;
TypeParse(Parser, &Typ, &TypeName, NULL); TypeParse(Parser, &Typ, &TypeName, NULL);
@ -528,12 +528,12 @@ void ParseTypedef(struct ParseState *Parser)
/* parse a statement */ /* parse a statement */
enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemicolon) enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemicolon)
{ {
int Condition;
enum LexToken Token;
struct Value *CValue; struct Value *CValue;
struct Value *LexerValue; struct Value *LexerValue;
struct Value *VarValue; struct Value *VarValue;
int Condition;
struct ParseState PreState; struct ParseState PreState;
enum LexToken Token;
/* if we're debugging, check for a breakpoint */ /* if we're debugging, check for a breakpoint */
if (Parser->DebugMode && Parser->Mode == RunModeRun) if (Parser->DebugMode && Parser->Mode == RunModeRun)
@ -816,10 +816,10 @@ enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemi
/* quick scan a source file for definitions */ /* quick scan a source file for definitions */
void PicocParse(Picoc *pc, const char *FileName, const char *Source, int SourceLen, int RunIt, int CleanupNow, int CleanupSource, int EnableDebugger) void PicocParse(Picoc *pc, const char *FileName, const char *Source, int SourceLen, int RunIt, int CleanupNow, int CleanupSource, int EnableDebugger)
{ {
struct ParseState Parser;
enum ParseResult Ok;
struct CleanupTokenNode *NewCleanupNode;
char *RegFileName = TableStrRegister(pc, FileName); char *RegFileName = TableStrRegister(pc, FileName);
enum ParseResult Ok;
struct ParseState Parser;
struct CleanupTokenNode *NewCleanupNode;
void *Tokens = LexAnalyse(pc, RegFileName, Source, SourceLen, NULL); void *Tokens = LexAnalyse(pc, RegFileName, Source, SourceLen, NULL);
@ -857,8 +857,8 @@ void PicocParse(Picoc *pc, const char *FileName, const char *Source, int SourceL
/* parse interactively */ /* parse interactively */
void PicocParseInteractiveNoStartPrompt(Picoc *pc, int EnableDebugger) void PicocParseInteractiveNoStartPrompt(Picoc *pc, int EnableDebugger)
{ {
struct ParseState Parser;
enum ParseResult Ok; enum ParseResult Ok;
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);

View file

@ -91,9 +91,9 @@ void PicocCallMain(Picoc *pc, int argc, char **argv)
void PrintSourceTextErrorLine(IOFILE *Stream, const char *FileName, const char *SourceText, int Line, int CharacterPos) void PrintSourceTextErrorLine(IOFILE *Stream, const char *FileName, const char *SourceText, int Line, int CharacterPos)
{ {
int LineCount; int LineCount;
int CCount;
const char *LinePos; const char *LinePos;
const char *CPos; const char *CPos;
int CCount;
if (SourceText != NULL) { if (SourceText != NULL) {
/* find the source line */ /* find the source line */

View file

@ -39,8 +39,9 @@ void TableInitTable(struct Table *Tbl, struct TableEntry **HashTable, int Size,
/* check a hash table entry for a key */ /* check a hash table entry for a key */
static struct TableEntry *TableSearch(struct Table *Tbl, const char *Key, int *AddAt) static struct TableEntry *TableSearch(struct Table *Tbl, const char *Key, int *AddAt)
{ {
struct TableEntry *Entry;
int HashValue = ((unsigned long)Key) % Tbl->Size; /* shared strings have unique addresses so we don't need to hash them */ int HashValue = ((unsigned long)Key) % Tbl->Size; /* shared strings have unique addresses so we don't need to hash them */
struct TableEntry *Entry;
for (Entry = Tbl->HashTable[HashValue]; Entry != NULL; Entry = Entry->Next) { for (Entry = Tbl->HashTable[HashValue]; Entry != NULL; Entry = Entry->Next) {
if (Entry->p.v.Key == Key) if (Entry->p.v.Key == Key)
return Entry; /* found */ return Entry; /* found */
@ -95,8 +96,8 @@ int TableGet(struct Table *Tbl, const char *Key, struct Value **Val, const char
/* remove an entry from the table */ /* remove an entry from the table */
struct Value *TableDelete(Picoc *pc, struct Table *Tbl, const char *Key) struct Value *TableDelete(Picoc *pc, struct Table *Tbl, const char *Key)
{ {
struct TableEntry **EntryPtr;
int HashValue = ((unsigned long)Key) % Tbl->Size; /* shared strings have unique addresses so we don't need to hash them */ int HashValue = ((unsigned long)Key) % Tbl->Size; /* shared strings have unique addresses so we don't need to hash them */
struct TableEntry **EntryPtr;
for (EntryPtr = &Tbl->HashTable[HashValue]; *EntryPtr != NULL; EntryPtr = &(*EntryPtr)->Next) { for (EntryPtr = &Tbl->HashTable[HashValue]; *EntryPtr != NULL; EntryPtr = &(*EntryPtr)->Next) {
if ((*EntryPtr)->p.v.Key == Key) { if ((*EntryPtr)->p.v.Key == Key) {
@ -115,8 +116,8 @@ struct Value *TableDelete(Picoc *pc, struct Table *Tbl, const char *Key)
/* check a hash table entry for an identifier */ /* check a hash table entry for an identifier */
static struct TableEntry *TableSearchIdentifier(struct Table *Tbl, const char *Key, int Len, int *AddAt) static struct TableEntry *TableSearchIdentifier(struct Table *Tbl, const char *Key, int Len, int *AddAt)
{ {
struct TableEntry *Entry;
int HashValue = TableHash(Key, Len) % Tbl->Size; int HashValue = TableHash(Key, Len) % Tbl->Size;
struct TableEntry *Entry;
for (Entry = Tbl->HashTable[HashValue]; Entry != NULL; Entry = Entry->Next) { for (Entry = Tbl->HashTable[HashValue]; Entry != NULL; Entry = Entry->Next) {
if (strncmp(&Entry->p.Key[0], (char *)Key, Len) == 0 && Entry->p.Key[Len] == '\0') if (strncmp(&Entry->p.Key[0], (char *)Key, Len) == 0 && Entry->p.Key[Len] == '\0')
@ -162,9 +163,9 @@ char *TableStrRegister(Picoc *pc, const char *Str)
/* free all the strings */ /* free all the strings */
void TableStrFree(Picoc *pc) void TableStrFree(Picoc *pc)
{ {
int Count;
struct TableEntry *Entry; struct TableEntry *Entry;
struct TableEntry *NextEntry; struct TableEntry *NextEntry;
int Count;
for (Count = 0; Count < pc->StringTable.Size; Count++) { for (Count = 0; Count < pc->StringTable.Size; Count++) {
for (Entry = pc->StringTable.HashTable[Count]; Entry != NULL; Entry = NextEntry) { for (Entry = pc->StringTable.HashTable[Count]; Entry != NULL; Entry = NextEntry) {

22
type.c
View file

@ -172,14 +172,14 @@ void TypeCleanup(Picoc *pc)
/* parse a struct or union declaration */ /* parse a struct or union declaration */
void TypeParseStruct(struct ParseState *Parser, struct ValueType **Typ, int IsStruct) void TypeParseStruct(struct ParseState *Parser, struct ValueType **Typ, int IsStruct)
{ {
struct Value *LexValue;
struct ValueType *MemberType;
char *MemberIdentifier; char *MemberIdentifier;
char *StructIdentifier; char *StructIdentifier;
struct Value *MemberValue;
enum LexToken Token; enum LexToken Token;
int AlignBoundary; int AlignBoundary;
struct Value *MemberValue;
Picoc *pc = Parser->pc; Picoc *pc = Parser->pc;
struct Value *LexValue;
struct ValueType *MemberType;
Token = LexGetToken(Parser, &LexValue, FALSE); Token = LexGetToken(Parser, &LexValue, FALSE);
if (Token == TokenIdentifier) { if (Token == TokenIdentifier) {
@ -273,11 +273,11 @@ struct ValueType *TypeCreateOpaqueStruct(Picoc *pc, struct ParseState *Parser, c
/* parse an enum declaration */ /* parse an enum declaration */
void TypeParseEnum(struct ParseState *Parser, struct ValueType **Typ) void TypeParseEnum(struct ParseState *Parser, struct ValueType **Typ)
{ {
struct Value *LexValue;
struct Value InitValue;
enum LexToken Token;
int EnumValue = 0; int EnumValue = 0;
char *EnumIdentifier; char *EnumIdentifier;
enum LexToken Token;
struct Value *LexValue;
struct Value InitValue;
Picoc *pc = Parser->pc; Picoc *pc = Parser->pc;
Token = LexGetToken(Parser, &LexValue, FALSE); Token = LexGetToken(Parser, &LexValue, FALSE);
@ -331,12 +331,12 @@ 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 StaticQualifier = FALSE;
enum LexToken Token;
struct ParseState Before; struct ParseState Before;
struct Value *LexerValue; struct Value *LexerValue;
enum LexToken Token;
int Unsigned = FALSE;
struct Value *VarValue; struct Value *VarValue;
int StaticQualifier = FALSE;
Picoc *pc = Parser->pc; Picoc *pc = Parser->pc;
*Typ = NULL; *Typ = NULL;
@ -442,10 +442,10 @@ 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)
{ {
struct ParseState Before; int Done = FALSE;
enum LexToken Token; enum LexToken Token;
struct Value *LexValue; struct Value *LexValue;
int Done = FALSE; struct ParseState Before;
*Typ = BasicTyp; *Typ = BasicTyp;
*Identifier = Parser->pc->StrEmpty; *Identifier = Parser->pc->StrEmpty;

View file

@ -40,9 +40,9 @@ void VariableFree(Picoc *pc, struct Value *Val)
/* deallocate the global table and the string literal table */ /* deallocate the global table and the string literal table */
void VariableTableCleanup(Picoc *pc, struct Table *HashTable) void VariableTableCleanup(Picoc *pc, struct Table *HashTable)
{ {
int Count;
struct TableEntry *Entry; struct TableEntry *Entry;
struct TableEntry *NextEntry; struct TableEntry *NextEntry;
int Count;
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) {
@ -114,10 +114,10 @@ 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);
char TmpBuf[MAX_TMP_COPY_BUF];
struct ValueType *DType = FromValue->Typ; struct ValueType *DType = FromValue->Typ;
struct Value *NewValue; struct Value *NewValue;
char TmpBuf[MAX_TMP_COPY_BUF];
int CopySize = TypeSizeValue(FromValue, TRUE);
assert(CopySize <= MAX_TMP_COPY_BUF); assert(CopySize <= MAX_TMP_COPY_BUF);
memcpy((void*)&TmpBuf[0], (void*)FromValue->Val, CopySize); memcpy((void*)&TmpBuf[0], (void*)FromValue->Val, CopySize);
@ -202,7 +202,6 @@ void VariableScopeEnd(struct ParseState *Parser, int ScopeID, int PrevScopeID)
int Count; int Count;
struct TableEntry *Entry; struct TableEntry *Entry;
struct TableEntry *NextEntry = NULL; struct TableEntry *NextEntry = NULL;
#ifdef VAR_SCOPE_DEBUG #ifdef VAR_SCOPE_DEBUG
int FirstPrint = 0; int FirstPrint = 0;
#endif #endif
@ -232,8 +231,8 @@ void VariableScopeEnd(struct ParseState *Parser, int ScopeID, int PrevScopeID)
int VariableDefinedAndOutOfScope(Picoc * pc, const char* Ident) int VariableDefinedAndOutOfScope(Picoc * pc, const char* Ident)
{ {
struct TableEntry *Entry;
int Count; int Count;
struct TableEntry *Entry;
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++) {
@ -248,10 +247,10 @@ int VariableDefinedAndOutOfScope(Picoc * pc, const char* Ident)
/* define a variable. Ident must be registered */ /* define a variable. Ident must be registered */
struct Value *VariableDefine(Picoc *pc, struct ParseState *Parser, char *Ident, struct Value *InitValue, struct ValueType *Typ, int MakeWritable) struct Value *VariableDefine(Picoc *pc, struct ParseState *Parser, char *Ident, struct Value *InitValue, struct ValueType *Typ, int MakeWritable)
{ {
int ScopeID = Parser ? Parser->ScopeID : -1;
struct Value * AssignValue; struct Value * AssignValue;
struct Table * currentTable = (pc->TopStackFrame == NULL) ? &(pc->GlobalTable) : &(pc->TopStackFrame)->LocalTable; struct Table * currentTable = (pc->TopStackFrame == NULL) ? &(pc->GlobalTable) : &(pc->TopStackFrame)->LocalTable;
int ScopeID = Parser ? Parser->ScopeID : -1;
#ifdef VAR_SCOPE_DEBUG #ifdef VAR_SCOPE_DEBUG
if (Parser) fprintf(stderr, "def %s %x (%s:%d:%d)\n", Ident, ScopeID, Parser->FileName, Parser->Line, Parser->CharacterPos); if (Parser) fprintf(stderr, "def %s %x (%s:%d:%d)\n", Ident, ScopeID, Parser->FileName, Parser->Line, Parser->CharacterPos);
#endif #endif
@ -274,11 +273,11 @@ struct Value *VariableDefine(Picoc *pc, struct ParseState *Parser, char *Ident,
/* define a variable. Ident must be registered. If it's a redefinition from the same declaration don't throw an error */ /* define a variable. Ident must be registered. If it's a redefinition from the same declaration don't throw an error */
struct Value *VariableDefineButIgnoreIdentical(struct ParseState *Parser, char *Ident, struct ValueType *Typ, int IsStatic, int *FirstVisit) struct Value *VariableDefineButIgnoreIdentical(struct ParseState *Parser, char *Ident, struct ValueType *Typ, int IsStatic, int *FirstVisit)
{ {
Picoc *pc = Parser->pc;
struct Value *ExistingValue;
const char *DeclFileName;
int DeclLine; int DeclLine;
int DeclColumn; int DeclColumn;
const char *DeclFileName;
Picoc *pc = Parser->pc;
struct Value *ExistingValue;
/* is the type a forward declaration? */ /* is the type a forward declaration? */
if (TypeIsForwardDeclared(Parser, Typ)) if (TypeIsForwardDeclared(Parser, Typ))