formatting
This commit is contained in:
parent
e58eac4ae6
commit
bbcf2fdd95
|
@ -56,8 +56,7 @@ struct Picoc_Struct;
|
||||||
typedef struct Picoc_Struct Picoc;
|
typedef struct Picoc_Struct Picoc;
|
||||||
|
|
||||||
/* lexical tokens */
|
/* lexical tokens */
|
||||||
enum LexToken
|
enum LexToken {
|
||||||
{
|
|
||||||
/* 0x00 */ TokenNone,
|
/* 0x00 */ TokenNone,
|
||||||
/* 0x01 */ TokenComma,
|
/* 0x01 */ TokenComma,
|
||||||
/* 0x02 */ TokenAssign,
|
/* 0x02 */ TokenAssign,
|
||||||
|
@ -157,15 +156,13 @@ enum LexToken
|
||||||
};
|
};
|
||||||
|
|
||||||
/* 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 */
|
||||||
|
@ -176,8 +173,7 @@ enum RunMode
|
||||||
};
|
};
|
||||||
|
|
||||||
/* 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 {
|
||||||
{
|
|
||||||
Picoc *pc; /* the picoc instance this parser is a part of */
|
Picoc *pc; /* the picoc instance this parser is a part of */
|
||||||
const unsigned char *Pos; /* the character position in the source text */
|
const unsigned char *Pos; /* the character position in the source text */
|
||||||
char *FileName; /* what file we're executing (registered string) */
|
char *FileName; /* what file we're executing (registered string) */
|
||||||
|
@ -196,8 +192,7 @@ struct ParseState
|
||||||
};
|
};
|
||||||
|
|
||||||
/* values */
|
/* values */
|
||||||
enum BaseType
|
enum BaseType {
|
||||||
{
|
|
||||||
TypeVoid, /* no type */
|
TypeVoid, /* no type */
|
||||||
TypeInt, /* integer */
|
TypeInt, /* integer */
|
||||||
TypeShort, /* short integer */
|
TypeShort, /* short integer */
|
||||||
|
@ -220,8 +215,7 @@ enum BaseType
|
||||||
};
|
};
|
||||||
|
|
||||||
/* 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 */
|
||||||
|
@ -236,8 +230,7 @@ struct ValueType
|
||||||
};
|
};
|
||||||
|
|
||||||
/* 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
|
int VarArgs; /* has a variable number of arguments after
|
||||||
|
@ -250,8 +243,7 @@ struct FuncDef
|
||||||
};
|
};
|
||||||
|
|
||||||
/* 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
|
struct ParseState Body; /* lexical tokens of the function body
|
||||||
|
@ -259,8 +251,7 @@ struct MacroDef
|
||||||
};
|
};
|
||||||
|
|
||||||
/* values */
|
/* values */
|
||||||
union AnyValue
|
union AnyValue {
|
||||||
{
|
|
||||||
char Character;
|
char Character;
|
||||||
short ShortInteger;
|
short ShortInteger;
|
||||||
int Integer;
|
int Integer;
|
||||||
|
@ -279,8 +270,7 @@ union AnyValue
|
||||||
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) */
|
||||||
|
@ -293,25 +283,22 @@ struct Value
|
||||||
};
|
};
|
||||||
|
|
||||||
/* 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 */
|
||||||
|
|
||||||
struct BreakpointEntry /* defines a breakpoint */
|
/* defines a breakpoint */
|
||||||
{
|
struct BreakpointEntry {
|
||||||
const char *FileName;
|
const char *FileName;
|
||||||
short int Line;
|
short int Line;
|
||||||
short int CharacterPos;
|
short int CharacterPos;
|
||||||
|
@ -320,16 +307,14 @@ struct TableEntry
|
||||||
} 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 */
|
||||||
|
@ -341,8 +326,7 @@ struct StackFrame
|
||||||
};
|
};
|
||||||
|
|
||||||
/* lexer state */
|
/* lexer state */
|
||||||
enum LexMode
|
enum LexMode {
|
||||||
{
|
|
||||||
LexModeNormal,
|
LexModeNormal,
|
||||||
LexModeHashInclude,
|
LexModeHashInclude,
|
||||||
LexModeHashDefine,
|
LexModeHashDefine,
|
||||||
|
@ -350,8 +334,7 @@ enum LexMode
|
||||||
LexModeHashDefineSpaceIdent
|
LexModeHashDefineSpaceIdent
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LexState
|
struct LexState {
|
||||||
{
|
|
||||||
const char *Pos;
|
const char *Pos;
|
||||||
const char *End;
|
const char *End;
|
||||||
const char *FileName;
|
const char *FileName;
|
||||||
|
@ -363,17 +346,14 @@ struct LexState
|
||||||
};
|
};
|
||||||
|
|
||||||
/* 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;
|
||||||
|
@ -383,8 +363,7 @@ union OutputStreamInfo
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
@ -393,16 +372,14 @@ struct OutputStream
|
||||||
enum ParseResult { ParseResultEOF, ParseResultError, ParseResultOk };
|
enum ParseResult { ParseResultEOF, ParseResultError, ParseResultOk };
|
||||||
|
|
||||||
/* a chunk of heap-allocated tokens we'll cleanup when we're done */
|
/* a chunk of heap-allocated tokens we'll cleanup when we're done */
|
||||||
struct CleanupTokenNode
|
struct CleanupTokenNode {
|
||||||
{
|
|
||||||
void *Tokens;
|
void *Tokens;
|
||||||
const char *SourceText;
|
const char *SourceText;
|
||||||
struct CleanupTokenNode *Next;
|
struct CleanupTokenNode *Next;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* linked list of lexical tokens used in interactive mode */
|
/* linked list of lexical tokens used in interactive mode */
|
||||||
struct TokenLine
|
struct TokenLine {
|
||||||
{
|
|
||||||
struct TokenLine *Next;
|
struct TokenLine *Next;
|
||||||
unsigned char *Tokens;
|
unsigned char *Tokens;
|
||||||
int NumBytes;
|
int NumBytes;
|
||||||
|
@ -410,8 +387,7 @@ struct TokenLine
|
||||||
|
|
||||||
|
|
||||||
/* a list of libraries we can include */
|
/* a list of libraries we can include */
|
||||||
struct IncludeLibrary
|
struct IncludeLibrary {
|
||||||
{
|
|
||||||
char *IncludeName;
|
char *IncludeName;
|
||||||
void (*SetupFunction)(Picoc *pc);
|
void (*SetupFunction)(Picoc *pc);
|
||||||
struct LibraryFunction *FuncList;
|
struct LibraryFunction *FuncList;
|
||||||
|
@ -425,8 +401,7 @@ struct IncludeLibrary
|
||||||
|
|
||||||
|
|
||||||
/* the entire state of the picoc system */
|
/* the entire state of the picoc system */
|
||||||
struct Picoc_Struct
|
struct Picoc_Struct {
|
||||||
{
|
|
||||||
/* parser global data */
|
/* parser global data */
|
||||||
struct Table GlobalTable;
|
struct Table GlobalTable;
|
||||||
struct CleanupTokenNode *CleanupTokenList;
|
struct CleanupTokenNode *CleanupTokenList;
|
||||||
|
|
6
picoc.h
6
picoc.h
|
@ -5,7 +5,8 @@
|
||||||
|
|
||||||
/* picoc version number */
|
/* picoc version number */
|
||||||
#ifdef VER
|
#ifdef VER
|
||||||
#define PICOC_VERSION TAG " r" VER /* VER is the git hash number, obtained via the Makefile */
|
/* VER is the git hash number, obtained via the Makefile */
|
||||||
|
#define PICOC_VERSION TAG " r" VER
|
||||||
#else
|
#else
|
||||||
#define PICOC_VERSION "v2.2"
|
#define PICOC_VERSION "v2.2"
|
||||||
#endif
|
#endif
|
||||||
|
@ -21,7 +22,8 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* parse.c */
|
/* parse.c */
|
||||||
extern void PicocParse(Picoc *pc, const char *FileName, const char *Source, int SourceLen, int RunIt, int CleanupNow, int CleanupSource, int EnableDebugger);
|
extern void PicocParse(Picoc *pc, const char *FileName, const char *Source,
|
||||||
|
int SourceLen, int RunIt, int CleanupNow, int CleanupSource, int EnableDebugger);
|
||||||
extern void PicocParseInteractive(Picoc *pc);
|
extern void PicocParseInteractive(Picoc *pc);
|
||||||
|
|
||||||
/* platform.c */
|
/* platform.c */
|
||||||
|
|
|
@ -32,9 +32,11 @@
|
||||||
|
|
||||||
|
|
||||||
#if defined(__hppa__) || defined(__sparc__)
|
#if defined(__hppa__) || defined(__sparc__)
|
||||||
#define ALIGN_TYPE double /* the default data type to use for alignment */
|
/* the default data type to use for alignment */
|
||||||
|
#define ALIGN_TYPE double
|
||||||
#else
|
#else
|
||||||
#define ALIGN_TYPE void * /* the default data type to use for alignment */
|
/* the default data type to use for alignment */
|
||||||
|
#define ALIGN_TYPE void *
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define GLOBAL_TABLE_SIZE (97) /* global variable table */
|
#define GLOBAL_TABLE_SIZE (97) /* global variable table */
|
||||||
|
|
Loading…
Reference in a new issue