diff --git a/clibrary.c b/clibrary.c index ef16493..d832aa1 100644 --- a/clibrary.c +++ b/clibrary.c @@ -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. @@ -100,9 +98,9 @@ void BasicIOInit(Picoc *pc) void CLibraryInit(Picoc *pc) { /* define some constants */ - VariableDefinePlatformVar(pc, NULL, "NULL", &IntType, (union AnyValue *)&ZeroValue, FALSE); - VariableDefinePlatformVar(pc, NULL, "TRUE", &IntType, (union AnyValue *)&TRUEValue, FALSE); - VariableDefinePlatformVar(pc, NULL, "FALSE", &IntType, (union AnyValue *)&ZeroValue, FALSE); + VariableDefinePlatformVar(pc, NULL, "NULL", &IntType, (union AnyValue*)&ZeroValue, FALSE); + VariableDefinePlatformVar(pc, NULL, "TRUE", &IntType, (union AnyValue*)&TRUEValue, FALSE); + VariableDefinePlatformVar(pc, NULL, "FALSE", &IntType, (union AnyValue*)&ZeroValue, FALSE); } /* stream for writing into strings */ @@ -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,53 +599,53 @@ 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);" }, - { LibTan, "float tan(float);" }, - { LibAsin, "float asin(float);" }, - { LibAcos, "float acos(float);" }, - { LibAtan, "float atan(float);" }, - { LibSinh, "float sinh(float);" }, - { LibCosh, "float cosh(float);" }, - { LibTanh, "float tanh(float);" }, - { LibExp, "float exp(float);" }, - { LibFabs, "float fabs(float);" }, - { LibLog, "float log(float);" }, - { LibLog10, "float log10(float);" }, - { LibPow, "float pow(float,float);" }, - { LibSqrt, "float sqrt(float);" }, - { LibRound, "float round(float);" }, - { LibCeil, "float ceil(float);" }, - { LibFloor, "float floor(float);" }, + {LibSin, "float sin(float);"}, + {LibCos, "float cos(float);"}, + {LibTan, "float tan(float);"}, + {LibAsin, "float asin(float);"}, + {LibAcos, "float acos(float);"}, + {LibAtan, "float atan(float);"}, + {LibSinh, "float sinh(float);"}, + {LibCosh, "float cosh(float);"}, + {LibTanh, "float tanh(float);"}, + {LibExp, "float exp(float);"}, + {LibFabs, "float fabs(float);"}, + {LibLog, "float log(float);"}, + {LibLog10, "float log10(float);"}, + {LibPow, "float pow(float,float);"}, + {LibSqrt, "float sqrt(float);"}, + {LibRound, "float round(float);"}, + {LibCeil, "float ceil(float);"}, + {LibFloor, "float floor(float);"}, #endif - { LibMalloc, "void *malloc(int);" }, + {LibMalloc, "void *malloc(int);"}, #ifndef NO_CALLOC - { LibCalloc, "void *calloc(int,int);" }, + {LibCalloc, "void *calloc(int,int);"}, #endif #ifndef NO_REALLOC - { LibRealloc, "void *realloc(void *,int);" }, + {LibRealloc, "void *realloc(void *,int);"}, #endif - { LibFree, "void free(void *);" }, + {LibFree, "void free(void *);"}, #ifndef NO_STRING_FUNCTIONS - { LibStrcpy, "void strcpy(char *,char *);" }, - { LibStrncpy, "void strncpy(char *,char *,int);" }, - { LibStrcmp, "int strcmp(char *,char *);" }, - { LibStrncmp, "int strncmp(char *,char *,int);" }, - { LibStrcat, "void strcat(char *,char *);" }, - { LibIndex, "char *index(char *,int);" }, - { LibRindex, "char *rindex(char *,int);" }, - { LibStrlen, "int strlen(char *);" }, - { LibMemset, "void memset(void *,int,int);" }, - { LibMemcpy, "void memcpy(void *,void *,int);" }, - { LibMemcmp, "int memcmp(void *,void *,int);" }, + {LibStrcpy, "void strcpy(char *,char *);"}, + {LibStrncpy, "void strncpy(char *,char *,int);"}, + {LibStrcmp, "int strcmp(char *,char *);"}, + {LibStrncmp, "int strncmp(char *,char *,int);"}, + {LibStrcat, "void strcat(char *,char *);"}, + {LibIndex, "char *index(char *,int);"}, + {LibRindex, "char *rindex(char *,int);"}, + {LibStrlen, "int strlen(char *);"}, + {LibMemset, "void memset(void *,int,int);"}, + {LibMemcpy, "void memcpy(void *,void *,int);"}, + {LibMemcmp, "int memcmp(void *,void *,int);"}, #endif - { NULL, NULL } + {NULL, NULL} }; #endif /* BUILTIN_MINI_STDLIB */ diff --git a/cstdlib/unistd.c b/cstdlib/unistd.c index ecbd5e0..c14c406 100644 --- a/cstdlib/unistd.c +++ b/cstdlib/unistd.c @@ -400,91 +400,91 @@ typedef int intptr_t;\ /* all unistd.h functions */ struct LibraryFunction UnistdFunctions[] = { - { UnistdAccess, "int access(char *, int);" }, - { UnistdAlarm, "unsigned int alarm(unsigned int);" }, -/* { UnistdBrk, "int brk(void *);" }, */ - { UnistdChdir, "int chdir(char *);" }, - { UnistdChroot, "int chroot(char *);" }, - { UnistdChown, "int chown(char *, uid_t, gid_t);" }, - { UnistdClose, "int close(int);" }, - { UnistdConfstr, "size_t confstr(int, char *, size_t);" }, - { UnistdCtermid, "char *ctermid(char *);" }, -/* { UnistdCuserid, "char *cuserid(char *);" }, */ - { UnistdDup, "int dup(int);" }, - { UnistdDup2, "int dup2(int, int);" }, -/* { UnistdEncrypt, "void encrypt(char[64], int);" }, */ -/* { UnistdExecl, "int execl(char *, char *, ...);" }, */ -/* { UnistdExecle, "int execle(char *, char *, ...);" }, */ -/* { UnistdExeclp, "int execlp(char *, char *, ...);" }, */ -/* { UnistdExecv, "int execv(char *, char *[]);" }, */ -/* { UnistdExecve, "int execve(char *, char *[], char *[]);" }, */ -/* { UnistdExecvp, "int execvp(char *, char *[]);" }, */ - { Unistd_Exit, "void _exit(int);" }, - { UnistdFchown, "int fchown(int, uid_t, gid_t);" }, - { UnistdFchdir, "int fchdir(int);" }, - { UnistdFdatasync, "int fdatasync(int);" }, - { UnistdFork, "pid_t fork(void);" }, - { UnistdFpathconf, "long fpathconf(int, int);" }, - { UnistdFsync, "int fsync(int);" }, - { UnistdFtruncate, "int ftruncate(int, off_t);" }, - { UnistdGetcwd, "char *getcwd(char *, size_t);" }, - { UnistdGetdtablesize, "int getdtablesize(void);" }, - { UnistdGetegid, "gid_t getegid(void);" }, - { UnistdGeteuid, "uid_t geteuid(void);" }, - { UnistdGetgid, "gid_t getgid(void);" }, -/* { UnistdGetgroups, "int getgroups(int, gid_t []);" }, */ - { UnistdGethostid, "long gethostid(void);" }, - { UnistdGetlogin, "char *getlogin(void);" }, - { UnistdGetlogin_r, "int getlogin_r(char *, size_t);" }, -/* { UnistdGetopt, "int getopt(int, char * [], char *);" }, */ - { UnistdGetpagesize, "int getpagesize(void);" }, - { UnistdGetpass, "char *getpass(char *);" }, -/* { UnistdGetpgid, "pid_t getpgid(pid_t);" }, */ - { UnistdGetpgrp, "pid_t getpgrp(void);" }, - { UnistdGetpid, "pid_t getpid(void);" }, - { UnistdGetppid, "pid_t getppid(void);" }, -/* { UnistdGetsid, "pid_t getsid(pid_t);" }, */ - { UnistdGetuid, "uid_t getuid(void);" }, - { UnistdGetwd, "char *getwd(char *);" }, - { UnistdIsatty, "int isatty(int);" }, - { UnistdLchown, "int lchown(char *, uid_t, gid_t);" }, - { UnistdLink, "int link(char *, char *);" }, - { UnistdLockf, "int lockf(int, int, off_t);" }, - { UnistdLseek, "off_t lseek(int, off_t, int);" }, - { UnistdNice, "int nice(int);" }, - { UnistdPathconf, "long pathconf(char *, int);" }, - { UnistdPause, "int pause(void);" }, -/* { UnistdPipe, "int pipe(int [2]);" }, */ -/* { UnistdPread, "ssize_t pread(int, void *, size_t, off_t);" }, */ -/* { UnistdPthread_atfork,"int pthread_atfork(void (*)(void), void (*)(void), void(*)(void));" }, */ -/* { UnistdPwrite, "ssize_t pwrite(int, void *, size_t, off_t);" }, */ - { UnistdRead, "ssize_t read(int, void *, size_t);" }, - { UnistdReadlink, "int readlink(char *, char *, size_t);" }, - { UnistdRmdir, "int rmdir(char *);" }, - { UnistdSbrk, "void *sbrk(intptr_t);" }, - { UnistdSetgid, "int setgid(gid_t);" }, - { UnistdSetpgid, "int setpgid(pid_t, pid_t);" }, - { UnistdSetpgrp, "pid_t setpgrp(void);" }, - { UnistdSetregid, "int setregid(gid_t, gid_t);" }, - { UnistdSetreuid, "int setreuid(uid_t, uid_t);" }, - { UnistdSetsid, "pid_t setsid(void);" }, - { UnistdSetuid, "int setuid(uid_t);" }, - { UnistdSleep, "unsigned int sleep(unsigned int);" }, -/* { UnistdSwab, "void swab(void *, void *, ssize_t);" }, */ - { UnistdSymlink, "int symlink(char *, char *);" }, - { UnistdSync, "void sync(void);" }, - { UnistdSysconf, "long sysconf(int);" }, - { UnistdTcgetpgrp, "pid_t tcgetpgrp(int);" }, - { UnistdTcsetpgrp, "int tcsetpgrp(int, pid_t);" }, - { UnistdTruncate, "int truncate(char *, off_t);" }, - { UnistdTtyname, "char *ttyname(int);" }, - { UnistdTtyname_r, "int ttyname_r(int, char *, size_t);" }, - { UnistdUalarm, "useconds_t ualarm(useconds_t, useconds_t);" }, - { UnistdUnlink, "int unlink(char *);" }, - { UnistdUsleep, "int usleep(useconds_t);" }, - { UnistdVfork, "pid_t vfork(void);" }, - { UnistdWrite, "ssize_t write(int, void *, size_t);" }, - { NULL, NULL } + {UnistdAccess, "int access(char *, int);"}, + {UnistdAlarm, "unsigned int alarm(unsigned int);"}, +/* {UnistdBrk, "int brk(void *);"}, */ + {UnistdChdir, "int chdir(char *);"}, + {UnistdChroot, "int chroot(char *);"}, + {UnistdChown, "int chown(char *, uid_t, gid_t);"}, + {UnistdClose, "int close(int);"}, + {UnistdConfstr, "size_t confstr(int, char *, size_t);"}, + {UnistdCtermid, "char *ctermid(char *);"}, +/* {UnistdCuserid, "char *cuserid(char *);"}, */ + {UnistdDup, "int dup(int);"}, + {UnistdDup2, "int dup2(int, int);"}, +/* {UnistdEncrypt, "void encrypt(char[64], int);"}, */ +/* {UnistdExecl, "int execl(char *, char *, ...);"}, */ +/* {UnistdExecle, "int execle(char *, char *, ...);"}, */ +/* {UnistdExeclp, "int execlp(char *, char *, ...);"}, */ +/* {UnistdExecv, "int execv(char *, char *[]);"}, */ +/* {UnistdExecve, "int execve(char *, char *[], char *[]);"}, */ +/* {UnistdExecvp, "int execvp(char *, char *[]);"}, */ + {Unistd_Exit, "void _exit(int);"}, + {UnistdFchown, "int fchown(int, uid_t, gid_t);"}, + {UnistdFchdir, "int fchdir(int);"}, + {UnistdFdatasync, "int fdatasync(int);"}, + {UnistdFork, "pid_t fork(void);"}, + {UnistdFpathconf, "long fpathconf(int, int);"}, + {UnistdFsync, "int fsync(int);"}, + {UnistdFtruncate, "int ftruncate(int, off_t);"}, + {UnistdGetcwd, "char *getcwd(char *, size_t);"}, + {UnistdGetdtablesize, "int getdtablesize(void);"}, + {UnistdGetegid, "gid_t getegid(void);"}, + {UnistdGeteuid, "uid_t geteuid(void);"}, + {UnistdGetgid, "gid_t getgid(void);"}, +/* {UnistdGetgroups, "int getgroups(int, gid_t []);"}, */ + {UnistdGethostid, "long gethostid(void);"}, + {UnistdGetlogin, "char *getlogin(void);"}, + {UnistdGetlogin_r, "int getlogin_r(char *, size_t);"}, +/* {UnistdGetopt, "int getopt(int, char * [], char *);"}, */ + {UnistdGetpagesize, "int getpagesize(void);"}, + {UnistdGetpass, "char *getpass(char *);"}, +/* {UnistdGetpgid, "pid_t getpgid(pid_t);"}, */ + {UnistdGetpgrp, "pid_t getpgrp(void);"}, + {UnistdGetpid, "pid_t getpid(void);"}, + {UnistdGetppid, "pid_t getppid(void);"}, +/* {UnistdGetsid, "pid_t getsid(pid_t);"}, */ + {UnistdGetuid, "uid_t getuid(void);"}, + {UnistdGetwd, "char *getwd(char *);"}, + {UnistdIsatty, "int isatty(int);"}, + {UnistdLchown, "int lchown(char *, uid_t, gid_t);"}, + {UnistdLink, "int link(char *, char *);"}, + {UnistdLockf, "int lockf(int, int, off_t);"}, + {UnistdLseek, "off_t lseek(int, off_t, int);"}, + {UnistdNice, "int nice(int);"}, + {UnistdPathconf, "long pathconf(char *, int);"}, + {UnistdPause, "int pause(void);"}, +/* {UnistdPipe, "int pipe(int [2]);"}, */ +/* {UnistdPread, "ssize_t pread(int, void *, size_t, off_t);"}, */ +/* {UnistdPthread_atfork,"int pthread_atfork(void (*)(void), void (*)(void), void(*)(void));"}, */ +/* {UnistdPwrite, "ssize_t pwrite(int, void *, size_t, off_t);"}, */ + {UnistdRead, "ssize_t read(int, void *, size_t);"}, + {UnistdReadlink, "int readlink(char *, char *, size_t);"}, + {UnistdRmdir, "int rmdir(char *);"}, + {UnistdSbrk, "void *sbrk(intptr_t);"}, + {UnistdSetgid, "int setgid(gid_t);"}, + {UnistdSetpgid, "int setpgid(pid_t, pid_t);"}, + {UnistdSetpgrp, "pid_t setpgrp(void);"}, + {UnistdSetregid, "int setregid(gid_t, gid_t);"}, + {UnistdSetreuid, "int setreuid(uid_t, uid_t);"}, + {UnistdSetsid, "pid_t setsid(void);"}, + {UnistdSetuid, "int setuid(uid_t);"}, + {UnistdSleep, "unsigned int sleep(unsigned int);"}, +/* {UnistdSwab, "void swab(void *, void *, ssize_t);"}, */ + {UnistdSymlink, "int symlink(char *, char *);"}, + {UnistdSync, "void sync(void);"}, + {UnistdSysconf, "long sysconf(int);"}, + {UnistdTcgetpgrp, "pid_t tcgetpgrp(int);"}, + {UnistdTcsetpgrp, "int tcsetpgrp(int, pid_t);"}, + {UnistdTruncate, "int truncate(char *, off_t);"}, + {UnistdTtyname, "char *ttyname(int);"}, + {UnistdTtyname_r, "int ttyname_r(int, char *, size_t);"}, + {UnistdUalarm, "useconds_t ualarm(useconds_t, useconds_t);"}, + {UnistdUnlink, "int unlink(char *);"}, + {UnistdUsleep, "int usleep(useconds_t);"}, + {UnistdVfork, "pid_t vfork(void);"}, + {UnistdWrite, "ssize_t write(int, void *, size_t);"}, + {NULL, NULL} }; /* creates various system-dependent definitions */ diff --git a/expression.c b/expression.c index 219236a..60b9aa6 100644 --- a/expression.c +++ b/expression.c @@ -53,26 +53,51 @@ struct OpPrecedence /* NOTE: the order of this array must correspond exactly to the order of these tokens in enum LexToken */ 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, ":" }, - /* 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, ")" } + /* 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, ":" }, + /* 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, ")"} }; void ExpressionParseFunctionCall(struct ParseState *Parser, struct ExpressionStack **StackTop, const char *FuncName, int RunIt); diff --git a/heap.c b/heap.c index f0b5cbf..48e5717 100644 --- a/heap.c +++ b/heap.c @@ -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); @@ -26,20 +27,20 @@ void HeapInit(Picoc *pc, int StackOrHeapSize) #ifdef USE_MALLOC_STACK pc->HeapMemory = malloc(StackOrHeapSize); - pc->HeapBottom = NULL; /* the bottom of the (downward-growing) heap */ - pc->StackFrame = NULL; /* the current stack frame */ - pc->HeapStackTop = NULL; /* the top of the stack */ + pc->HeapBottom = NULL; /* the bottom of the (downward-growing) heap */ + pc->StackFrame = NULL; /* the current stack frame */ + pc->HeapStackTop = NULL; /* the top of the stack */ #else # ifdef SURVEYOR_HOST - pc->HeapMemory = (unsigned char *)C_HEAPSTART; /* all memory - stack and heap */ + pc->HeapMemory = (unsigned char *)C_HEAPSTART; /* all memory - stack and heap */ pc->HeapBottom = (void *)C_HEAPSTART + HEAP_SIZE; /* the bottom of the (downward-growing) heap */ - pc->StackFrame = (void *)C_HEAPSTART; /* the current stack frame */ - pc->HeapStackTop = (void *)C_HEAPSTART; /* the top of the stack */ + pc->StackFrame = (void *)C_HEAPSTART; /* the current stack frame */ + pc->HeapStackTop = (void *)C_HEAPSTART; /* the top of the stack */ pc->HeapMemStart = (void *)C_HEAPSTART; # else - pc->HeapBottom = &HeapMemory[HEAP_SIZE]; /* the bottom of the (downward-growing) heap */ - pc->StackFrame = &HeapMemory[0]; /* the current stack frame */ - pc->HeapStackTop = &HeapMemory[0]; /* the top of the stack */ + pc->HeapBottom = &HeapMemory[HEAP_SIZE]; /* the bottom of the (downward-growing) heap */ + pc->StackFrame = &HeapMemory[0]; /* the current stack frame */ + pc->HeapStackTop = &HeapMemory[0]; /* the top of the stack */ # endif #endif @@ -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); @@ -157,7 +159,7 @@ void *HeapAllocMem(Picoc *pc, int Size) printf("allocating %d(%d) from bucket", Size, AllocSize); #endif NewMem = pc->FreeListBucket[Bucket]; - assert((unsigned long)NewMem >= (unsigned long)&(pc->HeapMemory)[0] && (unsigned char *)NewMem - &(pc->HeapMemory)[0] < HEAP_SIZE); + assert((unsigned long)NewMem >= (unsigned long)&(pc->HeapMemory)[0] && (unsigned char*)NewMem - &(pc->HeapMemory)[0] < HEAP_SIZE); pc->FreeListBucket[Bucket] = *(struct AllocNode **)NewMem; assert(pc->FreeListBucket[Bucket] == NULL || ((unsigned long)pc->FreeListBucket[Bucket] >= (unsigned long)&(pc->HeapMemory)[0] && (unsigned char *)pc->FreeListBucket[Bucket] - &(pc->HeapMemory)[0] < HEAP_SIZE)); NewMem->Size = AllocSize; @@ -167,7 +169,7 @@ void *HeapAllocMem(Picoc *pc, int Size) } if (*FreeNode != NULL) { - assert((unsigned long)*FreeNode >= (unsigned long)&(pc->HeapMemory)[0] && (unsigned char *)*FreeNode - &(pc->HeapMemory)[0] < HEAP_SIZE); + assert((unsigned long)*FreeNode >= (unsigned long)&(pc->HeapMemory)[0] && (unsigned char*)*FreeNode - &(pc->HeapMemory)[0] < HEAP_SIZE); assert((*FreeNode)->Size < HEAP_SIZE && (*FreeNode)->Size > 0); if ((*FreeNode)->Size < AllocSize + SPLIT_MEM_THRESHOLD) { /* close in size - reduce fragmentation by not splitting */ @@ -175,7 +177,7 @@ void *HeapAllocMem(Picoc *pc, int Size) printf("allocating %d(%d) from freelist, no split (%d)", Size, AllocSize, (*FreeNode)->Size); #endif NewMem = *FreeNode; - assert((unsigned long)NewMem >= (unsigned long)&(pc->HeapMemory)[0] && (unsigned char *)NewMem - &(pc->HeapMemory)[0] < HEAP_SIZE); + assert((unsigned long)NewMem >= (unsigned long)&(pc->HeapMemory)[0] && (unsigned char*)NewMem - &(pc->HeapMemory)[0] < HEAP_SIZE); *FreeNode = NewMem->NextFree; } else { /* split this big memory chunk */ @@ -183,7 +185,7 @@ void *HeapAllocMem(Picoc *pc, int Size) printf("allocating %d(%d) from freelist, split chunk (%d)", Size, AllocSize, (*FreeNode)->Size); #endif NewMem = (void *)((char *)*FreeNode + (*FreeNode)->Size - AllocSize); - assert((unsigned long)NewMem >= (unsigned long)&(pc->HeapMemory)[0] && (unsigned char *)NewMem - &(pc->HeapMemory)[0] < HEAP_SIZE); + assert((unsigned long)NewMem >= (unsigned long)&(pc->HeapMemory)[0] && (unsigned char*)NewMem - &(pc->HeapMemory)[0] < HEAP_SIZE); (*FreeNode)->Size -= AllocSize; NewMem->Size = AllocSize; } @@ -193,17 +195,17 @@ void *HeapAllocMem(Picoc *pc, int Size) if (NewMem == NULL) { /* couldn't allocate from a freelist - try to increase the size of the heap area */ #ifdef DEBUG_HEAP - printf("allocating %d(%d) at bottom of heap (0x%lx-0x%lx)", Size, AllocSize, (long)((char *)pc->HeapBottom - AllocSize), (long)HeapBottom); + printf("allocating %d(%d) at bottom of heap (0x%lx-0x%lx)", Size, AllocSize, (long)((char*)pc->HeapBottom - AllocSize), (long)HeapBottom); #endif - if ((char *)pc->HeapBottom - AllocSize < (char *)pc->HeapStackTop) + if ((char*)pc->HeapBottom - AllocSize < (char*)pc->HeapStackTop) return NULL; - pc->HeapBottom = (void *)((char *)pc->HeapBottom - AllocSize); + pc->HeapBottom = (void*)((char*)pc->HeapBottom - AllocSize); NewMem = pc->HeapBottom; NewMem->Size = AllocSize; } - ReturnMem = (void *)((char *)NewMem + MEM_ALIGN(sizeof(NewMem->Size))); + ReturnMem = (void*)((char*)NewMem + MEM_ALIGN(sizeof(NewMem->Size))); memset(ReturnMem, '\0', AllocSize - MEM_ALIGN(sizeof(NewMem->Size))); #ifdef DEBUG_HEAP printf(" = %lx\n", (unsigned long)ReturnMem); @@ -218,13 +220,13 @@ void HeapFreeMem(Picoc *pc, void *Mem) #ifdef USE_MALLOC_HEAP free(Mem); #else - struct AllocNode *MemNode = (struct AllocNode *)((char *)Mem - MEM_ALIGN(sizeof(MemNode->Size))); + struct AllocNode *MemNode = (struct AllocNode*)((char*)Mem - MEM_ALIGN(sizeof(MemNode->Size))); int Bucket = MemNode->Size >> 2; #ifdef DEBUG_HEAP printf("HeapFreeMem(0x%lx)\n", (unsigned long)Mem); #endif - assert((unsigned long)Mem >= (unsigned long)&(pc->HeapMemory)[0] && (unsigned char *)Mem - &(pc->HeapMemory)[0] < HEAP_SIZE); + assert((unsigned long)Mem >= (unsigned long)&(pc->HeapMemory)[0] && (unsigned char*)Mem - &(pc->HeapMemory)[0] < HEAP_SIZE); assert(MemNode->Size < HEAP_SIZE && MemNode->Size > 0); if (Mem == NULL) return; diff --git a/lex.c b/lex.c index 5eb50bc..0bd6415 100644 --- a/lex.c +++ b/lex.c @@ -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 @@ -36,49 +36,49 @@ struct ReservedWord static struct ReservedWord ReservedWords[] = { - { "#define", TokenHashDefine }, - { "#else", TokenHashElse }, - { "#endif", TokenHashEndif }, - { "#if", TokenHashIf }, - { "#ifdef", TokenHashIfdef }, - { "#ifndef", TokenHashIfndef }, - { "#include", TokenHashInclude }, - { "auto", TokenAutoType }, - { "break", TokenBreak }, - { "case", TokenCase }, - { "char", TokenCharType }, - { "continue", TokenContinue }, - { "default", TokenDefault }, - { "delete", TokenDelete }, - { "do", TokenDo }, + {"#define", TokenHashDefine}, + {"#else", TokenHashElse}, + {"#endif", TokenHashEndif}, + {"#if", TokenHashIf}, + {"#ifdef", TokenHashIfdef}, + {"#ifndef", TokenHashIfndef}, + {"#include", TokenHashInclude}, + {"auto", TokenAutoType}, + {"break", TokenBreak}, + {"case", TokenCase}, + {"char", TokenCharType}, + {"continue", TokenContinue}, + {"default", TokenDefault}, + {"delete", TokenDelete}, + {"do", TokenDo}, #ifndef NO_FP - { "double", TokenDoubleType }, + {"double", TokenDoubleType}, #endif - { "else", TokenElse }, - { "enum", TokenEnumType }, - { "extern", TokenExternType }, + {"else", TokenElse}, + {"enum", TokenEnumType}, + {"extern", TokenExternType}, #ifndef NO_FP - { "float", TokenFloatType }, + {"float", TokenFloatType}, #endif - { "for", TokenFor }, - { "goto", TokenGoto }, - { "if", TokenIf }, - { "int", TokenIntType }, - { "long", TokenLongType }, - { "new", TokenNew }, - { "register", TokenRegisterType }, - { "return", TokenReturn }, - { "short", TokenShortType }, - { "signed", TokenSignedType }, - { "sizeof", TokenSizeof }, - { "static", TokenStaticType }, - { "struct", TokenStructType }, - { "switch", TokenSwitch }, - { "typedef", TokenTypedef }, - { "union", TokenUnionType }, - { "unsigned", TokenUnsignedType }, - { "void", TokenVoidType }, - { "while", TokenWhile } + {"for", TokenFor}, + {"goto", TokenGoto}, + {"if", TokenIf}, + {"int", TokenIntType}, + {"long", TokenLongType}, + {"new", TokenNew}, + {"register", TokenRegisterType}, + {"return", TokenReturn}, + {"short", TokenShortType}, + {"signed", TokenSignedType}, + {"sizeof", TokenSizeof}, + {"static", TokenStaticType}, + {"struct", TokenStructType}, + {"switch", TokenSwitch}, + {"typedef", TokenTypedef}, + {"union", TokenUnionType}, + {"unsigned", TokenUnsignedType}, + {"void", TokenVoidType}, + {"while", TokenWhile} }; @@ -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++; diff --git a/picoc.c b/picoc.c index 0098dad..74829c0 100644 --- a/picoc.c +++ b/picoc.c @@ -24,7 +24,7 @@ int main(int argc, char **argv) printf(PICOC_VERSION " \n" "Format: picoc ... [- ...] : run a program (calls main() to start it)\n" " picoc -s ... [- ...] : script mode - runs the program without calling main()\n" - " picoc -i : interactive mode\n"); + " picoc -i : interactive mode\n"); exit(1); } @@ -56,7 +56,6 @@ int main(int argc, char **argv) return pc.PicocExitValue; } #elif defined(SURVEYOR_HOST) - #define HEAP_SIZE C_HEAPSIZE #include #include "../srv.h" diff --git a/picoc.h b/picoc.h index bf6f555..f3d3391 100644 --- a/picoc.h +++ b/picoc.h @@ -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 */ diff --git a/type.c b/type.c index fdd9b2f..88bcba9 100644 --- a/type.c +++ b/type.c @@ -48,7 +48,7 @@ struct ValueType *TypeGetMatching(Picoc *pc, struct ParseState *Parser, struct V case TypePointer: Sizeof = sizeof(void *); AlignBytes = PointerAlignBytes; break; case TypeArray: Sizeof = ArraySize * ParentType->Sizeof; AlignBytes = ParentType->AlignBytes; break; case TypeEnum: Sizeof = sizeof(int); AlignBytes = IntAlignBytes; break; - default: Sizeof = 0; AlignBytes = 0; break; /* structs and unions will get bigger when we add members to them */ + default: Sizeof = 0; AlignBytes = 0; break; /* structs and unions will get bigger when we add members to them */ } return TypeAdd(pc, Parser, ParentType, Base, ArraySize, Identifier, Sizeof, AlignBytes); @@ -67,7 +67,7 @@ int TypeStackSizeValue(struct Value *Val) int TypeSizeValue(struct Value *Val, int Compact) { if (IS_INTEGER_NUMERIC(Val) && !Compact) - return sizeof(ALIGN_TYPE); /* allow some extra room for type extension */ + return sizeof(ALIGN_TYPE); /* allow some extra room for type extension */ else if (Val->Typ->Base != TypeArray) return Val->Typ->Sizeof; else @@ -78,7 +78,7 @@ int TypeSizeValue(struct Value *Val, int Compact) int TypeSize(struct ValueType *Typ, int ArraySize, int Compact) { if (IS_INTEGER_NUMERIC_TYPE(Typ) && !Compact) - return sizeof(ALIGN_TYPE); /* allow some extra room for type extension */ + return sizeof(ALIGN_TYPE); /* allow some extra room for type extension */ else if (Typ->Base != TypeArray) return Typ->Sizeof; else @@ -104,41 +104,41 @@ void TypeAddBaseType(Picoc *pc, struct ValueType *TypeNode, enum BaseType Base, /* initialise the type system */ void TypeInit(Picoc *pc) { - struct IntAlign { char x; int y; } ia; - struct ShortAlign { char x; short y; } sa; - struct CharAlign { char x; char y; } ca; - struct LongAlign { char x; long y; } la; + struct IntAlign {char x; int y;} ia; + struct ShortAlign {char x; short y;} sa; + struct CharAlign {char x; char y;} ca; + struct LongAlign {char x; long y;} la; #ifndef NO_FP - struct DoubleAlign { char x; double y; } da; + struct DoubleAlign {char x; double y;} da; #endif - struct PointerAlign { char x; void *y; } pa; + struct PointerAlign {char x; void *y;} pa; - IntAlignBytes = (char *)&ia.y - &ia.x; - PointerAlignBytes = (char *)&pa.y - &pa.x; + IntAlignBytes = (char*)&ia.y - &ia.x; + PointerAlignBytes = (char*)&pa.y - &pa.x; pc->UberType.DerivedTypeList = NULL; TypeAddBaseType(pc, &pc->IntType, TypeInt, sizeof(int), IntAlignBytes); - TypeAddBaseType(pc, &pc->ShortType, TypeShort, sizeof(short), (char *)&sa.y - &sa.x); - TypeAddBaseType(pc, &pc->CharType, TypeChar, sizeof(char), (char *)&ca.y - &ca.x); - TypeAddBaseType(pc, &pc->LongType, TypeLong, sizeof(long), (char *)&la.y - &la.x); + TypeAddBaseType(pc, &pc->ShortType, TypeShort, sizeof(short), (char*)&sa.y - &sa.x); + TypeAddBaseType(pc, &pc->CharType, TypeChar, sizeof(char), (char*)&ca.y - &ca.x); + TypeAddBaseType(pc, &pc->LongType, TypeLong, sizeof(long), (char*)&la.y - &la.x); TypeAddBaseType(pc, &pc->UnsignedIntType, TypeUnsignedInt, sizeof(unsigned int), IntAlignBytes); - TypeAddBaseType(pc, &pc->UnsignedShortType, TypeUnsignedShort, sizeof(unsigned short), (char *)&sa.y - &sa.x); - TypeAddBaseType(pc, &pc->UnsignedLongType, TypeUnsignedLong, sizeof(unsigned long), (char *)&la.y - &la.x); - TypeAddBaseType(pc, &pc->UnsignedCharType, TypeUnsignedChar, sizeof(unsigned char), (char *)&ca.y - &ca.x); + TypeAddBaseType(pc, &pc->UnsignedShortType, TypeUnsignedShort, sizeof(unsigned short), (char*)&sa.y - &sa.x); + TypeAddBaseType(pc, &pc->UnsignedLongType, TypeUnsignedLong, sizeof(unsigned long), (char*)&la.y - &la.x); + TypeAddBaseType(pc, &pc->UnsignedCharType, TypeUnsignedChar, sizeof(unsigned char), (char*)&ca.y - &ca.x); TypeAddBaseType(pc, &pc->VoidType, TypeVoid, 0, 1); TypeAddBaseType(pc, &pc->FunctionType, TypeFunction, sizeof(int), IntAlignBytes); TypeAddBaseType(pc, &pc->MacroType, TypeMacro, sizeof(int), IntAlignBytes); TypeAddBaseType(pc, &pc->GotoLabelType, TypeGotoLabel, 0, 1); #ifndef NO_FP - TypeAddBaseType(pc, &pc->FPType, TypeFP, sizeof(double), (char *)&da.y - &da.x); - TypeAddBaseType(pc, &pc->TypeType, Type_Type, sizeof(double), (char *)&da.y - &da.x); /* must be large enough to cast to a double */ + TypeAddBaseType(pc, &pc->FPType, TypeFP, sizeof(double), (char*)&da.y - &da.x); + TypeAddBaseType(pc, &pc->TypeType, Type_Type, sizeof(double), (char*)&da.y - &da.x); /* must be large enough to cast to a double */ #else TypeAddBaseType(pc, &pc->TypeType, Type_Type, sizeof(struct ValueType *), PointerAlignBytes); #endif - pc->CharArrayType = TypeAdd(pc, NULL, &pc->CharType, TypeArray, 0, pc->StrEmpty, sizeof(char), (char *)&ca.y - &ca.x); - pc->CharPtrType = TypeAdd(pc, NULL, &pc->CharType, TypePointer, 0, pc->StrEmpty, sizeof(void *), PointerAlignBytes); - pc->CharPtrPtrType = TypeAdd(pc, NULL, pc->CharPtrType, TypePointer, 0, pc->StrEmpty, sizeof(void *), PointerAlignBytes); - pc->VoidPtrType = TypeAdd(pc, NULL, &pc->VoidType, TypePointer, 0, pc->StrEmpty, sizeof(void *), PointerAlignBytes); + pc->CharArrayType = TypeAdd(pc, NULL, &pc->CharType, TypeArray, 0, pc->StrEmpty, sizeof(char), (char*)&ca.y - &ca.x); + pc->CharPtrType = TypeAdd(pc, NULL, &pc->CharType, TypePointer, 0, pc->StrEmpty, sizeof(void*), PointerAlignBytes); + pc->CharPtrPtrType = TypeAdd(pc, NULL, pc->CharPtrType, TypePointer, 0, pc->StrEmpty, sizeof(void*), PointerAlignBytes); + pc->VoidPtrType = TypeAdd(pc, NULL, &pc->VoidType, TypePointer, 0, pc->StrEmpty, sizeof(void*), PointerAlignBytes); } /* deallocate heap-allocated types */ @@ -210,8 +210,8 @@ void TypeParseStruct(struct ParseState *Parser, struct ValueType **Typ, int IsSt LexGetToken(Parser, NULL, TRUE); (*Typ)->Members = VariableAlloc(pc, Parser, sizeof(struct Table) + STRUCT_TABLE_SIZE * sizeof(struct TableEntry), TRUE); - (*Typ)->Members->HashTable = (struct TableEntry **)((char *)(*Typ)->Members + sizeof(struct Table)); - TableInitTable((*Typ)->Members, (struct TableEntry **)((char *)(*Typ)->Members + sizeof(struct Table)), STRUCT_TABLE_SIZE, TRUE); + (*Typ)->Members->HashTable = (struct TableEntry**)((char*)(*Typ)->Members + sizeof(struct Table)); + TableInitTable((*Typ)->Members, (struct TableEntry**)((char*)(*Typ)->Members + sizeof(struct Table)), STRUCT_TABLE_SIZE, TRUE); do { TypeParse(Parser, &MemberType, &MemberIdentifier, NULL); @@ -263,8 +263,8 @@ struct ValueType *TypeCreateOpaqueStruct(Picoc *pc, struct ParseState *Parser, c /* create the (empty) table */ Typ->Members = VariableAlloc(pc, Parser, sizeof(struct Table) + STRUCT_TABLE_SIZE * sizeof(struct TableEntry), TRUE); - Typ->Members->HashTable = (struct TableEntry **)((char *)Typ->Members + sizeof(struct Table)); - TableInitTable(Typ->Members, (struct TableEntry **)((char *)Typ->Members + sizeof(struct Table)), STRUCT_TABLE_SIZE, TRUE); + Typ->Members->HashTable = (struct TableEntry**)((char*)Typ->Members + sizeof(struct Table)); + TableInitTable(Typ->Members, (struct TableEntry**)((char*)Typ->Members + sizeof(struct Table)), STRUCT_TABLE_SIZE, TRUE); Typ->Sizeof = Size; return Typ; diff --git a/variable.c b/variable.c index 0f0bd4a..ee68326 100644 --- a/variable.c +++ b/variable.c @@ -86,7 +86,7 @@ void *VariableAlloc(Picoc *pc, struct ParseState *Parser, int Size, int OnHeap) struct Value *VariableAllocValueAndData(Picoc *pc, struct ParseState *Parser, int DataSize, int IsLValue, struct Value *LValueFrom, int OnHeap) { struct Value *NewValue = VariableAlloc(pc, Parser, MEM_ALIGN(sizeof(struct Value)) + DataSize, OnHeap); - NewValue->Val = (union AnyValue *)((char *)NewValue + MEM_ALIGN(sizeof(struct Value))); + NewValue->Val = (union AnyValue*)((char*)NewValue + MEM_ALIGN(sizeof(struct Value))); NewValue->ValOnHeap = OnHeap; NewValue->AnyValOnHeap = FALSE; NewValue->ValOnStack = !OnHeap; @@ -120,10 +120,10 @@ struct Value *VariableAllocValueAndCopy(Picoc *pc, struct ParseState *Parser, st int CopySize = TypeSizeValue(FromValue, TRUE); assert(CopySize <= MAX_TMP_COPY_BUF); - memcpy((void *)&TmpBuf[0], (void *)FromValue->Val, CopySize); + memcpy((void*)&TmpBuf[0], (void*)FromValue->Val, CopySize); NewValue = VariableAllocValueAndData(pc, Parser, CopySize, FromValue->IsLValue, FromValue->LValueFrom, OnHeap); NewValue->Typ = DType; - memcpy((void *)NewValue->Val, (void *)&TmpBuf[0], CopySize); + memcpy((void*)NewValue->Val, (void*)&TmpBuf[0], CopySize); return NewValue; } @@ -163,13 +163,13 @@ int VariableScopeBegin(struct ParseState * Parser, int* OldScopeID) { struct TableEntry *Entry; struct TableEntry *NextEntry; - Picoc * pc = Parser->pc; + Picoc *pc = Parser->pc; int Count; #ifdef VAR_SCOPE_DEBUG int FirstPrint = 0; #endif - struct Table * HashTable = (pc->TopStackFrame == NULL) ? &(pc->GlobalTable) : &(pc->TopStackFrame)->LocalTable; + struct Table *HashTable = (pc->TopStackFrame == NULL) ? &(pc->GlobalTable) : &(pc->TopStackFrame)->LocalTable; if (Parser->ScopeID == -1) return -1; @@ -266,7 +266,7 @@ struct Value *VariableDefine(Picoc *pc, struct ParseState *Parser, char *Ident, AssignValue->ScopeID = ScopeID; AssignValue->OutOfScope = FALSE; - if (!TableSet(pc, currentTable, Ident, AssignValue, Parser ? ((char *)Parser->FileName) : NULL, Parser ? Parser->Line : 0, Parser ? Parser->CharacterPos : 0)) + if (!TableSet(pc, currentTable, Ident, AssignValue, Parser ? ((char*)Parser->FileName) : NULL, Parser ? Parser->Line : 0, Parser ? Parser->CharacterPos : 0)) ProgramFail(Parser, "'%s' is already defined", Ident); return AssignValue; @@ -294,13 +294,13 @@ struct Value *VariableDefineButIgnoreIdentical(struct ParseState *Parser, char * /* make the mangled static name (avoiding using sprintf() to minimise library impact) */ memset((void *)&MangledName, '\0', sizeof(MangledName)); *MNPos++ = '/'; - strncpy(MNPos, (char *)Parser->FileName, MNEnd - MNPos); + strncpy(MNPos, (char*)Parser->FileName, MNEnd - MNPos); MNPos += strlen(MNPos); if (pc->TopStackFrame != NULL) { /* we're inside a function */ if (MNEnd - MNPos > 0) *MNPos++ = '/'; - strncpy(MNPos, (char *)pc->TopStackFrame->FuncName, MNEnd - MNPos); + strncpy(MNPos, (char*)pc->TopStackFrame->FuncName, MNEnd - MNPos); MNPos += strlen(MNPos); } @@ -312,7 +312,7 @@ struct Value *VariableDefineButIgnoreIdentical(struct ParseState *Parser, char * if (!TableGet(&pc->GlobalTable, RegisteredMangledName, &ExistingValue, &DeclFileName, &DeclLine, &DeclColumn)) { /* define the mangled-named static variable store in the global scope */ ExistingValue = VariableAllocValueFromType(Parser->pc, Parser, Typ, TRUE, NULL, TRUE); - TableSet(pc, &pc->GlobalTable, (char *)RegisteredMangledName, ExistingValue, (char *)Parser->FileName, Parser->Line, Parser->CharacterPos); + TableSet(pc, &pc->GlobalTable, (char*)RegisteredMangledName, ExistingValue, (char *)Parser->FileName, Parser->Line, Parser->CharacterPos); *FirstVisit = TRUE; } @@ -401,7 +401,7 @@ void VariableStackFrameAdd(struct ParseState *Parser, const char *FuncName, int ParserCopy(&NewFrame->ReturnParser, Parser); NewFrame->FuncName = FuncName; - NewFrame->Parameter = (NumParams > 0) ? ((void *)((char *)NewFrame + sizeof(struct StackFrame))) : NULL; + NewFrame->Parameter = (NumParams > 0) ? ((void*)((char *)NewFrame + sizeof(struct StackFrame))) : NULL; TableInitTable(&NewFrame->LocalTable, &NewFrame->LocalHashTable[0], LOCAL_TABLE_SIZE, FALSE); NewFrame->PreviousStackFrame = Parser->pc->TopStackFrame; Parser->pc->TopStackFrame = NewFrame;