Author: Remi Meier <remi.me...@inf.ethz.ch> Branch: Changeset: r1325:dbe9b14b252f Date: 2014-08-29 11:24 +0200 http://bitbucket.org/pypy/stmgc/changeset/dbe9b14b252f/
Log: Merge diff --git a/duhton/glob.c b/duhton/glob.c --- a/duhton/glob.c +++ b/duhton/glob.c @@ -144,24 +144,13 @@ DuObject *du_xor(DuObject *cons, DuObject *locals) { int result = 0; - /* _du_read1(cons); IMMUTABLE */ - DuObject *expr = _DuCons_CAR(cons); - DuObject *next = _DuCons_NEXT(cons); - - _du_save2(next, locals); - DuObject *obj = Du_Eval(expr, locals); - result = DuInt_AsInt(obj); - _du_restore2(next, locals); - - cons = next; - while (cons != Du_None) { /* _du_read1(cons); IMMUTABLE */ - expr = _DuCons_CAR(cons); - next = _DuCons_NEXT(cons); + DuObject *expr = _DuCons_CAR(cons); + DuObject *next = _DuCons_NEXT(cons); _du_save2(next, locals); - obj = Du_Eval(expr, locals); + DuObject *obj = Du_Eval(expr, locals); result ^= DuInt_AsInt(obj); _du_restore2(next, locals); @@ -353,8 +342,6 @@ case 3: r = a != b; break; case 4: r = a > b; break; case 5: r = a >= b; break; - case 6: r = a && b; break; - case 7: r = a || b; break; } return DuInt_FromInt(r); } @@ -371,11 +358,48 @@ { return _du_intcmp(cons, locals, 4); } DuObject *du_ge(DuObject *cons, DuObject *locals) { return _du_intcmp(cons, locals, 5); } + DuObject *du_and(DuObject *cons, DuObject *locals) -{ return _du_intcmp(cons, locals, 6); } +{ + while (cons != Du_None) { + /* _du_read1(cons); IMMUTABLE */ + DuObject *expr = _DuCons_CAR(cons); + DuObject *next = _DuCons_NEXT(cons); + + _du_save2(next, locals); + DuObject *obj = Du_Eval(expr, locals); + int result = DuObject_IsTrue(obj); + _du_restore2(next, locals); + + if (!result) + return DuInt_FromInt(0); + + cons = next; + } + + return DuInt_FromInt(1); +} + DuObject *du_or(DuObject *cons, DuObject *locals) -{ return _du_intcmp(cons, locals, 7); } +{ + while (cons != Du_None) { + /* _du_read1(cons); IMMUTABLE */ + DuObject *expr = _DuCons_CAR(cons); + DuObject *next = _DuCons_NEXT(cons); + _du_save2(next, locals); + DuObject *obj = Du_Eval(expr, locals); + int result = DuObject_IsTrue(obj); + _du_restore2(next, locals); + + if (result) + return DuInt_FromInt(1); + + cons = next; + } + + return DuInt_FromInt(0); +} DuObject *du_type(DuObject *cons, DuObject *locals) diff --git a/duhton/test/test_int.py b/duhton/test/test_int.py --- a/duhton/test/test_int.py +++ b/duhton/test/test_int.py @@ -20,9 +20,11 @@ assert evaluate("(* 2 3 7)") == 42 assert evaluate("(* (+ 5 1) (+ 6 1))") == 42 -def test_div(): +def test_div_mod(): assert evaluate("(/ 11 2)") == 5 assert evaluate("(/ 29 2 3)") == 4 + assert evaluate("(% 29 2)") == 1 + assert evaluate("(% 29 10 3)") == 0 def test_cmp(): assert evaluate("(< 6 6)") == 0 @@ -47,3 +49,35 @@ assert evaluate("(>= 7 6)") == 1 # assert evaluate("(< (+ 10 2) (+ 4 5))") == 0 + +def test_and_or(): + assert evaluate("(&& 1 1 1)") == 1 + assert evaluate("(&& 1 0 1)") == 0 + assert evaluate("(&& 0 sdfdsfsd)") == 0 + assert evaluate("(&& None)") == 0 + assert evaluate("(&& (quote bla))") == 1 + assert evaluate("(&& )") == 1 + + assert evaluate("(|| 0 1)") == 1 + assert evaluate("(|| 0 0 0 1)") == 1 + assert evaluate("(|| 0 0 0)") == 0 + assert evaluate("(|| 1 sdfdsfafds)") == 1 + assert evaluate("(|| None)") == 0 + assert evaluate("(|| (quote bla))") == 1 + assert evaluate("(|| )") == 0 + + +def test_shifts_bitwise(): + assert evaluate("(<< 1 1)") == 2 + assert evaluate("(<< 12)") == 12 + assert evaluate("(<< 1 1 1)") == 4 + assert evaluate("(<< 0 1)") == 0 + + assert evaluate("(>> 4 1 1)") == 1 + assert evaluate("(>> 4 3)") == 0 + assert evaluate("(>> 4)") == 4 + + assert evaluate("(^ 1 4)") == 1 ^ 4 + assert evaluate("(^ 1 4 122)") == 1 ^ 4 ^ 122 + assert evaluate("(^ 1)") == 1 + assert evaluate("(^)") == 0 _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit