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

View file

@ -55,24 +55,49 @@ static struct OpPrecedence OperatorPrecedence[] =
{
/* TokenNone, */ {0, 0, 0, "none"},
/* TokenComma, */ {0, 0, 0, ","},
/* TokenAssign, */ { 0, 0, 2, "=" }, /* TokenAddAssign, */ { 0, 0, 2, "+=" }, /* TokenSubtractAssign, */ { 0, 0, 2, "-=" },
/* TokenMultiplyAssign, */ { 0, 0, 2, "*=" }, /* 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, ":" },
/* TokenAssign, */ {0, 0, 2, "="},
/* TokenAddAssign, */ {0, 0, 2, "+="},
/* TokenSubtractAssign, */ {0, 0, 2, "-="},
/* TokenMultiplyAssign, */ {0, 0, 2, "*="},
/* 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, "||"},
/* TokenLogicalAnd, */ {0, 0, 5, "&&"},
/* TokenArithmeticOr, */ {0, 0, 6, "|"},
/* TokenArithmeticExor, */ {0, 0, 7, "^"},
/* TokenAmpersand, */ {14, 0, 8, "&"},
/* TokenEqual, */ { 0, 0, 9, "==" }, /* TokenNotEqual, */ { 0, 0, 9, "!=" },
/* TokenLessThan, */ { 0, 0, 10, "<" }, /* TokenGreaterThan, */ { 0, 0, 10, ">" }, /* TokenLessEqual, */ { 0, 0, 10, "<=" }, /* TokenGreaterEqual, */ { 0, 0, 10, ">=" },
/* TokenShiftLeft, */ { 0, 0, 11, "<<" }, /* 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, ")" }
/* TokenEqual, */ {0, 0, 9, "=="},
/* TokenNotEqual, */ {0, 0, 9, "!="},
/* TokenLessThan, */ {0, 0, 10, "<"},
/* TokenGreaterThan, */ {0, 0, 10, ">"},
/* TokenLessEqual, */ {0, 0, 10, "<="},
/* TokenGreaterEqual, */ {0, 0, 10, ">="},
/* TokenShiftLeft, */ {0, 0, 11, "<<"},
/* 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);

6
heap.c
View file

@ -10,7 +10,8 @@ void ShowBigList(Picoc *pc)
{
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)
printf("0x%lx:%d ", (long)LPos, LPos->Size);
@ -96,7 +97,8 @@ int HeapPopStack(Picoc *pc, void *Addr, int Size)
return FALSE;
#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
pc->HeapStackTop = (void *)((char *)pc->HeapStackTop - ToLose);
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_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
@ -383,8 +383,7 @@ void LexSkipComment(struct LexState *Lexer, char NextChar, enum LexToken *Return
{
if (NextChar == '*') {
/* 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')
Lexer->EmitExtraNewlines++;

View file

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

14
picoc.h
View file

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