formatting

This commit is contained in:
Joseph Poirier 2015-06-07 01:28:10 -05:00
parent af9b423aaa
commit e0775801f9
9 changed files with 282 additions and 261 deletions

View file

@ -77,9 +77,7 @@ void PrintType(struct ValueType *Typ, IOFILE *Stream)
} }
} }
#ifdef BUILTIN_MINI_STDLIB #ifdef BUILTIN_MINI_STDLIB
/* /*
* This is a simplified standard library for small embedded systems. It doesn't require * This is a simplified standard library for small embedded systems. It doesn't require
* a system stdio library to operate. * a system stdio library to operate.
@ -276,12 +274,10 @@ void GenericPrintf(struct ParseState *Parser, struct Value *ReturnValue, struct
case 's': case 's':
{ {
char *Str; char *Str;
if (NextArg->Typ->Base == TypePointer) if (NextArg->Typ->Base == TypePointer)
Str = NextArg->Val->Pointer; Str = NextArg->Val->Pointer;
else else
Str = &NextArg->Val->ArrayMem[0]; Str = &NextArg->Val->ArrayMem[0];
if (Str == NULL) if (Str == NULL)
PrintStr("NULL", Stream); PrintStr("NULL", Stream);
else else
@ -603,11 +599,11 @@ void LibMemcmp(struct ParseState *Parser, struct Value *ReturnValue, struct Valu
/* list of all library functions and their prototypes */ /* list of all library functions and their prototypes */
struct LibraryFunction CLibrary[] = struct LibraryFunction CLibrary[] =
{ {
{ LibPrintf, "void printf(char *, ...);" }, LibPrintf, "void printf(char *, ...);"},
{ LibSPrintf, "char *sprintf(char *, char *, ...);" }, LibSPrintf, "char *sprintf(char *, char *, ...);"},
{ LibGets, "char *gets(char *);" }, LibGets, "char *gets(char *);"},
{ LibGetc, "int getchar();" }, LibGetc, "int getchar();"},
{ LibExit, "void exit(int);" }, LibExit, "void exit(int);"},
#ifdef PICOC_LIBRARY #ifdef PICOC_LIBRARY
{LibSin, "float sin(float);"}, {LibSin, "float sin(float);"},
{LibCos, "float cos(float);"}, {LibCos, "float cos(float);"},

View file

