Fixed a problem with passing unnamed parameters.
Fixed a problem with file reading. git-svn-id: http://picoc.googlecode.com/svn/trunk@30 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
parent
ef8969d975
commit
a15cf7dd36
31
parse.c
31
parse.c
|
@ -92,20 +92,23 @@ void ParseParameterList(struct LexState *CallLexer, struct LexState *FuncLexer,
|
||||||
{
|
{
|
||||||
ParseType(FuncLexer, &Typ);
|
ParseType(FuncLexer, &Typ);
|
||||||
Token = LexGetToken(FuncLexer, &Identifier);
|
Token = LexGetToken(FuncLexer, &Identifier);
|
||||||
if (Token != TokenIdentifier)
|
|
||||||
ProgramFail(FuncLexer, "invalid parameter");
|
|
||||||
|
|
||||||
if (RunIt)
|
|
||||||
{
|
|
||||||
if (Parameter[ParamCount].Typ != Typ)
|
|
||||||
ProgramFail(CallLexer, "parameter %d has the wrong type", ParamCount+1);
|
|
||||||
|
|
||||||
VariableDefine(FuncLexer, &Identifier.String, &Parameter[ParamCount]);
|
|
||||||
}
|
|
||||||
|
|
||||||
Token = LexGetPlainToken(FuncLexer);
|
|
||||||
if (Token != TokenComma && Token != TokenCloseBracket)
|
if (Token != TokenComma && Token != TokenCloseBracket)
|
||||||
ProgramFail(FuncLexer, "comma expected");
|
{ /* there's an identifier */
|
||||||
|
if (Token != TokenIdentifier)
|
||||||
|
ProgramFail(FuncLexer, "invalid parameter");
|
||||||
|
|
||||||
|
if (RunIt)
|
||||||
|
{
|
||||||
|
if (Parameter[ParamCount].Typ != Typ)
|
||||||
|
ProgramFail(CallLexer, "parameter %d has the wrong type", ParamCount+1);
|
||||||
|
|
||||||
|
VariableDefine(FuncLexer, &Identifier.String, &Parameter[ParamCount]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Token = LexGetPlainToken(FuncLexer);
|
||||||
|
if (Token != TokenComma && Token != TokenCloseBracket)
|
||||||
|
ProgramFail(FuncLexer, "comma expected");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (ParameterUsed == 0)
|
if (ParameterUsed == 0)
|
||||||
Token = LexGetPlainToken(FuncLexer);
|
Token = LexGetPlainToken(FuncLexer);
|
||||||
|
@ -580,9 +583,9 @@ int ParseStatement(struct LexState *Lexer, int RunIt)
|
||||||
LexToEndOfLine(Lexer);
|
LexToEndOfLine(Lexer);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TokenBreak:
|
|
||||||
case TokenSwitch:
|
case TokenSwitch:
|
||||||
case TokenCase:
|
case TokenCase:
|
||||||
|
case TokenBreak:
|
||||||
case TokenReturn:
|
case TokenReturn:
|
||||||
case TokenDefault:
|
case TokenDefault:
|
||||||
ProgramFail(Lexer, "not implemented yet");
|
ProgramFail(Lexer, "not implemented yet");
|
||||||
|
|
21
picoc.c
21
picoc.c
|
@ -31,10 +31,11 @@ void ProgramFail(struct LexState *Lexer, const char *Message, ...)
|
||||||
|
|
||||||
/* read a file into memory. this is the only function using malloc().
|
/* read a file into memory. this is the only function using malloc().
|
||||||
* do it differently for embedded devices without malloc */
|
* do it differently for embedded devices without malloc */
|
||||||
char *ReadFile(const Str *FileName)
|
Str ReadFile(const Str *FileName)
|
||||||
{
|
{
|
||||||
struct stat FileInfo;
|
struct stat FileInfo;
|
||||||
char *Text;
|
char *ReadText;
|
||||||
|
Str Text;
|
||||||
FILE *InFile;
|
FILE *InFile;
|
||||||
char CFileName[PATH_MAX];
|
char CFileName[PATH_MAX];
|
||||||
|
|
||||||
|
@ -43,15 +44,19 @@ char *ReadFile(const Str *FileName)
|
||||||
if (stat(CFileName, &FileInfo))
|
if (stat(CFileName, &FileInfo))
|
||||||
Fail("can't read file %s\n", CFileName);
|
Fail("can't read file %s\n", CFileName);
|
||||||
|
|
||||||
Text = malloc(FileInfo.st_size);
|
ReadText = malloc(FileInfo.st_size);
|
||||||
|
if (ReadText == NULL)
|
||||||
|
Fail("out of memory\n");
|
||||||
|
|
||||||
InFile = fopen(CFileName, "r");
|
InFile = fopen(CFileName, "r");
|
||||||
if (InFile == NULL)
|
if (InFile == NULL)
|
||||||
Fail("can't read file %s\n", CFileName);
|
Fail("can't read file %s\n", CFileName);
|
||||||
|
|
||||||
if (fread(Text, 1, FileInfo.st_size, InFile) != FileInfo.st_size)
|
if (fread(ReadText, 1, FileInfo.st_size, InFile) != FileInfo.st_size)
|
||||||
Fail("can't read file %s\n", CFileName);
|
Fail("can't read file %s\n", CFileName);
|
||||||
|
|
||||||
|
Text.Str = ReadText;
|
||||||
|
Text.Len = FileInfo.st_size;
|
||||||
fclose(InFile);
|
fclose(InFile);
|
||||||
|
|
||||||
return Text;
|
return Text;
|
||||||
|
@ -60,11 +65,7 @@ char *ReadFile(const Str *FileName)
|
||||||
/* read and scan a file for definitions */
|
/* read and scan a file for definitions */
|
||||||
void ScanFile(const Str *FileName)
|
void ScanFile(const Str *FileName)
|
||||||
{
|
{
|
||||||
char *Source;
|
Str SourceStr = ReadFile(FileName);
|
||||||
Str SourceStr;
|
|
||||||
|
|
||||||
Source = ReadFile(FileName);
|
|
||||||
StrFromC(&SourceStr, Source);
|
|
||||||
Parse(FileName, &SourceStr, TRUE);
|
Parse(FileName, &SourceStr, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue