• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/corennnnn


Commit MetaInfo

Revisión0c01774816245e59aac7f2109c28523eeb6492ac (tree)
Tiempo2009-08-01 04:00:39
AutorJack Palevich <jackpal@goog...>
CommiterJack Palevich

Log Message

Implement op=.

Cambiar Resumen

Diferencia incremental

--- a/libacc/acc.cpp
+++ b/libacc/acc.cpp
@@ -3188,6 +3188,7 @@ class Compiler : public ErrorSink {
31883188 static const int TOK_NUM = 2;
31893189 static const int TOK_NUM_FLOAT = 3;
31903190 static const int TOK_NUM_DOUBLE = 4;
3191+ static const int TOK_OP_ASSIGNMENT = 5;
31913192
31923193 // 3..255 are character and/or operators
31933194
@@ -3626,6 +3627,13 @@ class Compiler : public ErrorSink {
36263627 inp();
36273628 tok = TOK_DUMMY; /* dummy token for double tokens */
36283629 }
3630+ /* check for op=, valid for * / % + - << >> & ^ | */
3631+ if (ch == '=' &&
3632+ ((tokl >= 1 && tokl <= 3)
3633+ || tokl >=6 && tokl <= 8) ) {
3634+ inp();
3635+ tok = TOK_OP_ASSIGNMENT;
3636+ }
36293637 break;
36303638 }
36313639 opIndex++;
@@ -3797,6 +3805,17 @@ class Compiler : public ErrorSink {
37973805 expr();
37983806 pGen->forceR0RVal();
37993807 pGen->storeR0ToTOS();
3808+ } else if (tok == TOK_OP_ASSIGNMENT) {
3809+ int t = tokc;
3810+ next();
3811+ checkLVal();
3812+ pGen->pushR0();
3813+ pGen->forceR0RVal();
3814+ pGen->pushR0();
3815+ expr();
3816+ pGen->forceR0RVal();
3817+ pGen->genOp(t);
3818+ pGen->storeR0ToTOS();
38003819 }
38013820 }
38023821
--- /dev/null
+++ b/libacc/tests/data/assignmentop.c
@@ -0,0 +1,66 @@
1+// Test assignment operations
2+
3+void testAssignment() {
4+ int a = 2;
5+ a *= 5;
6+ printf("2 *= 5 %d\n", a);
7+ a = 20;
8+ a /= 5;
9+ printf("20 /= 5 %d\n", a);
10+ a = 17;
11+ a %= 5;
12+ printf("17 %%= 5 %d\n", a);
13+ a = 17;
14+ a += 5;
15+ printf("17 += 5 %d\n", a);
16+ a = 17;
17+ a-=5;
18+ printf("17 -= 5 %d\n", a);
19+ a = 17;
20+ a<<=1;
21+ printf("17<<= 1 %d\n", a);
22+ a = 17;
23+ a>>=1;
24+ printf("17>>= 1 %d\n", a);
25+ a = 17;
26+ a&=1;
27+ printf("17&= 1 %d\n", a);
28+ a = 17;
29+ a^=1;
30+ printf("17^= 1 %d\n", a);
31+ a = 16;
32+ a^=1;
33+ printf("16|= 1 %d\n", a);
34+}
35+
36+/* Can't use because int* f() is not parsed as a function decl.
37+int a;
38+
39+int* f() {
40+ printf("f()\n");
41+ return &a;
42+}
43+
44+void testEval() {
45+ a = 0;
46+ printf("*f() = *f() + 10;");
47+ *f() = *f() + 10;
48+ printf("a = %d\n", a);
49+}
50+
51+void testOpEval() {
52+ a = 0;
53+ printf("*f() += 10;");
54+ *f() += 10;
55+ printf("a = %d\n", a);
56+}
57+
58+*/
59+int main() {
60+ testAssignment();
61+ /*
62+ testEval();
63+ testOpEval();
64+ */
65+ return 0;
66+}
--- a/libacc/tests/test.py
+++ b/libacc/tests/test.py
@@ -340,6 +340,20 @@ a = 0, *pa = 0 **ppa = 0
340340 a = 2, *pa = 2 **ppa = 2
341341 """)
342342
343+ def testassignmentop(self):
344+ self.compileCheck(["-R", "data/assignmentop.c"], """Executing compiled code:
345+result: 0""", """2 *= 5 10
346+20 /= 5 4
347+17 %= 5 2
348+17 += 5 22
349+17 -= 5 12
350+17<<= 1 34
351+17>>= 1 8
352+17&= 1 1
353+17^= 1 16
354+16|= 1 17
355+""")
356+
343357 if __name__ == '__main__':
344358 if not outputCanRun():
345359 print "Many tests are expected to fail, because acc is not a 32-bit x86 Linux executable."