-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Big reorganisation to make it easier to port to different targets
- Loading branch information
zik.saleeba
committed
Feb 24, 2009
1 parent
6fcd7f5
commit d8b4458
Showing
12 changed files
with
256 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,44 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <stdarg.h> | ||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <unistd.h> | ||
|
||
#include "picoc.h" | ||
|
||
/* all platform-dependent code is in this file */ | ||
|
||
void ProgramFail(struct ParseState *Parser, const char *Message, ...) | ||
{ | ||
va_list Args; | ||
|
||
if (Parser != NULL) | ||
IntrinsicHostPrintf("%s:%d: ", Parser->FileName, Parser->Line); | ||
|
||
va_start(Args, Message); | ||
IntrinsicHostVPrintf(Message, Args); | ||
IntrinsicHostPrintf("\n"); | ||
exit(1); | ||
} | ||
|
||
/* exit with a message */ | ||
void LexFail(struct LexState *Lexer, const char *Message, ...) | ||
{ | ||
va_list Args; | ||
|
||
IntrinsicHostPrintf("%s:%d: ", Lexer->FileName, Lexer->Line); | ||
va_start(Args, Message); | ||
IntrinsicHostVPrintf(Message, Args); | ||
IntrinsicHostPrintf("\n"); | ||
exit(1); | ||
} | ||
|
||
/* read a file into memory */ | ||
char *ReadFile(const char *FileName) | ||
{ | ||
struct stat FileInfo; | ||
char *ReadText; | ||
FILE *InFile; | ||
|
||
if (stat(FileName, &FileInfo)) | ||
ProgramFail(NULL, "can't read file %s\n", FileName); | ||
|
||
ReadText = malloc(FileInfo.st_size + 1); | ||
if (ReadText == NULL) | ||
ProgramFail(NULL, "out of memory\n"); | ||
|
||
InFile = fopen(FileName, "r"); | ||
if (InFile == NULL) | ||
ProgramFail(NULL, "can't read file %s\n", FileName); | ||
|
||
if (fread(ReadText, 1, FileInfo.st_size, InFile) != FileInfo.st_size) | ||
ProgramFail(NULL, "can't read file %s\n", FileName); | ||
|
||
ReadText[FileInfo.st_size] = '\0'; | ||
fclose(InFile); | ||
|
||
return ReadText; | ||
} | ||
|
||
/* read and scan a file for definitions */ | ||
void ScanFile(const char *FileName) | ||
/* initialise everything */ | ||
void Initialise() | ||
{ | ||
char *SourceStr = ReadFile(FileName); | ||
Parse(FileName, SourceStr, strlen(SourceStr), TRUE); | ||
free(SourceStr); | ||
HeapInit(); | ||
TableInit(); | ||
VariableInit(); | ||
LexInit(); | ||
VariableInit(); | ||
TypeInit(); | ||
LibraryInit(&GlobalTable, "c library", &CLibrary); | ||
LibraryInit(&GlobalTable, "platform library", &PlatformLibrary); | ||
ParseInit(); | ||
} | ||
|
||
/* platform-dependent code for running programs is in this file */ | ||
#ifdef UNIX_HOST | ||
int main(int argc, char **argv) | ||
{ | ||
if (argc < 2) | ||
ProgramFail(NULL, "Format: picoc <program.c> <args>...\n"); | ||
|
||
HeapInit(); | ||
TableInit(); | ||
VariableInit(); | ||
LexInit(); | ||
ParseInit(); | ||
|
||
ScanFile(argv[1]); | ||
Initialise(); | ||
PlatformScanFile(argv[1]); | ||
|
||
return 0; | ||
} | ||
#else | ||
# ifdef SURVEYOR_HOST | ||
static char *SourceStr = "\ | ||
printf(\"This is a test program\n\");\ | ||
for (Count = 1; Count <= 10; Count++)\ | ||
printf(\"%d\n\");\ | ||
"; | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
Initialise(); | ||
Parse("test.c", SourceStr, strlen(SourceStr), TRUE); | ||
return 0; | ||
} | ||
# endif | ||
#endif |
Oops, something went wrong.