Implemented array lookup

git-svn-id: http://picoc.googlecode.com/svn/trunk@79 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2009-02-15 06:46:37 +00:00
parent 038431067f
commit 78e0ff8bc1
3 changed files with 21 additions and 13 deletions

11
TODO
View file

@ -1,24 +1,13 @@
TODO
* struct
* pointers
* switch
* arrays
* operator precedence
* enum
* interactive mode
New type system:
* basic types: picoc int, picoc char, native int, native char
* structs
* arrays of picoc types or structs
* pointers to:
Also:
* Change function store system to use dynamic allocation
* Check for Alloc returns checking NULL
* Do we really need OnHeap? Isn't every value on the stack anyway?
* Remove Var parameter from HeapPopStack() once we're certain it all works
* Allocating a variable on the heap isn't correct since we need the struct Value to be on the stack anyway

23
parse.c
View file

@ -193,6 +193,25 @@ int ParseValue(struct ParseState *Parser, struct Value **Result, int ResultOnHea
(*Result)->Val->Integer--;
}
}
else if (Token == TokenLeftSquareBracket)
{ /* array access */
LexGetToken(Parser, &LexValue, TRUE);
IntValue = ParseIntExpression(Parser, RunIt);
if (LexGetToken(Parser, &LexValue, TRUE) != TokenRightSquareBracket)
ProgramFail(Parser, "expected ']'");
if (RunIt)
{ /* look up the array element */
if ((*Result)->Typ->Base != TypeArray)
ProgramFail(Parser, "not an array");
if (IntValue < 0 || IntValue >= (*Result)->Typ->ArraySize)
ProgramFail(Parser, "illegal array index");
VariableStackPop(Parser, *Result);
LocalLValue = VariableAllocValueFromExistingData(Parser, (*Result)->Typ->FromType, (union AnyValue *)((void *)(&(*Result)->Val) + (*Result)->Typ->FromType->Sizeof * IntValue), TRUE, ResultOnHeap);
}
}
}
break;
@ -296,7 +315,7 @@ int ParseExpression(struct ParseState *Parser, struct Value **Result, int Result
if (RunIt)
{
if (CurrentValue->Typ->Base == TypeFP || TotalValue->Typ->Base == TypeFP)
{
{ /* floating point expression */
double FPTotal, FPCurrent, FPResult;
if (CurrentValue->Typ->Base != TypeFP || TotalValue->Typ->Base != TypeFP)
@ -336,7 +355,7 @@ int ParseExpression(struct ParseState *Parser, struct Value **Result, int Result
TotalValue = ParsePushFP(Parser, ResultOnHeap, FPResult);
}
else
{
{ /* integer expression */
int IntX, IntY, IntResult;
if (CurrentValue->Typ->Base != TypeInt || TotalValue->Typ->Base != TypeInt)