diff --git a/python/builtins.py b/python/builtins.py index 41d7f669..3a578bfd 100644 --- a/python/builtins.py +++ b/python/builtins.py @@ -38,7 +38,7 @@ def enumerate(iterable, start=0): n = start for elem in iterable: yield n, elem - n += 1 + ++n def sum(iterable): res = 0 @@ -87,7 +87,7 @@ def str@split(self, sep): self = self[i+len(sep):] i = 0 else: - i += 1 + ++i res.append(self) return res @@ -104,10 +104,10 @@ def str@strip(self, chars=None): chars = chars or ' \t\n\r' i = 0 while i < len(self) and self[i] in chars: - i += 1 + ++i j = len(self) - 1 while j >= 0 and self[j] in chars: - j -= 1 + --j return self[i:j+1] ##### list ##### @@ -122,12 +122,11 @@ def __qsort(a: list, L: int, R: int, key): mid = key(mid) i, j = L, R while i<=j: - while key(a[i])mid: j-=1 + while key(a[i])mid: --j; if i<=j: a[i], a[j] = a[j], a[i] - i+=1 - j-=1 + ++i; --j; __qsort(a, L, j, key) __qsort(a, i, R, key) diff --git a/src/vm.h b/src/vm.h index 550c35a7..1b9f3f98 100644 --- a/src/vm.h +++ b/src/vm.h @@ -934,10 +934,10 @@ inline std::string _opcode_argstr(VM* vm, Bytecode byte, const CodeObject* co){ case OP_LOAD_NAME: case OP_LOAD_GLOBAL: case OP_LOAD_NONLOCAL: case OP_STORE_GLOBAL: case OP_LOAD_ATTR: case OP_LOAD_METHOD: case OP_STORE_ATTR: case OP_DELETE_ATTR: case OP_IMPORT_NAME: case OP_BEGIN_CLASS: - case OP_DELETE_GLOBAL: + case OP_DELETE_GLOBAL: case OP_INC_GLOBAL: case OP_DEC_GLOBAL: argStr += fmt(" (", StrName(byte.arg).sv(), ")"); break; - case OP_LOAD_FAST: case OP_STORE_FAST: case OP_DELETE_FAST: + case OP_LOAD_FAST: case OP_STORE_FAST: case OP_DELETE_FAST: case OP_INC_FAST: case OP_DEC_FAST: argStr += fmt(" (", co->varnames[byte.arg].sv(), ")"); break; case OP_LOAD_FUNCTION: diff --git a/tests/29_incdec.py b/tests/29_incdec.py new file mode 100644 index 00000000..222af881 --- /dev/null +++ b/tests/29_incdec.py @@ -0,0 +1,15 @@ +a = 1 + +++a +assert a == 2 +++a; ++a; --a; +assert a == 3 + +def f(a): + ++a + ++a + --a + return a + +assert f(3) == 4 +assert f(-2) == -1 \ No newline at end of file