@ -55,24 +55,49 @@ static struct OpPrecedence OperatorPrecedence[] =
{ {
/* TokenNone, */ {0, 0, 0, "none"}, /* TokenNone, */ {0, 0, 0, "none"},
/* TokenComma, */ {0, 0, 0, ","}, /* TokenComma, */ {0, 0, 0, ","},
/* TokenAssign, */ { 0, 0, 2, "=" }, /* TokenAddAssign, */ { 0, 0, 2, "+=" }, /* TokenSubtractAssign, */ { 0, 0, 2, "-=" }, /* TokenAssign, */ {0, 0, 2, "="},
/* TokenMultiplyAssign, */ { 0, 0, 2, "*=" }, /* TokenDivideAssign, */ { 0, 0, 2, "/=" }, /* TokenModulusAssign, */ { 0, 0, 2, "%=" }, /* TokenAddAssign, */ {0, 0, 2, "+="},
/* TokenShiftLeftAssign, */ { 0, 0, 2, "<<=" }, /* TokenShiftRightAssign, */ { 0, 0, 2, ">>=" }, /* TokenArithmeticAndAssign, */ { 0, 0, 2, "&=" }, /* TokenSubtractAssign, */ {0, 0, 2, "-="},
/* TokenArithmeticOrAssign, */ { 0, 0, 2, "|=" }, /* TokenArithmeticExorAssign, */ { 0, 0, 2, "^=" }, /* TokenMultiplyAssign, */ {0, 0, 2, "*="},
/* TokenQuestionMark, */ { 0, 0, 3, "?" }, /* TokenColon, */ { 0, 0, 3, ":" }, /* TokenDivideAssign, */ { 0, 0, 2, "/=" },
/* TokenModulusAssign, */ { 0, 0, 2, "%=" },
/* TokenShiftLeftAssign, */ {0, 0, 2, "<<="},
/* TokenShiftRightAssign, */ { 0, 0, 2, ">>=" },
/* TokenArithmeticAndAssign, */ { 0, 0, 2, "&=" },
/* TokenArithmeticOrAssign, */ {0, 0, 2, "|="},
/* TokenArithmeticExorAssign, */ { 0, 0, 2, "^=" },
/* TokenQuestionMark, */ {0, 0, 3, "?"},
/* TokenColon, */ {0, 0, 3, ":" },
/* TokenLogicalOr, */ {0, 0, 4, "||"}, /* TokenLogicalOr, */ {0, 0, 4, "||"},
/* TokenLogicalAnd, */ {0, 0, 5, "&&"}, /* TokenLogicalAnd, */ {0, 0, 5, "&&"},
/* TokenArithmeticOr, */ {0, 0, 6, "|"}, /* TokenArithmeticOr, */ {0, 0, 6, "|"},
/* TokenArithmeticExor, */ {0, 0, 7, "^"}, /* TokenArithmeticExor, */ {0, 0, 7, "^"},
/* TokenAmpersand, */ {14, 0, 8, "&"}, /* TokenAmpersand, */ {14, 0, 8, "&"},
/* TokenEqual, */ { 0, 0, 9, "==" }, /* TokenNotEqual, */ { 0, 0, 9, "!=" }, /* TokenEqual, */ {0, 0, 9, "=="},
/* TokenLessThan, */ { 0, 0, 10, "<" }, /* TokenGreaterThan, */ { 0, 0, 10, ">" }, /* TokenLessEqual, */ { 0, 0, 10, "<=" }, /* TokenGreaterEqual, */ { 0, 0, 10, ">=" }, /* TokenNotEqual, */ {0, 0, 9, "!="},
/* TokenShiftLeft, */ { 0, 0, 11, "<<" }, /* TokenShiftRight, */ { 0, 0, 11, ">>" }, /* TokenLessThan, */ {0, 0, 10, "<"},
/* TokenPlus, */ { 14, 0, 12, "+" }, /* TokenMinus, */ { 14, 0, 12, "-" }, /* TokenGreaterThan, */ {0, 0, 10, ">"},
/* TokenAsterisk, */ { 14, 0, 13, "*" }, /* TokenSlash, */ { 0, 0, 13, "/" }, /* TokenModulus, */ { 0, 0, 13, "%" }, /* TokenLessEqual, */ {0, 0, 10, "<="},
/* TokenIncrement, */ { 14, 15, 0, "++" }, /* TokenDecrement, */ { 14, 15, 0, "--" }, /* TokenUnaryNot, */ { 14, 0, 0, "!" }, /* TokenUnaryExor, */ { 14, 0, 0, "~" }, /* TokenSizeof, */ { 14, 0, 0, "sizeof" }, /* TokenCast, */ { 14, 0, 0, "cast" }, /* TokenGreaterEqual, */ {0, 0, 10, ">="},
/* TokenLeftSquareBracket, */ { 0, 0, 15, "[" }, /* TokenRightSquareBracket, */ { 0, 15, 0, "]" }, /* TokenDot, */ { 0, 0, 15, "." }, /* TokenArrow, */ { 0, 0, 15, "->" }, /* TokenShiftLeft, */ {0, 0, 11, "<<"},
/* TokenOpenBracket, */ { 15, 0, 0, "(" }, /* TokenCloseBracket, */ { 0, 15, 0, ")" } /* TokenShiftRight, */ {0, 0, 11, ">>"},
/* TokenPlus, */ {14, 0, 12, "+"},
/* TokenMinus, */ {14, 0, 12, "-"},
/* TokenAsterisk, */ {14, 0, 13, "*"},
/* TokenSlash, */ {0, 0, 13, "/"},
/* TokenModulus, */ {0, 0, 13, "%"},
/* TokenIncrement, */ {14, 15, 0, "++"},
/* TokenDecrement, */ {14, 15, 0, "--"},
/* TokenUnaryNot, */ {14, 0, 0, "!"},
/* TokenUnaryExor, */ {14, 0, 0, "~"},
/* TokenSizeof, */ {14, 0, 0, "sizeof"},
/* TokenCast, */ {14, 0, 0, "cast"},
/* TokenLeftSquareBracket, */ {0, 0, 15, "["},
/* TokenRightSquareBracket, */ {0, 15, 0, "]"},
/* TokenDot, */ {0, 0, 15, "."},
/* TokenArrow, */ {0, 0, 15, "->"},
/* TokenOpenBracket, */ {15, 0, 0, "("},
/* TokenCloseBracket, */ {0, 15, 0, ")"}
}; };
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);

6
heap.c
View file

