fix the unary not (logical not) handling for issue #5, add tests
This commit is contained in:
parent
63cd9d074b
commit
e780f43222
12
expression.c
12
expression.c
|
@ -761,23 +761,25 @@ void ExpressionPrefixOperator(struct ParseState *Parser,
|
||||||
ProgramFail(Parser, "can't assign to this");
|
ProgramFail(Parser, "can't assign to this");
|
||||||
switch (Op) {
|
switch (Op) {
|
||||||
case TokenIncrement:
|
case TokenIncrement:
|
||||||
TopValue->Val->Pointer =
|
ResultPtr = TopValue->Val->Pointer =
|
||||||
(void*)((char*)TopValue->Val->Pointer+Size);
|
(void*)((char*)TopValue->Val->Pointer+Size);
|
||||||
break;
|
break;
|
||||||
case TokenDecrement:
|
case TokenDecrement:
|
||||||
TopValue->Val->Pointer =
|
ResultPtr = TopValue->Val->Pointer =
|
||||||
(void*)((char*)TopValue->Val->Pointer-Size);
|
(void*)((char*)TopValue->Val->Pointer-Size);
|
||||||
break;
|
break;
|
||||||
case TokenUnaryNot:
|
case TokenUnaryNot:
|
||||||
/* conditionally checking a pointer's value */
|
/* conditionally checking a pointer's value, we only want
|
||||||
|
to change the stack value (ResultPtr) and not the pointer's
|
||||||
|
actual value */
|
||||||
TopValue->Val->Pointer =
|
TopValue->Val->Pointer =
|
||||||
(void*)((TopValue->Val->Pointer) ? NULL : (void*)1);
|
(void*)((char*)TopValue->Val->Pointer);
|
||||||
|
ResultPtr = TopValue->Val->Pointer ? NULL : (void*)0x01;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ProgramFail(Parser, "invalid operation");
|
ProgramFail(Parser, "invalid operation");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ResultPtr = TopValue->Val->Pointer;
|
|
||||||
StackValue = ExpressionStackPushValueByType(Parser, StackTop,
|
StackValue = ExpressionStackPushValueByType(Parser, StackTop,
|
||||||
TopValue->Typ);
|
TopValue->Typ);
|
||||||
StackValue->Val->Pointer = ResultPtr;
|
StackValue->Val->Pointer = ResultPtr;
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
int a;
|
int a;
|
||||||
int p;
|
int p;
|
||||||
int t;
|
int t;
|
||||||
|
int *pp;
|
||||||
|
|
||||||
a = 1;
|
a = 1;
|
||||||
p = 0;
|
p = 0;
|
||||||
|
@ -16,4 +17,22 @@ while (a < 100)
|
||||||
p = t;
|
p = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a = 0;
|
||||||
|
pp = NULL;
|
||||||
|
while (!pp) {
|
||||||
|
printf("%d\n", a);
|
||||||
|
a += 1;
|
||||||
|
if (a == 8)
|
||||||
|
pp = &a;
|
||||||
|
}
|
||||||
|
|
||||||
|
p = 10;
|
||||||
|
pp = &p;
|
||||||
|
while (pp) {
|
||||||
|
printf("%d\n", p);
|
||||||
|
p -= 1;
|
||||||
|
if (p == 2)
|
||||||
|
pp = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void main() {}
|
void main() {}
|
||||||
|
|
|
@ -9,3 +9,19 @@
|
||||||
34
|
34
|
||||||
55
|
55
|
||||||
89
|
89
|
||||||
|
0
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
4
|
||||||
|
5
|
||||||
|
6
|
||||||
|
7
|
||||||
|
10
|
||||||
|
9
|
||||||
|
8
|
||||||
|
7
|
||||||
|
6
|
||||||
|
5
|
||||||
|
4
|
||||||
|
3
|
||||||
|
|
Loading…
Reference in a new issue