Fixes in handling void values.
Making quicksort test more real. Better error reporting for invalid parameters. git-svn-id: http://picoc.googlecode.com/svn/trunk@318 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
parent
9f9728dab5
commit
a4889edcf1
16
expression.c
16
expression.c
|
@ -270,34 +270,34 @@ void ExpressionAssignToPointer(struct ParseState *Parser, struct Value *ToValue,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ProgramFail(Parser, "can't assign from a %t to a %t", FromValue->Typ, ToValue->Typ);
|
ProgramFail(Parser, "can't set a %t from a %t", ToValue->Typ, FromValue->Typ);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* assign any kind of value */
|
/* assign any kind of value */
|
||||||
void ExpressionAssign(struct ParseState *Parser, struct Value *DestValue, struct Value *SourceValue, int Force)
|
void ExpressionAssign(struct ParseState *Parser, struct Value *DestValue, struct Value *SourceValue, int Force)
|
||||||
{
|
{
|
||||||
if (!DestValue->IsLValue && !Force)
|
if (!DestValue->IsLValue && !Force)
|
||||||
ProgramFail(Parser, "can't assign to this");
|
ProgramFail(Parser, "can't set this");
|
||||||
|
|
||||||
switch (DestValue->Typ->Base)
|
switch (DestValue->Typ->Base)
|
||||||
{
|
{
|
||||||
case TypeInt:
|
case TypeInt:
|
||||||
if (!IS_NUMERIC_COERCIBLE(SourceValue))
|
if (!IS_NUMERIC_COERCIBLE(SourceValue))
|
||||||
ProgramFail(Parser, "can't assign to this");
|
ProgramFail(Parser, "can't set a %t from a %t", DestValue->Typ, SourceValue->Typ);
|
||||||
|
|
||||||
DestValue->Val->Integer = COERCE_INTEGER(SourceValue);
|
DestValue->Val->Integer = COERCE_INTEGER(SourceValue);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TypeChar:
|
case TypeChar:
|
||||||
if (!IS_NUMERIC_COERCIBLE(SourceValue))
|
if (!IS_NUMERIC_COERCIBLE(SourceValue))
|
||||||
ProgramFail(Parser, "can't assign to this");
|
ProgramFail(Parser, "can't set a %t from a %t", DestValue->Typ, SourceValue->Typ);
|
||||||
|
|
||||||
DestValue->Val->Character = COERCE_INTEGER(SourceValue);
|
DestValue->Val->Character = COERCE_INTEGER(SourceValue);
|
||||||
break;
|
break;
|
||||||
#ifndef NO_FP
|
#ifndef NO_FP
|
||||||
case TypeFP:
|
case TypeFP:
|
||||||
if (!IS_NUMERIC_COERCIBLE(SourceValue))
|
if (!IS_NUMERIC_COERCIBLE(SourceValue))
|
||||||
ProgramFail(Parser, "can't assign to this");
|
ProgramFail(Parser, "can't set a %t from a %t", DestValue->Typ, SourceValue->Typ);
|
||||||
|
|
||||||
DestValue->Val->FP = COERCE_FP(SourceValue);
|
DestValue->Val->FP = COERCE_FP(SourceValue);
|
||||||
break;
|
break;
|
||||||
|
@ -308,7 +308,7 @@ void ExpressionAssign(struct ParseState *Parser, struct Value *DestValue, struct
|
||||||
|
|
||||||
case TypeArray:
|
case TypeArray:
|
||||||
if (DestValue->Typ != SourceValue->Typ)
|
if (DestValue->Typ != SourceValue->Typ)
|
||||||
ProgramFail(Parser, "can't assign from a %t to a %t", SourceValue->Typ, DestValue->Typ);
|
ProgramFail(Parser, "can't set a %t from a %t", DestValue->Typ, SourceValue->Typ);
|
||||||
|
|
||||||
if (DestValue->Val->Array.Size != SourceValue->Val->Array.Size)
|
if (DestValue->Val->Array.Size != SourceValue->Val->Array.Size)
|
||||||
ProgramFail(Parser, "can't assign from an array of size %d to one of size %d", SourceValue->Val->Array.Size, DestValue->Val->Array.Size);
|
ProgramFail(Parser, "can't assign from an array of size %d to one of size %d", SourceValue->Val->Array.Size, DestValue->Val->Array.Size);
|
||||||
|
@ -319,13 +319,13 @@ void ExpressionAssign(struct ParseState *Parser, struct Value *DestValue, struct
|
||||||
case TypeStruct:
|
case TypeStruct:
|
||||||
case TypeUnion:
|
case TypeUnion:
|
||||||
if (DestValue->Typ != SourceValue->Typ)
|
if (DestValue->Typ != SourceValue->Typ)
|
||||||
ProgramFail(Parser, "can't assign from a %t to a %t", SourceValue->Typ, DestValue->Typ);
|
ProgramFail(Parser, "can't set a %t from a %t", DestValue->Typ, SourceValue->Typ);
|
||||||
|
|
||||||
memcpy((void *)DestValue->Val, (void *)SourceValue->Val, TypeSizeValue(SourceValue));
|
memcpy((void *)DestValue->Val, (void *)SourceValue->Val, TypeSizeValue(SourceValue));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ProgramFail(Parser, "can't assign to a %t", DestValue->Typ);
|
ProgramFail(Parser, "can't set a %t", DestValue->Typ);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
4
parse.c
4
parse.c
|
@ -474,7 +474,9 @@ int ParseStatement(struct ParseState *Parser)
|
||||||
if (!ExpressionParse(Parser, &CValue) && TopStackFrame->ReturnValue->Typ->Base != TypeVoid)
|
if (!ExpressionParse(Parser, &CValue) && TopStackFrame->ReturnValue->Typ->Base != TypeVoid)
|
||||||
ProgramFail(Parser, "value required in return");
|
ProgramFail(Parser, "value required in return");
|
||||||
|
|
||||||
ExpressionAssign(Parser, TopStackFrame->ReturnValue, CValue, TRUE);
|
if (TopStackFrame->ReturnValue->Typ->Base != TypeVoid)
|
||||||
|
ExpressionAssign(Parser, TopStackFrame->ReturnValue, CValue, TRUE);
|
||||||
|
|
||||||
VariableStackPop(Parser, CValue);
|
VariableStackPop(Parser, CValue);
|
||||||
Parser->Mode = RunModeReturn;
|
Parser->Mode = RunModeReturn;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ int partition(int left, int right)
|
||||||
{
|
{
|
||||||
if(array[i] < pivotValue)
|
if(array[i] < pivotValue)
|
||||||
{
|
{
|
||||||
swap(array, i, index);
|
swap(i, index);
|
||||||
index += 1;
|
index += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ for (i = 0; i < 16; i++)
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
//quicksort(0, 15);
|
quicksort(0, 15);
|
||||||
|
|
||||||
for (i = 0; i < 16; i++)
|
for (i = 0; i < 16; i++)
|
||||||
printf("%d ", array[i]);
|
printf("%d ", array[i]);
|
||||||
|
|
|
@ -216,7 +216,9 @@ void VariableStackPop(struct ParseState *Parser, struct Value *Var)
|
||||||
|
|
||||||
if (Var->ValOnHeap)
|
if (Var->ValOnHeap)
|
||||||
{
|
{
|
||||||
HeapFree(Var->Val);
|
if (Var->Val != NULL)
|
||||||
|
HeapFree(Var->Val);
|
||||||
|
|
||||||
Success = HeapPopStack(Var, sizeof(struct Value)); /* free from heap */
|
Success = HeapPopStack(Var, sizeof(struct Value)); /* free from heap */
|
||||||
}
|
}
|
||||||
else if (Var->ValOnStack)
|
else if (Var->ValOnStack)
|
||||||
|
|
Loading…
Reference in a new issue