Removed annoying CRs

git-svn-id: http://picoc.googlecode.com/svn/trunk@555 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2011-02-18 03:45:08 +00:00
parent 72b7c7de0b
commit fc164556fb

View file

@ -1,495 +1,495 @@
#ifndef INTERPRETER_H #ifndef INTERPRETER_H
#define INTERPRETER_H #define INTERPRETER_H
#include "platform.h" #include "platform.h"
/* handy definitions */ /* handy definitions */
#ifndef TRUE #ifndef TRUE
#define TRUE 1 #define TRUE 1
#define FALSE 0 #define FALSE 0
#endif #endif
#ifndef NULL #ifndef NULL
#define NULL 0 #define NULL 0
#endif #endif
#ifndef min #ifndef min
#define min(x,y) (((x)<(y))?(x):(y)) #define min(x,y) (((x)<(y))?(x):(y))
#endif #endif
#define MEM_ALIGN(x) (((x) + sizeof(ALIGN_TYPE) - 1) & ~(sizeof(ALIGN_TYPE)-1)) #define MEM_ALIGN(x) (((x) + sizeof(ALIGN_TYPE) - 1) & ~(sizeof(ALIGN_TYPE)-1))
#define GETS_BUF_MAX 256 #define GETS_BUF_MAX 256
/* small processors use a simplified FILE * for stdio, otherwise use the system FILE * */ /* small processors use a simplified FILE * for stdio, otherwise use the system FILE * */
#ifdef BUILTIN_MINI_STDLIB #ifdef BUILTIN_MINI_STDLIB
typedef struct OutputStream IOFILE; typedef struct OutputStream IOFILE;
#else #else
typedef FILE IOFILE; typedef FILE IOFILE;
#endif #endif
/* coercion of numeric types to other numeric types */ /* coercion of numeric types to other numeric types */
#ifndef NO_FP #ifndef NO_FP
#define IS_FP(v) ((v)->Typ->Base == TypeFP) #define IS_FP(v) ((v)->Typ->Base == TypeFP)
#define FP_VAL(v) ((v)->Val->FP) #define FP_VAL(v) ((v)->Val->FP)
#else #else
#define IS_FP(v) 0 #define IS_FP(v) 0
#define FP_VAL(v) 0 #define FP_VAL(v) 0
#endif #endif
#define IS_POINTER_COERCIBLE(v, ap) ((ap) ? ((v)->Typ->Base == TypePointer) : 0) #define IS_POINTER_COERCIBLE(v, ap) ((ap) ? ((v)->Typ->Base == TypePointer) : 0)
#define POINTER_COERCE(v) ((int)(v)->Val->Pointer) #define POINTER_COERCE(v) ((int)(v)->Val->Pointer)
#define IS_INTEGER_NUMERIC_TYPE(t) ((t)->Base >= TypeInt && (t)->Base <= TypeUnsignedLong) #define IS_INTEGER_NUMERIC_TYPE(t) ((t)->Base >= TypeInt && (t)->Base <= TypeUnsignedLong)
#define IS_INTEGER_NUMERIC(v) IS_INTEGER_NUMERIC_TYPE((v)->Typ) #define IS_INTEGER_NUMERIC(v) IS_INTEGER_NUMERIC_TYPE((v)->Typ)
#define IS_NUMERIC_COERCIBLE(v) (IS_INTEGER_NUMERIC(v) || IS_FP(v)) #define IS_NUMERIC_COERCIBLE(v) (IS_INTEGER_NUMERIC(v) || IS_FP(v))
#define IS_NUMERIC_COERCIBLE_PLUS_POINTERS(v,ap) (IS_NUMERIC_COERCIBLE(v) || IS_POINTER_COERCIBLE(v,ap)) #define IS_NUMERIC_COERCIBLE_PLUS_POINTERS(v,ap) (IS_NUMERIC_COERCIBLE(v) || IS_POINTER_COERCIBLE(v,ap))
struct Table; struct Table;
/* lexical tokens */ /* lexical tokens */
enum LexToken enum LexToken
{ {
/* 0x00 */ TokenNone, /* 0x00 */ TokenNone,
/* 0x01 */ TokenComma, /* 0x01 */ TokenComma,
/* 0x02 */ TokenAssign, TokenAddAssign, TokenSubtractAssign, TokenMultiplyAssign, TokenDivideAssign, TokenModulusAssign, /* 0x02 */ TokenAssign, TokenAddAssign, TokenSubtractAssign, TokenMultiplyAssign, TokenDivideAssign, TokenModulusAssign,
/* 0x08 */ TokenShiftLeftAssign, TokenShiftRightAssign, TokenArithmeticAndAssign, TokenArithmeticOrAssign, TokenArithmeticExorAssign, /* 0x08 */ TokenShiftLeftAssign, TokenShiftRightAssign, TokenArithmeticAndAssign, TokenArithmeticOrAssign, TokenArithmeticExorAssign,
/* 0x0d */ TokenQuestionMark, TokenColon, /* 0x0d */ TokenQuestionMark, TokenColon,
/* 0x0f */ TokenLogicalOr, /* 0x0f */ TokenLogicalOr,
/* 0x10 */ TokenLogicalAnd, /* 0x10 */ TokenLogicalAnd,
/* 0x11 */ TokenArithmeticOr, /* 0x11 */ TokenArithmeticOr,
/* 0x12 */ TokenArithmeticExor, /* 0x12 */ TokenArithmeticExor,
/* 0x13 */ TokenAmpersand, /* 0x13 */ TokenAmpersand,
/* 0x14 */ TokenEqual, TokenNotEqual, /* 0x14 */ TokenEqual, TokenNotEqual,
/* 0x16 */ TokenLessThan, TokenGreaterThan, TokenLessEqual, TokenGreaterEqual, /* 0x16 */ TokenLessThan, TokenGreaterThan, TokenLessEqual, TokenGreaterEqual,
/* 0x1a */ TokenShiftLeft, TokenShiftRight, /* 0x1a */ TokenShiftLeft, TokenShiftRight,
/* 0x1c */ TokenPlus, TokenMinus, /* 0x1c */ TokenPlus, TokenMinus,
/* 0x1e */ TokenAsterisk, TokenSlash, TokenModulus, /* 0x1e */ TokenAsterisk, TokenSlash, TokenModulus,
/* 0x21 */ TokenIncrement, TokenDecrement, TokenUnaryNot, TokenUnaryExor, TokenSizeof, TokenCast, /* 0x21 */ TokenIncrement, TokenDecrement, TokenUnaryNot, TokenUnaryExor, TokenSizeof, TokenCast,
/* 0x27 */ TokenLeftSquareBracket, TokenRightSquareBracket, TokenDot, TokenArrow, /* 0x27 */ TokenLeftSquareBracket, TokenRightSquareBracket, TokenDot, TokenArrow,
/* 0x2b */ TokenOpenBracket, TokenCloseBracket, /* 0x2b */ TokenOpenBracket, TokenCloseBracket,
/* 0x2d */ TokenIdentifier, TokenIntegerConstant, TokenFPConstant, TokenStringConstant, TokenCharacterConstant, /* 0x2d */ TokenIdentifier, TokenIntegerConstant, TokenFPConstant, TokenStringConstant, TokenCharacterConstant,
/* 0x32 */ TokenSemicolon, TokenEllipsis, /* 0x32 */ TokenSemicolon, TokenEllipsis,
/* 0x34 */ TokenLeftBrace, TokenRightBrace, /* 0x34 */ TokenLeftBrace, TokenRightBrace,
/* 0x36 */ TokenIntType, TokenCharType, TokenFloatType, TokenDoubleType, TokenVoidType, TokenEnumType, /* 0x36 */ TokenIntType, TokenCharType, TokenFloatType, TokenDoubleType, TokenVoidType, TokenEnumType,
/* 0x3c */ TokenLongType, TokenSignedType, TokenShortType, TokenStaticType, TokenAutoType, TokenRegisterType, TokenExternType, TokenStructType, TokenUnionType, TokenUnsignedType, TokenTypedef, /* 0x3c */ TokenLongType, TokenSignedType, TokenShortType, TokenStaticType, TokenAutoType, TokenRegisterType, TokenExternType, TokenStructType, TokenUnionType, TokenUnsignedType, TokenTypedef,
/* 0x46 */ TokenContinue, TokenDo, TokenElse, TokenFor, TokenIf, TokenWhile, TokenBreak, TokenSwitch, TokenCase, TokenDefault, TokenReturn, /* 0x46 */ TokenContinue, TokenDo, TokenElse, TokenFor, TokenIf, TokenWhile, TokenBreak, TokenSwitch, TokenCase, TokenDefault, TokenReturn,
/* 0x51 */ TokenHashDefine, TokenHashInclude, TokenHashIf, TokenHashIfdef, TokenHashIfndef, TokenHashElse, TokenHashEndif, /* 0x51 */ TokenHashDefine, TokenHashInclude, TokenHashIf, TokenHashIfdef, TokenHashIfndef, TokenHashElse, TokenHashEndif,
/* 0x58 */ TokenNew, TokenDelete, /* 0x58 */ TokenNew, TokenDelete,
/* 0x5a */ TokenOpenMacroBracket, /* 0x5a */ TokenOpenMacroBracket,
/* 0x5b */ TokenEOF, TokenEndOfLine, TokenEndOfFunction /* 0x5b */ TokenEOF, TokenEndOfLine, TokenEndOfFunction
}; };
/* used in dynamic memory allocation */ /* used in dynamic memory allocation */
struct AllocNode struct AllocNode
{ {
unsigned int Size; unsigned int Size;
struct AllocNode *NextFree; struct AllocNode *NextFree;
}; };
/* whether we're running or skipping code */ /* whether we're running or skipping code */
enum RunMode enum RunMode
{ {
RunModeRun, /* we're running code as we parse it */ RunModeRun, /* we're running code as we parse it */
RunModeSkip, /* skipping code, not running */ RunModeSkip, /* skipping code, not running */
RunModeReturn, /* returning from a function */ RunModeReturn, /* returning from a function */
RunModeCaseSearch, /* searching for a case label */ RunModeCaseSearch, /* searching for a case label */
RunModeBreak, /* breaking out of a switch/while/do */ RunModeBreak, /* breaking out of a switch/while/do */
RunModeContinue /* as above but repeat the loop */ RunModeContinue /* as above but repeat the loop */
}; };
/* parser state - has all this detail so we can parse nested files */ /* parser state - has all this detail so we can parse nested files */
struct ParseState struct ParseState
{ {
const unsigned char *Pos; const unsigned char *Pos;
const char *FileName; const char *FileName;
short int Line; short int Line;
short int CharacterPos; short int CharacterPos;
enum RunMode Mode; /* whether to skip or run code */ enum RunMode Mode; /* whether to skip or run code */
int SearchLabel; /* what case label we're searching for */ int SearchLabel; /* what case label we're searching for */
short int HashIfLevel; short int HashIfLevel;
short int HashIfEvaluateToLevel; short int HashIfEvaluateToLevel;
const char *SourceText; const char *SourceText;
}; };
/* values */ /* values */
enum BaseType enum BaseType
{ {
TypeVoid, /* no type */ TypeVoid, /* no type */
TypeInt, /* integer */ TypeInt, /* integer */
TypeShort, /* short integer */ TypeShort, /* short integer */
TypeChar, /* a single character (unsigned) */ TypeChar, /* a single character (unsigned) */
TypeLong, /* long integer */ TypeLong, /* long integer */
TypeUnsignedInt, /* unsigned integer */ TypeUnsignedInt, /* unsigned integer */
TypeUnsignedShort, /* unsigned short integer */ TypeUnsignedShort, /* unsigned short integer */
TypeUnsignedLong, /* unsigned long integer */ TypeUnsignedLong, /* unsigned long integer */
#ifndef NO_FP #ifndef NO_FP
TypeFP, /* floating point */ TypeFP, /* floating point */
#endif #endif
TypeFunction, /* a function */ TypeFunction, /* a function */
TypeMacro, /* a macro */ TypeMacro, /* a macro */
TypePointer, /* a pointer */ TypePointer, /* a pointer */
TypeArray, /* an array of a sub-type */ TypeArray, /* an array of a sub-type */
TypeStruct, /* aggregate type */ TypeStruct, /* aggregate type */
TypeUnion, /* merged type */ TypeUnion, /* merged type */
TypeEnum, /* enumerated integer type */ TypeEnum, /* enumerated integer type */
Type_Type /* a type for storing types */ Type_Type /* a type for storing types */
}; };
/* data type */ /* data type */
struct ValueType struct ValueType
{ {
enum BaseType Base; /* what kind of type this is */ enum BaseType Base; /* what kind of type this is */
int ArraySize; /* the size of an array type */ int ArraySize; /* the size of an array type */
int Sizeof; /* the storage required */ int Sizeof; /* the storage required */
int AlignBytes; /* the alignment boundary of this type */ int AlignBytes; /* the alignment boundary of this type */
const char *Identifier; /* the name of a struct or union */ const char *Identifier; /* the name of a struct or union */
struct ValueType *FromType; /* the type we're derived from (or NULL) */ struct ValueType *FromType; /* the type we're derived from (or NULL) */
struct ValueType *DerivedTypeList; /* first in a list of types derived from this one */ struct ValueType *DerivedTypeList; /* first in a list of types derived from this one */
struct ValueType *Next; /* next item in the derived type list */ struct ValueType *Next; /* next item in the derived type list */
struct Table *Members; /* members of a struct or union */ struct Table *Members; /* members of a struct or union */
int OnHeap; /* true if allocated on the heap */ int OnHeap; /* true if allocated on the heap */
int StaticQualifier; /* true if it's a static */ int StaticQualifier; /* true if it's a static */
}; };
/* function definition */ /* function definition */
struct FuncDef struct FuncDef
{ {
struct ValueType *ReturnType; /* the return value type */ struct ValueType *ReturnType; /* the return value type */
int NumParams; /* the number of parameters */ int NumParams; /* the number of parameters */
int VarArgs; /* has a variable number of arguments after the explicitly specified ones */ int VarArgs; /* has a variable number of arguments after the explicitly specified ones */
struct ValueType **ParamType; /* array of parameter types */ struct ValueType **ParamType; /* array of parameter types */
char **ParamName; /* array of parameter names */ char **ParamName; /* array of parameter names */
void (*Intrinsic)(); /* intrinsic call address or NULL */ void (*Intrinsic)(); /* intrinsic call address or NULL */
struct ParseState Body; /* lexical tokens of the function body if not intrinsic */ struct ParseState Body; /* lexical tokens of the function body if not intrinsic */
}; };
/* macro definition */ /* macro definition */
struct MacroDef struct MacroDef
{ {
int NumParams; /* the number of parameters */ int NumParams; /* the number of parameters */
char **ParamName; /* array of parameter names */ char **ParamName; /* array of parameter names */
struct ParseState Body; /* lexical tokens of the function body if not intrinsic */ struct ParseState Body; /* lexical tokens of the function body if not intrinsic */
}; };
/* values */ /* values */
union AnyValue union AnyValue
{ {
unsigned char Character; unsigned char Character;
short ShortInteger; short ShortInteger;
int Integer; int Integer;
long LongInteger; long LongInteger;
unsigned short UnsignedShortInteger; unsigned short UnsignedShortInteger;
unsigned int UnsignedInteger; unsigned int UnsignedInteger;
unsigned long UnsignedLongInteger; unsigned long UnsignedLongInteger;
char *Identifier; char *Identifier;
char ArrayMem[2]; /* placeholder for where the data starts, doesn't point to it */ char ArrayMem[2]; /* placeholder for where the data starts, doesn't point to it */
struct ValueType *Typ; struct ValueType *Typ;
struct FuncDef FuncDef; struct FuncDef FuncDef;
struct MacroDef MacroDef; struct MacroDef MacroDef;
#ifndef NO_FP #ifndef NO_FP
double FP; double FP;
#endif #endif
void *Pointer; /* unsafe native pointers */ void *Pointer; /* unsafe native pointers */
}; };
struct Value struct Value
{ {
struct ValueType *Typ; /* the type of this value */ struct ValueType *Typ; /* the type of this value */
union AnyValue *Val; /* pointer to the AnyValue which holds the actual content */ union AnyValue *Val; /* pointer to the AnyValue which holds the actual content */
struct Value *LValueFrom; /* if an LValue, this is a Value our LValue is contained within (or NULL) */ struct Value *LValueFrom; /* if an LValue, this is a Value our LValue is contained within (or NULL) */
char ValOnHeap; /* the AnyValue is on the heap (but this Value is on the stack) */ char ValOnHeap; /* the AnyValue is on the heap (but this Value is on the stack) */
char ValOnStack; /* the AnyValue is on the stack along with this Value */ char ValOnStack; /* the AnyValue is on the stack along with this Value */
char IsLValue; /* is modifiable and is allocated somewhere we can usefully modify it */ char IsLValue; /* is modifiable and is allocated somewhere we can usefully modify it */
}; };
/* hash table data structure */ /* hash table data structure */
struct TableEntry struct TableEntry
{ {
struct TableEntry *Next; /* next item in this hash chain */ struct TableEntry *Next; /* next item in this hash chain */
const char *DeclFileName; /* where the variable was declared */ const char *DeclFileName; /* where the variable was declared */
unsigned short DeclLine; unsigned short DeclLine;
unsigned short DeclColumn; unsigned short DeclColumn;
union TableEntryPayload union TableEntryPayload
{ {
struct ValueEntry struct ValueEntry
{ {
char *Key; /* points to the shared string table */ char *Key; /* points to the shared string table */
struct Value *Val; /* the value we're storing */ struct Value *Val; /* the value we're storing */
} v; /* used for tables of values */ } v; /* used for tables of values */
char Key[1]; /* dummy size - used for the shared string table */ char Key[1]; /* dummy size - used for the shared string table */
} p; } p;
}; };
struct Table struct Table
{ {
short Size; short Size;
short OnHeap; short OnHeap;
struct TableEntry **HashTable; struct TableEntry **HashTable;
}; };
/* stack frame for function calls */ /* stack frame for function calls */
struct StackFrame struct StackFrame
{ {
struct ParseState ReturnParser; /* how we got here */ struct ParseState ReturnParser; /* how we got here */
const char *FuncName; /* the name of the function we're in */ const char *FuncName; /* the name of the function we're in */
struct Value *ReturnValue; /* copy the return value here */ struct Value *ReturnValue; /* copy the return value here */
struct Value **Parameter; /* array of parameter values */ struct Value **Parameter; /* array of parameter values */
int NumParams; /* the number of parameters */ int NumParams; /* the number of parameters */
struct Table LocalTable; /* the local variables and parameters */ struct Table LocalTable; /* the local variables and parameters */
struct TableEntry *LocalHashTable[LOCAL_TABLE_SIZE]; struct TableEntry *LocalHashTable[LOCAL_TABLE_SIZE];
struct StackFrame *PreviousStackFrame; /* the next lower stack frame */ struct StackFrame *PreviousStackFrame; /* the next lower stack frame */
}; };
/* lexer state */ /* lexer state */
enum LexMode enum LexMode
{ {
LexModeNormal, LexModeNormal,
LexModeHashInclude, LexModeHashInclude,
LexModeHashDefine, LexModeHashDefine,
LexModeHashDefineSpace, LexModeHashDefineSpace,
LexModeHashDefineSpaceIdent LexModeHashDefineSpaceIdent
}; };
struct LexState struct LexState
{ {
const char *Pos; const char *Pos;
const char *End; const char *End;
const char *FileName; const char *FileName;
int Line; int Line;
int CharacterPos; int CharacterPos;
const char *SourceText; const char *SourceText;
enum LexMode Mode; enum LexMode Mode;
int EmitExtraNewlines; int EmitExtraNewlines;
}; };
/* library function definition */ /* library function definition */
struct LibraryFunction struct LibraryFunction
{ {
void (*Func)(struct ParseState *Parser, struct Value *, struct Value **, int); void (*Func)(struct ParseState *Parser, struct Value *, struct Value **, int);
const char *Prototype; const char *Prototype;
}; };
/* output stream-type specific state information */ /* output stream-type specific state information */
union OutputStreamInfo union OutputStreamInfo
{ {
struct StringOutputStream struct StringOutputStream
{ {
struct ParseState *Parser; struct ParseState *Parser;
char *WritePos; char *WritePos;
} Str; } Str;
}; };
/* stream-specific method for writing characters to the console */ /* stream-specific method for writing characters to the console */
typedef void CharWriter(unsigned char, union OutputStreamInfo *); typedef void CharWriter(unsigned char, union OutputStreamInfo *);
/* used when writing output to a string - eg. sprintf() */ /* used when writing output to a string - eg. sprintf() */
struct OutputStream struct OutputStream
{ {
CharWriter *Putch; CharWriter *Putch;
union OutputStreamInfo i; union OutputStreamInfo i;
}; };
/* possible results of parsing a statement */ /* possible results of parsing a statement */
enum ParseResult { ParseResultEOF, ParseResultError, ParseResultOk }; enum ParseResult { ParseResultEOF, ParseResultError, ParseResultOk };
/* globals */ /* globals */
extern void *HeapStackTop; extern void *HeapStackTop;
extern struct Table GlobalTable; extern struct Table GlobalTable;
extern struct StackFrame *TopStackFrame; extern struct StackFrame *TopStackFrame;
extern struct ValueType UberType; extern struct ValueType UberType;
extern struct ValueType IntType; extern struct ValueType IntType;
extern struct ValueType CharType; extern struct ValueType CharType;
#ifndef NO_FP #ifndef NO_FP
extern struct ValueType FPType; extern struct ValueType FPType;
#endif #endif
extern struct ValueType VoidType; extern struct ValueType VoidType;
extern struct ValueType TypeType; extern struct ValueType TypeType;
extern struct ValueType FunctionType; extern struct ValueType FunctionType;
extern struct ValueType MacroType; extern struct ValueType MacroType;
extern struct ValueType *CharPtrType; extern struct ValueType *CharPtrType;
extern struct ValueType *CharPtrPtrType; extern struct ValueType *CharPtrPtrType;
extern struct ValueType *CharArrayType; extern struct ValueType *CharArrayType;
extern struct ValueType *VoidPtrType; extern struct ValueType *VoidPtrType;
extern char *StrEmpty; extern char *StrEmpty;
extern struct PointerValue NULLPointer; extern struct PointerValue NULLPointer;
extern struct LibraryFunction CLibrary[]; extern struct LibraryFunction CLibrary[];
extern struct LibraryFunction PlatformLibrary[]; extern struct LibraryFunction PlatformLibrary[];
extern IOFILE *CStdOut; extern IOFILE *CStdOut;
/* table.c */ /* table.c */
void TableInit(); void TableInit();
char *TableStrRegister(const char *Str); char *TableStrRegister(const char *Str);
char *TableStrRegister2(const char *Str, int Len); char *TableStrRegister2(const char *Str, int Len);
void TableInitTable(struct Table *Tbl, struct TableEntry **HashTable, int Size, int OnHeap); void TableInitTable(struct Table *Tbl, struct TableEntry **HashTable, int Size, int OnHeap);
int TableSet(struct Table *Tbl, char *Key, struct Value *Val, const char *DeclFileName, int DeclLine, int DeclColumn); int TableSet(struct Table *Tbl, char *Key, struct Value *Val, const char *DeclFileName, int DeclLine, int DeclColumn);
int TableGet(struct Table *Tbl, const char *Key, struct Value **Val, const char **DeclFileName, int *DeclLine, int *DeclColumn); int TableGet(struct Table *Tbl, const char *Key, struct Value **Val, const char **DeclFileName, int *DeclLine, int *DeclColumn);
struct Value *TableDelete(struct Table *Tbl, const char *Key); struct Value *TableDelete(struct Table *Tbl, const char *Key);
char *TableSetIdentifier(struct Table *Tbl, const char *Ident, int IdentLen); char *TableSetIdentifier(struct Table *Tbl, const char *Ident, int IdentLen);
void TableStrFree(); void TableStrFree();
/* lex.c */ /* lex.c */
void LexInit(); void LexInit();
void LexCleanup(); void LexCleanup();
void *LexAnalyse(const char *FileName, const char *Source, int SourceLen, int *TokenLen); void *LexAnalyse(const char *FileName, const char *Source, int SourceLen, int *TokenLen);
void LexInitParser(struct ParseState *Parser, const char *SourceText, void *TokenSource, const char *FileName, int RunIt); void LexInitParser(struct ParseState *Parser, const char *SourceText, void *TokenSource, const char *FileName, int RunIt);
enum LexToken LexGetToken(struct ParseState *Parser, struct Value **Value, int IncPos); enum LexToken LexGetToken(struct ParseState *Parser, struct Value **Value, int IncPos);
enum LexToken LexRawPeekToken(struct ParseState *Parser); enum LexToken LexRawPeekToken(struct ParseState *Parser);
void LexToEndOfLine(struct ParseState *Parser); void LexToEndOfLine(struct ParseState *Parser);
void *LexCopyTokens(struct ParseState *StartParser, struct ParseState *EndParser); void *LexCopyTokens(struct ParseState *StartParser, struct ParseState *EndParser);
void LexInteractiveClear(struct ParseState *Parser); void LexInteractiveClear(struct ParseState *Parser);
void LexInteractiveCompleted(struct ParseState *Parser); void LexInteractiveCompleted(struct ParseState *Parser);
void LexInteractiveStatementPrompt(); void LexInteractiveStatementPrompt();
/* parse.c */ /* parse.c */
/* the following are defined in picoc.h: /* the following are defined in picoc.h:
* 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(); */
enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemicolon); enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemicolon);
struct Value *ParseFunctionDefinition(struct ParseState *Parser, struct ValueType *ReturnType, char *Identifier); struct Value *ParseFunctionDefinition(struct ParseState *Parser, struct ValueType *ReturnType, char *Identifier);
void ParseCleanup(); void ParseCleanup();
void ParserCopyPos(struct ParseState *To, struct ParseState *From); void ParserCopyPos(struct ParseState *To, struct ParseState *From);
void ParserCopy(struct ParseState *To, struct ParseState *From); void ParserCopy(struct ParseState *To, struct ParseState *From);
/* expression.c */ /* expression.c */
int ExpressionParse(struct ParseState *Parser, struct Value **Result); int ExpressionParse(struct ParseState *Parser, struct Value **Result);
long ExpressionParseInt(struct ParseState *Parser); long ExpressionParseInt(struct ParseState *Parser);
void ExpressionAssign(struct ParseState *Parser, struct Value *DestValue, struct Value *SourceValue, int Force, const char *FuncName, int ParamNo, int AllowPointerCoercion); void ExpressionAssign(struct ParseState *Parser, struct Value *DestValue, struct Value *SourceValue, int Force, const char *FuncName, int ParamNo, int AllowPointerCoercion);
long ExpressionCoerceInteger(struct Value *Val); long ExpressionCoerceInteger(struct Value *Val);
unsigned long ExpressionCoerceUnsignedInteger(struct Value *Val); unsigned long ExpressionCoerceUnsignedInteger(struct Value *Val);
#ifndef NO_FP #ifndef NO_FP
double ExpressionCoerceFP(struct Value *Val); double ExpressionCoerceFP(struct Value *Val);
#endif #endif
/* type.c */ /* type.c */
void TypeInit(); void TypeInit();
void TypeCleanup(); void TypeCleanup();
int TypeSize(struct ValueType *Typ, int ArraySize, int Compact); int TypeSize(struct ValueType *Typ, int ArraySize, int Compact);
int TypeSizeValue(struct Value *Val, int Compact); int TypeSizeValue(struct Value *Val, int Compact);
int TypeStackSizeValue(struct Value *Val); int TypeStackSizeValue(struct Value *Val);
int TypeLastAccessibleOffset(struct Value *Val); 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, int AllowDuplicates); 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 */
void HeapInit(int StackSize); void HeapInit(int StackSize);
void HeapCleanup(); void HeapCleanup();
void *HeapAllocStack(int Size); void *HeapAllocStack(int Size);
int HeapPopStack(void *Addr, int Size); int HeapPopStack(void *Addr, int Size);
void HeapUnpopStack(int Size); void HeapUnpopStack(int Size);
void HeapPushStackFrame(); void HeapPushStackFrame();
int HeapPopStackFrame(); int HeapPopStackFrame();
void *HeapAllocMem(int Size); void *HeapAllocMem(int Size);
void HeapFreeMem(void *Mem); void HeapFreeMem(void *Mem);
/* variable.c */ /* variable.c */
void VariableInit(); void VariableInit();
void VariableCleanup(); void VariableCleanup();
void VariableFree(struct Value *Val); void VariableFree(struct Value *Val);
void VariableTableCleanup(struct Table *HashTable); void VariableTableCleanup(struct Table *HashTable);
void *VariableAlloc(struct ParseState *Parser, int Size, int OnHeap); void *VariableAlloc(struct ParseState *Parser, int Size, int OnHeap);
void VariableStackPop(struct ParseState *Parser, struct Value *Var); void VariableStackPop(struct ParseState *Parser, struct Value *Var);
struct Value *VariableAllocValueAndData(struct ParseState *Parser, int DataSize, int IsLValue, struct Value *LValueFrom, int OnHeap); struct Value *VariableAllocValueAndData(struct ParseState *Parser, int DataSize, int IsLValue, struct Value *LValueFrom, int OnHeap);
struct Value *VariableAllocValueAndCopy(struct ParseState *Parser, struct Value *FromValue, int OnHeap); struct Value *VariableAllocValueAndCopy(struct ParseState *Parser, struct Value *FromValue, int OnHeap);
struct Value *VariableAllocValueFromType(struct ParseState *Parser, struct ValueType *Typ, int IsLValue, struct Value *LValueFrom, int OnHeap); struct Value *VariableAllocValueFromType(struct ParseState *Parser, struct ValueType *Typ, int IsLValue, struct Value *LValueFrom, int OnHeap);
struct Value *VariableAllocValueFromExistingData(struct ParseState *Parser, struct ValueType *Typ, union AnyValue *FromValue, int IsLValue, struct Value *LValueFrom); struct Value *VariableAllocValueFromExistingData(struct ParseState *Parser, struct ValueType *Typ, union AnyValue *FromValue, int IsLValue, struct Value *LValueFrom);
struct Value *VariableAllocValueShared(struct ParseState *Parser, struct Value *FromValue); struct Value *VariableAllocValueShared(struct ParseState *Parser, struct Value *FromValue);
struct Value *VariableDefine(struct ParseState *Parser, char *Ident, struct Value *InitValue, struct ValueType *Typ, int MakeWritable); struct Value *VariableDefine(struct ParseState *Parser, char *Ident, struct Value *InitValue, struct ValueType *Typ, int MakeWritable);
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);
int VariableDefined(const char *Ident); int VariableDefined(const char *Ident);
void VariableGet(struct ParseState *Parser, const char *Ident, struct Value **LVal); void VariableGet(struct ParseState *Parser, const char *Ident, struct Value **LVal);
void VariableDefinePlatformVar(struct ParseState *Parser, char *Ident, struct ValueType *Typ, union AnyValue *FromValue, int IsWritable); void VariableDefinePlatformVar(struct ParseState *Parser, char *Ident, struct ValueType *Typ, union AnyValue *FromValue, int IsWritable);
void VariableStackFrameAdd(struct ParseState *Parser, const char *FuncName, int NumParams); void VariableStackFrameAdd(struct ParseState *Parser, const char *FuncName, int NumParams);
void VariableStackFramePop(struct ParseState *Parser); void VariableStackFramePop(struct ParseState *Parser);
struct Value *VariableStringLiteralGet(char *Ident); struct Value *VariableStringLiteralGet(char *Ident);
void VariableStringLiteralDefine(char *Ident, struct Value *Val); void VariableStringLiteralDefine(char *Ident, struct Value *Val);
void *VariableDereferencePointer(struct ParseState *Parser, struct Value *PointerValue, struct Value **DerefVal, int *DerefOffset, struct ValueType **DerefType, int *DerefIsLValue); void *VariableDereferencePointer(struct ParseState *Parser, struct Value *PointerValue, struct Value **DerefVal, int *DerefOffset, struct ValueType **DerefType, int *DerefIsLValue);
/* clibrary.c */ /* clibrary.c */
void BasicIOInit(); void BasicIOInit();
void LibraryInit(); void LibraryInit();
void LibraryAdd(struct Table *GlobalTable, const char *LibraryName, struct LibraryFunction *FuncList); void LibraryAdd(struct Table *GlobalTable, const char *LibraryName, struct LibraryFunction *FuncList);
void CLibraryInit(); void CLibraryInit();
void PrintCh(char OutCh, IOFILE *Stream); void PrintCh(char OutCh, IOFILE *Stream);
void PrintSimpleInt(long Num, IOFILE *Stream); void PrintSimpleInt(long Num, IOFILE *Stream);
void PrintInt(long Num, int FieldWidth, int ZeroPad, int LeftJustify, IOFILE *Stream); void PrintInt(long Num, int FieldWidth, int ZeroPad, int LeftJustify, IOFILE *Stream);
void PrintStr(const char *Str, IOFILE *Stream); void PrintStr(const char *Str, IOFILE *Stream);
void PrintFP(double Num, IOFILE *Stream); void PrintFP(double Num, IOFILE *Stream);
void PrintType(struct ValueType *Typ, IOFILE *Stream); void PrintType(struct ValueType *Typ, IOFILE *Stream);
void LibPrintf(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs); void LibPrintf(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs);
/* platform.c */ /* platform.c */
/* the following are defined in picoc.h: /* the following are defined in picoc.h:
* void PicocCallMain(int argc, char **argv); * void PicocCallMain(int argc, char **argv);
* int PicocPlatformSetExitPoint(); * int PicocPlatformSetExitPoint();
* void PicocInitialise(int StackSize); * void PicocInitialise(int StackSize);
* void PicocCleanup(); * void PicocCleanup();
* void PicocPlatformScanFile(const char *FileName); * void PicocPlatformScanFile(const char *FileName);
* extern int PicocExitValue; */ * extern int PicocExitValue; */
void ProgramFail(struct ParseState *Parser, const char *Message, ...); void ProgramFail(struct ParseState *Parser, const char *Message, ...);
void AssignFail(struct ParseState *Parser, const char *Format, struct ValueType *Type1, struct ValueType *Type2, int Num1, int Num2, const char *FuncName, int ParamNo); void AssignFail(struct ParseState *Parser, const char *Format, struct ValueType *Type1, struct ValueType *Type2, int Num1, int Num2, const char *FuncName, int ParamNo);
void LexFail(struct LexState *Lexer, const char *Message, ...); void LexFail(struct LexState *Lexer, const char *Message, ...);
void PlatformCleanup(); void PlatformCleanup();
char *PlatformGetLine(char *Buf, int MaxLen, const char *Prompt); char *PlatformGetLine(char *Buf, int MaxLen, const char *Prompt);
int PlatformGetCharacter(); int PlatformGetCharacter();
void PlatformPutc(unsigned char OutCh, union OutputStreamInfo *); void PlatformPutc(unsigned char OutCh, union OutputStreamInfo *);
void PlatformErrorPrefix(struct ParseState *Parser); 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); char *PlatformMakeTempName(char *TempNameBuffer);
void PlatformLibraryInit(); void PlatformLibraryInit();
/* include.c */ /* include.c */
void IncludeInit(); void IncludeInit();
void IncludeCleanup(); void IncludeCleanup();
void IncludeRegister(const char *IncludeName, void (*SetupFunction)(void), struct LibraryFunction *FuncList, const char *SetupCSource); void IncludeRegister(const char *IncludeName, void (*SetupFunction)(void), struct LibraryFunction *FuncList, const char *SetupCSource);
void IncludeFile(char *Filename); void IncludeFile(char *Filename);
/* the following is defined in picoc.h: /* the following is defined in picoc.h:
* void PicocIncludeAllSystemHeaders(); */ * void PicocIncludeAllSystemHeaders(); */
/* stdio.c */ /* stdio.c */
extern const char StdioDefs[]; extern const char StdioDefs[];
extern struct LibraryFunction StdioFunctions[]; extern struct LibraryFunction StdioFunctions[];
void StdioSetupFunc(void); void StdioSetupFunc(void);
/* math.c */ /* math.c */
extern struct LibraryFunction MathFunctions[]; extern struct LibraryFunction MathFunctions[];
void MathSetupFunc(void); void MathSetupFunc(void);
/* string.c */ /* string.c */
extern struct LibraryFunction StringFunctions[]; extern struct LibraryFunction StringFunctions[];
void StringSetupFunc(void); void StringSetupFunc(void);
/* stdlib.c */ /* stdlib.c */
extern struct LibraryFunction StdlibFunctions[]; extern struct LibraryFunction StdlibFunctions[];
void StdlibSetupFunc(void); void StdlibSetupFunc(void);
/* time.c */ /* time.c */
extern const char StdTimeDefs[]; extern const char StdTimeDefs[];
extern struct LibraryFunction StdTimeFunctions[]; extern struct LibraryFunction StdTimeFunctions[];
void StdTimeSetupFunc(void); void StdTimeSetupFunc(void);
/* errno.c */ /* errno.c */
void StdErrnoSetupFunc(void); void StdErrnoSetupFunc(void);
/* ctype.c */ /* ctype.c */
extern struct LibraryFunction StdCtypeFunctions[]; extern struct LibraryFunction StdCtypeFunctions[];
/* stdbool.c */ /* stdbool.c */
extern const char StdboolDefs[]; extern const char StdboolDefs[];
void StdboolSetupFunc(void); void StdboolSetupFunc(void);
/* unistd.c */ /* unistd.c */
extern const char UnistdDefs[]; extern const char UnistdDefs[];
extern struct LibraryFunction UnistdFunctions[]; extern struct LibraryFunction UnistdFunctions[];
void UnistdSetupFunc(void); void UnistdSetupFunc(void);
#endif /* INTERPRETER_H */ #endif /* INTERPRETER_H */