@ -10,7 +10,8 @@ void ShowBigList(Picoc *pc)
{ {
struct AllocNode *LPos; struct AllocNode *LPos;
printf("Heap: bottom=0x%lx 0x%lx-0x%lx, big freelist=", (long)pc->HeapBottom, (long)&(pc->HeapMemory)[0], (long)&(pc->HeapMemory)[HEAP_SIZE]); printf("Heap: bottom=0x%lx 0x%lx-0x%lx, big freelist=", (long)pc->HeapBottom,
(long)&(pc->HeapMemory)[0], (long)&(pc->HeapMemory)[HEAP_SIZE]);
for (LPos = pc->FreeListBig; LPos != NULL; LPos = LPos->NextFree) for (LPos = pc->FreeListBig; LPos != NULL; LPos = LPos->NextFree)
printf("0x%lx:%d ", (long)LPos, LPos->Size); printf("0x%lx:%d ", (long)LPos, LPos->Size);
@ -96,7 +97,8 @@ int HeapPopStack(Picoc *pc, void *Addr, int Size)
return FALSE; return FALSE;
#ifdef DEBUG_HEAP #ifdef DEBUG_HEAP
printf("HeapPopStack(0x%lx, %ld) back to 0x%lx\n", (unsigned long)Addr, (unsigned long)MEM_ALIGN(Size), (unsigned long)pc->HeapStackTop - ToLose); printf("HeapPopStack(0x%lx, %ld) back to 0x%lx\n", (unsigned long)Addr,
(unsigned long)MEM_ALIGN(Size), (unsigned long)pc->HeapStackTop - ToLose);
#endif #endif
pc->HeapStackTop = (void *)((char *)pc->HeapStackTop - ToLose); pc->HeapStackTop = (void *)((char *)pc->HeapStackTop - ToLose);
assert(Addr == NULL || pc->HeapStackTop == Addr); assert(Addr == NULL || pc->HeapStackTop == Addr);

7
lex.c
View file

@ -23,9 +23,9 @@
#define LEXER_INC(l) ( (l)->Pos++, (l)->CharacterPos++ ) #define LEXER_INC(l) ( (l)->Pos++, (l)->CharacterPos++ )
#define LEXER_INCN(l, n) ( (l)->Pos+=(n), (l)->CharacterPos+=(n) ) #define LEXER_INCN(l, n) ( (l)->Pos+=(n), (l)->CharacterPos+=(n) )
#define TOKEN_DATA_OFFSET 2 #define TOKEN_DATA_OFFSET (2)
#define MAX_CHAR_VALUE 255 /* maximum value which can be represented by a "char" data type */ #define MAX_CHAR_VALUE (255) /* maximum value which can be represented by a "char" data type */
struct ReservedWord struct ReservedWord
@ -383,8 +383,7 @@ void LexSkipComment(struct LexState *Lexer, char NextChar, enum LexToken *Return
{ {
if (NextChar == '*') { if (NextChar == '*') {
/* conventional C comment */ /* conventional C comment */
while (Lexer->Pos != Lexer->End && (*(Lexer->Pos-1) != '*' || *Lexer->Pos != '/')) while (Lexer->Pos != Lexer->End && (*(Lexer->Pos-1) != '*' || *Lexer->Pos != '/')) {
{
if (*Lexer->Pos == '\n') if (*Lexer->Pos == '\n')
Lexer->EmitExtraNewlines++; Lexer->EmitExtraNewlines++;

View file

@ -56,7 +56,6 @@ int main(int argc, char **argv)
return pc.PicocExitValue; return pc.PicocExitValue;
} }
#elif defined(SURVEYOR_HOST) #elif defined(SURVEYOR_HOST)
#define HEAP_SIZE C_HEAPSIZE #define HEAP_SIZE C_HEAPSIZE
#include <setjmp.h> #include <setjmp.h>
#include "../srv.h" #include "../srv.h"

14
picoc.h
View file

@ -34,16 +34,16 @@ extern int PicocExitBuf[];
#endif #endif
/* parse.c */ /* parse.c */
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);
void PicocParseInteractive(Picoc *pc); extern void PicocParseInteractive(Picoc *pc);
/* platform.c */ /* platform.c */
void PicocCallMain(Picoc *pc, int argc, char **argv); extern void PicocCallMain(Picoc *pc, int argc, char **argv);
void PicocInitialise(Picoc *pc, int StackSize); extern void PicocInitialise(Picoc *pc, int StackSize);
void PicocCleanup(Picoc *pc); extern void PicocCleanup(Picoc *pc);
void PicocPlatformScanFile(Picoc *pc, const char *FileName); extern void PicocPlatformScanFile(Picoc *pc, const char *FileName);
/* include.c */ /* include.c */
void PicocIncludeAllSystemHeaders(Picoc *pc); extern void PicocIncludeAllSystemHeaders(Picoc *pc);
#endif /* PICOC_H */ #endif /* PICOC_H */