diff options
| author | CoprDistGit <infra@openeuler.org> | 2023-06-08 15:17:25 +0000 |
|---|---|---|
| committer | CoprDistGit <infra@openeuler.org> | 2023-06-08 15:17:25 +0000 |
| commit | 23e558b9021bc576d8375111c324e49fce153708 (patch) | |
| tree | cbc3eef169b5a1779f5dea3461930b0b9ef29d24 | |
| parent | 4fa9c638f4d2141d1b6f73d74b1a2605b0c98b36 (diff) | |
automatic import of python-goto-statementopeneuler20.03
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | python-goto-statement.spec | 564 | ||||
| -rw-r--r-- | sources | 1 |
3 files changed, 566 insertions, 0 deletions
@@ -0,0 +1 @@ +/goto-statement-1.2.tar.gz diff --git a/python-goto-statement.spec b/python-goto-statement.spec new file mode 100644 index 0000000..d4c00c7 --- /dev/null +++ b/python-goto-statement.spec @@ -0,0 +1,564 @@ +%global _empty_manifest_terminate_build 0 +Name: python-goto-statement +Version: 1.2 +Release: 1 +Summary: A function decorator, that rewrites the bytecode, to enable goto in Python +License: Public Domain +URL: https://github.com/snoack/python-goto/ +Source0: https://mirrors.aliyun.com/pypi/web/packages/82/be/f2c30d577110f05a3a9e97e84b586a1564f9abbb8f8317c92e0cad82e099/goto-statement-1.2.tar.gz +BuildArch: noarch + + +%description +# goto + +[](https://travis-ci.org/snoack/python-goto) +[](https://pypi.python.org/pypi/goto-statement) + +A function decorator to use `goto` in Python. +Tested on Python 2.6 through 3.6 and PyPy. + +[](https://xkcd.com/292/) + +## Installation + +``` +pip install goto-statement +``` + +## Usage + +```python +from goto import with_goto + +@with_goto +def range(start, stop): + i = start + result = [] + + label .begin + if i == stop: + goto .end + + result.append(i) + i += 1 + goto .begin + + label .end + return result +``` + +## Implementation + +Note that `label .begin` and `goto .begin` is regular Python syntax to retrieve +the attribute `begin` from the objects with the variable names `label` and +`goto`. However, in the example above these variables aren't defined. +So this code would usually cause a `NameError`. But since it's valid +syntax the function can be parsed, and results in following bytecode: + + +``` + 2 0 LOAD_FAST 0 (start) + 3 STORE_FAST 2 (i) + + 3 6 BUILD_LIST 0 + 9 STORE_FAST 3 (result) + + 5 12 LOAD_GLOBAL 0 (label) + 15 LOAD_ATTR 1 (begin) + 18 POP_TOP + + 6 19 LOAD_FAST 2 (i) + 22 LOAD_FAST 1 (stop) + 25 COMPARE_OP 2 (==) + 28 POP_JUMP_IF_FALSE 41 + + 7 31 LOAD_GLOBAL 2 (goto) + 34 LOAD_ATTR 3 (end) + 37 POP_TOP + 38 JUMP_FORWARD 0 (to 41) + + 9 >> 41 LOAD_FAST 3 (result) + 44 LOAD_ATTR 4 (append) + 47 LOAD_FAST 2 (i) + 50 CALL_FUNCTION 1 + 53 POP_TOP + + 10 54 LOAD_FAST 2 (i) + 57 LOAD_CONST 1 (1) + 60 INPLACE_ADD + 61 STORE_FAST 2 (i) + + 11 64 LOAD_GLOBAL 2 (goto) + 67 LOAD_ATTR 1 (begin) + 70 POP_TOP + + 13 71 LOAD_GLOBAL 0 (label) + 74 LOAD_ATTR 3 (end) + 77 POP_TOP + + 14 78 LOAD_FAST 3 (result) + 81 RETURN_VALUE +``` + +The `with_goto` decorator then removes the respective bytecode that has been +generated for the attribute lookups of the `label` and `goto` variables, and +injects a `JUMP_ABSOLUTE` instruction for each `goto`: + +``` + 2 0 LOAD_FAST 0 (start) + 3 STORE_FAST 2 (i) + + 3 6 BUILD_LIST 0 + 9 STORE_FAST 3 (result) + + 5 12 NOP + 13 NOP + 14 NOP + 15 NOP + 16 NOP + 17 NOP + 18 NOP + + 6 >> 19 LOAD_FAST 2 (i) + 22 LOAD_FAST 1 (stop) + 25 COMPARE_OP 2 (==) + 28 POP_JUMP_IF_FALSE 41 + + 7 31 JUMP_ABSOLUTE 78 + 34 NOP + 35 NOP + 36 NOP + 37 NOP + 38 JUMP_FORWARD 0 (to 41) + + 9 >> 41 LOAD_FAST 3 (result) + 44 LOAD_ATTR 4 (append) + 47 LOAD_FAST 2 (i) + 50 CALL_FUNCTION 1 + 53 POP_TOP + + 10 54 LOAD_FAST 2 (i) + 57 LOAD_CONST 1 (1) + 60 INPLACE_ADD + 61 STORE_FAST 2 (i) + + 11 64 JUMP_ABSOLUTE 19 + 67 NOP + 68 NOP + 69 NOP + 70 NOP + + 13 71 NOP + 72 NOP + 73 NOP + 74 NOP + 75 NOP + 76 NOP + 77 NOP + + 14 >> 78 LOAD_FAST 3 (result) + 81 RETURN_VALUE +``` + +## Alternative implementation + +The idea of `goto` in Python isn't new. +There is [another module](http://entrian.com/goto/) that has been released +as April Fool's joke in 2004. That implementation doesn't touch the bytecode, +but uses a trace function, similar to how debuggers are written. + +While this eliminates the need for a decorator, it comes with significant +runtime overhead and a more elaborate implementation. Modifying the bytecode, +on the other hand, is fairly simple and doesn't add overhead at function +execution. + + + + +%package -n python3-goto-statement +Summary: A function decorator, that rewrites the bytecode, to enable goto in Python +Provides: python-goto-statement +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-goto-statement +# goto + +[](https://travis-ci.org/snoack/python-goto) +[](https://pypi.python.org/pypi/goto-statement) + +A function decorator to use `goto` in Python. +Tested on Python 2.6 through 3.6 and PyPy. + +[](https://xkcd.com/292/) + +## Installation + +``` +pip install goto-statement +``` + +## Usage + +```python +from goto import with_goto + +@with_goto +def range(start, stop): + i = start + result = [] + + label .begin + if i == stop: + goto .end + + result.append(i) + i += 1 + goto .begin + + label .end + return result +``` + +## Implementation + +Note that `label .begin` and `goto .begin` is regular Python syntax to retrieve +the attribute `begin` from the objects with the variable names `label` and +`goto`. However, in the example above these variables aren't defined. +So this code would usually cause a `NameError`. But since it's valid +syntax the function can be parsed, and results in following bytecode: + + +``` + 2 0 LOAD_FAST 0 (start) + 3 STORE_FAST 2 (i) + + 3 6 BUILD_LIST 0 + 9 STORE_FAST 3 (result) + + 5 12 LOAD_GLOBAL 0 (label) + 15 LOAD_ATTR 1 (begin) + 18 POP_TOP + + 6 19 LOAD_FAST 2 (i) + 22 LOAD_FAST 1 (stop) + 25 COMPARE_OP 2 (==) + 28 POP_JUMP_IF_FALSE 41 + + 7 31 LOAD_GLOBAL 2 (goto) + 34 LOAD_ATTR 3 (end) + 37 POP_TOP + 38 JUMP_FORWARD 0 (to 41) + + 9 >> 41 LOAD_FAST 3 (result) + 44 LOAD_ATTR 4 (append) + 47 LOAD_FAST 2 (i) + 50 CALL_FUNCTION 1 + 53 POP_TOP + + 10 54 LOAD_FAST 2 (i) + 57 LOAD_CONST 1 (1) + 60 INPLACE_ADD + 61 STORE_FAST 2 (i) + + 11 64 LOAD_GLOBAL 2 (goto) + 67 LOAD_ATTR 1 (begin) + 70 POP_TOP + + 13 71 LOAD_GLOBAL 0 (label) + 74 LOAD_ATTR 3 (end) + 77 POP_TOP + + 14 78 LOAD_FAST 3 (result) + 81 RETURN_VALUE +``` + +The `with_goto` decorator then removes the respective bytecode that has been +generated for the attribute lookups of the `label` and `goto` variables, and +injects a `JUMP_ABSOLUTE` instruction for each `goto`: + +``` + 2 0 LOAD_FAST 0 (start) + 3 STORE_FAST 2 (i) + + 3 6 BUILD_LIST 0 + 9 STORE_FAST 3 (result) + + 5 12 NOP + 13 NOP + 14 NOP + 15 NOP + 16 NOP + 17 NOP + 18 NOP + + 6 >> 19 LOAD_FAST 2 (i) + 22 LOAD_FAST 1 (stop) + 25 COMPARE_OP 2 (==) + 28 POP_JUMP_IF_FALSE 41 + + 7 31 JUMP_ABSOLUTE 78 + 34 NOP + 35 NOP + 36 NOP + 37 NOP + 38 JUMP_FORWARD 0 (to 41) + + 9 >> 41 LOAD_FAST 3 (result) + 44 LOAD_ATTR 4 (append) + 47 LOAD_FAST 2 (i) + 50 CALL_FUNCTION 1 + 53 POP_TOP + + 10 54 LOAD_FAST 2 (i) + 57 LOAD_CONST 1 (1) + 60 INPLACE_ADD + 61 STORE_FAST 2 (i) + + 11 64 JUMP_ABSOLUTE 19 + 67 NOP + 68 NOP + 69 NOP + 70 NOP + + 13 71 NOP + 72 NOP + 73 NOP + 74 NOP + 75 NOP + 76 NOP + 77 NOP + + 14 >> 78 LOAD_FAST 3 (result) + 81 RETURN_VALUE +``` + +## Alternative implementation + +The idea of `goto` in Python isn't new. +There is [another module](http://entrian.com/goto/) that has been released +as April Fool's joke in 2004. That implementation doesn't touch the bytecode, +but uses a trace function, similar to how debuggers are written. + +While this eliminates the need for a decorator, it comes with significant +runtime overhead and a more elaborate implementation. Modifying the bytecode, +on the other hand, is fairly simple and doesn't add overhead at function +execution. + + + + +%package help +Summary: Development documents and examples for goto-statement +Provides: python3-goto-statement-doc +%description help +# goto + +[](https://travis-ci.org/snoack/python-goto) +[](https://pypi.python.org/pypi/goto-statement) + +A function decorator to use `goto` in Python. +Tested on Python 2.6 through 3.6 and PyPy. + +[](https://xkcd.com/292/) + +## Installation + +``` +pip install goto-statement +``` + +## Usage + +```python +from goto import with_goto + +@with_goto +def range(start, stop): + i = start + result = [] + + label .begin + if i == stop: + goto .end + + result.append(i) + i += 1 + goto .begin + + label .end + return result +``` + +## Implementation + +Note that `label .begin` and `goto .begin` is regular Python syntax to retrieve +the attribute `begin` from the objects with the variable names `label` and +`goto`. However, in the example above these variables aren't defined. +So this code would usually cause a `NameError`. But since it's valid +syntax the function can be parsed, and results in following bytecode: + + +``` + 2 0 LOAD_FAST 0 (start) + 3 STORE_FAST 2 (i) + + 3 6 BUILD_LIST 0 + 9 STORE_FAST 3 (result) + + 5 12 LOAD_GLOBAL 0 (label) + 15 LOAD_ATTR 1 (begin) + 18 POP_TOP + + 6 19 LOAD_FAST 2 (i) + 22 LOAD_FAST 1 (stop) + 25 COMPARE_OP 2 (==) + 28 POP_JUMP_IF_FALSE 41 + + 7 31 LOAD_GLOBAL 2 (goto) + 34 LOAD_ATTR 3 (end) + 37 POP_TOP + 38 JUMP_FORWARD 0 (to 41) + + 9 >> 41 LOAD_FAST 3 (result) + 44 LOAD_ATTR 4 (append) + 47 LOAD_FAST 2 (i) + 50 CALL_FUNCTION 1 + 53 POP_TOP + + 10 54 LOAD_FAST 2 (i) + 57 LOAD_CONST 1 (1) + 60 INPLACE_ADD + 61 STORE_FAST 2 (i) + + 11 64 LOAD_GLOBAL 2 (goto) + 67 LOAD_ATTR 1 (begin) + 70 POP_TOP + + 13 71 LOAD_GLOBAL 0 (label) + 74 LOAD_ATTR 3 (end) + 77 POP_TOP + + 14 78 LOAD_FAST 3 (result) + 81 RETURN_VALUE +``` + +The `with_goto` decorator then removes the respective bytecode that has been +generated for the attribute lookups of the `label` and `goto` variables, and +injects a `JUMP_ABSOLUTE` instruction for each `goto`: + +``` + 2 0 LOAD_FAST 0 (start) + 3 STORE_FAST 2 (i) + + 3 6 BUILD_LIST 0 + 9 STORE_FAST 3 (result) + + 5 12 NOP + 13 NOP + 14 NOP + 15 NOP + 16 NOP + 17 NOP + 18 NOP + + 6 >> 19 LOAD_FAST 2 (i) + 22 LOAD_FAST 1 (stop) + 25 COMPARE_OP 2 (==) + 28 POP_JUMP_IF_FALSE 41 + + 7 31 JUMP_ABSOLUTE 78 + 34 NOP + 35 NOP + 36 NOP + 37 NOP + 38 JUMP_FORWARD 0 (to 41) + + 9 >> 41 LOAD_FAST 3 (result) + 44 LOAD_ATTR 4 (append) + 47 LOAD_FAST 2 (i) + 50 CALL_FUNCTION 1 + 53 POP_TOP + + 10 54 LOAD_FAST 2 (i) + 57 LOAD_CONST 1 (1) + 60 INPLACE_ADD + 61 STORE_FAST 2 (i) + + 11 64 JUMP_ABSOLUTE 19 + 67 NOP + 68 NOP + 69 NOP + 70 NOP + + 13 71 NOP + 72 NOP + 73 NOP + 74 NOP + 75 NOP + 76 NOP + 77 NOP + + 14 >> 78 LOAD_FAST 3 (result) + 81 RETURN_VALUE +``` + +## Alternative implementation + +The idea of `goto` in Python isn't new. +There is [another module](http://entrian.com/goto/) that has been released +as April Fool's joke in 2004. That implementation doesn't touch the bytecode, +but uses a trace function, similar to how debuggers are written. + +While this eliminates the need for a decorator, it comes with significant +runtime overhead and a more elaborate implementation. Modifying the bytecode, +on the other hand, is fairly simple and doesn't add overhead at function +execution. + + + + +%prep +%autosetup -n goto-statement-1.2 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "\"/%h/%f\"\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "\"/%h/%f\"\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "\"/%h/%f\"\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "\"/%h/%f\"\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "\"/%h/%f.gz\"\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-goto-statement -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Thu Jun 08 2023 Python_Bot <Python_Bot@openeuler.org> - 1.2-1 +- Package Spec generated @@ -0,0 +1 @@ +785c11581cae5f68f57d1efc9bb6a281 goto-statement-1.2.tar.gz |
