Przeglądaj źródła

remove unused bc

blueloveTH 1 rok temu
rodzic
commit
97d6f384f4

+ 0 - 23
docs/features/incdec.md

@@ -1,23 +0,0 @@
----
-icon: dot
-title: Increment Statement
----
-
-pkpy provides `++i` and `--j` statements to operate a simple named `int` variable.
-
-+ `++i` is equivalent to `i+=1`, but much faster
-+ `--j` is equivalent to `j-=1`, but much faster
-
-## Example
-
-```python
-a = 1
-++a
-assert a == 2
-
-def f(a):
-  --a
-  return a
-
-assert f(3) == 2
-```

+ 0 - 4
include/pocketpy/opcodes.h

@@ -149,8 +149,4 @@ OPCODE(POP_EXCEPTION)
 /**************************/
 /**************************/
 OPCODE(FORMAT_STRING)
 OPCODE(FORMAT_STRING)
 /**************************/
 /**************************/
-OPCODE(INC_FAST)
-OPCODE(DEC_FAST)
-OPCODE(INC_GLOBAL)
-OPCODE(DEC_GLOBAL)
 #endif
 #endif

+ 1 - 1
python/builtins.py

@@ -16,7 +16,7 @@ def enumerate(iterable, start=0):
     n = start
     n = start
     for elem in iterable:
     for elem in iterable:
         yield n, elem
         yield n, elem
-        ++n
+        n += 1
 
 
 def sum(iterable):
 def sum(iterable):
     res = 0
     res = 0

Plik diff jest za duży
+ 0 - 0
src/common/_generated.cpp


+ 0 - 25
src/compiler/compiler.cpp

@@ -864,31 +864,6 @@ void Compiler::compile_stmt() {
         case TK("try"): compile_try_except(); break;
         case TK("try"): compile_try_except(); break;
         case TK("pass"): consume_end_stmt(); break;
         case TK("pass"): consume_end_stmt(); break;
         /*************************************************/
         /*************************************************/
-        case TK("++"): {
-            consume(TK("@id"));
-            StrName name(prev().sv());
-            NameScope scope = name_scope();
-            bool is_global = ctx()->global_names.contains(name.sv());
-            if(is_global) scope = NAME_GLOBAL;
-            switch(scope) {
-                case NAME_LOCAL: ctx()->emit_(OP_INC_FAST, ctx()->add_varname(name), prev().line); break;
-                case NAME_GLOBAL: ctx()->emit_(OP_INC_GLOBAL, name.index, prev().line); break;
-                default: SyntaxError(); break;
-            }
-            consume_end_stmt();
-            break;
-        }
-        case TK("--"): {
-            consume(TK("@id"));
-            StrName name(prev().sv());
-            switch(name_scope()) {
-                case NAME_LOCAL: ctx()->emit_(OP_DEC_FAST, ctx()->add_varname(name), prev().line); break;
-                case NAME_GLOBAL: ctx()->emit_(OP_DEC_GLOBAL, name.index, prev().line); break;
-                default: SyntaxError(); break;
-            }
-            consume_end_stmt();
-            break;
-        }
         case TK("assert"): {
         case TK("assert"): {
             EXPR();  // condition
             EXPR();  // condition
             ctx()->emit_expr();
             ctx()->emit_expr();

+ 0 - 27
src/interpreter/ceval.cpp

@@ -1127,33 +1127,6 @@ PyVar VM::__run_top_frame() {
                     }
                     }
                         DISPATCH()
                         DISPATCH()
                     /*****************************************/
                     /*****************************************/
-                    case OP_INC_FAST: {
-                        PyVar* p = &frame->_locals[byte.arg];
-                        if(*p == PY_NULL) vm->NameError(frame->co->varnames[byte.arg]);
-                        *p = VAR(CAST(i64, *p) + 1);
-                    }
-                        DISPATCH()
-                    case OP_DEC_FAST: {
-                        PyVar* p = &frame->_locals[byte.arg];
-                        if(*p == PY_NULL) vm->NameError(frame->co->varnames[byte.arg]);
-                        *p = VAR(CAST(i64, *p) - 1);
-                    }
-                        DISPATCH()
-                    case OP_INC_GLOBAL: {
-                        StrName _name(byte.arg);
-                        PyVar* p = frame->f_globals().try_get_2_likely_found(_name);
-                        if(p == nullptr) vm->NameError(_name);
-                        *p = VAR(CAST(i64, *p) + 1);
-                    }
-                        DISPATCH()
-                    case OP_DEC_GLOBAL: {
-                        StrName _name(byte.arg);
-                        PyVar* p = frame->f_globals().try_get_2_likely_found(_name);
-                        if(p == nullptr) vm->NameError(_name);
-                        *p = VAR(CAST(i64, *p) - 1);
-                    }
-                        DISPATCH()
-                    /*****************************************/
                     default: PK_UNREACHABLE()
                     default: PK_UNREACHABLE()
                 }
                 }
             }
             }

+ 0 - 4
src/interpreter/vm.cpp

@@ -758,15 +758,11 @@ static std::string _opcode_argstr(VM* vm, int i, Bytecode byte, const CodeObject
         case OP_BEGIN_CLASS:
         case OP_BEGIN_CLASS:
         case OP_GOTO:
         case OP_GOTO:
         case OP_DELETE_GLOBAL:
         case OP_DELETE_GLOBAL:
-        case OP_INC_GLOBAL:
-        case OP_DEC_GLOBAL:
         case OP_STORE_CLASS_ATTR:
         case OP_STORE_CLASS_ATTR:
         case OP_FOR_ITER_STORE_GLOBAL: ss << " (" << StrName(byte.arg).sv() << ")"; break;
         case OP_FOR_ITER_STORE_GLOBAL: ss << " (" << StrName(byte.arg).sv() << ")"; break;
         case OP_LOAD_FAST:
         case OP_LOAD_FAST:
         case OP_STORE_FAST:
         case OP_STORE_FAST:
         case OP_DELETE_FAST:
         case OP_DELETE_FAST:
-        case OP_INC_FAST:
-        case OP_DEC_FAST:
         case OP_FOR_ITER_STORE_FAST:
         case OP_FOR_ITER_STORE_FAST:
         case OP_LOAD_SUBSCR_FAST:
         case OP_LOAD_SUBSCR_FAST:
         case OP_STORE_SUBSCR_FAST: ss << " (" << co->varnames[byte.arg].sv() << ")"; break;
         case OP_STORE_SUBSCR_FAST: ss << " (" << co->varnames[byte.arg].sv() << ")"; break;

+ 12 - 12
tests/29_incdec.py

@@ -1,15 +1,15 @@
-a = 1
+# a = 1
 
 
-++a
-assert a == 2
-++a; ++a; --a;
-assert a == 3
+# ++a
+# assert a == 2
+# ++a; ++a; --a;
+# assert a == 3
 
 
-def f(a):
-    ++a
-    ++a
-    --a
-    return a
+# def f(a):
+#     ++a
+#     ++a
+#     --a
+#     return a
 
 
-assert f(3) == 4
-assert f(-2) == -1
+# assert f(3) == 4
+# assert f(-2) == -1

+ 1 - 1
tests/99_bugs.py

@@ -91,7 +91,7 @@ except UnboundLocalError:
 g = 1
 g = 1
 def f():
 def f():
     global g
     global g
-    ++g
+    g += 1
 
 
 f(); f()
 f(); f()
 assert g == 3
 assert g == 3

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików