Skip to content

Commit

Permalink
picoc release 0.91
Browse files Browse the repository at this point in the history
  • Loading branch information
zik.saleeba committed May 28, 2009
1 parent 664478d commit e33da74
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 80 deletions.
4 changes: 2 additions & 2 deletions clibrary.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void GenericPrintf(struct ParseState *Parser, struct Value *ReturnValue, struct
else
{
NextArg = (struct Value *)((void *)NextArg + sizeof(struct Value) + TypeStackSizeValue(NextArg));
if (NextArg->Typ != FormatType && !((FormatType == &IntType || *FPos == 'f') && IS_NUMERIC_COERCIBLE(NextArg)))
if (NextArg->Typ != FormatType && !(FormatType == &IntType && IS_NUMERIC_COERCIBLE(NextArg)))
PrintStr("XXX", Stream); /* bad type for format */
else
{
Expand All @@ -221,7 +221,7 @@ void GenericPrintf(struct ParseState *Parser, struct Value *ReturnValue, struct
case 'd': PrintInt(COERCE_INTEGER(NextArg), Stream); break;
case 'c': PrintCh(COERCE_INTEGER(NextArg), Stream); break;
#ifndef NO_FP
case 'f': PrintFP(COERCE_FP(NextArg), Stream); break;
case 'f': PrintFP(NextArg->Val->FP, Stream); break;
#endif
}
}
Expand Down
24 changes: 8 additions & 16 deletions expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -1095,27 +1095,19 @@ void ExpressionParseFunctionCall(struct ParseState *Parser, struct ExpressionSta
if (FuncValue->Val->FuncDef.ParamType[ArgCount] != Param->Typ)
{
/* parameter is the wrong type - can we coerce it to being the type we want? */
if (IS_NUMERIC_COERCIBLE(Param))
{
int IntVal = COERCE_INTEGER(Param); /* cast to int */
#ifndef NO_FP
double FloatVal = COERCE_FP(Param); /* cast to float */
#endif
VariableStackPop(Parser, Param);
Param = VariableAllocValueFromType(Parser, FuncValue->Val->FuncDef.ParamType[ArgCount], FALSE, NULL);
if (FuncValue->Val->FuncDef.ParamType[ArgCount] == &IntType && IS_NUMERIC_COERCIBLE(Param))
Param->Val->Integer = COERCE_INTEGER(Param); /* cast to int */

if (FuncValue->Val->FuncDef.ParamType[ArgCount] == &IntType)
Param->Val->Integer = IntVal;

else if (FuncValue->Val->FuncDef.ParamType[ArgCount] == &CharType)
Param->Val->Character = IntVal;
else if (FuncValue->Val->FuncDef.ParamType[ArgCount] == &CharType && IS_NUMERIC_COERCIBLE(Param))
Param->Val->Character = COERCE_INTEGER(Param); /* cast to char */
#ifndef NO_FP
else
Param->Val->FP = FloatVal;
else if (FuncValue->Val->FuncDef.ParamType[ArgCount] == &FPType && IS_NUMERIC_COERCIBLE(Param))
Param->Val->FP = COERCE_FP(Param); /* cast to floating point */
#endif
}
else
ProgramFail(Parser, "parameter %d to %s() is %t instead of %t", ArgCount+1, FuncName, Param->Typ, FuncValue->Val->FuncDef.ParamType[ArgCount]);

Param->Typ = FuncValue->Val->FuncDef.ParamType[ArgCount];
}

ParamArray[ArgCount] = Param;
Expand Down
45 changes: 0 additions & 45 deletions tests/23_type_coercion.c

This file was deleted.

15 changes: 0 additions & 15 deletions tests/23_type_coercion.expect

This file was deleted.

3 changes: 1 addition & 2 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ TESTS= 00_assignment.test \
18_include.test \
19_pointer_arithmetic.test \
20_pointer_comparison.test \
22_floating_point.test \
23_type_coercion.test
22_floating_point.test

%.test: %.expect %.c
@echo Test: $*...
Expand Down

0 comments on commit e33da74

Please sign in to comment.