├── .gitmodules ├── src └── main │ ├── resources │ ├── assets │ │ └── openpython │ │ │ ├── opos │ │ │ ├── v1.0 │ │ │ │ ├── usr │ │ │ │ │ └── bin │ │ │ │ │ │ └── env.py │ │ │ │ ├── lib │ │ │ │ │ ├── urllib │ │ │ │ │ │ └── request.py │ │ │ │ │ ├── micropython │ │ │ │ │ │ ├── binhex.py │ │ │ │ │ │ ├── code.py │ │ │ │ │ │ ├── codecs.py │ │ │ │ │ │ ├── codeop.py │ │ │ │ │ │ ├── csv.py │ │ │ │ │ │ ├── dbm.py │ │ │ │ │ │ ├── decimal.py │ │ │ │ │ │ ├── difflib.py │ │ │ │ │ │ ├── ftplib.py │ │ │ │ │ │ ├── getpass.py │ │ │ │ │ │ ├── imaplib.py │ │ │ │ │ │ ├── imp.py │ │ │ │ │ │ ├── mailbox.py │ │ │ │ │ │ ├── mailcap.py │ │ │ │ │ │ ├── nntplib.py │ │ │ │ │ │ ├── numbers.py │ │ │ │ │ │ ├── pathlib.py │ │ │ │ │ │ ├── pdb.py │ │ │ │ │ │ ├── poplib.py │ │ │ │ │ │ ├── profile.py │ │ │ │ │ │ ├── pty.py │ │ │ │ │ │ ├── queue.py │ │ │ │ │ │ ├── reprlib.py │ │ │ │ │ │ ├── runpy.py │ │ │ │ │ │ ├── sched.py │ │ │ │ │ │ ├── shelve.py │ │ │ │ │ │ ├── shlex.py │ │ │ │ │ │ ├── smtplib.py │ │ │ │ │ │ ├── sys.py │ │ │ │ │ │ ├── tarfile.py │ │ │ │ │ │ ├── trace.py │ │ │ │ │ │ ├── typing.py │ │ │ │ │ │ ├── urllib.py │ │ │ │ │ │ ├── uuid.py │ │ │ │ │ │ ├── venv.py │ │ │ │ │ │ ├── zipfile.py │ │ │ │ │ │ ├── calendar.py │ │ │ │ │ │ ├── formatter.py │ │ │ │ │ │ ├── fractions.py │ │ │ │ │ │ ├── importlib.py │ │ │ │ │ │ ├── ipaddress.py │ │ │ │ │ │ ├── mimetypes.py │ │ │ │ │ │ ├── optparse.py │ │ │ │ │ │ ├── pickletools.py │ │ │ │ │ │ ├── platform.py │ │ │ │ │ │ ├── posixpath.py │ │ │ │ │ │ ├── readline.py │ │ │ │ │ │ ├── selectors.py │ │ │ │ │ │ ├── socketserver.py │ │ │ │ │ │ ├── statistics.py │ │ │ │ │ │ ├── stringprep.py │ │ │ │ │ │ ├── subprocess.py │ │ │ │ │ │ ├── telnetlib.py │ │ │ │ │ │ ├── tempfile.py │ │ │ │ │ │ ├── concurrent │ │ │ │ │ │ │ └── futures │ │ │ │ │ │ │ │ └── __init__.py │ │ │ │ │ │ ├── linecache.py │ │ │ │ │ │ ├── tty.py │ │ │ │ │ │ ├── zlib.py │ │ │ │ │ │ ├── abc.py │ │ │ │ │ │ ├── hashlib │ │ │ │ │ │ │ ├── _sha224.py │ │ │ │ │ │ │ ├── _sha384.py │ │ │ │ │ │ │ └── __init__.py │ │ │ │ │ │ ├── locale.py │ │ │ │ │ │ ├── io.py │ │ │ │ │ │ ├── pprint.py │ │ │ │ │ │ ├── unicodedata.py │ │ │ │ │ │ ├── warnings.py │ │ │ │ │ │ ├── machine │ │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ │ └── pin.py │ │ │ │ │ │ ├── __future__.py │ │ │ │ │ │ ├── weakref.py │ │ │ │ │ │ ├── pkgutil.py │ │ │ │ │ │ ├── gettext.py │ │ │ │ │ │ ├── struct.py │ │ │ │ │ │ ├── threading.py │ │ │ │ │ │ ├── signal.py │ │ │ │ │ │ ├── collections │ │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ │ ├── deque.py │ │ │ │ │ │ │ └── defaultdict.py │ │ │ │ │ │ ├── pyb.py │ │ │ │ │ │ ├── pickle.py │ │ │ │ │ │ ├── operator.py │ │ │ │ │ │ ├── random.py │ │ │ │ │ │ ├── gzip.py │ │ │ │ │ │ ├── pwd.py │ │ │ │ │ │ ├── _libc.py │ │ │ │ │ │ ├── traceback.py │ │ │ │ │ │ ├── functools.py │ │ │ │ │ │ ├── pkg_resources.py │ │ │ │ │ │ ├── html │ │ │ │ │ │ │ └── __init__.py │ │ │ │ │ │ ├── shutil.py │ │ │ │ │ │ ├── string.py │ │ │ │ │ │ ├── uasyncio │ │ │ │ │ │ │ ├── synchro.py │ │ │ │ │ │ │ ├── udp.py │ │ │ │ │ │ │ └── websocket │ │ │ │ │ │ │ │ └── server.py │ │ │ │ │ │ ├── fcntl.py │ │ │ │ │ │ ├── tests.py │ │ │ │ │ │ ├── ssl.py │ │ │ │ │ │ ├── json │ │ │ │ │ │ │ └── tool.py │ │ │ │ │ │ ├── ffilib.py │ │ │ │ │ │ ├── umqtt │ │ │ │ │ │ │ └── robust.py │ │ │ │ │ │ ├── os │ │ │ │ │ │ │ └── path.py │ │ │ │ │ │ ├── inspect.py │ │ │ │ │ │ ├── errno.py │ │ │ │ │ │ ├── socket.py │ │ │ │ │ │ ├── itertools.py │ │ │ │ │ │ ├── tests │ │ │ │ │ │ │ └── test.py │ │ │ │ │ │ ├── test │ │ │ │ │ │ │ └── support.py │ │ │ │ │ │ ├── upysh.py │ │ │ │ │ │ ├── udnspkt.py │ │ │ │ │ │ ├── urllib │ │ │ │ │ │ │ └── urequest.py │ │ │ │ │ │ └── time.py │ │ │ │ │ ├── imp.py │ │ │ │ │ ├── re.py │ │ │ │ │ ├── errno.py │ │ │ │ │ ├── heapq.py │ │ │ │ │ ├── json.py │ │ │ │ │ ├── time.py │ │ │ │ │ ├── computer.py │ │ │ │ │ ├── msgpack.py │ │ │ │ │ ├── random.py │ │ │ │ │ ├── shell.py │ │ │ │ │ ├── monitor.py │ │ │ │ │ ├── os.py │ │ │ │ │ ├── event.py │ │ │ │ │ ├── ocpath.py │ │ │ │ │ ├── value.py │ │ │ │ │ └── component.py │ │ │ │ ├── init.lua │ │ │ │ ├── boot │ │ │ │ │ ├── 98_filesystem.py │ │ │ │ │ ├── 01_basic.py │ │ │ │ │ ├── 03_builtin.py │ │ │ │ │ └── 02_screen.py │ │ │ │ ├── bin │ │ │ │ │ └── python.py │ │ │ │ └── init.py │ │ │ └── v1.1 │ │ │ │ ├── usr │ │ │ │ └── bin │ │ │ │ │ └── env.py │ │ │ │ ├── lib │ │ │ │ ├── urllib │ │ │ │ │ └── request.py │ │ │ │ ├── micropython │ │ │ │ │ ├── binhex.py │ │ │ │ │ ├── code.py │ │ │ │ │ ├── codecs.py │ │ │ │ │ ├── codeop.py │ │ │ │ │ ├── csv.py │ │ │ │ │ ├── dbm.py │ │ │ │ │ ├── decimal.py │ │ │ │ │ ├── difflib.py │ │ │ │ │ ├── ftplib.py │ │ │ │ │ ├── getpass.py │ │ │ │ │ ├── imaplib.py │ │ │ │ │ ├── imp.py │ │ │ │ │ ├── mailbox.py │ │ │ │ │ ├── mailcap.py │ │ │ │ │ ├── nntplib.py │ │ │ │ │ ├── numbers.py │ │ │ │ │ ├── pathlib.py │ │ │ │ │ ├── pdb.py │ │ │ │ │ ├── poplib.py │ │ │ │ │ ├── profile.py │ │ │ │ │ ├── pty.py │ │ │ │ │ ├── queue.py │ │ │ │ │ ├── reprlib.py │ │ │ │ │ ├── runpy.py │ │ │ │ │ ├── sched.py │ │ │ │ │ ├── shelve.py │ │ │ │ │ ├── shlex.py │ │ │ │ │ ├── smtplib.py │ │ │ │ │ ├── sys.py │ │ │ │ │ ├── tarfile.py │ │ │ │ │ ├── trace.py │ │ │ │ │ ├── urllib.py │ │ │ │ │ ├── uuid.py │ │ │ │ │ ├── venv.py │ │ │ │ │ ├── zipfile.py │ │ │ │ │ ├── calendar.py │ │ │ │ │ ├── formatter.py │ │ │ │ │ ├── fractions.py │ │ │ │ │ ├── importlib.py │ │ │ │ │ ├── ipaddress.py │ │ │ │ │ ├── mimetypes.py │ │ │ │ │ ├── optparse.py │ │ │ │ │ ├── pickletools.py │ │ │ │ │ ├── platform.py │ │ │ │ │ ├── readline.py │ │ │ │ │ ├── selectors.py │ │ │ │ │ ├── socketserver.py │ │ │ │ │ ├── statistics.py │ │ │ │ │ ├── stringprep.py │ │ │ │ │ ├── subprocess.py │ │ │ │ │ ├── telnetlib.py │ │ │ │ │ ├── tempfile.py │ │ │ │ │ ├── concurrent │ │ │ │ │ │ └── futures │ │ │ │ │ │ │ └── __init__.py │ │ │ │ │ ├── linecache.py │ │ │ │ │ ├── tty.py │ │ │ │ │ ├── zlib.py │ │ │ │ │ ├── abc.py │ │ │ │ │ ├── hashlib │ │ │ │ │ │ ├── _sha224.py │ │ │ │ │ │ ├── _sha384.py │ │ │ │ │ │ └── __init__.py │ │ │ │ │ ├── locale.py │ │ │ │ │ ├── io.py │ │ │ │ │ ├── pprint.py │ │ │ │ │ ├── unicodedata.py │ │ │ │ │ ├── warnings.py │ │ │ │ │ ├── machine │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ └── pin.py │ │ │ │ │ ├── __future__.py │ │ │ │ │ ├── weakref.py │ │ │ │ │ ├── pkgutil.py │ │ │ │ │ ├── gettext.py │ │ │ │ │ ├── struct.py │ │ │ │ │ ├── threading.py │ │ │ │ │ ├── signal.py │ │ │ │ │ ├── collections │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ ├── deque.py │ │ │ │ │ │ └── defaultdict.py │ │ │ │ │ ├── pyb.py │ │ │ │ │ ├── pickle.py │ │ │ │ │ ├── operator.py │ │ │ │ │ ├── random.py │ │ │ │ │ ├── gzip.py │ │ │ │ │ ├── pwd.py │ │ │ │ │ ├── _libc.py │ │ │ │ │ ├── traceback.py │ │ │ │ │ ├── functools.py │ │ │ │ │ ├── pkg_resources.py │ │ │ │ │ ├── html │ │ │ │ │ │ └── __init__.py │ │ │ │ │ ├── shutil.py │ │ │ │ │ ├── string.py │ │ │ │ │ ├── uasyncio │ │ │ │ │ │ ├── synchro.py │ │ │ │ │ │ ├── udp.py │ │ │ │ │ │ └── websocket │ │ │ │ │ │ │ └── server.py │ │ │ │ │ ├── fcntl.py │ │ │ │ │ ├── tests.py │ │ │ │ │ ├── ssl.py │ │ │ │ │ ├── json │ │ │ │ │ │ └── tool.py │ │ │ │ │ ├── ffilib.py │ │ │ │ │ ├── umqtt │ │ │ │ │ │ └── robust.py │ │ │ │ │ ├── os │ │ │ │ │ │ └── path.py │ │ │ │ │ ├── inspect.py │ │ │ │ │ ├── errno.py │ │ │ │ │ ├── socket.py │ │ │ │ │ ├── itertools.py │ │ │ │ │ ├── tests │ │ │ │ │ │ └── test.py │ │ │ │ │ ├── test │ │ │ │ │ │ └── support.py │ │ │ │ │ ├── upysh.py │ │ │ │ │ ├── udnspkt.py │ │ │ │ │ ├── urllib │ │ │ │ │ │ └── urequest.py │ │ │ │ │ └── time.py │ │ │ │ ├── openos │ │ │ │ │ ├── devfs.py │ │ │ │ │ ├── term.py │ │ │ │ │ ├── text.py │ │ │ │ │ ├── uuid.py │ │ │ │ │ ├── vt100.py │ │ │ │ │ ├── rc.py │ │ │ │ │ ├── pipe.py │ │ │ │ │ ├── shell.py │ │ │ │ │ ├── serialization.py │ │ │ │ │ ├── sides.py │ │ │ │ │ ├── note.py │ │ │ │ │ ├── internet.py │ │ │ │ │ ├── colors.py │ │ │ │ │ └── computer.py │ │ │ │ ├── internal │ │ │ │ │ ├── imp.py │ │ │ │ │ ├── json.py │ │ │ │ │ ├── re.py │ │ │ │ │ ├── time.py │ │ │ │ │ ├── heapq.py │ │ │ │ │ ├── msgpack.py │ │ │ │ │ └── random.py │ │ │ │ ├── monitor.py │ │ │ │ └── value.py │ │ │ │ ├── boot │ │ │ │ ├── 02_event.py │ │ │ │ ├── 04_value.py │ │ │ │ ├── 99_process.py │ │ │ │ ├── 03_component.py │ │ │ │ ├── 98_filesystem.py │ │ │ │ ├── 01_sys.py │ │ │ │ ├── 05_screen.py │ │ │ │ └── 04_builtin.py │ │ │ │ ├── .prop │ │ │ │ ├── init.lua │ │ │ │ ├── bin │ │ │ │ ├── dir.py │ │ │ │ ├── shell.py │ │ │ │ └── python.py │ │ │ │ └── init.py │ │ │ ├── firmwares │ │ │ └── v1.0.1 │ │ │ │ ├── firmware.bin │ │ │ │ └── eeprom.py │ │ │ └── blockstates │ │ │ └── hello.json │ └── mcmod.info │ └── java │ └── kr │ └── pe │ └── ecmaxp │ ├── openpython │ ├── arch │ │ ├── consts │ │ │ └── ByteSizeConsts.kt │ │ ├── types │ │ │ ├── Entry.kt │ │ │ ├── interrupt │ │ │ │ ├── InterruptHandler.kt │ │ │ │ └── Interrupt.kt │ │ │ └── call │ │ │ │ ├── InvokeResult.kt │ │ │ │ ├── ValueInvokeable.kt │ │ │ │ ├── ValueCall.kt │ │ │ │ ├── ValueApply.kt │ │ │ │ ├── ValueUnapply.kt │ │ │ │ ├── ComponentInvoke.kt │ │ │ │ └── ValueInvoke.kt │ │ ├── msgpack │ │ │ ├── Msgpack.kt │ │ │ └── MsgpackUnpacker.kt │ │ ├── versions │ │ │ └── v1 │ │ │ │ ├── OpenPythonMemoryRegionV1.kt │ │ │ │ ├── OpenPythonVirtualMachineStateV1.kt │ │ │ │ └── OpenPythonArchitectureV1.kt │ │ └── state │ │ │ ├── ValueContainer.kt │ │ │ ├── FileHandle.kt │ │ │ └── ValueContainerMap.kt │ ├── OpenPythonArchitectureLogic.kt │ ├── OpenPythonVirtualMachine.kt │ └── console │ │ └── OpenPieBenchmark.kt │ └── thumbsf │ ├── MemoryFlag.kt │ ├── exc │ ├── UnexceptedLogicError.kt │ ├── InvalidAddressArmException.kt │ ├── UnknownInstructionException.kt │ ├── UnsupportedInstructionException.kt │ └── InvalidMemoryException.kt │ ├── signal │ ├── ControlPauseSignal.kt │ ├── ControlStopSignal.kt │ └── ControlSignal.kt │ └── consts │ ├── ParseInsn.kt │ ├── RegisterIndex.kt │ └── BitConsts.kt ├── gradle └── wrapper │ └── gradle-wrapper.properties ├── gradle.properties ├── opmod.iml ├── LICENSE ├── LICENSE-mpack ├── LICENSE-micropython ├── README.md └── LICENSE-OpenComputers /.gitmodules: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/usr/bin/env.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/usr/bin/env.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/urllib/request.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/urllib/request.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/binhex.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/code.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/codecs.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/codeop.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/csv.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/dbm.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/decimal.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/difflib.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/ftplib.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/getpass.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/imaplib.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/imp.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/mailbox.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/mailcap.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/nntplib.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/numbers.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/pathlib.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/pdb.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/poplib.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/profile.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/pty.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/queue.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/reprlib.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/runpy.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/sched.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/shelve.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/shlex.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/smtplib.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/sys.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/tarfile.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/trace.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/typing.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/urllib.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/uuid.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/venv.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/zipfile.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/binhex.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/code.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/codecs.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/codeop.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/csv.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/dbm.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/decimal.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/difflib.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/ftplib.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/getpass.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/imaplib.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/imp.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/mailbox.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/mailcap.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/nntplib.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/numbers.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/pathlib.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/pdb.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/poplib.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/profile.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/pty.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/queue.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/reprlib.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/runpy.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/sched.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/shelve.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/shlex.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/smtplib.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/sys.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/tarfile.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/trace.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/urllib.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/uuid.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/venv.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/zipfile.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/calendar.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/formatter.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/fractions.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/importlib.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/ipaddress.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/mimetypes.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/optparse.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/pickletools.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/platform.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/posixpath.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/readline.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/selectors.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/socketserver.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/statistics.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/stringprep.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/subprocess.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/telnetlib.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/tempfile.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/calendar.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/formatter.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/fractions.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/importlib.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/ipaddress.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/mimetypes.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/optparse.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/pickletools.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/platform.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/readline.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/selectors.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/socketserver.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/statistics.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/stringprep.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/subprocess.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/telnetlib.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/tempfile.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/concurrent/futures/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/linecache.py: -------------------------------------------------------------------------------- 1 | cache = {} 2 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/concurrent/futures/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/linecache.py: -------------------------------------------------------------------------------- 1 | cache = {} 2 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/tty.py: -------------------------------------------------------------------------------- 1 | from termios import * 2 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/zlib.py: -------------------------------------------------------------------------------- 1 | from uzlib import * 2 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/tty.py: -------------------------------------------------------------------------------- 1 | from termios import * 2 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/zlib.py: -------------------------------------------------------------------------------- 1 | from uzlib import * 2 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/openos/devfs.py: -------------------------------------------------------------------------------- 1 | raise NotImplementedError 2 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/boot/02_event.py: -------------------------------------------------------------------------------- 1 | import event 2 | 3 | event.setup() 4 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/boot/04_value.py: -------------------------------------------------------------------------------- 1 | import value 2 | 3 | value.setup() 4 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/abc.py: -------------------------------------------------------------------------------- 1 | def abstractmethod(f): 2 | return f 3 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/hashlib/_sha224.py: -------------------------------------------------------------------------------- 1 | from ._sha256 import sha224 2 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/hashlib/_sha384.py: -------------------------------------------------------------------------------- 1 | from ._sha512 import sha384 2 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/boot/99_process.py: -------------------------------------------------------------------------------- 1 | import process 2 | 3 | process.setup() 4 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/abc.py: -------------------------------------------------------------------------------- 1 | def abstractmethod(f): 2 | return f 3 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/hashlib/_sha224.py: -------------------------------------------------------------------------------- 1 | from ._sha256 import sha224 2 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/hashlib/_sha384.py: -------------------------------------------------------------------------------- 1 | from ._sha512 import sha384 2 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/.prop: -------------------------------------------------------------------------------- 1 | {label="OpenPython OS", reboot=true, setlabel=true, setboot=true} -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/boot/03_component.py: -------------------------------------------------------------------------------- 1 | import component 2 | 3 | component.setup() 4 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/imp.py: -------------------------------------------------------------------------------- 1 | # noinspection PyUnresolvedReferences 2 | from uimp import * 3 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/re.py: -------------------------------------------------------------------------------- 1 | # noinspection PyUnresolvedReferences 2 | from ure import * 3 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/errno.py: -------------------------------------------------------------------------------- 1 | # noinspection PyUnresolvedReferences 2 | from uerrno import * 3 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/heapq.py: -------------------------------------------------------------------------------- 1 | # noinspection PyUnresolvedReferences 2 | from uheapq import * 3 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/json.py: -------------------------------------------------------------------------------- 1 | # noinspection PyUnresolvedReferences 2 | from ujson import * 3 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/locale.py: -------------------------------------------------------------------------------- 1 | def getpreferredencoding(): 2 | return "utf-8" 3 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/time.py: -------------------------------------------------------------------------------- 1 | # noinspection PyUnresolvedReferences 2 | from utime import * 3 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/locale.py: -------------------------------------------------------------------------------- 1 | def getpreferredencoding(): 2 | return "utf-8" 3 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/computer.py: -------------------------------------------------------------------------------- 1 | # noinspection PyUnresolvedReferences 2 | from ucomputer import * 3 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/msgpack.py: -------------------------------------------------------------------------------- 1 | # noinspection PyUnresolvedReferences 2 | from umsgpack import * 3 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/internal/imp.py: -------------------------------------------------------------------------------- 1 | # noinspection PyUnresolvedReferences 2 | from uimp import * 3 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/internal/json.py: -------------------------------------------------------------------------------- 1 | # noinspection PyUnresolvedReferences 2 | from ujson import * 3 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/internal/re.py: -------------------------------------------------------------------------------- 1 | # noinspection PyUnresolvedReferences 2 | from ure import * 3 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/internal/time.py: -------------------------------------------------------------------------------- 1 | # noinspection PyUnresolvedReferences 2 | from utime import * 3 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/internal/heapq.py: -------------------------------------------------------------------------------- 1 | # noinspection PyUnresolvedReferences 2 | from uheapq import * 3 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/init.lua: -------------------------------------------------------------------------------- 1 | error("This Operating System requires a CPU running the OpenPython architecture.") 2 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/init.lua: -------------------------------------------------------------------------------- 1 | error("This Operating System requires a CPU running the OpenPython architecture.") 2 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/internal/msgpack.py: -------------------------------------------------------------------------------- 1 | # noinspection PyUnresolvedReferences 2 | from umsgpack import * 3 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/openpython/arch/consts/ByteSizeConsts.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.openpython.arch.consts 2 | 3 | const val KB = 1024 4 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/thumbsf/MemoryFlag.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.thumbsf 2 | 3 | enum class MemoryFlag { 4 | RX, 5 | RW, 6 | } 7 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/io.py: -------------------------------------------------------------------------------- 1 | from uio import * 2 | 3 | SEEK_SET = 0 4 | SEEK_CUR = 1 5 | SEEK_END = 2 6 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/io.py: -------------------------------------------------------------------------------- 1 | from uio import * 2 | 3 | SEEK_SET = 0 4 | SEEK_CUR = 1 5 | SEEK_END = 2 6 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/thumbsf/exc/UnexceptedLogicError.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.thumbsf.exc 2 | 3 | class UnexceptedLogicError : AssertionError() -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/thumbsf/exc/InvalidAddressArmException.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.thumbsf.exc 2 | 3 | class InvalidAddressArmException : Exception() 4 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/thumbsf/exc/UnknownInstructionException.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.thumbsf.exc 2 | 3 | open class UnknownInstructionException : Exception() 4 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/pprint.py: -------------------------------------------------------------------------------- 1 | def pformat(obj): 2 | return repr(obj) 3 | 4 | def pprint(obj): 5 | print(repr(obj)) 6 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/pprint.py: -------------------------------------------------------------------------------- 1 | def pformat(obj): 2 | return repr(obj) 3 | 4 | def pprint(obj): 5 | print(repr(obj)) 6 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/thumbsf/signal/ControlPauseSignal.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.thumbsf.signal 2 | 3 | class ControlPauseSignal(value: Any? = null) : ControlSignal(value) 4 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/thumbsf/signal/ControlStopSignal.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.thumbsf.signal 2 | 3 | class ControlStopSignal(value: Any? = null) : ControlSignal(value) 4 | 5 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/unicodedata.py: -------------------------------------------------------------------------------- 1 | def east_asian_width(c): 2 | return 1 3 | 4 | 5 | def normalize(form, unistr): 6 | return unistr 7 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/unicodedata.py: -------------------------------------------------------------------------------- 1 | def east_asian_width(c): 2 | return 1 3 | 4 | 5 | def normalize(form, unistr): 6 | return unistr 7 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/thumbsf/exc/UnsupportedInstructionException.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.thumbsf.exc 2 | 3 | class UnsupportedInstructionException : UnknownInstructionException() 4 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/thumbsf/signal/ControlSignal.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.thumbsf.signal 2 | 3 | open class ControlSignal protected constructor(val value: Any? = null) : Throwable() 4 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/firmwares/v1.0.1/firmware.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenPythons/OpenPython/HEAD/src/main/resources/assets/openpython/firmwares/v1.0.1/firmware.bin -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/warnings.py: -------------------------------------------------------------------------------- 1 | def warn(msg, cat=None, stacklevel=1): 2 | print("%s: %s" % ("Warning" if cat is None else cat.__name__, msg)) 3 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/warnings.py: -------------------------------------------------------------------------------- 1 | def warn(msg, cat=None, stacklevel=1): 2 | print("%s: %s" % ("Warning" if cat is None else cat.__name__, msg)) 3 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/openpython/arch/types/Entry.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.openpython.arch.types 2 | 3 | class Entry(val address: Int, val size: Int, val type: String, val name: String) 4 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/bin/dir.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | 4 | def main(): 5 | print(os.listdir('.')) 6 | 7 | 8 | if __name__ == '__main__': 9 | main() 10 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/openos/term.py: -------------------------------------------------------------------------------- 1 | # https://github.com/MightyPirates/OpenComputers/blob/master-MC1.12/ 2 | # - src/main/resources/assets/opencomputers/loot/openos/lib/term.lua 3 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/openos/text.py: -------------------------------------------------------------------------------- 1 | # https://github.com/MightyPirates/OpenComputers/blob/master-MC1.12/ 2 | # - src/main/resources/assets/opencomputers/loot/openos/lib/text.lua 3 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/openos/uuid.py: -------------------------------------------------------------------------------- 1 | # https://github.com/MightyPirates/OpenComputers/blob/master-MC1.12/ 2 | # - src/main/resources/assets/opencomputers/loot/openos/lib/uuid.lua 3 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/openos/vt100.py: -------------------------------------------------------------------------------- 1 | # https://github.com/MightyPirates/OpenComputers/blob/master-MC1.12/ 2 | # - src/main/resources/assets/opencomputers/loot/openos/lib/vt100.lua 3 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/thumbsf/exc/InvalidMemoryException.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.thumbsf.exc 2 | 3 | class InvalidMemoryException(val address: Int) : Exception(String.format("memory access in %08X", address)) 4 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/machine/__init__.py: -------------------------------------------------------------------------------- 1 | from umachine import * 2 | from .timer import * 3 | from .pin import * 4 | 5 | def unique_id(): 6 | return b"upy-non-unique" 7 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/machine/__init__.py: -------------------------------------------------------------------------------- 1 | from umachine import * 2 | from .timer import * 3 | from .pin import * 4 | 5 | def unique_id(): 6 | return b"upy-non-unique" 7 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/thumbsf/consts/ParseInsn.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.thumbsf.consts 2 | 3 | const val RDEST = 8 4 | const val RSRC = 12 5 | const val RNUM = 16 6 | const val RMASK = 0b1111 7 | const val RIMM = 16 8 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/openos/rc.py: -------------------------------------------------------------------------------- 1 | # https://github.com/MightyPirates/OpenComputers/blob/master-MC1.12/ 2 | # - src/main/resources/assets/opencomputers/loot/openos/lib/rc.lua 3 | 4 | loaded = {} 5 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/openos/pipe.py: -------------------------------------------------------------------------------- 1 | # https://github.com/MightyPirates/OpenComputers/blob/master-MC1.12/ 2 | # - src/main/resources/assets/opencomputers/loot/openos/lib/pipe.lua 3 | 4 | raise NotImplementedError 5 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/openpython/arch/types/interrupt/InterruptHandler.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.openpython.arch.types.interrupt 2 | 3 | interface InterruptHandler { 4 | operator fun invoke(interrupt: Interrupt, synchronized: Boolean) 5 | } 6 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/__future__.py: -------------------------------------------------------------------------------- 1 | nested_scopes = True 2 | generators = True 3 | division = True 4 | absolute_import = True 5 | with_statement = True 6 | print_function = True 7 | unicode_literals = True 8 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/__future__.py: -------------------------------------------------------------------------------- 1 | nested_scopes = True 2 | generators = True 3 | division = True 4 | absolute_import = True 5 | with_statement = True 6 | print_function = True 7 | unicode_literals = True 8 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/weakref.py: -------------------------------------------------------------------------------- 1 | # 2 | # This is completely dummy implementation, which does not 3 | # provide real weak references, and thus will hoard memory! 4 | # 5 | 6 | def proxy(obj, cb=None): 7 | return obj 8 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/weakref.py: -------------------------------------------------------------------------------- 1 | # 2 | # This is completely dummy implementation, which does not 3 | # provide real weak references, and thus will hoard memory! 4 | # 5 | 6 | def proxy(obj, cb=None): 7 | return obj 8 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/boot/98_filesystem.py: -------------------------------------------------------------------------------- 1 | import uos 2 | 3 | import computer 4 | from filesystem import FileSystem 5 | 6 | uos.umount('/') 7 | uos.mount(FileSystem(__path__), '/') 8 | uos.mount(FileSystem(computer.get_tmp_address()), '/tmp') 9 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/pkgutil.py: -------------------------------------------------------------------------------- 1 | import pkg_resources 2 | 3 | def get_data(package, resource): 4 | f = pkg_resources.resource_stream(package, resource) 5 | try: 6 | return f.read() 7 | finally: 8 | f.close() 9 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/boot/98_filesystem.py: -------------------------------------------------------------------------------- 1 | import uos 2 | 3 | import computer 4 | from filesystem import FileSystem 5 | 6 | uos.umount('/') 7 | uos.mount(FileSystem(__path__, root=True), '/') 8 | uos.mount(FileSystem(computer.tmp_address()), '/tmp') 9 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/pkgutil.py: -------------------------------------------------------------------------------- 1 | import pkg_resources 2 | 3 | def get_data(package, resource): 4 | f = pkg_resources.resource_stream(package, resource) 5 | try: 6 | return f.read() 7 | finally: 8 | f.close() 9 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Sep 23 12:22:07 KST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-all.zip 7 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/blockstates/hello.json: -------------------------------------------------------------------------------- 1 | { 2 | "forge_marker": 1, 3 | "defaults": { 4 | "textures": { 5 | "all": "blocks/dirt" 6 | }, 7 | "model": "cube_all", 8 | "uvlock": true 9 | }, 10 | "variants": { 11 | "normal": [ 12 | {} 13 | ] 14 | } 15 | } -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/boot/01_sys.py: -------------------------------------------------------------------------------- 1 | from uimp import new_module 2 | 3 | import sys 4 | 5 | sys_module = new_module('sys') 6 | 7 | for name in dir(sys): 8 | obj = getattr(sys, name) 9 | setattr(sys_module, name, obj) 10 | 11 | sys.modules['sys'] = sys_module 12 | sys.modules['usys'] = sys 13 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/openpython/arch/types/call/InvokeResult.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.openpython.arch.types.call 2 | 3 | import java.util.* 4 | 5 | class InvokeResult(val args: Array? = null, val error: Throwable? = null) { 6 | override fun toString(): String = "InvokeResult(args=${Arrays.toString(args)}, error=$error)" 7 | } 8 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/openos/shell.py: -------------------------------------------------------------------------------- 1 | # https://github.com/MightyPirates/OpenComputers/blob/master-MC1.12/ 2 | # - src/main/resources/assets/opencomputers/loot/openos/lib/shell.lua 3 | # - src/main/resources/assets/opencomputers/loot/openos/lib/core/full_shell.lua 4 | 5 | 6 | from process import spawn 7 | 8 | __all__ = ["spawn"] 9 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/random.py: -------------------------------------------------------------------------------- 1 | from urandom import * 2 | 3 | from time import ticks_us as _ticks_us 4 | 5 | seed(_ticks_us()) 6 | del _ticks_us 7 | 8 | 9 | # micropython-lib # 10 | 11 | def shuffle(seq): 12 | l = len(seq) 13 | for i in range(l): 14 | j = randrange(l) 15 | seq[i], seq[j] = seq[j], seq[i] 16 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/internal/random.py: -------------------------------------------------------------------------------- 1 | from urandom import * 2 | 3 | from time import ticks_us as _ticks_us 4 | 5 | seed(_ticks_us()) 6 | del _ticks_us 7 | 8 | 9 | # micropython-lib # 10 | 11 | def shuffle(seq): 12 | l = len(seq) 13 | for i in range(l): 14 | j = randrange(l) 15 | seq[i], seq[j] = seq[j], seq[i] 16 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/openpython/OpenPythonArchitectureLogic.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.openpython 2 | 3 | import kr.pe.ecmaxp.openpython.arch.OpenPythonFirmware 4 | import li.cil.oc.api.machine.Machine 5 | 6 | interface OpenPythonArchitectureLogic { 7 | val LATEST_FIRMWARE: OpenPythonFirmware 8 | fun spawn(machine: Machine, memorySize: Int): OpenPythonVirtualMachine 9 | } 10 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/gettext.py: -------------------------------------------------------------------------------- 1 | import ffilib 2 | 3 | libc = ffilib.libc() 4 | 5 | gettext_ = libc.func("s", "gettext", "s") 6 | ngettext_ = libc.func("s", "ngettext", "ssL") 7 | 8 | 9 | def gettext(message): 10 | return gettext_(message) 11 | 12 | 13 | def ngettext(singular, plural, n): 14 | return ngettext_(singular, plural, n) 15 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/gettext.py: -------------------------------------------------------------------------------- 1 | import ffilib 2 | 3 | libc = ffilib.libc() 4 | 5 | gettext_ = libc.func("s", "gettext", "s") 6 | ngettext_ = libc.func("s", "ngettext", "ssL") 7 | 8 | 9 | def gettext(message): 10 | return gettext_(message) 11 | 12 | 13 | def ngettext(singular, plural, n): 14 | return ngettext_(singular, plural, n) 15 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/struct.py: -------------------------------------------------------------------------------- 1 | from ustruct import * 2 | 3 | class Struct: 4 | 5 | def __init__(self, format): 6 | self.format = format 7 | self.size = calcsize(format) 8 | 9 | def unpack(self, buf): 10 | return unpack(self.format, buf) 11 | 12 | def pack(self, *vals): 13 | return pack(self.format, *vals) 14 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/struct.py: -------------------------------------------------------------------------------- 1 | from ustruct import * 2 | 3 | class Struct: 4 | 5 | def __init__(self, format): 6 | self.format = format 7 | self.size = calcsize(format) 8 | 9 | def unpack(self, buf): 10 | return unpack(self.format, buf) 11 | 12 | def pack(self, *vals): 13 | return pack(self.format, *vals) 14 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # forge_gradle_version = 2.3-SNAPSHOT 2 | java_version = 1.8 3 | forgelin_version = 1.8.2 4 | kotlin_version = 1.3.10 5 | 6 | minecraft_version=1.12.2 7 | minecraft_mappings=snapshot_20180704 8 | forge_version=14.23.4.2727 9 | 10 | mod_name=OpenPython 11 | mod_version=1.1.0 12 | mod_group=kr.pe.ecmaxp.openpython 13 | 14 | opencomputers_version = 1.7 15 | 16 | org.gradle.jvmargs=-Xmx2048m 17 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/boot/01_basic.py: -------------------------------------------------------------------------------- 1 | import machine 2 | 3 | import event 4 | import value 5 | 6 | buf = [] 7 | 8 | 9 | @machine.hook_stdin 10 | def input_handler(): 11 | while not buf: 12 | event.wait(10) 13 | 14 | return int(buf.pop(0)) 15 | 16 | 17 | @event.register("key_down") 18 | def handle_key_down(_1, char, *_): 19 | buf.append(char) 20 | 21 | 22 | event.setup() 23 | value.setup() 24 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/thumbsf/consts/RegisterIndex.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.thumbsf.consts 2 | 3 | const val R0 = 0 4 | const val R1 = 1 5 | const val R2 = 2 6 | const val R3 = 3 7 | const val R4 = 4 8 | const val R5 = 5 9 | const val R6 = 6 10 | const val R7 = 7 11 | const val R8 = 8 12 | const val R9 = 9 13 | const val R10 = 10 14 | const val R11 = 11 15 | const val R12 = 12 16 | const val SP = 13 17 | const val LR = 14 18 | const val PC = 15 19 | const val CPSR = 16 20 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/openos/serialization.py: -------------------------------------------------------------------------------- 1 | # https://github.com/MightyPirates/OpenComputers/blob/master-MC1.12/ 2 | # - src/main/resources/assets/opencomputers/loot/openos/lib/serialization.lua 3 | 4 | __all__ = ["serialize", "unserialize"] 5 | 6 | 7 | def serialize(value, pretty=False): 8 | raise NotImplementedError 9 | 10 | 11 | def unserialize(value): 12 | raise NotImplementedError 13 | 14 | 15 | raise NotImplementedError 16 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/shell.py: -------------------------------------------------------------------------------- 1 | try: 2 | import usys as sys 3 | except ImportError: 4 | import sys 5 | 6 | sys.modules["usys"] = sys 7 | # sys.modules["sys"] = sys 8 | 9 | 10 | def spawn(path): 11 | context = {'__name__': '__main__', '__path__': path} 12 | 13 | try: 14 | # noinspection PyUnresolvedReferences 15 | execfile(path, context) 16 | except SystemExit as e: 17 | return e.code 18 | 19 | return 0 20 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/threading.py: -------------------------------------------------------------------------------- 1 | import _thread 2 | 3 | 4 | class Thread: 5 | 6 | def __init__(self, group=None, target=None, name=None, args=(), kwargs=None): 7 | self.target = target 8 | self.args = args 9 | self.kwargs = {} if kwargs is None else kwargs 10 | 11 | def start(self): 12 | _thread.start_new_thread(self.run, ()) 13 | 14 | def run(self): 15 | self.target(*self.args, **self.kwargs) 16 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/threading.py: -------------------------------------------------------------------------------- 1 | import _thread 2 | 3 | 4 | class Thread: 5 | 6 | def __init__(self, group=None, target=None, name=None, args=(), kwargs=None): 7 | self.target = target 8 | self.args = args 9 | self.kwargs = {} if kwargs is None else kwargs 10 | 11 | def start(self): 12 | _thread.start_new_thread(self.run, ()) 13 | 14 | def run(self): 15 | self.target(*self.args, **self.kwargs) 16 | -------------------------------------------------------------------------------- /src/main/resources/mcmod.info: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "modid": "openpython", 4 | "name": "OpenPython", 5 | "description": "Micropython for OpenComputer", 6 | "version": "${version}", 7 | "mcversion": "${mcversion}", 8 | "url": "https://github.com/EcmaXp/OpenPython", 9 | "updateUrl": "", 10 | "authorList": ["EcmaXp"], 11 | "credits": "OpenComputers, micropython, unicorn, ...", 12 | "logoFile": "", 13 | "screenshots": [] 14 | } 15 | ] -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/signal.py: -------------------------------------------------------------------------------- 1 | import ffilib 2 | 3 | 4 | SIG_DFL = 0 5 | SIG_IGN = 1 6 | 7 | SIGINT = 2 8 | SIGPIPE = 13 9 | SIGTERM = 15 10 | 11 | libc = ffilib.libc() 12 | 13 | signal_i = libc.func("i", "signal", "ii") 14 | signal_p = libc.func("i", "signal", "ip") 15 | 16 | def signal(n, handler): 17 | if isinstance(handler, int): 18 | return signal_i(n, handler) 19 | import ffi 20 | cb = ffi.callback("v", handler, "i") 21 | return signal_p(n, cb) 22 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/signal.py: -------------------------------------------------------------------------------- 1 | import ffilib 2 | 3 | 4 | SIG_DFL = 0 5 | SIG_IGN = 1 6 | 7 | SIGINT = 2 8 | SIGPIPE = 13 9 | SIGTERM = 15 10 | 11 | libc = ffilib.libc() 12 | 13 | signal_i = libc.func("i", "signal", "ii") 14 | signal_p = libc.func("i", "signal", "ip") 15 | 16 | def signal(n, handler): 17 | if isinstance(handler, int): 18 | return signal_i(n, handler) 19 | import ffi 20 | cb = ffi.callback("v", handler, "i") 21 | return signal_p(n, cb) 22 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/collections/__init__.py: -------------------------------------------------------------------------------- 1 | # Should be reimplemented for MicroPython 2 | # Reason: 3 | # CPython implementation brings in metaclasses and other bloat. 4 | # This is going to be just import-all for other modules in a namespace package 5 | from ucollections import * 6 | try: 7 | from .defaultdict import defaultdict 8 | except ImportError: 9 | pass 10 | try: 11 | from .deque import deque 12 | except ImportError: 13 | pass 14 | 15 | class MutableMapping: 16 | pass 17 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/collections/__init__.py: -------------------------------------------------------------------------------- 1 | # Should be reimplemented for MicroPython 2 | # Reason: 3 | # CPython implementation brings in metaclasses and other bloat. 4 | # This is going to be just import-all for other modules in a namespace package 5 | from ucollections import * 6 | try: 7 | from .defaultdict import defaultdict 8 | except ImportError: 9 | pass 10 | try: 11 | from .deque import deque 12 | except ImportError: 13 | pass 14 | 15 | class MutableMapping: 16 | pass 17 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/pyb.py: -------------------------------------------------------------------------------- 1 | class LED: 2 | 3 | def __init__(self, id): 4 | self.f = open("/sys/class/leds/%s/brightness" % id, "r+b") 5 | 6 | def on(self): 7 | self.f.write(b"255") 8 | 9 | def off(self): 10 | self.f.write(b"0") 11 | 12 | def get(self): 13 | self.f.seek(0) 14 | return int(self.f.read()) 15 | 16 | def toggle(self): 17 | v = self.get() 18 | if v: 19 | self.off() 20 | else: 21 | self.on() 22 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/pyb.py: -------------------------------------------------------------------------------- 1 | class LED: 2 | 3 | def __init__(self, id): 4 | self.f = open("/sys/class/leds/%s/brightness" % id, "r+b") 5 | 6 | def on(self): 7 | self.f.write(b"255") 8 | 9 | def off(self): 10 | self.f.write(b"0") 11 | 12 | def get(self): 13 | self.f.seek(0) 14 | return int(self.f.read()) 15 | 16 | def toggle(self): 17 | v = self.get() 18 | if v: 19 | self.off() 20 | else: 21 | self.on() 22 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/openpython/arch/msgpack/Msgpack.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.openpython.arch.msgpack 2 | 3 | import kr.pe.ecmaxp.openpython.OpenPythonVirtualMachine 4 | 5 | class Msgpack(val vm: OpenPythonVirtualMachine? = null) { 6 | fun loads(buffer: ByteArray): Any? { 7 | val unpacker = MsgpackUnpacker(buffer, vm) 8 | return unpacker.unpackObj() 9 | } 10 | 11 | fun dumps(o: Any?): ByteArray { 12 | val packer = MsgpackPacker(vm) 13 | packer.pack(o) 14 | return packer.toByteArray() 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/pickle.py: -------------------------------------------------------------------------------- 1 | HIGHEST_PROTOCOL = 0 2 | 3 | def dump(obj, f, proto=0): 4 | f.write(repr(obj)) 5 | 6 | def dumps(obj, proto=0): 7 | return repr(obj).encode() 8 | 9 | def load(f): 10 | s = f.read() 11 | return loads(s) 12 | 13 | def loads(s): 14 | d = {} 15 | s = s.decode() 16 | if "(" in s: 17 | qualname = s.split("(", 1)[0] 18 | if "." in qualname: 19 | pkg = qualname.rsplit(".", 1)[0] 20 | mod = __import__(pkg) 21 | d[pkg] = mod 22 | return eval(s, d) 23 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/pickle.py: -------------------------------------------------------------------------------- 1 | HIGHEST_PROTOCOL = 0 2 | 3 | def dump(obj, f, proto=0): 4 | f.write(repr(obj)) 5 | 6 | def dumps(obj, proto=0): 7 | return repr(obj).encode() 8 | 9 | def load(f): 10 | s = f.read() 11 | return loads(s) 12 | 13 | def loads(s): 14 | d = {} 15 | s = s.decode() 16 | if "(" in s: 17 | qualname = s.split("(", 1)[0] 18 | if "." in qualname: 19 | pkg = qualname.rsplit(".", 1)[0] 20 | mod = __import__(pkg) 21 | d[pkg] = mod 22 | return eval(s, d) 23 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/openpython/arch/versions/v1/OpenPythonMemoryRegionV1.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.openpython.arch.versions.v1 2 | 3 | import kr.pe.ecmaxp.openpython.arch.consts.KB 4 | import kr.pe.ecmaxp.thumbsf.MemoryFlag 5 | import kr.pe.ecmaxp.thumbsf.MemoryFlag.RW 6 | import kr.pe.ecmaxp.thumbsf.MemoryFlag.RX 7 | 8 | enum class OpenPythonMemoryRegionV1(val address: Int, val size: Int, val flag: MemoryFlag) { 9 | FLASH(0x08000000, 256 * KB, RX), 10 | SRAM(0x20000000, 64 * KB, RW), 11 | RAM(0x60000000, 256 * KB, RW), // dynamic size 12 | SYSCALL(0xE0000000.toInt(), 16 * KB, RW) 13 | } 14 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/hashlib/__init__.py: -------------------------------------------------------------------------------- 1 | try: 2 | import uhashlib 3 | except ImportError: 4 | uhashlib = None 5 | 6 | def init(): 7 | for i in ("sha1", "sha224", "sha256", "sha384", "sha512"): 8 | c = getattr(uhashlib, i, None) 9 | if not c: 10 | c = __import__("_" + i, None, None, (), 1) 11 | c = getattr(c, i) 12 | globals()[i] = c 13 | 14 | init() 15 | 16 | 17 | def new(algo, data=b""): 18 | try: 19 | c = globals()[algo] 20 | return c(data) 21 | except KeyError: 22 | raise ValueError(algo) 23 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/hashlib/__init__.py: -------------------------------------------------------------------------------- 1 | try: 2 | import uhashlib 3 | except ImportError: 4 | uhashlib = None 5 | 6 | def init(): 7 | for i in ("sha1", "sha224", "sha256", "sha384", "sha512"): 8 | c = getattr(uhashlib, i, None) 9 | if not c: 10 | c = __import__("_" + i, None, None, (), 1) 11 | c = getattr(c, i) 12 | globals()[i] = c 13 | 14 | init() 15 | 16 | 17 | def new(algo, data=b""): 18 | try: 19 | c = globals()[algo] 20 | return c(data) 21 | except KeyError: 22 | raise ValueError(algo) 23 | -------------------------------------------------------------------------------- /opmod.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/openpython/arch/types/call/ValueInvokeable.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.openpython.arch.types.call 2 | 3 | import li.cil.oc.api.machine.LimitReachedException 4 | import li.cil.oc.api.machine.Machine 5 | import li.cil.oc.api.machine.Value 6 | 7 | abstract class ValueInvokeable(val value: Value, vararg args: Any?) { 8 | val args: ArgumentsImpl = ArgumentsImpl(args) 9 | 10 | override fun toString(): String { 11 | return "${this.javaClass.simpleName}(value='$value', args=${args})" 12 | } 13 | 14 | @Throws(LimitReachedException::class) 15 | abstract operator fun invoke(machine: Machine): InvokeResult 16 | } 17 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/operator.py: -------------------------------------------------------------------------------- 1 | def attrgetter(attr): 2 | assert "." not in attr 3 | def _attrgetter(obj): 4 | return getattr(obj, attr) 5 | return _attrgetter 6 | 7 | 8 | def lt(a, b): 9 | return a < b 10 | 11 | def le(a, b): 12 | return a <= b 13 | 14 | def gt(a, b): 15 | return a > b 16 | 17 | def ge(a, b): 18 | return a >= b 19 | 20 | def eq(a, b): 21 | return a == b 22 | 23 | def ne(a, b): 24 | return a != b 25 | 26 | def mod(a, b): 27 | return a % b 28 | 29 | def truediv(a, b): 30 | return a / b 31 | 32 | def floordiv(a, b): 33 | return a // b 34 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/operator.py: -------------------------------------------------------------------------------- 1 | def attrgetter(attr): 2 | assert "." not in attr 3 | def _attrgetter(obj): 4 | return getattr(obj, attr) 5 | return _attrgetter 6 | 7 | 8 | def lt(a, b): 9 | return a < b 10 | 11 | def le(a, b): 12 | return a <= b 13 | 14 | def gt(a, b): 15 | return a > b 16 | 17 | def ge(a, b): 18 | return a >= b 19 | 20 | def eq(a, b): 21 | return a == b 22 | 23 | def ne(a, b): 24 | return a != b 25 | 26 | def mod(a, b): 27 | return a % b 28 | 29 | def truediv(a, b): 30 | return a / b 31 | 32 | def floordiv(a, b): 33 | return a // b 34 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/thumbsf/consts/BitConsts.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.thumbsf.consts 2 | 3 | const val UINT_MAX = 0xFFFFFFFFL 4 | const val I0 = 1 5 | const val I1 = 1 shl 1 6 | const val I7 = 1 shl 7 7 | const val I8 = 1 shl 8 8 | const val I9 = 1 shl 9 9 | const val I10 = 1 shl 10 10 | const val I11 = 1 shl 11 11 | const val I12 = 1 shl 12 12 | const val L1 = 1 13 | const val L2 = 3 14 | const val L3 = 7 15 | const val L4 = 15 16 | const val L5 = 31 17 | const val L7 = 127 18 | const val L8 = 255 19 | const val L10 = 1023 20 | const val L11 = 2047 21 | const val FV = 1 shl 28 22 | const val FC = 1 shl 29 23 | const val FZ = 1 shl 30 24 | const val FN = 1 shl 31 25 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/openpython/OpenPythonVirtualMachine.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.openpython 2 | 3 | import kr.pe.ecmaxp.openpython.repack.org.msgpack.core.MessagePacker 4 | import kr.pe.ecmaxp.openpython.repack.org.msgpack.core.MessageUnpacker 5 | import li.cil.oc.api.Persistable 6 | import li.cil.oc.api.machine.ExecutionResult 7 | import li.cil.oc.api.machine.Value 8 | 9 | interface OpenPythonVirtualMachine : Persistable { 10 | val memorySize: Int 11 | 12 | fun close() 13 | fun step(synchronized: Boolean): ExecutionResult 14 | 15 | fun unpackExtension(unpacker: MessageUnpacker): Any? 16 | fun packValue(packer: MessagePacker, value: Value) 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/openpython/arch/types/interrupt/Interrupt.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.openpython.arch.types.interrupt 2 | 3 | import kr.pe.ecmaxp.openpython.arch.types.call.InvokeResult 4 | 5 | interface Interrupt { 6 | fun readBuffer(): ByteArray 7 | fun readBuffer(address: Int, size: Int): ByteArray 8 | 9 | fun readString(): String? 10 | fun readString(address: Int, maxSize: Int): String 11 | 12 | fun readObject(): Any? 13 | 14 | fun responseNone(): Int 15 | fun responseResult(ret: InvokeResult): Int 16 | fun responseValue(value: Any?): Int 17 | fun responseError(value: Throwable): Int 18 | fun responseBuffer(buffer: ByteArray): Int 19 | } 20 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/random.py: -------------------------------------------------------------------------------- 1 | from urandom import * 2 | 3 | 4 | def randrange(start, stop=None): 5 | if stop is None: 6 | stop = start 7 | start = 0 8 | upper = stop - start 9 | bits = 0 10 | pwr2 = 1 11 | while upper > pwr2: 12 | pwr2 <<= 1 13 | bits += 1 14 | while True: 15 | r = getrandbits(bits) 16 | if r < upper: 17 | break 18 | return r + start 19 | 20 | def randint(start, stop): 21 | return randrange(start, stop + 1) 22 | 23 | def shuffle(seq): 24 | l = len(seq) 25 | for i in range(l): 26 | j = randrange(l) 27 | seq[i], seq[j] = seq[j], seq[i] 28 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/random.py: -------------------------------------------------------------------------------- 1 | from urandom import * 2 | 3 | 4 | def randrange(start, stop=None): 5 | if stop is None: 6 | stop = start 7 | start = 0 8 | upper = stop - start 9 | bits = 0 10 | pwr2 = 1 11 | while upper > pwr2: 12 | pwr2 <<= 1 13 | bits += 1 14 | while True: 15 | r = getrandbits(bits) 16 | if r < upper: 17 | break 18 | return r + start 19 | 20 | def randint(start, stop): 21 | return randrange(start, stop + 1) 22 | 23 | def shuffle(seq): 24 | l = len(seq) 25 | for i in range(l): 26 | j = randrange(l) 27 | seq[i], seq[j] = seq[j], seq[i] 28 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/gzip.py: -------------------------------------------------------------------------------- 1 | #import zlib 2 | import uzlib as zlib 3 | 4 | FTEXT = 1 5 | FHCRC = 2 6 | FEXTRA = 4 7 | FNAME = 8 8 | FCOMMENT = 16 9 | 10 | def decompress(data): 11 | assert data[0] == 0x1f and data[1] == 0x8b 12 | assert data[2] == 8 13 | flg = data[3] 14 | assert flg & 0xe0 == 0 15 | i = 10 16 | if flg & FEXTRA: 17 | i += data[11] << 8 + data[10] + 2 18 | if flg & FNAME: 19 | while data[i]: 20 | i += 1 21 | i += 1 22 | if flg & FCOMMENT: 23 | while data[i]: 24 | i += 1 25 | i += 1 26 | if flg & FHCRC: 27 | i += 2 28 | return zlib.decompress(memoryview(data)[i:], -15) 29 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/gzip.py: -------------------------------------------------------------------------------- 1 | #import zlib 2 | import uzlib as zlib 3 | 4 | FTEXT = 1 5 | FHCRC = 2 6 | FEXTRA = 4 7 | FNAME = 8 8 | FCOMMENT = 16 9 | 10 | def decompress(data): 11 | assert data[0] == 0x1f and data[1] == 0x8b 12 | assert data[2] == 8 13 | flg = data[3] 14 | assert flg & 0xe0 == 0 15 | i = 10 16 | if flg & FEXTRA: 17 | i += data[11] << 8 + data[10] + 2 18 | if flg & FNAME: 19 | while data[i]: 20 | i += 1 21 | i += 1 22 | if flg & FCOMMENT: 23 | while data[i]: 24 | i += 1 25 | i += 1 26 | if flg & FHCRC: 27 | i += 2 28 | return zlib.decompress(memoryview(data)[i:], -15) 29 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/pwd.py: -------------------------------------------------------------------------------- 1 | import ffilib 2 | import uctypes 3 | import ustruct 4 | 5 | from ucollections import namedtuple 6 | 7 | 8 | libc = ffilib.libc() 9 | 10 | getpwnam_ = libc.func("P", "getpwnam", "s") 11 | 12 | 13 | struct_passwd = namedtuple("struct_passwd", 14 | ["pw_name", "pw_passwd", "pw_uid", "pw_gid", "pw_gecos", "pw_dir", "pw_shell"]) 15 | 16 | 17 | def getpwnam(user): 18 | passwd = getpwnam_(user) 19 | if not passwd: 20 | raise KeyError("getpwnam(): name not found: {}".format(user)) 21 | passwd_fmt = "SSIISSS" 22 | passwd = uctypes.bytes_at(passwd, ustruct.calcsize(passwd_fmt)) 23 | passwd = ustruct.unpack(passwd_fmt, passwd) 24 | return struct_passwd(*passwd) 25 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/pwd.py: -------------------------------------------------------------------------------- 1 | import ffilib 2 | import uctypes 3 | import ustruct 4 | 5 | from ucollections import namedtuple 6 | 7 | 8 | libc = ffilib.libc() 9 | 10 | getpwnam_ = libc.func("P", "getpwnam", "s") 11 | 12 | 13 | struct_passwd = namedtuple("struct_passwd", 14 | ["pw_name", "pw_passwd", "pw_uid", "pw_gid", "pw_gecos", "pw_dir", "pw_shell"]) 15 | 16 | 17 | def getpwnam(user): 18 | passwd = getpwnam_(user) 19 | if not passwd: 20 | raise KeyError("getpwnam(): name not found: {}".format(user)) 21 | passwd_fmt = "SSIISSS" 22 | passwd = uctypes.bytes_at(passwd, ustruct.calcsize(passwd_fmt)) 23 | passwd = ustruct.unpack(passwd_fmt, passwd) 24 | return struct_passwd(*passwd) 25 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/_libc.py: -------------------------------------------------------------------------------- 1 | import ffi 2 | import sys 3 | 4 | 5 | _h = None 6 | 7 | names = ('libc.so', 'libc.so.0', 'libc.so.6', 'libc.dylib') 8 | 9 | def get(): 10 | global _h 11 | if _h: 12 | return _h 13 | err = None 14 | for n in names: 15 | try: 16 | _h = ffi.open(n) 17 | return _h 18 | except OSError as e: 19 | err = e 20 | raise err 21 | 22 | 23 | def set_names(n): 24 | global names 25 | names = n 26 | 27 | # Find out bitness of the platform, even if long ints are not supported 28 | # TODO: All bitness differences should be removed from micropython-lib, and 29 | # this snippet too. 30 | bitness = 1 31 | v = sys.maxsize 32 | while v: 33 | bitness += 1 34 | v >>= 1 35 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/_libc.py: -------------------------------------------------------------------------------- 1 | import ffi 2 | import sys 3 | 4 | 5 | _h = None 6 | 7 | names = ('libc.so', 'libc.so.0', 'libc.so.6', 'libc.dylib') 8 | 9 | def get(): 10 | global _h 11 | if _h: 12 | return _h 13 | err = None 14 | for n in names: 15 | try: 16 | _h = ffi.open(n) 17 | return _h 18 | except OSError as e: 19 | err = e 20 | raise err 21 | 22 | 23 | def set_names(n): 24 | global names 25 | names = n 26 | 27 | # Find out bitness of the platform, even if long ints are not supported 28 | # TODO: All bitness differences should be removed from micropython-lib, and 29 | # this snippet too. 30 | bitness = 1 31 | v = sys.maxsize 32 | while v: 33 | bitness += 1 34 | v >>= 1 35 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/traceback.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | def format_tb(tb, limit): 4 | return ["traceback.format_tb() not implemented\n"] 5 | 6 | def format_exception_only(type, value): 7 | return [repr(value) + "\n"] 8 | 9 | def format_exception(etype, value, tb, limit=None, chain=True): 10 | return format_exception_only(etype, value) 11 | 12 | def print_exception(t, e, tb, limit=None, file=None, chain=True): 13 | if file is None: 14 | file = sys.stdout 15 | sys.print_exception(e, file) 16 | 17 | def print_exc(limit=None, file=None, chain=True): 18 | print_exception(*sys.exc_info(), limit=limit, file=file, chain=chain) 19 | 20 | def format_exc(limit=None, chain=True): 21 | return "".join(format_exception(*sys.exc_info(), limit=limit, chain=chain)) 22 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/traceback.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | def format_tb(tb, limit): 4 | return ["traceback.format_tb() not implemented\n"] 5 | 6 | def format_exception_only(type, value): 7 | return [repr(value) + "\n"] 8 | 9 | def format_exception(etype, value, tb, limit=None, chain=True): 10 | return format_exception_only(etype, value) 11 | 12 | def print_exception(t, e, tb, limit=None, file=None, chain=True): 13 | if file is None: 14 | file = sys.stdout 15 | sys.print_exception(e, file) 16 | 17 | def print_exc(limit=None, file=None, chain=True): 18 | print_exception(*sys.exc_info(), limit=limit, file=file, chain=chain) 19 | 20 | def format_exc(limit=None, chain=True): 21 | return "".join(format_exception(*sys.exc_info(), limit=limit, chain=chain)) 22 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/functools.py: -------------------------------------------------------------------------------- 1 | def partial(func, *args, **kwargs): 2 | def _partial(*more_args, **more_kwargs): 3 | kw = kwargs.copy() 4 | kw.update(more_kwargs) 5 | return func(*(args + more_args), **kw) 6 | return _partial 7 | 8 | 9 | def update_wrapper(wrapper, wrapped, assigned=None, updated=None): 10 | # Dummy impl 11 | return wrapper 12 | 13 | 14 | def wraps(wrapped, assigned=None, updated=None): 15 | # Dummy impl 16 | return lambda x: x 17 | 18 | 19 | def reduce(function, iterable, initializer=None): 20 | it = iter(iterable) 21 | if initializer is None: 22 | value = next(it) 23 | else: 24 | value = initializer 25 | for element in it: 26 | value = function(value, element) 27 | return value 28 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/functools.py: -------------------------------------------------------------------------------- 1 | def partial(func, *args, **kwargs): 2 | def _partial(*more_args, **more_kwargs): 3 | kw = kwargs.copy() 4 | kw.update(more_kwargs) 5 | return func(*(args + more_args), **kw) 6 | return _partial 7 | 8 | 9 | def update_wrapper(wrapper, wrapped, assigned=None, updated=None): 10 | # Dummy impl 11 | return wrapper 12 | 13 | 14 | def wraps(wrapped, assigned=None, updated=None): 15 | # Dummy impl 16 | return lambda x: x 17 | 18 | 19 | def reduce(function, iterable, initializer=None): 20 | it = iter(iterable) 21 | if initializer is None: 22 | value = next(it) 23 | else: 24 | value = initializer 25 | for element in it: 26 | value = function(value, element) 27 | return value 28 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/boot/03_builtin.py: -------------------------------------------------------------------------------- 1 | import builtins 2 | import sys 3 | 4 | 5 | # noinspection PyShadowingBuiltins 6 | def input(prompt=None): 7 | if prompt is not None: 8 | print(prompt, end="") 9 | 10 | read = sys.stdin.read 11 | write = sys.stdout.write 12 | buf = [] 13 | ignore = 0 14 | while True: 15 | ch = read(1) 16 | if ignore > 0: 17 | ignore -= 1 18 | continue 19 | 20 | if ch == '\n': 21 | write(ch) 22 | break 23 | elif ch == '\b': 24 | if buf: 25 | buf.pop() 26 | write(ch + "---") 27 | continue 28 | else: 29 | write(ch) 30 | buf.append(ch) 31 | 32 | return ''.join(buf) 33 | 34 | 35 | builtins.input = input 36 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/openos/sides.py: -------------------------------------------------------------------------------- 1 | # https://github.com/MightyPirates/OpenComputers/blob/master-MC1.12/ 2 | # - src/main/resources/assets/opencomputers/loot/openos/lib/sides.lua 3 | 4 | from micropython import const 5 | 6 | __all__ = ["BOTTOM", "TOP", "BACK", "FRONT", "RIGHT", "LEFT"] 7 | 8 | BOTTOM = const(0) 9 | TOP = const(1) 10 | BACK = const(2) 11 | FRONT = const(3) 12 | RIGHT = const(4) 13 | LEFT = const(5) 14 | 15 | # alias 16 | NEGY = DOWN = BOTTOM 17 | POSY = UP = TOP 18 | NEGZ = NORTH = BACK 19 | POSZ = SOUTH = FORWARD = FRONT 20 | NEGX = WEST = RIGHT 21 | POSX = EAST = LEFT 22 | 23 | # alias for lowercase 24 | negy = down = bottom = BOTTOM 25 | posy = up = top = TOP 26 | negz = north = back = BACK 27 | posz = south = forward = front = FRONT 28 | negx = west = right = RIGHT 29 | posx = east = left = LEFT 30 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/openos/note.py: -------------------------------------------------------------------------------- 1 | # https://github.com/MightyPirates/OpenComputers/blob/master-MC1.12/ 2 | # - src/main/resources/assets/opencomputers/loot/openos/lib/note.lua 3 | 4 | note = {} 5 | notes = {} # The table that maps note names to their respective MIDI codes 6 | reverseNotes = {} # The reversed table "notes" 7 | 8 | tempNotes = ["c", "c#", "d", "d#", "e", "f", "f#", "g", "g#", "a", "a#", "b"] 9 | sNotes = ["a0", "a#0", "b0"] 10 | bNotes = ["bb0"] 11 | 12 | for i in range(1, 6 + 1): 13 | for v in tempNotes: 14 | sNotes.append(v + str(i)) 15 | if len(v) == 1 and v != "c" and v != "f": 16 | bNotes.append(v + "b" + str(i)) 17 | 18 | for v in range(21, 95 + 1): 19 | k = sNotes[v - 20 - 1] 20 | notes[k] = str(v) 21 | reverseNotes[v] = k 22 | 23 | # TODO: ? 24 | raise NotImplementedError 25 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/pkg_resources.py: -------------------------------------------------------------------------------- 1 | import uio 2 | 3 | c = {} 4 | 5 | def resource_stream(package, resource): 6 | if package not in c: 7 | try: 8 | if package: 9 | p = __import__(package + ".R", None, None, True) 10 | else: 11 | p = __import__("R") 12 | c[package] = p.R 13 | except ImportError: 14 | if package: 15 | p = __import__(package) 16 | d = p.__path__ 17 | else: 18 | d = "." 19 | # if d[0] != "/": 20 | # import uos 21 | # d = uos.getcwd() + "/" + d 22 | c[package] = d + "/" 23 | 24 | p = c[package] 25 | if isinstance(p, dict): 26 | return uio.BytesIO(p[resource]) 27 | return open(p + resource, "rb") 28 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/pkg_resources.py: -------------------------------------------------------------------------------- 1 | import uio 2 | 3 | c = {} 4 | 5 | def resource_stream(package, resource): 6 | if package not in c: 7 | try: 8 | if package: 9 | p = __import__(package + ".R", None, None, True) 10 | else: 11 | p = __import__("R") 12 | c[package] = p.R 13 | except ImportError: 14 | if package: 15 | p = __import__(package) 16 | d = p.__path__ 17 | else: 18 | d = "." 19 | # if d[0] != "/": 20 | # import uos 21 | # d = uos.getcwd() + "/" + d 22 | c[package] = d + "/" 23 | 24 | p = c[package] 25 | if isinstance(p, dict): 26 | return uio.BytesIO(p[resource]) 27 | return open(p + resource, "rb") 28 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/machine/pin.py: -------------------------------------------------------------------------------- 1 | import umachine 2 | 3 | class Pin(umachine.PinBase): 4 | 5 | IN = "in" 6 | OUT = "out" 7 | 8 | def __init__(self, no, dir=IN): 9 | pref = "/sys/class/gpio/gpio{}/".format(no) 10 | dirf = pref + "direction" 11 | try: 12 | f = open(dirf, "w") 13 | except OSError: 14 | with open("/sys/class/gpio/export", "w") as f: 15 | f.write(str(no)) 16 | f = open(dirf, "w") 17 | f.write(dir) 18 | f.close() 19 | self.f = open(pref + "value", "r+b") 20 | 21 | def value(self, v=None): 22 | if v is None: 23 | self.f.seek(0) 24 | return 1 if self.f.read(1) == b"1" else 0 25 | self.f.write(b"1" if v else b"0") 26 | 27 | def deinit(self): 28 | self.f.close() 29 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/machine/pin.py: -------------------------------------------------------------------------------- 1 | import umachine 2 | 3 | class Pin(umachine.PinBase): 4 | 5 | IN = "in" 6 | OUT = "out" 7 | 8 | def __init__(self, no, dir=IN): 9 | pref = "/sys/class/gpio/gpio{}/".format(no) 10 | dirf = pref + "direction" 11 | try: 12 | f = open(dirf, "w") 13 | except OSError: 14 | with open("/sys/class/gpio/export", "w") as f: 15 | f.write(str(no)) 16 | f = open(dirf, "w") 17 | f.write(dir) 18 | f.close() 19 | self.f = open(pref + "value", "r+b") 20 | 21 | def value(self, v=None): 22 | if v is None: 23 | self.f.seek(0) 24 | return 1 if self.f.read(1) == b"1" else 0 25 | self.f.write(b"1" if v else b"0") 26 | 27 | def deinit(self): 28 | self.f.close() 29 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/bin/shell.py: -------------------------------------------------------------------------------- 1 | import os 2 | import shell 3 | 4 | 5 | def main(): 6 | while True: 7 | command, *args = input(os.getcwd() + "> ").split() 8 | if command == "exit": 9 | break 10 | elif command == "cd": 11 | try: 12 | os.chdir(args[0] if args else '.') 13 | except OSError as e: 14 | print("fail", e) 15 | else: 16 | programs = os.listdir('/bin') 17 | filename = command + '.py' 18 | if filename in programs: 19 | progpath = os.path.join('/bin', filename) 20 | exitcode = shell.spawn(progpath, *args) 21 | print("exitcode:", exitcode) 22 | else: 23 | print("Program not found:", filename) 24 | 25 | 26 | if __name__ == '__main__': 27 | main() 28 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/html/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | General functions for HTML manipulation. 3 | """ 4 | 5 | 6 | _escape_map = {ord('&'): '&', ord('<'): '<', ord('>'): '>'} 7 | _escape_map_full = {ord('&'): '&', ord('<'): '<', ord('>'): '>', 8 | ord('"'): '"', ord('\''): '''} 9 | 10 | # NB: this is a candidate for a bytes/string polymorphic interface 11 | 12 | def escape(s, quote=True): 13 | """ 14 | Replace special characters "&", "<" and ">" to HTML-safe sequences. 15 | If the optional flag quote is true (the default), the quotation mark 16 | characters, both double quote (") and single quote (') characters are also 17 | translated. 18 | """ 19 | import string 20 | if quote: 21 | return string.translate(s, _escape_map_full) 22 | return string.translate(s, _escape_map) 23 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/html/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | General functions for HTML manipulation. 3 | """ 4 | 5 | 6 | _escape_map = {ord('&'): '&', ord('<'): '<', ord('>'): '>'} 7 | _escape_map_full = {ord('&'): '&', ord('<'): '<', ord('>'): '>', 8 | ord('"'): '"', ord('\''): '''} 9 | 10 | # NB: this is a candidate for a bytes/string polymorphic interface 11 | 12 | def escape(s, quote=True): 13 | """ 14 | Replace special characters "&", "<" and ">" to HTML-safe sequences. 15 | If the optional flag quote is true (the default), the quotation mark 16 | characters, both double quote (") and single quote (') characters are also 17 | translated. 18 | """ 19 | import string 20 | if quote: 21 | return string.translate(s, _escape_map_full) 22 | return string.translate(s, _escape_map) 23 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/shutil.py: -------------------------------------------------------------------------------- 1 | # Reimplement, because CPython3.3 impl is rather bloated 2 | import os 3 | 4 | 5 | def rmtree(top): 6 | for path, dirs, files in os.walk(top, False): 7 | for f in files: 8 | os.unlink(path + "/" + f) 9 | os.rmdir(path) 10 | 11 | def copyfileobj(src, dest, length=512): 12 | if hasattr(src, "readinto"): 13 | buf = bytearray(length) 14 | while True: 15 | sz = src.readinto(buf) 16 | if not sz: 17 | break 18 | if sz == length: 19 | dest.write(buf) 20 | else: 21 | b = memoryview(buf)[:sz] 22 | dest.write(b) 23 | else: 24 | while True: 25 | buf = src.read(length) 26 | if not buf: 27 | break 28 | dest.write(buf) 29 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/shutil.py: -------------------------------------------------------------------------------- 1 | # Reimplement, because CPython3.3 impl is rather bloated 2 | import os 3 | 4 | 5 | def rmtree(top): 6 | for path, dirs, files in os.walk(top, False): 7 | for f in files: 8 | os.unlink(path + "/" + f) 9 | os.rmdir(path) 10 | 11 | def copyfileobj(src, dest, length=512): 12 | if hasattr(src, "readinto"): 13 | buf = bytearray(length) 14 | while True: 15 | sz = src.readinto(buf) 16 | if not sz: 17 | break 18 | if sz == length: 19 | dest.write(buf) 20 | else: 21 | b = memoryview(buf)[:sz] 22 | dest.write(b) 23 | else: 24 | while True: 25 | buf = src.read(length) 26 | if not buf: 27 | break 28 | dest.write(buf) 29 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/collections/deque.py: -------------------------------------------------------------------------------- 1 | class deque: 2 | 3 | def __init__(self, iterable=None): 4 | if iterable is None: 5 | self.q = [] 6 | else: 7 | self.q = list(iterable) 8 | 9 | def popleft(self): 10 | return self.q.pop(0) 11 | 12 | def popright(self): 13 | return self.q.pop() 14 | 15 | def pop(self): 16 | return self.q.pop() 17 | 18 | def append(self, a): 19 | self.q.append(a) 20 | 21 | def appendleft(self, a): 22 | self.q.insert(0, a) 23 | 24 | def extend(self, a): 25 | self.q.extend(a) 26 | 27 | def __len__(self): 28 | return len(self.q) 29 | 30 | def __bool__(self): 31 | return bool(self.q) 32 | 33 | def __iter__(self): 34 | yield from self.q 35 | 36 | def __str__(self): 37 | return 'deque({})'.format(self.q) 38 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/string.py: -------------------------------------------------------------------------------- 1 | # Some strings for ctype-style character classification 2 | whitespace = ' \t\n\r\v\f' 3 | ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz' 4 | ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 5 | ascii_letters = ascii_lowercase + ascii_uppercase 6 | digits = '0123456789' 7 | hexdigits = digits + 'abcdef' + 'ABCDEF' 8 | octdigits = '01234567' 9 | punctuation = """!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~""" 10 | printable = digits + ascii_letters + punctuation + whitespace 11 | 12 | 13 | def translate(s, map): 14 | import io 15 | sb = io.StringIO() 16 | for c in s: 17 | v = ord(c) 18 | if v in map: 19 | v = map[v] 20 | if isinstance(v, int): 21 | sb.write(chr(v)) 22 | elif v is not None: 23 | sb.write(v) 24 | else: 25 | sb.write(c) 26 | return sb.getvalue() 27 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/collections/deque.py: -------------------------------------------------------------------------------- 1 | class deque: 2 | 3 | def __init__(self, iterable=None): 4 | if iterable is None: 5 | self.q = [] 6 | else: 7 | self.q = list(iterable) 8 | 9 | def popleft(self): 10 | return self.q.pop(0) 11 | 12 | def popright(self): 13 | return self.q.pop() 14 | 15 | def pop(self): 16 | return self.q.pop() 17 | 18 | def append(self, a): 19 | self.q.append(a) 20 | 21 | def appendleft(self, a): 22 | self.q.insert(0, a) 23 | 24 | def extend(self, a): 25 | self.q.extend(a) 26 | 27 | def __len__(self): 28 | return len(self.q) 29 | 30 | def __bool__(self): 31 | return bool(self.q) 32 | 33 | def __iter__(self): 34 | yield from self.q 35 | 36 | def __str__(self): 37 | return 'deque({})'.format(self.q) 38 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/string.py: -------------------------------------------------------------------------------- 1 | # Some strings for ctype-style character classification 2 | whitespace = ' \t\n\r\v\f' 3 | ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz' 4 | ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 5 | ascii_letters = ascii_lowercase + ascii_uppercase 6 | digits = '0123456789' 7 | hexdigits = digits + 'abcdef' + 'ABCDEF' 8 | octdigits = '01234567' 9 | punctuation = """!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~""" 10 | printable = digits + ascii_letters + punctuation + whitespace 11 | 12 | 13 | def translate(s, map): 14 | import io 15 | sb = io.StringIO() 16 | for c in s: 17 | v = ord(c) 18 | if v in map: 19 | v = map[v] 20 | if isinstance(v, int): 21 | sb.write(chr(v)) 22 | elif v is not None: 23 | sb.write(v) 24 | else: 25 | sb.write(c) 26 | return sb.getvalue() 27 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/openpython/arch/types/call/ValueCall.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.openpython.arch.types.call 2 | 3 | import li.cil.oc.api.machine.Machine 4 | import li.cil.oc.api.machine.Value 5 | 6 | class ValueCall(value: Value, vararg args: Any?) : ValueInvokeable(value, *args) { 7 | override operator fun invoke(machine: Machine): InvokeResult { 8 | return try { 9 | InvokeResult(value.call(machine, this.args)) 10 | } catch (e: Error) { 11 | InvokeResult(error = e) 12 | } catch (e: Exception) { 13 | InvokeResult(error = e) 14 | } 15 | } 16 | 17 | companion object { 18 | fun fromArray(array: Array<*>): ValueCall? { 19 | if (array.size < 1) 20 | return null 21 | 22 | val args = arrayOfNulls(array.size - 1) 23 | System.arraycopy(array, 1, args, 0, args.size) 24 | 25 | return ValueCall(array[0] as Value, *args) 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/boot/02_screen.py: -------------------------------------------------------------------------------- 1 | import machine 2 | 3 | from component import get_component, find_components 4 | from monitor import Monitor, _set_monitor 5 | 6 | gpu = get_component("gpu") 7 | 8 | screen = None 9 | for screen in find_components("screen"): 10 | if screen.getKeyboards(): 11 | break 12 | 13 | if gpu and screen: 14 | monitor = Monitor(gpu.address, gpu.type) 15 | monitor.bind(screen.address) 16 | w, h = monitor.maxResolution() 17 | monitor.w, monitor.h = w, h 18 | monitor.setResolution(w, h) 19 | monitor.setBackground(0x000000) 20 | monitor.setForeground(0xFFFFFF) 21 | monitor.fill(1, 1, w, h, " ") 22 | 23 | 24 | @machine.hook_stdout 25 | def print_handler(string): 26 | try: 27 | for char in string: 28 | monitor.put(char) 29 | except BaseException as e: 30 | machine.debug("print_handler exc =? %s: %s" % (type(e).__name__, e)) 31 | 32 | 33 | _set_monitor(monitor) 34 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/openpython/arch/types/call/ValueApply.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.openpython.arch.types.call 2 | 3 | import li.cil.oc.api.machine.Machine 4 | import li.cil.oc.api.machine.Value 5 | 6 | class ValueApply(value: Value, vararg args: Any?) : ValueInvokeable(value, *args) { 7 | override operator fun invoke(machine: Machine): InvokeResult { 8 | return try { 9 | InvokeResult(args = arrayOf(value.apply(machine, this.args))) 10 | } catch (e: Error) { 11 | InvokeResult(error = e) 12 | } catch (e: Exception) { 13 | InvokeResult(error = e) 14 | } 15 | } 16 | 17 | companion object { 18 | fun fromArray(array: Array<*>): ValueApply? { 19 | if (array.isEmpty()) 20 | return null 21 | 22 | val args = arrayOfNulls(array.size - 1) 23 | System.arraycopy(array, 1, args, 0, args.size) 24 | 25 | return ValueApply(array[0] as Value, *args) 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/openpython/arch/state/ValueContainer.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.openpython.arch.state 2 | 3 | import li.cil.oc.api.Persistable 4 | import li.cil.oc.api.machine.Value 5 | import net.minecraft.nbt.NBTTagCompound 6 | 7 | class ValueContainer(var value: Value? = null, var id: Int = 0) : Persistable { 8 | override fun load(nbt: NBTTagCompound) { 9 | val clsName = nbt.getString("class") 10 | val cls = Class.forName(clsName) 11 | val instance = cls.newInstance() as? Value ?: throw TypeCastException() 12 | val data = nbt.getCompoundTag("data") 13 | val id = nbt.getInteger("id") 14 | 15 | instance.load(data) 16 | 17 | this.id = id 18 | this.value = instance 19 | } 20 | 21 | override fun save(nbt: NBTTagCompound) { 22 | val data = NBTTagCompound() 23 | value!!.save(data) 24 | 25 | nbt.setString("class", value!!.javaClass.name) 26 | nbt.setTag("data", data) 27 | nbt.setInteger("id", id) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/uasyncio/synchro.py: -------------------------------------------------------------------------------- 1 | from uasyncio import core 2 | 3 | class Lock: 4 | 5 | def __init__(self): 6 | self.locked = False 7 | self.wlist = [] 8 | 9 | def release(self): 10 | assert self.locked 11 | self.locked = False 12 | if self.wlist: 13 | #print(self.wlist) 14 | coro = self.wlist.pop(0) 15 | core.get_event_loop().call_soon(coro) 16 | 17 | def acquire(self): 18 | # As release() is not coro, assume we just released and going to acquire again 19 | # so, yield first to let someone else to acquire it first 20 | yield 21 | #print("acquire:", self.locked) 22 | while 1: 23 | if not self.locked: 24 | self.locked = True 25 | return True 26 | #print("putting", core.get_event_loop().cur_task, "on waiting list") 27 | self.wlist.append(core.get_event_loop().cur_task) 28 | yield False 29 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/uasyncio/synchro.py: -------------------------------------------------------------------------------- 1 | from uasyncio import core 2 | 3 | class Lock: 4 | 5 | def __init__(self): 6 | self.locked = False 7 | self.wlist = [] 8 | 9 | def release(self): 10 | assert self.locked 11 | self.locked = False 12 | if self.wlist: 13 | #print(self.wlist) 14 | coro = self.wlist.pop(0) 15 | core.get_event_loop().call_soon(coro) 16 | 17 | def acquire(self): 18 | # As release() is not coro, assume we just released and going to acquire again 19 | # so, yield first to let someone else to acquire it first 20 | yield 21 | #print("acquire:", self.locked) 22 | while 1: 23 | if not self.locked: 24 | self.locked = True 25 | return True 26 | #print("putting", core.get_event_loop().cur_task, "on waiting list") 27 | self.wlist.append(core.get_event_loop().cur_task) 28 | yield False 29 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/fcntl.py: -------------------------------------------------------------------------------- 1 | import ffi 2 | import os 3 | import ffilib 4 | 5 | 6 | libc = ffilib.libc() 7 | 8 | fcntl_l = libc.func("i", "fcntl", "iil") 9 | fcntl_s = libc.func("i", "fcntl", "iip") 10 | ioctl_l = libc.func("i", "ioctl", "iil") 11 | ioctl_s = libc.func("i", "ioctl", "iip") 12 | 13 | 14 | def fcntl(fd, op, arg=0): 15 | if type(arg) is int: 16 | r = fcntl_l(fd, op, arg) 17 | os.check_error(r) 18 | return r 19 | else: 20 | r = fcntl_s(fd, op, arg) 21 | os.check_error(r) 22 | # TODO: Not compliant. CPython says that arg should be immutable, 23 | # and possibly mutated buffer is returned. 24 | return r 25 | 26 | 27 | def ioctl(fd, op, arg=0, mut=False): 28 | if type(arg) is int: 29 | r = ioctl_l(fd, op, arg) 30 | os.check_error(r) 31 | return r 32 | else: 33 | # TODO 34 | assert mut 35 | r = ioctl_s(fd, op, arg) 36 | os.check_error(r) 37 | return r 38 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/fcntl.py: -------------------------------------------------------------------------------- 1 | import ffi 2 | import os 3 | import ffilib 4 | 5 | 6 | libc = ffilib.libc() 7 | 8 | fcntl_l = libc.func("i", "fcntl", "iil") 9 | fcntl_s = libc.func("i", "fcntl", "iip") 10 | ioctl_l = libc.func("i", "ioctl", "iil") 11 | ioctl_s = libc.func("i", "ioctl", "iip") 12 | 13 | 14 | def fcntl(fd, op, arg=0): 15 | if type(arg) is int: 16 | r = fcntl_l(fd, op, arg) 17 | os.check_error(r) 18 | return r 19 | else: 20 | r = fcntl_s(fd, op, arg) 21 | os.check_error(r) 22 | # TODO: Not compliant. CPython says that arg should be immutable, 23 | # and possibly mutated buffer is returned. 24 | return r 25 | 26 | 27 | def ioctl(fd, op, arg=0, mut=False): 28 | if type(arg) is int: 29 | r = ioctl_l(fd, op, arg) 30 | os.check_error(r) 31 | return r 32 | else: 33 | # TODO 34 | assert mut 35 | r = ioctl_s(fd, op, arg) 36 | os.check_error(r) 37 | return r 38 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/openpython/arch/types/call/ValueUnapply.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.openpython.arch.types.call 2 | 3 | import li.cil.oc.api.machine.Machine 4 | import li.cil.oc.api.machine.Value 5 | 6 | class ValueUnapply(value: Value, vararg args: Any?) : ValueInvokeable(value, *args) { 7 | override operator fun invoke(machine: Machine): InvokeResult { 8 | return try { 9 | value.unapply(machine, this.args) 10 | InvokeResult(args = arrayOf()) 11 | } catch (e: Error) { 12 | InvokeResult(error = e) 13 | } catch (e: Exception) { 14 | InvokeResult(error = e) 15 | } 16 | } 17 | 18 | companion object { 19 | fun fromArray(array: Array<*>): ValueUnapply? { 20 | if (array.isEmpty()) 21 | return null 22 | 23 | val args = arrayOfNulls(array.size - 1) 24 | System.arraycopy(array, 1, args, 0, args.size) 25 | 26 | return ValueUnapply(array[0] as Value, *args) 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/openos/internet.py: -------------------------------------------------------------------------------- 1 | # https://github.com/MightyPirates/OpenComputers/blob/master-MC1.12/ 2 | # src/main/resources/assets/opencomputers/loot/openos/lib/internet.lua 3 | 4 | import component 5 | 6 | robot = component.import_component("robot", __name__) 7 | 8 | 9 | def request(url: str, data=None, headers: dict = None): 10 | internet = component.get_primary("internet") 11 | 12 | post = None 13 | if data is None: 14 | pass 15 | elif isinstance(data, (str, bytes)): 16 | post = data 17 | elif isinstance(data, dict): 18 | post = "&".join("{}={}".format(key, value) for key, value in data.items()) 19 | else: 20 | raise TypeError 21 | 22 | return internet.request(url, post, headers) 23 | 24 | 25 | def socket(address, port): 26 | internet = component.get_primary("internet") 27 | return internet.socket(address, port) 28 | 29 | 30 | def open(address, port): 31 | internet = component.get_primary("internet") 32 | return internet.open(address, port) 33 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/tests.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from ucontextlib import contextmanager 3 | 4 | 5 | class ContextManagerTestCase(unittest.TestCase): 6 | 7 | def setUp(self): 8 | self._history = [] 9 | 10 | @contextmanager 11 | def manager(x): 12 | self._history.append('start') 13 | try: 14 | yield x 15 | finally: 16 | self._history.append('finish') 17 | 18 | self._manager = manager 19 | 20 | def test_context_manager(self): 21 | with self._manager(123) as x: 22 | self.assertEqual(x, 123) 23 | self.assertEqual(self._history, ['start', 'finish']) 24 | 25 | def test_context_manager_on_error(self): 26 | exc = Exception() 27 | try: 28 | with self._manager(123) as x: 29 | raise exc 30 | except Exception as e: 31 | self.assertEqual(exc, e) 32 | self.assertEqual(self._history, ['start', 'finish']) 33 | 34 | 35 | if __name__ == '__main__': 36 | unittest.main() 37 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/tests.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from ucontextlib import contextmanager 3 | 4 | 5 | class ContextManagerTestCase(unittest.TestCase): 6 | 7 | def setUp(self): 8 | self._history = [] 9 | 10 | @contextmanager 11 | def manager(x): 12 | self._history.append('start') 13 | try: 14 | yield x 15 | finally: 16 | self._history.append('finish') 17 | 18 | self._manager = manager 19 | 20 | def test_context_manager(self): 21 | with self._manager(123) as x: 22 | self.assertEqual(x, 123) 23 | self.assertEqual(self._history, ['start', 'finish']) 24 | 25 | def test_context_manager_on_error(self): 26 | exc = Exception() 27 | try: 28 | with self._manager(123) as x: 29 | raise exc 30 | except Exception as e: 31 | self.assertEqual(exc, e) 32 | self.assertEqual(self._history, ['start', 'finish']) 33 | 34 | 35 | if __name__ == '__main__': 36 | unittest.main() 37 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/ssl.py: -------------------------------------------------------------------------------- 1 | from ussl import * 2 | import ussl as _ussl 3 | 4 | # Constants 5 | for sym in "CERT_NONE", "CERT_OPTIONAL", "CERT_REQUIRED": 6 | if sym not in globals(): 7 | globals()[sym] = object() 8 | 9 | 10 | def wrap_socket(sock, keyfile=None, certfile=None, server_side=False, 11 | cert_reqs=CERT_NONE, *, ca_certs=None, server_hostname=None): 12 | # TODO: More arguments accepted by CPython could also be handled here. 13 | # That would allow us to accept ca_certs as a positional argument, which 14 | # we should. 15 | kw = {} 16 | if keyfile is not None: 17 | kw["keyfile"] = keyfile 18 | if certfile is not None: 19 | kw["certfile"] = certfile 20 | if server_side is not False: 21 | kw["server_side"] = server_side 22 | if cert_reqs is not CERT_NONE: 23 | kw["cert_reqs"] = cert_reqs 24 | if ca_certs is not None: 25 | kw["ca_certs"] = ca_certs 26 | if server_hostname is not None: 27 | kw["server_hostname"] = server_hostname 28 | return _ussl.wrap_socket(sock, **kw) 29 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/ssl.py: -------------------------------------------------------------------------------- 1 | from ussl import * 2 | import ussl as _ussl 3 | 4 | # Constants 5 | for sym in "CERT_NONE", "CERT_OPTIONAL", "CERT_REQUIRED": 6 | if sym not in globals(): 7 | globals()[sym] = object() 8 | 9 | 10 | def wrap_socket(sock, keyfile=None, certfile=None, server_side=False, 11 | cert_reqs=CERT_NONE, *, ca_certs=None, server_hostname=None): 12 | # TODO: More arguments accepted by CPython could also be handled here. 13 | # That would allow us to accept ca_certs as a positional argument, which 14 | # we should. 15 | kw = {} 16 | if keyfile is not None: 17 | kw["keyfile"] = keyfile 18 | if certfile is not None: 19 | kw["certfile"] = certfile 20 | if server_side is not False: 21 | kw["server_side"] = server_side 22 | if cert_reqs is not CERT_NONE: 23 | kw["cert_reqs"] = cert_reqs 24 | if ca_certs is not None: 25 | kw["ca_certs"] = ca_certs 26 | if server_hostname is not None: 27 | kw["server_hostname"] = server_hostname 28 | return _ussl.wrap_socket(sock, **kw) 29 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/openos/colors.py: -------------------------------------------------------------------------------- 1 | # https://github.com/MightyPirates/OpenComputers/blob/master-MC1.12/ 2 | # - src/main/resources/assets/opencomputers/loot/openos/lib/colors.lua 3 | 4 | from micropython import const 5 | 6 | __all__ = ["WHITE", "ORANGE", "MAGENTA", "LIGHTBLUE", 7 | "YELLOW", "LIME", "PINK", "GRAY", 8 | "SILVER", "CYAN", "PURPLE", "BLUE", 9 | "BROWN", "GREEN", "RED", "BLACK"] 10 | 11 | WHITE = const(0) 12 | ORANGE = const(1) 13 | MAGENTA = const(2) 14 | LIGHTBLUE = const(3) 15 | YELLOW = const(4) 16 | LIME = const(5) 17 | PINK = const(6) 18 | GRAY = const(7) 19 | SILVER = const(8) 20 | CYAN = const(9) 21 | PURPLE = const(10) 22 | BLUE = const(11) 23 | BROWN = const(12) 24 | GREEN = const(13) 25 | RED = const(14) 26 | BLACK = const(15) 27 | 28 | # alias 29 | white = WHITE 30 | orange = ORANGE 31 | magenta = MAGENTA 32 | lightblue = LIGHTBLUE 33 | yellow = YELLOW 34 | lime = LIME 35 | pink = PINK 36 | gray = GRAY 37 | silver = SILVER 38 | cyan = CYAN 39 | purple = PURPLE 40 | blue = BLUE 41 | brown = BROWN 42 | green = GREEN 43 | red = RED 44 | black = BLACK 45 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 EcmaXp 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/boot/05_screen.py: -------------------------------------------------------------------------------- 1 | import machine 2 | 3 | import component 4 | from monitor import Monitor, _set_monitor 5 | 6 | gpu = component.get_primary("gpu") 7 | 8 | screen = None 9 | for screen in component.list("screen"): 10 | if screen.getKeyboards(): 11 | component.set_primary("screen", screen.address) 12 | break 13 | 14 | if gpu and screen: 15 | monitor = Monitor(gpu) 16 | gpu.bind(screen.address) 17 | w, h = gpu.maxResolution() 18 | monitor.w, monitor.h = w, h 19 | gpu.setResolution(w, h) 20 | gpu.setBackground(0x000000) 21 | gpu.setForeground(0xFFFFFF) 22 | gpu.fill(1, 1, w, h, " ") 23 | 24 | 25 | @machine.hook_stdout 26 | def print_handler(string): 27 | try: 28 | for char in string: 29 | monitor.put(char) 30 | except BaseException as e: 31 | machine.debug("print_handler exc =? %s: %s" % (type(e).__name__, e)) 32 | 33 | 34 | _set_monitor(monitor) 35 | 36 | import tty 37 | 38 | tty.bind(gpu) 39 | 40 | 41 | @machine.hook_stdout 42 | def print_handler(buf): 43 | tty.stream.write(buf) 44 | -------------------------------------------------------------------------------- /LICENSE-mpack: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015-2016 Nicholas Fraser 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /LICENSE-micropython: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013, 2014 Damien P. George 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/collections/defaultdict.py: -------------------------------------------------------------------------------- 1 | class defaultdict: 2 | 3 | @staticmethod 4 | def __new__(cls, default_factory=None, **kwargs): 5 | # Some code (e.g. urllib.urlparse) expects that basic defaultdict 6 | # functionality will be available to subclasses without them 7 | # calling __init__(). 8 | self = super(defaultdict, cls).__new__(cls) 9 | self.d = {} 10 | return self 11 | 12 | def __init__(self, default_factory=None, **kwargs): 13 | self.d = kwargs 14 | self.default_factory = default_factory 15 | 16 | def __getitem__(self, key): 17 | try: 18 | return self.d[key] 19 | except KeyError: 20 | v = self.__missing__(key) 21 | self.d[key] = v 22 | return v 23 | 24 | def __setitem__(self, key, v): 25 | self.d[key] = v 26 | 27 | def __delitem__(self, key): 28 | del self.d[key] 29 | 30 | def __contains__(self, key): 31 | return key in self.d 32 | 33 | def __missing__(self, key): 34 | if self.default_factory is None: 35 | raise KeyError(key) 36 | return self.default_factory() 37 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/collections/defaultdict.py: -------------------------------------------------------------------------------- 1 | class defaultdict: 2 | 3 | @staticmethod 4 | def __new__(cls, default_factory=None, **kwargs): 5 | # Some code (e.g. urllib.urlparse) expects that basic defaultdict 6 | # functionality will be available to subclasses without them 7 | # calling __init__(). 8 | self = super(defaultdict, cls).__new__(cls) 9 | self.d = {} 10 | return self 11 | 12 | def __init__(self, default_factory=None, **kwargs): 13 | self.d = kwargs 14 | self.default_factory = default_factory 15 | 16 | def __getitem__(self, key): 17 | try: 18 | return self.d[key] 19 | except KeyError: 20 | v = self.__missing__(key) 21 | self.d[key] = v 22 | return v 23 | 24 | def __setitem__(self, key, v): 25 | self.d[key] = v 26 | 27 | def __delitem__(self, key): 28 | del self.d[key] 29 | 30 | def __contains__(self, key): 31 | return key in self.d 32 | 33 | def __missing__(self, key): 34 | if self.default_factory is None: 35 | raise KeyError(key) 36 | return self.default_factory() 37 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/json/tool.py: -------------------------------------------------------------------------------- 1 | r"""Command-line tool to validate and pretty-print JSON 2 | 3 | Usage:: 4 | 5 | $ echo '{"json":"obj"}' | python -m json.tool 6 | { 7 | "json": "obj" 8 | } 9 | $ echo '{ 1.2:3.4}' | python -m json.tool 10 | Expecting property name enclosed in double quotes: line 1 column 3 (char 2) 11 | 12 | """ 13 | import sys 14 | import json 15 | 16 | def main(): 17 | if len(sys.argv) == 1: 18 | infile = sys.stdin 19 | outfile = sys.stdout 20 | elif len(sys.argv) == 2: 21 | infile = open(sys.argv[1], 'r') 22 | outfile = sys.stdout 23 | elif len(sys.argv) == 3: 24 | infile = open(sys.argv[1], 'r') 25 | outfile = open(sys.argv[2], 'w') 26 | else: 27 | raise SystemExit(sys.argv[0] + " [infile [outfile]]") 28 | with infile: 29 | try: 30 | obj = json.load(infile) 31 | except ValueError as e: 32 | raise SystemExit(e) 33 | with outfile: 34 | json.dump(obj, outfile, sort_keys=True, 35 | indent=4, separators=(',', ': ')) 36 | outfile.write('\n') 37 | 38 | 39 | if __name__ == '__main__': 40 | main() 41 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/json/tool.py: -------------------------------------------------------------------------------- 1 | r"""Command-line tool to validate and pretty-print JSON 2 | 3 | Usage:: 4 | 5 | $ echo '{"json":"obj"}' | python -m json.tool 6 | { 7 | "json": "obj" 8 | } 9 | $ echo '{ 1.2:3.4}' | python -m json.tool 10 | Expecting property name enclosed in double quotes: line 1 column 3 (char 2) 11 | 12 | """ 13 | import sys 14 | import json 15 | 16 | def main(): 17 | if len(sys.argv) == 1: 18 | infile = sys.stdin 19 | outfile = sys.stdout 20 | elif len(sys.argv) == 2: 21 | infile = open(sys.argv[1], 'r') 22 | outfile = sys.stdout 23 | elif len(sys.argv) == 3: 24 | infile = open(sys.argv[1], 'r') 25 | outfile = open(sys.argv[2], 'w') 26 | else: 27 | raise SystemExit(sys.argv[0] + " [infile [outfile]]") 28 | with infile: 29 | try: 30 | obj = json.load(infile) 31 | except ValueError as e: 32 | raise SystemExit(e) 33 | with outfile: 34 | json.dump(obj, outfile, sort_keys=True, 35 | indent=4, separators=(',', ': ')) 36 | outfile.write('\n') 37 | 38 | 39 | if __name__ == '__main__': 40 | main() 41 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/ffilib.py: -------------------------------------------------------------------------------- 1 | import sys 2 | try: 3 | import ffi 4 | except ImportError: 5 | ffi = None 6 | 7 | _cache = {} 8 | 9 | def open(name, maxver=10, extra=()): 10 | if not ffi: 11 | return None 12 | try: 13 | return _cache[name] 14 | except KeyError: 15 | pass 16 | def libs(): 17 | if sys.platform == "linux": 18 | yield '%s.so' % name 19 | for i in range(maxver, -1, -1): 20 | yield '%s.so.%u' % (name, i) 21 | else: 22 | for ext in ('dylib', 'dll'): 23 | yield '%s.%s' % (name, ext) 24 | for n in extra: 25 | yield n 26 | err = None 27 | for n in libs(): 28 | try: 29 | l = ffi.open(n) 30 | _cache[name] = l 31 | return l 32 | except OSError as e: 33 | err = e 34 | raise err 35 | 36 | def libc(): 37 | return open("libc", 6) 38 | 39 | # Find out bitness of the platform, even if long ints are not supported 40 | # TODO: All bitness differences should be removed from micropython-lib, and 41 | # this snippet too. 42 | bitness = 1 43 | v = sys.maxsize 44 | while v: 45 | bitness += 1 46 | v >>= 1 47 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/ffilib.py: -------------------------------------------------------------------------------- 1 | import sys 2 | try: 3 | import ffi 4 | except ImportError: 5 | ffi = None 6 | 7 | _cache = {} 8 | 9 | def open(name, maxver=10, extra=()): 10 | if not ffi: 11 | return None 12 | try: 13 | return _cache[name] 14 | except KeyError: 15 | pass 16 | def libs(): 17 | if sys.platform == "linux": 18 | yield '%s.so' % name 19 | for i in range(maxver, -1, -1): 20 | yield '%s.so.%u' % (name, i) 21 | else: 22 | for ext in ('dylib', 'dll'): 23 | yield '%s.%s' % (name, ext) 24 | for n in extra: 25 | yield n 26 | err = None 27 | for n in libs(): 28 | try: 29 | l = ffi.open(n) 30 | _cache[name] = l 31 | return l 32 | except OSError as e: 33 | err = e 34 | raise err 35 | 36 | def libc(): 37 | return open("libc", 6) 38 | 39 | # Find out bitness of the platform, even if long ints are not supported 40 | # TODO: All bitness differences should be removed from micropython-lib, and 41 | # this snippet too. 42 | bitness = 1 43 | v = sys.maxsize 44 | while v: 45 | bitness += 1 46 | v >>= 1 47 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/umqtt/robust.py: -------------------------------------------------------------------------------- 1 | import utime 2 | from . import simple 3 | 4 | class MQTTClient(simple.MQTTClient): 5 | 6 | DELAY = 2 7 | DEBUG = False 8 | 9 | def delay(self, i): 10 | utime.sleep(self.DELAY) 11 | 12 | def log(self, in_reconnect, e): 13 | if self.DEBUG: 14 | if in_reconnect: 15 | print("mqtt reconnect: %r" % e) 16 | else: 17 | print("mqtt: %r" % e) 18 | 19 | def reconnect(self): 20 | i = 0 21 | while 1: 22 | try: 23 | return super().connect(False) 24 | except OSError as e: 25 | self.log(True, e) 26 | i += 1 27 | self.delay(i) 28 | 29 | def publish(self, topic, msg, retain=False, qos=0): 30 | while 1: 31 | try: 32 | return super().publish(topic, msg, retain, qos) 33 | except OSError as e: 34 | self.log(False, e) 35 | self.reconnect() 36 | 37 | def wait_msg(self): 38 | while 1: 39 | try: 40 | return super().wait_msg() 41 | except OSError as e: 42 | self.log(False, e) 43 | self.reconnect() 44 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/boot/04_builtin.py: -------------------------------------------------------------------------------- 1 | import builtins 2 | 3 | import event 4 | import machine 5 | import sys 6 | 7 | last_input = [] 8 | buf = [] 9 | 10 | 11 | def check_key_down(name, *_): 12 | return name == "key_down" 13 | 14 | 15 | @machine.hook_stdin 16 | def input_handler(): 17 | while True: 18 | signal = event.pull_filtered(1, check_key_down) 19 | if signal is not None: 20 | _name, _address, char, code, _user = signal 21 | if char: 22 | return int(char) 23 | 24 | 25 | # noinspection PyShadowingBuiltins 26 | def input(prompt=None): 27 | if prompt is not None: 28 | print(prompt, end="") 29 | 30 | read = sys.stdin.read 31 | write = sys.stdout.write 32 | buf = [] 33 | ignore = 0 34 | while True: 35 | ch = read(1) 36 | if ignore > 0: 37 | ignore -= 1 38 | continue 39 | 40 | if ch == '\n': 41 | write(ch) 42 | break 43 | elif ch == '\b': 44 | if buf: 45 | buf.pop() 46 | write(ch) 47 | continue 48 | else: 49 | write(ch) 50 | buf.append(ch) 51 | 52 | return ''.join(buf) 53 | 54 | 55 | builtins.input = input 56 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/umqtt/robust.py: -------------------------------------------------------------------------------- 1 | import utime 2 | from . import simple 3 | 4 | class MQTTClient(simple.MQTTClient): 5 | 6 | DELAY = 2 7 | DEBUG = False 8 | 9 | def delay(self, i): 10 | utime.sleep(self.DELAY) 11 | 12 | def log(self, in_reconnect, e): 13 | if self.DEBUG: 14 | if in_reconnect: 15 | print("mqtt reconnect: %r" % e) 16 | else: 17 | print("mqtt: %r" % e) 18 | 19 | def reconnect(self): 20 | i = 0 21 | while 1: 22 | try: 23 | return super().connect(False) 24 | except OSError as e: 25 | self.log(True, e) 26 | i += 1 27 | self.delay(i) 28 | 29 | def publish(self, topic, msg, retain=False, qos=0): 30 | while 1: 31 | try: 32 | return super().publish(topic, msg, retain, qos) 33 | except OSError as e: 34 | self.log(False, e) 35 | self.reconnect() 36 | 37 | def wait_msg(self): 38 | while 1: 39 | try: 40 | return super().wait_msg() 41 | except OSError as e: 42 | self.log(False, e) 43 | self.reconnect() 44 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/openpython/arch/state/FileHandle.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.openpython.arch.state 2 | 3 | import kr.pe.ecmaxp.openpython.arch.types.call.ComponentInvoke 4 | import li.cil.oc.api.Persistable 5 | import net.minecraft.nbt.NBTTagCompound 6 | 7 | class FileHandle(var fd: Int, var address: String, var handle: Int, var pos: Int = 0) : Persistable { 8 | operator fun invoke(func: String, vararg args: Any): ComponentInvoke = ComponentInvoke(this.address, func, this.handle, *args) 9 | 10 | override fun toString(): String { 11 | return "FileHandle(fd='$fd', address='$address', handle=$handle, pos=$pos)" 12 | } 13 | 14 | override fun load(tag: NBTTagCompound) { 15 | fd = tag.getInteger("fd") 16 | address = tag.getString("address") 17 | handle = tag.getInteger("handle") 18 | pos = tag.getInteger("pos") 19 | } 20 | 21 | override fun save(tag: NBTTagCompound) { 22 | tag.setInteger("fd", fd) 23 | tag.setString("address", address) 24 | tag.setInteger("handle", handle) 25 | tag.setInteger("pos", pos) 26 | } 27 | 28 | companion object { 29 | fun load(tag: NBTTagCompound): FileHandle { 30 | val handle = FileHandle(0, "", 0, 0) 31 | handle.load(tag) 32 | return handle 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/monitor.py: -------------------------------------------------------------------------------- 1 | from component import Component 2 | 3 | __all__ = ["Monitor", "monitor", "_set_monitor"] 4 | 5 | 6 | class Monitor: 7 | def __init__(self, gpu: Component): 8 | self.gpu = gpu 9 | self.w = 80 10 | self.h = 25 11 | self.x = 1 12 | self.y = 1 13 | self.bc = 0 14 | 15 | def scroll(self): 16 | self.gpu.copy(1, 2, self.w, self.h, 0, - 1) 17 | self.gpu.fill(1, self.h, self.w, 1, " ") 18 | 19 | def put(self, char: str): 20 | assert len(char) == 1 21 | if char == "\n": 22 | self.x = 1 23 | self.y += 1 24 | 25 | if self.x > self.w: 26 | self.x = 1 27 | self.y += 1 28 | 29 | if self.y > self.h: 30 | self.scroll() 31 | self.y = self.h 32 | 33 | if char == "\r" or char == "\n": 34 | return 35 | 36 | if self.bc > 0: 37 | self.bc -= 1 38 | elif char == "\b": 39 | self.x -= 1 40 | self.gpu.set(self.x, self.y, " ") 41 | self.bc = 3 42 | else: 43 | self.gpu.set(self.x, self.y, char) 44 | self.x += 1 45 | 46 | 47 | monitor = None 48 | 49 | 50 | def _set_monitor(obj): 51 | global monitor 52 | monitor = obj 53 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/monitor.py: -------------------------------------------------------------------------------- 1 | from component import Component 2 | 3 | __all__ = ["Monitor", "monitor", "_set_monitor"] 4 | 5 | 6 | class Monitor(Component): 7 | def __init__(self, address, type): 8 | super().__init__(address, type) 9 | self.w = 80 10 | self.h = 25 11 | self.x = 1 12 | self.y = 1 13 | self.bc = 0 14 | 15 | def scroll(self): 16 | self.copy(1, 2, self.w, self.h, 0, - 1) 17 | self.fill(1, self.h, self.w, 1, " ") 18 | 19 | def put(self, char: str): 20 | assert len(char) == 1 21 | if char == "\n": 22 | self.x = 1 23 | self.y += 1 24 | 25 | if self.x > self.w: 26 | self.x = 1 27 | self.y += 1 28 | 29 | if self.y > self.h: 30 | self.scroll() 31 | self.y = self.h 32 | 33 | if char == "\r" or char == "\n": 34 | return 35 | 36 | if self.bc > 0: 37 | self.bc -= 1 38 | elif char == "\b": 39 | self.x -= 1 40 | self.set(self.x, self.y, " ") 41 | self.bc = 3 42 | else: 43 | self.set(self.x, self.y, char) 44 | self.x += 1 45 | 46 | 47 | monitor = None 48 | 49 | 50 | def _set_monitor(obj): 51 | global monitor 52 | monitor = obj 53 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/bin/python.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from ucode import MICROPY_GIT_TAG, MICROPY_BUILD_DATE, MICROPY_HW_BOARD_NAME, MICROPY_HW_MCU_NAME 4 | from ucode import repl_input, repl_compile, repl_call 5 | 6 | 7 | def main(): 8 | context = {"__name__": ""} 9 | 10 | print("MicroPython", 11 | MICROPY_GIT_TAG, 12 | "on", MICROPY_BUILD_DATE + ";", 13 | MICROPY_HW_BOARD_NAME, 14 | "with", MICROPY_HW_MCU_NAME) 15 | 16 | try: 17 | # noinspection PyStatementEffect 18 | help 19 | except NameError: 20 | pass 21 | else: 22 | print("Type \"help()\" for more information.") 23 | 24 | while True: 25 | try: 26 | code = repl_input() 27 | except Exception as e: 28 | print(type(e).__name__, e) 29 | continue 30 | 31 | if code == 'exit': 32 | break 33 | 34 | try: 35 | func = repl_compile(code, context) 36 | except BaseException as e: 37 | sys.print_exception(e) 38 | continue 39 | 40 | try: 41 | repl_call(func, context) 42 | except SystemExit as e: 43 | return e.args[0] if e.args else 0 44 | except BaseException as e: 45 | sys.print_exception(e) 46 | 47 | 48 | if __name__ == '__main__': 49 | main() 50 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/bin/python.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from ucode import MICROPY_GIT_TAG, MICROPY_BUILD_DATE, MICROPY_HW_BOARD_NAME, MICROPY_HW_MCU_NAME 4 | from ucode import repl_input, repl_compile, repl_call 5 | 6 | 7 | def main(): 8 | context = {"__name__": ""} 9 | 10 | print("MicroPython", 11 | MICROPY_GIT_TAG, 12 | "on", MICROPY_BUILD_DATE + ";", 13 | MICROPY_HW_BOARD_NAME, 14 | "with", MICROPY_HW_MCU_NAME) 15 | 16 | try: 17 | # noinspection PyStatementEffect 18 | help 19 | except NameError: 20 | pass 21 | else: 22 | print("Type \"help()\" for more information.") 23 | 24 | while True: 25 | try: 26 | code = repl_input() 27 | except Exception as e: 28 | print(type(e).__name__, e) 29 | continue 30 | 31 | if code == 'exit': 32 | break 33 | 34 | try: 35 | func = repl_compile(code, context) 36 | except BaseException as e: 37 | sys.print_exception(e) 38 | continue 39 | 40 | try: 41 | repl_call(func, context) 42 | except SystemExit as e: 43 | return e.args[0] if e.args else 0 44 | except BaseException as e: 45 | sys.print_exception(e) 46 | 47 | 48 | if __name__ == '__main__': 49 | main() 50 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/os.py: -------------------------------------------------------------------------------- 1 | from uos import * 2 | 3 | # import ocpath as path 4 | from ocpath import curdir, pardir, sep, extsep, altsep, pathsep, linesep, defpath, devnull 5 | 6 | __all__ = [ 7 | # uos.* 8 | "chdir", "getcwd", "ilistdir", "listdir", "mkdir", "remove", "rmdir", "rename", "stat", "statvfs", "sync", 9 | "urandom", "dupterm", "mount", "umount", 10 | # ocpath 11 | # "path", 12 | # ocpath.* 13 | "curdir", "pardir", "sep", "extsep", "altsep", "pathsep", "linesep", "defpath", "devnull", 14 | # os 15 | "name", "Environ", "environ", "getenv" 16 | ] 17 | 18 | name = "oc" 19 | 20 | 21 | class Environ: 22 | def __init__(self, default): 23 | self.data = default 24 | 25 | def __getitem__(self, item): 26 | return self.data[item] 27 | 28 | def __setitem__(self, key, value): 29 | self.data[key] = value 30 | 31 | def __delitem__(self, key): 32 | del self.data[key] 33 | 34 | def __contains__(self, item): 35 | return item in self.data 36 | 37 | def get(self, default=None): 38 | return self.data.get(default) 39 | 40 | 41 | environ = Environ({ 42 | "TMPDIR": "/tmp", 43 | "PATH": defpath, 44 | "PWD": "/", # TODO: dynamic 45 | "HOME": "/home", 46 | "_": "" 47 | }) 48 | 49 | 50 | def getenv(name): 51 | return environ.get(name) 52 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/openpython/arch/types/call/ComponentInvoke.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.openpython.arch.types.call 2 | 3 | import li.cil.oc.api.machine.LimitReachedException 4 | import li.cil.oc.api.machine.Machine 5 | import java.util.* 6 | 7 | class ComponentInvoke(val component: String, val function: String, vararg args: Any?) { 8 | val args: Array<*> = args 9 | 10 | override fun toString(): String { 11 | return "ComponentInvoke(component='$component', function='$function', args=${Arrays.toString(args)})" 12 | } 13 | 14 | @Throws(LimitReachedException::class) 15 | operator fun invoke(machine: Machine): InvokeResult { 16 | return try { 17 | InvokeResult(machine.invoke(component, function, args)) 18 | } catch (e: LimitReachedException) { 19 | throw e 20 | } catch (e: Error) { 21 | InvokeResult(error = e) 22 | } catch (e: Exception) { 23 | InvokeResult(error = e) 24 | } 25 | } 26 | 27 | companion object { 28 | fun fromArray(array: Array<*>): ComponentInvoke? { 29 | if (array.size < 2) 30 | return null 31 | 32 | val args = arrayOfNulls(array.size - 2) 33 | System.arraycopy(array, 2, args, 0, args.size) 34 | 35 | return ComponentInvoke(array[0] as String, array[1] as String, *args) 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/openpython/arch/types/call/ValueInvoke.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.openpython.arch.types.call 2 | 3 | import li.cil.oc.api.machine.LimitReachedException 4 | import li.cil.oc.api.machine.Machine 5 | import li.cil.oc.api.machine.Value 6 | import java.util.* 7 | 8 | class ValueInvoke(val value: Value, val function: String, vararg args: Any?) { 9 | val args: Array<*> = args 10 | 11 | override fun toString(): String { 12 | return "ValueInvoke(value='$value', function='$function', args=${Arrays.toString(args)})" 13 | } 14 | 15 | @Throws(LimitReachedException::class) 16 | operator fun invoke(machine: Machine): InvokeResult { 17 | return try { 18 | InvokeResult(machine.invoke(value, function, args)) 19 | } catch (e: LimitReachedException) { 20 | throw e 21 | } catch (e: Error) { 22 | InvokeResult(error = e) 23 | } catch (e: Exception) { 24 | InvokeResult(error = e) 25 | } 26 | } 27 | 28 | companion object { 29 | fun fromArray(array: Array<*>): ValueInvoke? { 30 | if (array.size < 2) 31 | return null 32 | 33 | val args = arrayOfNulls(array.size - 2) 34 | System.arraycopy(array, 2, args, 0, args.size) 35 | 36 | return ValueInvoke(array[0] as Value, array[1] as String, *args) 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/os/path.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | 4 | sep = "/" 5 | 6 | def normcase(s): 7 | return s 8 | 9 | def normpath(s): 10 | return s 11 | 12 | def abspath(s): 13 | if s[0] != "/": 14 | return os.getcwd() + "/" + s 15 | return s 16 | 17 | def join(*args): 18 | # TODO: this is non-compliant 19 | if type(args[0]) is bytes: 20 | return b"/".join(args) 21 | else: 22 | return "/".join(args) 23 | 24 | def split(path): 25 | if path == "": 26 | return ("", "") 27 | r = path.rsplit("/", 1) 28 | if len(r) == 1: 29 | return ("", path) 30 | head = r[0] #.rstrip("/") 31 | if not head: 32 | head = "/" 33 | return (head, r[1]) 34 | 35 | def dirname(path): 36 | return split(path)[0] 37 | 38 | def basename(path): 39 | return split(path)[1] 40 | 41 | def exists(path): 42 | return os.access(path, os.F_OK) 43 | 44 | # TODO 45 | lexists = exists 46 | 47 | def isdir(path): 48 | import stat 49 | try: 50 | mode = os.stat(path)[0] 51 | return stat.S_ISDIR(mode) 52 | except OSError: 53 | return False 54 | 55 | 56 | def expanduser(s): 57 | if s == "~" or s.startswith("~/"): 58 | h = os.getenv("HOME") 59 | return h + s[1:] 60 | if s[0] == "~": 61 | # Sorry folks, follow conventions 62 | return "/home/" + s[1:] 63 | return s 64 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/os/path.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | 4 | sep = "/" 5 | 6 | def normcase(s): 7 | return s 8 | 9 | def normpath(s): 10 | return s 11 | 12 | def abspath(s): 13 | if s[0] != "/": 14 | return os.getcwd() + "/" + s 15 | return s 16 | 17 | def join(*args): 18 | # TODO: this is non-compliant 19 | if type(args[0]) is bytes: 20 | return b"/".join(args) 21 | else: 22 | return "/".join(args) 23 | 24 | def split(path): 25 | if path == "": 26 | return ("", "") 27 | r = path.rsplit("/", 1) 28 | if len(r) == 1: 29 | return ("", path) 30 | head = r[0] #.rstrip("/") 31 | if not head: 32 | head = "/" 33 | return (head, r[1]) 34 | 35 | def dirname(path): 36 | return split(path)[0] 37 | 38 | def basename(path): 39 | return split(path)[1] 40 | 41 | def exists(path): 42 | return os.access(path, os.F_OK) 43 | 44 | # TODO 45 | lexists = exists 46 | 47 | def isdir(path): 48 | import stat 49 | try: 50 | mode = os.stat(path)[0] 51 | return stat.S_ISDIR(mode) 52 | except OSError: 53 | return False 54 | 55 | 56 | def expanduser(s): 57 | if s == "~" or s.startswith("~/"): 58 | h = os.getenv("HOME") 59 | return h + s[1:] 60 | if s[0] == "~": 61 | # Sorry folks, follow conventions 62 | return "/home/" + s[1:] 63 | return s 64 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/inspect.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | def getmembers(obj, pred=None): 5 | res = [] 6 | for name in dir(obj): 7 | val = getattr(obj, name) 8 | if pred is None or pred(val): 9 | res.append((name, val)) 10 | res.sort() 11 | return res 12 | 13 | def isfunction(obj): 14 | return isinstance(obj, type(isfunction)) 15 | 16 | def isgeneratorfunction(obj): 17 | return isinstance(obj, type(lambda:(yield))) 18 | 19 | def isgenerator(obj): 20 | return isinstance(obj, type(lambda:(yield)())) 21 | 22 | class _Class: 23 | def meth(): pass 24 | _Instance = _Class() 25 | 26 | def ismethod(obj): 27 | return isinstance(obj, type(_Instance.meth)) 28 | 29 | def isclass(obj): 30 | return isinstance(obj, type) 31 | 32 | def ismodule(obj): 33 | return isinstance(obj, type(sys)) 34 | 35 | 36 | def getargspec(func): 37 | raise NotImplementedError("This is over-dynamic function, not supported by MicroPython") 38 | 39 | def getmodule(obj, _filename=None): 40 | return None # Not known 41 | 42 | def getmro(cls): 43 | return [cls] 44 | 45 | def getsourcefile(obj): 46 | return None # Not known 47 | 48 | def getfile(obj): 49 | return "" 50 | 51 | def getsource(obj): 52 | return "" 53 | 54 | 55 | def currentframe(): 56 | return None 57 | 58 | def getframeinfo(frame, context=1): 59 | return ("", -1, "", [""], 0) 60 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/inspect.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | def getmembers(obj, pred=None): 5 | res = [] 6 | for name in dir(obj): 7 | val = getattr(obj, name) 8 | if pred is None or pred(val): 9 | res.append((name, val)) 10 | res.sort() 11 | return res 12 | 13 | def isfunction(obj): 14 | return isinstance(obj, type(isfunction)) 15 | 16 | def isgeneratorfunction(obj): 17 | return isinstance(obj, type(lambda:(yield))) 18 | 19 | def isgenerator(obj): 20 | return isinstance(obj, type(lambda:(yield)())) 21 | 22 | class _Class: 23 | def meth(): pass 24 | _Instance = _Class() 25 | 26 | def ismethod(obj): 27 | return isinstance(obj, type(_Instance.meth)) 28 | 29 | def isclass(obj): 30 | return isinstance(obj, type) 31 | 32 | def ismodule(obj): 33 | return isinstance(obj, type(sys)) 34 | 35 | 36 | def getargspec(func): 37 | raise NotImplementedError("This is over-dynamic function, not supported by MicroPython") 38 | 39 | def getmodule(obj, _filename=None): 40 | return None # Not known 41 | 42 | def getmro(cls): 43 | return [cls] 44 | 45 | def getsourcefile(obj): 46 | return None # Not known 47 | 48 | def getfile(obj): 49 | return "" 50 | 51 | def getsource(obj): 52 | return "" 53 | 54 | 55 | def currentframe(): 56 | return None 57 | 58 | def getframeinfo(frame, context=1): 59 | return ("", -1, "", [""], 0) 60 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/errno.py: -------------------------------------------------------------------------------- 1 | EPERM = 1 # Operation not permitted 2 | ENOENT = 2 # No such file or directory 3 | ESRCH = 3 # No such process 4 | EINTR = 4 # Interrupted system call 5 | EIO = 5 # I/O error 6 | ENXIO = 6 # No such device or address 7 | E2BIG = 7 # Argument list too long 8 | ENOEXEC = 8 # Exec format error 9 | EBADF = 9 # Bad file number 10 | ECHILD = 10 # No child processes 11 | EAGAIN = 11 # Try again 12 | ENOMEM = 12 # Out of memory 13 | EACCES = 13 # Permission denied 14 | EFAULT = 14 # Bad address 15 | ENOTBLK = 15 # Block device required 16 | EBUSY = 16 # Device or resource busy 17 | EEXIST = 17 # File exists 18 | EXDEV = 18 # Cross-device link 19 | ENODEV = 19 # No such device 20 | ENOTDIR = 20 # Not a directory 21 | EISDIR = 21 # Is a directory 22 | EINVAL = 22 # Invalid argument 23 | ENFILE = 23 # File table overflow 24 | EMFILE = 24 # Too many open files 25 | ENOTTY = 25 # Not a typewriter 26 | ETXTBSY = 26 # Text file busy 27 | EFBIG = 27 # File too large 28 | ENOSPC = 28 # No space left on device 29 | ESPIPE = 29 # Illegal seek 30 | EROFS = 30 # Read-only file system 31 | EMLINK = 31 # Too many links 32 | EPIPE = 32 # Broken pipe 33 | EDOM = 33 # Math argument out of domain of func 34 | ERANGE = 34 # Math result not representable 35 | EAFNOSUPPORT = 97 # Address family not supported by protocol 36 | ECONNRESET = 104 # Connection timed out 37 | ETIMEDOUT = 110 # Connection timed out 38 | EINPROGRESS = 115 # Operation now in progress 39 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/errno.py: -------------------------------------------------------------------------------- 1 | EPERM = 1 # Operation not permitted 2 | ENOENT = 2 # No such file or directory 3 | ESRCH = 3 # No such process 4 | EINTR = 4 # Interrupted system call 5 | EIO = 5 # I/O error 6 | ENXIO = 6 # No such device or address 7 | E2BIG = 7 # Argument list too long 8 | ENOEXEC = 8 # Exec format error 9 | EBADF = 9 # Bad file number 10 | ECHILD = 10 # No child processes 11 | EAGAIN = 11 # Try again 12 | ENOMEM = 12 # Out of memory 13 | EACCES = 13 # Permission denied 14 | EFAULT = 14 # Bad address 15 | ENOTBLK = 15 # Block device required 16 | EBUSY = 16 # Device or resource busy 17 | EEXIST = 17 # File exists 18 | EXDEV = 18 # Cross-device link 19 | ENODEV = 19 # No such device 20 | ENOTDIR = 20 # Not a directory 21 | EISDIR = 21 # Is a directory 22 | EINVAL = 22 # Invalid argument 23 | ENFILE = 23 # File table overflow 24 | EMFILE = 24 # Too many open files 25 | ENOTTY = 25 # Not a typewriter 26 | ETXTBSY = 26 # Text file busy 27 | EFBIG = 27 # File too large 28 | ENOSPC = 28 # No space left on device 29 | ESPIPE = 29 # Illegal seek 30 | EROFS = 30 # Read-only file system 31 | EMLINK = 31 # Too many links 32 | EPIPE = 32 # Broken pipe 33 | EDOM = 33 # Math argument out of domain of func 34 | ERANGE = 34 # Math result not representable 35 | EAFNOSUPPORT = 97 # Address family not supported by protocol 36 | ECONNRESET = 104 # Connection timed out 37 | ETIMEDOUT = 110 # Connection timed out 38 | EINPROGRESS = 115 # Operation now in progress 39 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/openpython/arch/versions/v1/OpenPythonVirtualMachineStateV1.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.openpython.arch.versions.v1 2 | 3 | import kr.pe.ecmaxp.openpython.arch.state.FileHandle 4 | import kr.pe.ecmaxp.openpython.arch.state.ValueContainerMap 5 | import li.cil.oc.api.Persistable 6 | import net.minecraft.nbt.NBTTagCompound 7 | import net.minecraft.nbt.NBTTagList 8 | import java.util.* 9 | 10 | class OpenPythonVirtualMachineStateV1 : Persistable { 11 | var fdCount = 3 12 | var fdMap: HashMap = HashMap() 13 | var valueMap: ValueContainerMap = ValueContainerMap() 14 | 15 | // TODO: component and method? 16 | 17 | override fun load(tag: NBTTagCompound) { 18 | fdCount = tag.getInteger("fdCount") 19 | for (fdBaseTag in tag.getTagList("fdMap", NBTTagCompound().id.toInt())) { 20 | val fdTag = fdBaseTag as NBTTagCompound 21 | val handle = FileHandle.load(fdTag) 22 | fdMap[handle.fd] = handle 23 | } 24 | 25 | valueMap.load(tag.getCompoundTag("valueMap")) 26 | } 27 | 28 | override fun save(tag: NBTTagCompound) { 29 | val valueTag = NBTTagCompound() 30 | valueMap.save(valueTag) 31 | 32 | val fdTagList = NBTTagList() 33 | for (item in fdMap) { 34 | val fdTag = NBTTagCompound() 35 | item.value.save(fdTag) 36 | fdTagList.appendTag(fdTag) 37 | } 38 | 39 | tag.setInteger("fdCount", 3) 40 | tag.setTag("fdMap", fdTagList) 41 | tag.setTag("valueMap", valueTag) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/event.py: -------------------------------------------------------------------------------- 1 | import machine 2 | 3 | from computer import pop_signal 4 | 5 | __all__ = ["register", "unregister", "setup"] 6 | 7 | event = {} 8 | handlers = {} 9 | lastInterrupt = None 10 | 11 | registered = {} 12 | 13 | 14 | def signal_handler(ticks): 15 | signal = pop_signal(ticks) 16 | if not signal: 17 | return 18 | 19 | name, args = signal 20 | handlers = registered.get(name) 21 | if not handlers: 22 | return 23 | 24 | for handler in handlers: 25 | try: 26 | handler(*args) 27 | except BaseException as e: 28 | machine.debug("signal_handler exc => %s: %s" % (type(e).__name__, e)) 29 | 30 | 31 | def listen(name, callback): 32 | handlers = registered.setdefault(name, []) 33 | if callback in handlers: 34 | return False 35 | 36 | handlers.append(callback) 37 | return True 38 | 39 | 40 | def ignore(name, callback): 41 | handlers = registered.get(name) # type: list 42 | if not handlers: 43 | return False 44 | 45 | if callback not in handlers: 46 | return False 47 | 48 | handlers.remove(callback) 49 | return True 50 | 51 | 52 | def register(name): 53 | def wrapper(callback): 54 | listen(name, callback) 55 | return callback 56 | 57 | return wrapper 58 | 59 | 60 | def unregister(name, func): 61 | handlers = registered.setdefault(name, []) 62 | handlers.remove(func) 63 | 64 | 65 | def setup(): 66 | machine.hook_signal(signal_handler) 67 | 68 | 69 | def wait(ticks): 70 | signal_handler(ticks) 71 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/ocpath.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | curdir = "." 4 | pardir = ".." 5 | sep = "/" 6 | extsep = "." 7 | altsep = "/" 8 | pathsep = ":" 9 | linesep = "\n" 10 | defpath = pathsep.join(("/bin", "/usr/bin")) 11 | devnull = "/dev/null" 12 | 13 | 14 | def normcase(s): 15 | return s 16 | 17 | 18 | def normpath(s): 19 | return s 20 | 21 | 22 | def abspath(s): 23 | if s[0] != "/": 24 | return os.getcwd() + "/" + s 25 | return s 26 | 27 | 28 | def join(*args): 29 | # TODO: this is non-compliant 30 | if type(args[0]) is bytes: 31 | return b"/".join(args) 32 | else: 33 | return "/".join(args) 34 | 35 | 36 | def split(path): 37 | if path == "": 38 | return ("", "") 39 | r = path.rsplit("/", 1) 40 | if len(r) == 1: 41 | return ("", path) 42 | head = r[0] # .rstrip("/") 43 | if not head: 44 | head = "/" 45 | return (head, r[1]) 46 | 47 | 48 | def dirname(path): 49 | return split(path)[0] 50 | 51 | 52 | def basename(path): 53 | return split(path)[1] 54 | 55 | 56 | def exists(path): 57 | return os.access(path, os.F_OK) 58 | 59 | 60 | # TODO 61 | lexists = exists 62 | 63 | 64 | def isdir(path): 65 | import stat 66 | try: 67 | mode = os.stat(path)[0] 68 | return stat.S_ISDIR(mode) 69 | except OSError: 70 | return False 71 | 72 | 73 | def expanduser(s): 74 | if s == "~" or s.startswith("~/"): 75 | h = os.getenv("HOME") 76 | return h + s[1:] 77 | if s[0] == "~": 78 | # Sorry folks, follow conventions 79 | return "/home/" + s[1:] 80 | return s 81 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/openpython/arch/versions/v1/OpenPythonArchitectureV1.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.openpython.arch.versions.v1 2 | 3 | import kr.pe.ecmaxp.openpython.OpenPythonArchitectureLogic 4 | import kr.pe.ecmaxp.openpython.OpenPythonVirtualMachine 5 | import kr.pe.ecmaxp.openpython.arch.OpenPythonArchitecture 6 | import kr.pe.ecmaxp.openpython.arch.OpenPythonFirmware 7 | import li.cil.oc.api.machine.Architecture 8 | import li.cil.oc.api.machine.Machine 9 | 10 | 11 | @Suppress("unused", "ClassName") 12 | @Architecture.Name("OpenPython v1.0") 13 | class OpenPythonArchitectureV1_0(machine: Machine) : OpenPythonArchitecture(machine, this) { 14 | companion object : OpenPythonArchitectureLogic { 15 | val FIRMWARE_v1_0_1: OpenPythonFirmware = OpenPythonFirmware("v1.0.1") 16 | override val LATEST_FIRMWARE: OpenPythonFirmware = FIRMWARE_v1_0_1 17 | 18 | override fun spawn(machine: Machine, memorySize: Int): OpenPythonVirtualMachine { 19 | return OpenPythonVirtualMachineV1(machine, memorySize, LATEST_FIRMWARE) 20 | } 21 | } 22 | } 23 | 24 | 25 | @Suppress("unused", "ClassName") 26 | @Architecture.Name("OpenPython v1.1") 27 | class OpenPythonArchitectureV1_1(machine: Machine) : OpenPythonArchitecture(machine, this) { 28 | companion object : OpenPythonArchitectureLogic { 29 | val FIRMWARE_v1_1_0: OpenPythonFirmware = OpenPythonFirmware("v1.1.0") 30 | override val LATEST_FIRMWARE: OpenPythonFirmware = FIRMWARE_v1_1_0 31 | 32 | override fun spawn(machine: Machine, memorySize: Int): OpenPythonVirtualMachine { 33 | return OpenPythonVirtualMachineV1(machine, memorySize, LATEST_FIRMWARE) 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/socket.py: -------------------------------------------------------------------------------- 1 | from usocket import * 2 | import usocket as _socket 3 | 4 | 5 | _GLOBAL_DEFAULT_TIMEOUT = 30 6 | IPPROTO_IP = 0 7 | IP_ADD_MEMBERSHIP = 35 8 | IP_DROP_MEMBERSHIP = 36 9 | INADDR_ANY = 0 10 | 11 | error = OSError 12 | 13 | def _resolve_addr(addr): 14 | if isinstance(addr, (bytes, bytearray)): 15 | return addr 16 | family = _socket.AF_INET 17 | if len(addr) != 2: 18 | family = _socket.AF_INET6 19 | if addr[0] == "": 20 | a = "0.0.0.0" if family == _socket.AF_INET else "::" 21 | else: 22 | a = addr[0] 23 | a = getaddrinfo(a, addr[1], family) 24 | return a[0][4] 25 | 26 | def inet_aton(addr): 27 | return inet_pton(AF_INET, addr) 28 | 29 | def create_connection(addr, timeout=None, source_address=None): 30 | s = socket() 31 | #print("Address:", addr) 32 | ais = getaddrinfo(addr[0], addr[1]) 33 | #print("Address infos:", ais) 34 | for ai in ais: 35 | try: 36 | s.connect(ai[4]) 37 | return s 38 | except: 39 | pass 40 | 41 | 42 | class socket(_socket.socket): 43 | 44 | def accept(self): 45 | s, addr = super().accept() 46 | addr = _socket.sockaddr(addr) 47 | return (s, (_socket.inet_ntop(addr[0], addr[1]), addr[2])) 48 | 49 | def bind(self, addr): 50 | return super().bind(_resolve_addr(addr)) 51 | 52 | def connect(self, addr): 53 | return super().connect(_resolve_addr(addr)) 54 | 55 | def sendall(self, *args): 56 | return self.send(*args) 57 | 58 | def sendto(self, data, addr): 59 | return super().sendto(data, _resolve_addr(addr)) 60 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/socket.py: -------------------------------------------------------------------------------- 1 | from usocket import * 2 | import usocket as _socket 3 | 4 | 5 | _GLOBAL_DEFAULT_TIMEOUT = 30 6 | IPPROTO_IP = 0 7 | IP_ADD_MEMBERSHIP = 35 8 | IP_DROP_MEMBERSHIP = 36 9 | INADDR_ANY = 0 10 | 11 | error = OSError 12 | 13 | def _resolve_addr(addr): 14 | if isinstance(addr, (bytes, bytearray)): 15 | return addr 16 | family = _socket.AF_INET 17 | if len(addr) != 2: 18 | family = _socket.AF_INET6 19 | if addr[0] == "": 20 | a = "0.0.0.0" if family == _socket.AF_INET else "::" 21 | else: 22 | a = addr[0] 23 | a = getaddrinfo(a, addr[1], family) 24 | return a[0][4] 25 | 26 | def inet_aton(addr): 27 | return inet_pton(AF_INET, addr) 28 | 29 | def create_connection(addr, timeout=None, source_address=None): 30 | s = socket() 31 | #print("Address:", addr) 32 | ais = getaddrinfo(addr[0], addr[1]) 33 | #print("Address infos:", ais) 34 | for ai in ais: 35 | try: 36 | s.connect(ai[4]) 37 | return s 38 | except: 39 | pass 40 | 41 | 42 | class socket(_socket.socket): 43 | 44 | def accept(self): 45 | s, addr = super().accept() 46 | addr = _socket.sockaddr(addr) 47 | return (s, (_socket.inet_ntop(addr[0], addr[1]), addr[2])) 48 | 49 | def bind(self, addr): 50 | return super().bind(_resolve_addr(addr)) 51 | 52 | def connect(self, addr): 53 | return super().connect(_resolve_addr(addr)) 54 | 55 | def sendall(self, *args): 56 | return self.send(*args) 57 | 58 | def sendto(self, data, addr): 59 | return super().sendto(data, _resolve_addr(addr)) 60 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/uasyncio/udp.py: -------------------------------------------------------------------------------- 1 | import usocket 2 | from uasyncio import core 3 | 4 | 5 | DEBUG = 0 6 | log = None 7 | 8 | def set_debug(val): 9 | global DEBUG, log 10 | DEBUG = val 11 | if val: 12 | import logging 13 | log = logging.getLogger("uasyncio.udp") 14 | 15 | def socket(af=usocket.AF_INET): 16 | s = usocket.socket(af, usocket.SOCK_DGRAM) 17 | s.setblocking(False) 18 | return s 19 | 20 | def recv(s, n): 21 | try: 22 | yield core.IORead(s) 23 | return s.recv(n) 24 | except: 25 | #print("recv: exc, cleaning up") 26 | #print(uasyncio.core._event_loop.objmap, uasyncio.core._event_loop.poller) 27 | #uasyncio.core._event_loop.poller.dump() 28 | yield core.IOReadDone(s) 29 | #print(uasyncio.core._event_loop.objmap) 30 | #uasyncio.core._event_loop.poller.dump() 31 | raise 32 | 33 | def recvfrom(s, n): 34 | try: 35 | yield core.IORead(s) 36 | return s.recvfrom(n) 37 | except: 38 | #print("recv: exc, cleaning up") 39 | #print(uasyncio.core._event_loop.objmap, uasyncio.core._event_loop.poller) 40 | #uasyncio.core._event_loop.poller.dump() 41 | yield core.IOReadDone(s) 42 | #print(uasyncio.core._event_loop.objmap) 43 | #uasyncio.core._event_loop.poller.dump() 44 | raise 45 | 46 | def sendto(s, buf, addr=None): 47 | while 1: 48 | res = s.sendto(buf, addr) 49 | #print("send res:", res) 50 | if res == len(buf): 51 | return 52 | print("sendto: IOWrite") 53 | yield core.IOWrite(s) 54 | 55 | def close(s): 56 | yield core.IOReadDone(s) 57 | s.close() 58 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/uasyncio/udp.py: -------------------------------------------------------------------------------- 1 | import usocket 2 | from uasyncio import core 3 | 4 | 5 | DEBUG = 0 6 | log = None 7 | 8 | def set_debug(val): 9 | global DEBUG, log 10 | DEBUG = val 11 | if val: 12 | import logging 13 | log = logging.getLogger("uasyncio.udp") 14 | 15 | def socket(af=usocket.AF_INET): 16 | s = usocket.socket(af, usocket.SOCK_DGRAM) 17 | s.setblocking(False) 18 | return s 19 | 20 | def recv(s, n): 21 | try: 22 | yield core.IORead(s) 23 | return s.recv(n) 24 | except: 25 | #print("recv: exc, cleaning up") 26 | #print(uasyncio.core._event_loop.objmap, uasyncio.core._event_loop.poller) 27 | #uasyncio.core._event_loop.poller.dump() 28 | yield core.IOReadDone(s) 29 | #print(uasyncio.core._event_loop.objmap) 30 | #uasyncio.core._event_loop.poller.dump() 31 | raise 32 | 33 | def recvfrom(s, n): 34 | try: 35 | yield core.IORead(s) 36 | return s.recvfrom(n) 37 | except: 38 | #print("recv: exc, cleaning up") 39 | #print(uasyncio.core._event_loop.objmap, uasyncio.core._event_loop.poller) 40 | #uasyncio.core._event_loop.poller.dump() 41 | yield core.IOReadDone(s) 42 | #print(uasyncio.core._event_loop.objmap) 43 | #uasyncio.core._event_loop.poller.dump() 44 | raise 45 | 46 | def sendto(s, buf, addr=None): 47 | while 1: 48 | res = s.sendto(buf, addr) 49 | #print("send res:", res) 50 | if res == len(buf): 51 | return 52 | print("sendto: IOWrite") 53 | yield core.IOWrite(s) 54 | 55 | def close(s): 56 | yield core.IOReadDone(s) 57 | s.close() 58 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/itertools.py: -------------------------------------------------------------------------------- 1 | def count(start=0, step=1): 2 | while True: 3 | yield start 4 | start += step 5 | 6 | def cycle(p): 7 | try: 8 | len(p) 9 | except TypeError: 10 | # len() is not defined for this type. Assume it is 11 | # a finite iterable so we must cache the elements. 12 | cache = [] 13 | for i in p: 14 | yield i 15 | cache.append(i) 16 | p = cache 17 | while p: 18 | yield from p 19 | 20 | 21 | def repeat(el, n=None): 22 | if n is None: 23 | while True: 24 | yield el 25 | else: 26 | for i in range(n): 27 | yield el 28 | 29 | def chain(*p): 30 | for i in p: 31 | yield from i 32 | 33 | def islice(p, start, stop=(), step=1): 34 | if stop == (): 35 | stop = start 36 | start = 0 37 | # TODO: optimizing or breaking semantics? 38 | if start >= stop: 39 | return 40 | it = iter(p) 41 | for i in range(start): 42 | next(it) 43 | 44 | while True: 45 | yield next(it) 46 | for i in range(step - 1): 47 | next(it) 48 | start += step 49 | if start >= stop: 50 | return 51 | 52 | def tee(iterable, n=2): 53 | return [iter(iterable)] * n 54 | 55 | def starmap(function, iterable): 56 | for args in iterable: 57 | yield function(*args) 58 | 59 | def accumulate(iterable, func=lambda x, y: x + y): 60 | it = iter(iterable) 61 | try: 62 | acc = next(it) 63 | except StopIteration: 64 | return 65 | yield acc 66 | for element in it: 67 | acc = func(acc, element) 68 | yield acc 69 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/itertools.py: -------------------------------------------------------------------------------- 1 | def count(start=0, step=1): 2 | while True: 3 | yield start 4 | start += step 5 | 6 | def cycle(p): 7 | try: 8 | len(p) 9 | except TypeError: 10 | # len() is not defined for this type. Assume it is 11 | # a finite iterable so we must cache the elements. 12 | cache = [] 13 | for i in p: 14 | yield i 15 | cache.append(i) 16 | p = cache 17 | while p: 18 | yield from p 19 | 20 | 21 | def repeat(el, n=None): 22 | if n is None: 23 | while True: 24 | yield el 25 | else: 26 | for i in range(n): 27 | yield el 28 | 29 | def chain(*p): 30 | for i in p: 31 | yield from i 32 | 33 | def islice(p, start, stop=(), step=1): 34 | if stop == (): 35 | stop = start 36 | start = 0 37 | # TODO: optimizing or breaking semantics? 38 | if start >= stop: 39 | return 40 | it = iter(p) 41 | for i in range(start): 42 | next(it) 43 | 44 | while True: 45 | yield next(it) 46 | for i in range(step - 1): 47 | next(it) 48 | start += step 49 | if start >= stop: 50 | return 51 | 52 | def tee(iterable, n=2): 53 | return [iter(iterable)] * n 54 | 55 | def starmap(function, iterable): 56 | for args in iterable: 57 | yield function(*args) 58 | 59 | def accumulate(iterable, func=lambda x, y: x + y): 60 | it = iter(iterable) 61 | try: 62 | acc = next(it) 63 | except StopIteration: 64 | return 65 | yield acc 66 | for element in it: 67 | acc = func(acc, element) 68 | yield acc 69 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/tests/test.py: -------------------------------------------------------------------------------- 1 | from unittest import TestCase, run_class 2 | import sys 3 | sys.path.insert(0, '../uasyncio') 4 | import queues 5 | 6 | 7 | class QueueTestCase(TestCase): 8 | 9 | def _val(self, gen): 10 | """Returns val from generator.""" 11 | while True: 12 | try: 13 | gen.send(None) 14 | except StopIteration as e: 15 | return e.value 16 | 17 | def test_get_put(self): 18 | q = queues.Queue(maxsize=1) 19 | self._val(q.put(42)) 20 | self.assertEqual(self._val(q.get()), 42) 21 | 22 | def test_get_put_nowait(self): 23 | q = queues.Queue(maxsize=1) 24 | q.put_nowait(12) 25 | try: 26 | q.put_nowait(42) 27 | self.assertTrue(False) 28 | except Exception as e: 29 | self.assertEqual(type(e), queues.QueueFull) 30 | self.assertEqual(q.get_nowait(), 12) 31 | try: 32 | q.get_nowait() 33 | self.assertTrue(False) 34 | except Exception as e: 35 | self.assertEqual(type(e), queues.QueueEmpty) 36 | 37 | def test_qsize(self): 38 | q = queues.Queue() 39 | for n in range(10): 40 | q.put_nowait(10) 41 | self.assertEqual(q.qsize(), 10) 42 | 43 | def test_empty(self): 44 | q = queues.Queue() 45 | self.assertTrue(q.empty()) 46 | q.put_nowait(10) 47 | self.assertFalse(q.empty()) 48 | 49 | def test_full(self): 50 | q = queues.Queue(maxsize=1) 51 | self.assertFalse(q.full()) 52 | q.put_nowait(10) 53 | self.assertTrue(q.full()) 54 | 55 | 56 | if __name__ == '__main__': 57 | run_class(QueueTestCase) 58 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/tests/test.py: -------------------------------------------------------------------------------- 1 | from unittest import TestCase, run_class 2 | import sys 3 | sys.path.insert(0, '../uasyncio') 4 | import queues 5 | 6 | 7 | class QueueTestCase(TestCase): 8 | 9 | def _val(self, gen): 10 | """Returns val from generator.""" 11 | while True: 12 | try: 13 | gen.send(None) 14 | except StopIteration as e: 15 | return e.value 16 | 17 | def test_get_put(self): 18 | q = queues.Queue(maxsize=1) 19 | self._val(q.put(42)) 20 | self.assertEqual(self._val(q.get()), 42) 21 | 22 | def test_get_put_nowait(self): 23 | q = queues.Queue(maxsize=1) 24 | q.put_nowait(12) 25 | try: 26 | q.put_nowait(42) 27 | self.assertTrue(False) 28 | except Exception as e: 29 | self.assertEqual(type(e), queues.QueueFull) 30 | self.assertEqual(q.get_nowait(), 12) 31 | try: 32 | q.get_nowait() 33 | self.assertTrue(False) 34 | except Exception as e: 35 | self.assertEqual(type(e), queues.QueueEmpty) 36 | 37 | def test_qsize(self): 38 | q = queues.Queue() 39 | for n in range(10): 40 | q.put_nowait(10) 41 | self.assertEqual(q.qsize(), 10) 42 | 43 | def test_empty(self): 44 | q = queues.Queue() 45 | self.assertTrue(q.empty()) 46 | q.put_nowait(10) 47 | self.assertFalse(q.empty()) 48 | 49 | def test_full(self): 50 | q = queues.Queue(maxsize=1) 51 | self.assertFalse(q.full()) 52 | q.put_nowait(10) 53 | self.assertTrue(q.full()) 54 | 55 | 56 | if __name__ == '__main__': 57 | run_class(QueueTestCase) 58 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/test/support.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import io 3 | import unittest 4 | import gc 5 | import contextlib 6 | 7 | 8 | TESTFN = '@test' 9 | 10 | def run_unittest(*classes): 11 | suite = unittest.TestSuite() 12 | for c in classes: 13 | if isinstance(c, str): 14 | c = __import__(c) 15 | for name in dir(c): 16 | obj = getattr(c, name) 17 | if isinstance(obj, type) and issubclass(obj, unittest.TestCase): 18 | suite.addTest(obj) 19 | else: 20 | suite.addTest(c) 21 | runner = unittest.TestRunner() 22 | result = runner.run(suite) 23 | 24 | def can_symlink(): 25 | return False 26 | 27 | def skip_unless_symlink(test): 28 | """Skip decorator for tests that require functional symlink""" 29 | ok = can_symlink() 30 | msg = "Requires functional symlink implementation" 31 | return test if ok else unittest.skip(msg)(test) 32 | 33 | def create_empty_file(name): 34 | open(name, "w").close() 35 | 36 | @contextlib.contextmanager 37 | def disable_gc(): 38 | have_gc = gc.isenabled() 39 | gc.disable() 40 | try: 41 | yield 42 | finally: 43 | if have_gc: 44 | gc.enable() 45 | 46 | def gc_collect(): 47 | gc.collect() 48 | gc.collect() 49 | gc.collect() 50 | 51 | @contextlib.contextmanager 52 | def captured_output(stream_name): 53 | org = getattr(sys, stream_name) 54 | buf = io.StringIO() 55 | setattr(sys, stream_name, buf) 56 | try: 57 | yield buf 58 | finally: 59 | setattr(sys, stream_name, org) 60 | 61 | def captured_stderr(): 62 | return captured_output("stderr") 63 | 64 | def requires_IEEE_754(f): 65 | return f 66 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/test/support.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import io 3 | import unittest 4 | import gc 5 | import contextlib 6 | 7 | 8 | TESTFN = '@test' 9 | 10 | def run_unittest(*classes): 11 | suite = unittest.TestSuite() 12 | for c in classes: 13 | if isinstance(c, str): 14 | c = __import__(c) 15 | for name in dir(c): 16 | obj = getattr(c, name) 17 | if isinstance(obj, type) and issubclass(obj, unittest.TestCase): 18 | suite.addTest(obj) 19 | else: 20 | suite.addTest(c) 21 | runner = unittest.TestRunner() 22 | result = runner.run(suite) 23 | 24 | def can_symlink(): 25 | return False 26 | 27 | def skip_unless_symlink(test): 28 | """Skip decorator for tests that require functional symlink""" 29 | ok = can_symlink() 30 | msg = "Requires functional symlink implementation" 31 | return test if ok else unittest.skip(msg)(test) 32 | 33 | def create_empty_file(name): 34 | open(name, "w").close() 35 | 36 | @contextlib.contextmanager 37 | def disable_gc(): 38 | have_gc = gc.isenabled() 39 | gc.disable() 40 | try: 41 | yield 42 | finally: 43 | if have_gc: 44 | gc.enable() 45 | 46 | def gc_collect(): 47 | gc.collect() 48 | gc.collect() 49 | gc.collect() 50 | 51 | @contextlib.contextmanager 52 | def captured_output(stream_name): 53 | org = getattr(sys, stream_name) 54 | buf = io.StringIO() 55 | setattr(sys, stream_name, buf) 56 | try: 57 | yield buf 58 | finally: 59 | setattr(sys, stream_name, org) 60 | 61 | def captured_stderr(): 62 | return captured_output("stderr") 63 | 64 | def requires_IEEE_754(f): 65 | return f 66 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/init.py: -------------------------------------------------------------------------------- 1 | """OpenPython Operating System""" 2 | 3 | import sys 4 | 5 | import machine 6 | import uos 7 | from ucomponent import invoke 8 | from uio import FileIO 9 | 10 | 11 | class FileSystem: 12 | def __init__(self, address): 13 | self.address = address 14 | 15 | def mount(self, readonly, mkfs): 16 | pass 17 | 18 | def umount(self): 19 | pass 20 | 21 | def getcwd(self): 22 | return '/' 23 | 24 | def ilistdir(self, dir): 25 | for name in invoke(self.address, 'list', dir): 26 | if invoke(self.address, 'isDirectory', dir + "/" + name): 27 | yield (name, 0x4000, 0, -1) 28 | else: 29 | yield (name, 0x8000, 0, 0) 30 | 31 | def stat(self, path): 32 | if not invoke(self.address, 'exists', path): 33 | raise OSError(1) 34 | 35 | return 0x4000 if invoke(self.address, 'isDirectory', path) else 0x8000, 0, 0, 0, 0, 0, 0, 0, 0, 0 36 | 37 | def open(self, file, mode): 38 | return FileIO(self.address, file, mode) 39 | 40 | 41 | @machine.hook_stdin 42 | def input_handler(): 43 | return 0 44 | 45 | 46 | @machine.hook_stdout 47 | def print_handler(string): 48 | machine.debug(string) 49 | 50 | 51 | def init(): 52 | uos.mount(FileSystem(__path__), '/') 53 | sys.path.append('/lib') 54 | sys.path.append('/lib/micropython') 55 | 56 | for filename in sorted(uos.listdir("/boot")): 57 | context = {'__name__': '__main__', '__path__': __path__} 58 | # noinspection PyUnresolvedReferences 59 | execfile("/boot/" + filename, context) 60 | 61 | from shell import spawn 62 | spawn("/bin/python.py") 63 | 64 | 65 | if __name__ == "__main__": 66 | init() 67 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/init.py: -------------------------------------------------------------------------------- 1 | """OpenPython Operating System""" 2 | 3 | import sys 4 | 5 | import machine 6 | import uos 7 | from ucomponent import invoke 8 | from uio import FileIO 9 | 10 | 11 | class FileSystem: 12 | def __init__(self, address): 13 | self.address = address 14 | 15 | def mount(self, readonly, mkfs): 16 | pass 17 | 18 | def umount(self): 19 | pass 20 | 21 | def getcwd(self): 22 | return '/' 23 | 24 | def ilistdir(self, dir): 25 | for name in invoke(self.address, 'list', dir): 26 | if invoke(self.address, 'isDirectory', dir + "/" + name): 27 | yield (name, 0x4000, 0, -1) 28 | else: 29 | yield (name, 0x8000, 0, 0) 30 | 31 | def stat(self, path): 32 | if not invoke(self.address, 'exists', path): 33 | raise OSError(1) 34 | 35 | return 0x4000 if invoke(self.address, 'isDirectory', path) else 0x8000, 0, 0, 0, 0, 0, 0, 0, 0, 0 36 | 37 | def open(self, file, mode): 38 | return FileIO(self.address, file, mode) 39 | 40 | 41 | @machine.hook_stdin 42 | def input_handler(): 43 | return 0 44 | 45 | 46 | @machine.hook_stdout 47 | def print_handler(string): 48 | machine.debug(string) 49 | 50 | 51 | def init(): 52 | uos.mount(FileSystem(__path__), '/') 53 | sys.path.append('/lib') 54 | sys.path.append('/lib/internal') 55 | sys.path.append('/lib/openos') 56 | sys.path.append('/usr/lib') 57 | sys.path.append('/lib/micropython') 58 | 59 | for filename in sorted(uos.listdir("/boot")): 60 | context = {'__name__': '__main__', '__path__': __path__} 61 | # noinspection PyUnresolvedReferences 62 | execfile("/boot/" + filename, context) 63 | 64 | from shell import spawn 65 | spawn("/bin/shell.py") 66 | 67 | 68 | if __name__ == "__main__": 69 | init() 70 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/openos/computer.py: -------------------------------------------------------------------------------- 1 | # noinspection PyUnresolvedReferences 2 | import gc 3 | 4 | import ucomputer 5 | import utime 6 | 7 | 8 | def address(): 9 | return ucomputer.get_computer_address() 10 | 11 | 12 | def tmp_address(): 13 | return ucomputer.get_tmp_address() 14 | 15 | 16 | def free_memory(): 17 | return gc.mem_free() 18 | 19 | 20 | def total_memory(): 21 | return gc.mem_alloc() + gc.mem_free() 22 | 23 | 24 | def uptime(): 25 | return utime.time_up() 26 | 27 | 28 | def shutdown(reboot: bool = False): 29 | if reboot: 30 | ucomputer.reboot() 31 | else: 32 | ucomputer.shutdown() 33 | 34 | raise NotImplementedError("invalid behavior") 35 | 36 | 37 | def reboot(): 38 | ucomputer.reboot() 39 | raise NotImplementedError("invalid behavior") 40 | 41 | 42 | def get_boot_address() -> str: 43 | import component 44 | 45 | # noinspection PyUnresolvedReferences 46 | eeprom = component.eeprom 47 | return eeprom.getData().decode() 48 | 49 | 50 | def set_boot_address(address: str): 51 | import component 52 | 53 | # noinspection PyUnresolvedReferences 54 | eeprom = component.eeprom 55 | eeprom.setData(address.encode()) 56 | 57 | 58 | def runlevel(): 59 | return 1 60 | 61 | 62 | def users(): 63 | return ucomputer.get_users() 64 | 65 | 66 | def add_user(user: str): 67 | return ucomputer.add_user(user) 68 | 69 | 70 | def remove_user(user: str): 71 | return ucomputer.remove_user(user) 72 | 73 | 74 | def push_signal(name, *args): 75 | ucomputer.push_signal(name, *args) 76 | 77 | 78 | def pull_signal(seconds): 79 | signal = ucomputer.pop_signal(int(seconds * 20)) 80 | if signal is None: 81 | return None 82 | 83 | name, args = signal 84 | return (name,) + args 85 | 86 | 87 | def beep(frequency=None, duration=None): 88 | return ucomputer.beep(frequency, duration) 89 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/upysh.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | 4 | class LS: 5 | 6 | def __repr__(self): 7 | self.__call__() 8 | return "" 9 | 10 | def __call__(self, path="."): 11 | l = os.listdir(path) 12 | l.sort() 13 | for f in l: 14 | st = os.stat("%s/%s" % (path, f)) 15 | if st[0] & 0x4000: # stat.S_IFDIR 16 | print(" %s" % f) 17 | else: 18 | print("% 8d %s" % (st[6], f)) 19 | 20 | class PWD: 21 | 22 | def __repr__(self): 23 | return os.getcwd() 24 | 25 | def __call__(self): 26 | return self.__repr__() 27 | 28 | class CLEAR: 29 | def __repr__(self): 30 | return "\x1b[2J\x1b[H" 31 | 32 | def __call__(self): 33 | return self.__repr__() 34 | 35 | 36 | pwd = PWD() 37 | ls = LS() 38 | clear = CLEAR() 39 | 40 | cd = os.chdir 41 | mkdir = os.mkdir 42 | mv = os.rename 43 | rm = os.remove 44 | rmdir = os.rmdir 45 | 46 | def head(f, n=10): 47 | with open(f) as f: 48 | for i in range(n): 49 | l = f.readline() 50 | if not l: break 51 | sys.stdout.write(l) 52 | 53 | def cat(f): 54 | head(f, 1 << 30) 55 | 56 | def newfile(path): 57 | print("Type file contents line by line, finish with EOF (Ctrl+D).") 58 | with open(path, "w") as f: 59 | while 1: 60 | try: 61 | l = input() 62 | except EOFError: 63 | break 64 | f.write(l) 65 | f.write("\n") 66 | 67 | class Man(): 68 | 69 | def __repr__(self): 70 | return(""" 71 | upysh is intended to be imported using: 72 | from upysh import * 73 | 74 | To see this help text again, type "man". 75 | 76 | upysh commands: 77 | pwd, cd("new_dir"), ls, ls(...), head(...), cat(...) 78 | newfile(...), mv("old", "new"), rm(...), mkdir(...), rmdir(...), 79 | clear 80 | """) 81 | 82 | man = Man() 83 | 84 | print(man) 85 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/upysh.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | 4 | class LS: 5 | 6 | def __repr__(self): 7 | self.__call__() 8 | return "" 9 | 10 | def __call__(self, path="."): 11 | l = os.listdir(path) 12 | l.sort() 13 | for f in l: 14 | st = os.stat("%s/%s" % (path, f)) 15 | if st[0] & 0x4000: # stat.S_IFDIR 16 | print(" %s" % f) 17 | else: 18 | print("% 8d %s" % (st[6], f)) 19 | 20 | class PWD: 21 | 22 | def __repr__(self): 23 | return os.getcwd() 24 | 25 | def __call__(self): 26 | return self.__repr__() 27 | 28 | class CLEAR: 29 | def __repr__(self): 30 | return "\x1b[2J\x1b[H" 31 | 32 | def __call__(self): 33 | return self.__repr__() 34 | 35 | 36 | pwd = PWD() 37 | ls = LS() 38 | clear = CLEAR() 39 | 40 | cd = os.chdir 41 | mkdir = os.mkdir 42 | mv = os.rename 43 | rm = os.remove 44 | rmdir = os.rmdir 45 | 46 | def head(f, n=10): 47 | with open(f) as f: 48 | for i in range(n): 49 | l = f.readline() 50 | if not l: break 51 | sys.stdout.write(l) 52 | 53 | def cat(f): 54 | head(f, 1 << 30) 55 | 56 | def newfile(path): 57 | print("Type file contents line by line, finish with EOF (Ctrl+D).") 58 | with open(path, "w") as f: 59 | while 1: 60 | try: 61 | l = input() 62 | except EOFError: 63 | break 64 | f.write(l) 65 | f.write("\n") 66 | 67 | class Man(): 68 | 69 | def __repr__(self): 70 | return(""" 71 | upysh is intended to be imported using: 72 | from upysh import * 73 | 74 | To see this help text again, type "man". 75 | 76 | upysh commands: 77 | pwd, cd("new_dir"), ls, ls(...), head(...), cat(...) 78 | newfile(...), mv("old", "new"), rm(...), mkdir(...), rmdir(...), 79 | clear 80 | """) 81 | 82 | man = Man() 83 | 84 | print(man) 85 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/value.py: -------------------------------------------------------------------------------- 1 | import uvalue 2 | from uvalue import * 3 | 4 | __all__ = ["Value", "setup"] 5 | 6 | 7 | class ValueMethod: 8 | def __init__(self, value, name): 9 | self.value = value 10 | self.name = name 11 | 12 | def __call__(self, *args): 13 | return invoke(self.value._uvalue, self.name, *args) 14 | 15 | @property 16 | def __doc__(self): 17 | return doc(self.value._uvalue, self.name) 18 | 19 | def __repr__(self): 20 | doc = self.__doc__ 21 | if doc: 22 | doc = "\n" + doc.replace(" -- ", "\n") 23 | else: 24 | doc = "" 25 | 26 | return "ValueMethod<{0!r}, {1!r}>{2}".format(self.value._uvalue, self.name, doc) 27 | 28 | 29 | class ValueCloseMethod(ValueMethod): 30 | def __call__(self, *args): 31 | result = ValueMethod.__call__(self, *args) 32 | self.value.dispose() 33 | return result 34 | 35 | 36 | class Value: 37 | def __init__(self, uvalue): 38 | self._uvalue = uvalue 39 | 40 | def __dir__(self): 41 | return dir(object()) + ["__dir__", "__getattr__", "__doc__", "__str__", "__repr__", "__bool__", "__del__", 42 | "dispose", "_uvalue"] + list(methods(self._uvalue)) 43 | 44 | def __getattr__(self, name): 45 | return ValueMethod(self, name) if name != "close" else ValueCloseMethod(self, "close") 46 | 47 | def __str__(self): 48 | return doc(self._uvalue) if self else repr(self) 49 | 50 | def __repr__(self): 51 | return "Value<{0}>".format(doc(self._uvalue) if self else None) 52 | 53 | def __bool__(self): 54 | return self._uvalue.value is not None 55 | 56 | def __del__(self): 57 | self._uvalue.dispose() 58 | 59 | def dispose(self): 60 | self._uvalue.dispose() 61 | 62 | 63 | def value_hook(raw_object): 64 | return Value(raw_object) 65 | 66 | 67 | def setup(): 68 | uvalue.hook_value(value_hook) 69 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/udnspkt.py: -------------------------------------------------------------------------------- 1 | import uio 2 | 3 | 4 | def write_fqdn(buf, name): 5 | parts = name.split(".") 6 | for p in parts: 7 | buf.writebin("B", len(p)) 8 | buf.write(p) 9 | buf.writebin("B", 0) 10 | 11 | 12 | def skip_fqdn(buf): 13 | while True: 14 | sz = buf.readbin("B") 15 | if not sz: 16 | break 17 | if sz >= 0xc0: 18 | buf.readbin("B") 19 | break 20 | buf.read(sz) 21 | 22 | 23 | def make_req(buf, fqdn, is_ipv6): 24 | typ = 1 # A 25 | if is_ipv6: 26 | typ = 28 # AAAA 27 | 28 | buf.writebin(">H", 0) 29 | buf.writebin(">H", 0x100) 30 | # q count 31 | buf.writebin(">H", 1) 32 | buf.writebin(">H", 0) 33 | # squashed together 34 | buf.writebin(">I", 0) 35 | 36 | write_fqdn(buf, fqdn) 37 | buf.writebin(">H", typ) 38 | buf.writebin(">H", 1) # Class 39 | 40 | 41 | def parse_resp(buf, is_ipv6): 42 | typ = 1 # A 43 | if is_ipv6: 44 | typ = 28 # AAAA 45 | 46 | id = buf.readbin(">H") 47 | flags = buf.readbin(">H") 48 | assert flags & 0x8000 49 | qcnt = buf.readbin(">H") 50 | acnt = buf.readbin(">H") 51 | nscnt = buf.readbin(">H") 52 | addcnt = buf.readbin(">H") 53 | #print(qcnt, acnt, nscnt, addcnt) 54 | 55 | skip_fqdn(buf) 56 | v = buf.readbin(">H") 57 | #print(v) 58 | v = buf.readbin(">H") 59 | #print(v) 60 | 61 | for i in range(acnt): 62 | #print("Resp #%d" % i) 63 | #v = read_fqdn(buf) 64 | #print(v) 65 | skip_fqdn(buf) 66 | t = buf.readbin(">H") 67 | #print("Type", t) 68 | v = buf.readbin(">H") 69 | #print("Class", v) 70 | v = buf.readbin(">I") 71 | #print("TTL", v) 72 | rlen = buf.readbin(">H") 73 | #print("rlen", rlen) 74 | rval = buf.read(rlen) 75 | #print(rval) 76 | 77 | if t == typ: 78 | return rval 79 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/udnspkt.py: -------------------------------------------------------------------------------- 1 | import uio 2 | 3 | 4 | def write_fqdn(buf, name): 5 | parts = name.split(".") 6 | for p in parts: 7 | buf.writebin("B", len(p)) 8 | buf.write(p) 9 | buf.writebin("B", 0) 10 | 11 | 12 | def skip_fqdn(buf): 13 | while True: 14 | sz = buf.readbin("B") 15 | if not sz: 16 | break 17 | if sz >= 0xc0: 18 | buf.readbin("B") 19 | break 20 | buf.read(sz) 21 | 22 | 23 | def make_req(buf, fqdn, is_ipv6): 24 | typ = 1 # A 25 | if is_ipv6: 26 | typ = 28 # AAAA 27 | 28 | buf.writebin(">H", 0) 29 | buf.writebin(">H", 0x100) 30 | # q count 31 | buf.writebin(">H", 1) 32 | buf.writebin(">H", 0) 33 | # squashed together 34 | buf.writebin(">I", 0) 35 | 36 | write_fqdn(buf, fqdn) 37 | buf.writebin(">H", typ) 38 | buf.writebin(">H", 1) # Class 39 | 40 | 41 | def parse_resp(buf, is_ipv6): 42 | typ = 1 # A 43 | if is_ipv6: 44 | typ = 28 # AAAA 45 | 46 | id = buf.readbin(">H") 47 | flags = buf.readbin(">H") 48 | assert flags & 0x8000 49 | qcnt = buf.readbin(">H") 50 | acnt = buf.readbin(">H") 51 | nscnt = buf.readbin(">H") 52 | addcnt = buf.readbin(">H") 53 | #print(qcnt, acnt, nscnt, addcnt) 54 | 55 | skip_fqdn(buf) 56 | v = buf.readbin(">H") 57 | #print(v) 58 | v = buf.readbin(">H") 59 | #print(v) 60 | 61 | for i in range(acnt): 62 | #print("Resp #%d" % i) 63 | #v = read_fqdn(buf) 64 | #print(v) 65 | skip_fqdn(buf) 66 | t = buf.readbin(">H") 67 | #print("Type", t) 68 | v = buf.readbin(">H") 69 | #print("Class", v) 70 | v = buf.readbin(">I") 71 | #print("TTL", v) 72 | rlen = buf.readbin(">H") 73 | #print("rlen", rlen) 74 | rval = buf.read(rlen) 75 | #print(rval) 76 | 77 | if t == typ: 78 | return rval 79 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/uasyncio/websocket/server.py: -------------------------------------------------------------------------------- 1 | import uasyncio 2 | import uhashlib, ubinascii 3 | import websocket 4 | 5 | 6 | def make_respkey(webkey): 7 | d = uhashlib.sha1(webkey) 8 | d.update(b"258EAFA5-E914-47DA-95CA-C5AB0DC85B11") 9 | respkey = d.digest() 10 | respkey = ubinascii.b2a_base64(respkey) #[:-1] 11 | # Return with trailing "\n". 12 | return respkey 13 | 14 | 15 | class WSWriter: 16 | 17 | def __init__(self, reader, writer): 18 | # Reader is passed for symmetry with WSReader() and ignored. 19 | self.s = writer 20 | 21 | async def awrite(self, data): 22 | assert len(data) < 126 23 | await self.s.awrite(b"\x81") 24 | await self.s.awrite(bytes([len(data)])) 25 | await self.s.awrite(data) 26 | 27 | 28 | def WSReader(reader, writer): 29 | 30 | webkey = None 31 | while 1: 32 | l = yield from reader.readline() 33 | print(l) 34 | if not l: 35 | raise ValueError() 36 | if l == b"\r\n": 37 | break 38 | if l.startswith(b'Sec-WebSocket-Key'): 39 | webkey = l.split(b":", 1)[1] 40 | webkey = webkey.strip() 41 | 42 | if not webkey: 43 | raise ValueError("Not a websocker request") 44 | 45 | respkey = make_respkey(webkey) 46 | 47 | await writer.awrite(b"""\ 48 | HTTP/1.1 101 Switching Protocols\r 49 | Upgrade: websocket\r 50 | Connection: Upgrade\r 51 | Sec-WebSocket-Accept: """) 52 | await writer.awrite(respkey) 53 | # This will lead to "\n\r\n" being written. Not exactly 54 | # "\r\n\r\n", but browsers seem to eat it. 55 | await writer.awrite("\r\n") 56 | #await writer.awrite("\r\n\r\n") 57 | 58 | print("Finished webrepl handshake") 59 | 60 | ws = websocket.websocket(reader.ios) 61 | rws = uasyncio.StreamReader(reader.ios, ws) 62 | 63 | return rws 64 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/uasyncio/websocket/server.py: -------------------------------------------------------------------------------- 1 | import uasyncio 2 | import uhashlib, ubinascii 3 | import websocket 4 | 5 | 6 | def make_respkey(webkey): 7 | d = uhashlib.sha1(webkey) 8 | d.update(b"258EAFA5-E914-47DA-95CA-C5AB0DC85B11") 9 | respkey = d.digest() 10 | respkey = ubinascii.b2a_base64(respkey) #[:-1] 11 | # Return with trailing "\n". 12 | return respkey 13 | 14 | 15 | class WSWriter: 16 | 17 | def __init__(self, reader, writer): 18 | # Reader is passed for symmetry with WSReader() and ignored. 19 | self.s = writer 20 | 21 | async def awrite(self, data): 22 | assert len(data) < 126 23 | await self.s.awrite(b"\x81") 24 | await self.s.awrite(bytes([len(data)])) 25 | await self.s.awrite(data) 26 | 27 | 28 | def WSReader(reader, writer): 29 | 30 | webkey = None 31 | while 1: 32 | l = yield from reader.readline() 33 | print(l) 34 | if not l: 35 | raise ValueError() 36 | if l == b"\r\n": 37 | break 38 | if l.startswith(b'Sec-WebSocket-Key'): 39 | webkey = l.split(b":", 1)[1] 40 | webkey = webkey.strip() 41 | 42 | if not webkey: 43 | raise ValueError("Not a websocker request") 44 | 45 | respkey = make_respkey(webkey) 46 | 47 | await writer.awrite(b"""\ 48 | HTTP/1.1 101 Switching Protocols\r 49 | Upgrade: websocket\r 50 | Connection: Upgrade\r 51 | Sec-WebSocket-Accept: """) 52 | await writer.awrite(respkey) 53 | # This will lead to "\n\r\n" being written. Not exactly 54 | # "\r\n\r\n", but browsers seem to eat it. 55 | await writer.awrite("\r\n") 56 | #await writer.awrite("\r\n\r\n") 57 | 58 | print("Finished webrepl handshake") 59 | 60 | ws = websocket.websocket(reader.ios) 61 | rws = uasyncio.StreamReader(reader.ios, ws) 62 | 63 | return rws 64 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenPython 2 | 3 | ![Python Interpreter in OpenPython v1.0](https://user-images.githubusercontent.com/21021916/47162981-0163aa80-d330-11e8-9e54-7b470a5e67b0.png) 4 | 5 | **OpenPython makes micropython available on OpenComputers.** 6 | 7 | micropython is Python for embedded devices and is different from CPython. 8 | Currently, micropython is partially compatible with Python version 3.4 as of October 2018. 9 | 10 | Features include: 11 | - Fully persistable. 12 | - Runs in a sandboxed environment and does not require a separate native DLL. 13 | - Supports virtual file system. 14 | - It can call other components and supports Lua architecture's UserData. 15 | 16 | Limitations include: 17 | - The firmware is 256 KB and the memory limit has the same limit as the Lua architecture, but the stack is allocated in a separate memory. 18 | - Most modules are difficult to use because the battery is partially included. 19 | - The operating system is not yet fully implemented, so the Python interpreter now runs. 20 | - Ctrl + C is not supported, so if you accidentally run infinite repeated code, the only way to stop it is to turn the computer off and then on. 21 | 22 | To use the Python architecture, you need the following items: 23 | - EEPROM (OpenPython): I'm sorry, but you have to bring items from the Creative tab. 24 | - Floppy Disk (OpenPython OS): This item can be obtained by creating a floppy disk and Scrench, or you can check it on the Creative tab. 25 | - OpenPython CPU: You can choose OpenPython architecture by holding Shift + Right Click on the Lua architecture CPU. 26 | 27 | It is still unstable, but we plan to make further improvements in the future. 28 | 29 | I need help from people who are familiar with OpenComputers and Python. 30 | 31 | Thank you for playing. 32 | 33 | Links 34 | - [minecraft.curseforge.com/projects/openpython](https://minecraft.curseforge.com/projects/openpython) 35 | - [OpenPython in oc.cil.li](https://oc.cil.li/index.php?/topic/1744-mc1122oc17-openpython%C2%A0micropython-available-on-opencomputers/) 36 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/urllib/urequest.py: -------------------------------------------------------------------------------- 1 | import usocket 2 | 3 | def urlopen(url, data=None, method="GET"): 4 | if data is not None and method == "GET": 5 | method = "POST" 6 | try: 7 | proto, dummy, host, path = url.split("/", 3) 8 | except ValueError: 9 | proto, dummy, host = url.split("/", 2) 10 | path = "" 11 | if proto == "http:": 12 | port = 80 13 | elif proto == "https:": 14 | import ussl 15 | port = 443 16 | else: 17 | raise ValueError("Unsupported protocol: " + proto) 18 | 19 | if ":" in host: 20 | host, port = host.split(":", 1) 21 | port = int(port) 22 | 23 | ai = usocket.getaddrinfo(host, port, 0, usocket.SOCK_STREAM) 24 | ai = ai[0] 25 | 26 | s = usocket.socket(ai[0], ai[1], ai[2]) 27 | try: 28 | s.connect(ai[-1]) 29 | if proto == "https:": 30 | s = ussl.wrap_socket(s, server_hostname=host) 31 | 32 | s.write(method) 33 | s.write(b" /") 34 | s.write(path) 35 | s.write(b" HTTP/1.0\r\nHost: ") 36 | s.write(host) 37 | s.write(b"\r\n") 38 | 39 | if data: 40 | s.write(b"Content-Length: ") 41 | s.write(str(len(data))) 42 | s.write(b"\r\n") 43 | s.write(b"\r\n") 44 | if data: 45 | s.write(data) 46 | 47 | l = s.readline() 48 | l = l.split(None, 2) 49 | #print(l) 50 | status = int(l[1]) 51 | while True: 52 | l = s.readline() 53 | if not l or l == b"\r\n": 54 | break 55 | #print(l) 56 | if l.startswith(b"Transfer-Encoding:"): 57 | if b"chunked" in l: 58 | raise ValueError("Unsupported " + l) 59 | elif l.startswith(b"Location:"): 60 | raise NotImplementedError("Redirects not yet supported") 61 | except OSError: 62 | s.close() 63 | raise 64 | 65 | return s 66 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/urllib/urequest.py: -------------------------------------------------------------------------------- 1 | import usocket 2 | 3 | def urlopen(url, data=None, method="GET"): 4 | if data is not None and method == "GET": 5 | method = "POST" 6 | try: 7 | proto, dummy, host, path = url.split("/", 3) 8 | except ValueError: 9 | proto, dummy, host = url.split("/", 2) 10 | path = "" 11 | if proto == "http:": 12 | port = 80 13 | elif proto == "https:": 14 | import ussl 15 | port = 443 16 | else: 17 | raise ValueError("Unsupported protocol: " + proto) 18 | 19 | if ":" in host: 20 | host, port = host.split(":", 1) 21 | port = int(port) 22 | 23 | ai = usocket.getaddrinfo(host, port, 0, usocket.SOCK_STREAM) 24 | ai = ai[0] 25 | 26 | s = usocket.socket(ai[0], ai[1], ai[2]) 27 | try: 28 | s.connect(ai[-1]) 29 | if proto == "https:": 30 | s = ussl.wrap_socket(s, server_hostname=host) 31 | 32 | s.write(method) 33 | s.write(b" /") 34 | s.write(path) 35 | s.write(b" HTTP/1.0\r\nHost: ") 36 | s.write(host) 37 | s.write(b"\r\n") 38 | 39 | if data: 40 | s.write(b"Content-Length: ") 41 | s.write(str(len(data))) 42 | s.write(b"\r\n") 43 | s.write(b"\r\n") 44 | if data: 45 | s.write(data) 46 | 47 | l = s.readline() 48 | l = l.split(None, 2) 49 | #print(l) 50 | status = int(l[1]) 51 | while True: 52 | l = s.readline() 53 | if not l or l == b"\r\n": 54 | break 55 | #print(l) 56 | if l.startswith(b"Transfer-Encoding:"): 57 | if b"chunked" in l: 58 | raise ValueError("Unsupported " + l) 59 | elif l.startswith(b"Location:"): 60 | raise NotImplementedError("Redirects not yet supported") 61 | except OSError: 62 | s.close() 63 | raise 64 | 65 | return s 66 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/value.py: -------------------------------------------------------------------------------- 1 | import uvalue 2 | from uvalue import * 3 | 4 | __all__ = ["Value", "setup"] 5 | 6 | 7 | class ValueMethod: 8 | def __init__(self, value, name): 9 | self.value = value 10 | self.name = name 11 | 12 | def __call__(self, *args): 13 | return invoke(self.value._uvalue, self.name, *args) 14 | 15 | @property 16 | def __doc__(self): 17 | return doc(self.value._uvalue, self.name) 18 | 19 | def __repr__(self): 20 | doc = self.__doc__ 21 | if doc: 22 | doc = "\n" + doc.replace(" -- ", "\n") 23 | else: 24 | doc = "" 25 | 26 | return "ValueMethod<{0!r}, {1!r}>{2}".format(self.value._uvalue, self.name, doc) 27 | 28 | 29 | class ValueCloseMethod(ValueMethod): 30 | def __call__(self, *args): 31 | result = ValueMethod.__call__(self, *args) 32 | self.value.dispose() 33 | return result 34 | 35 | 36 | class Value: 37 | def __init__(self, uvalue): 38 | self._uvalue = uvalue 39 | 40 | def __dir__(self): 41 | return dir(object()) + ["__dir__", "__getattr__", "__doc__", "__str__", "__repr__", "__bool__", "__del__", 42 | "dispose", "_uvalue"] + list(methods(self._uvalue)) 43 | 44 | def __getattr__(self, name): 45 | return ValueMethod(self, name) 46 | 47 | def __str__(self): 48 | return doc(self._uvalue) if self else repr(self) 49 | 50 | def __repr__(self): 51 | return "Value<{0}>".format(doc(self._uvalue) if self else None) 52 | 53 | def __bool__(self): 54 | return self._uvalue.value is not None 55 | 56 | def __del__(self): 57 | self._uvalue.dispose() 58 | 59 | @property 60 | def close(self): 61 | return ValueCloseMethod(self, "close") 62 | 63 | def dispose(self): 64 | self._uvalue.dispose() 65 | 66 | 67 | def value_hook(raw_object): 68 | return Value(raw_object) 69 | 70 | 71 | def setup(): 72 | uvalue.hook_value(value_hook) 73 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/firmwares/v1.0.1/eeprom.py: -------------------------------------------------------------------------------- 1 | --[==[ 2 | """OpenPython EEPROM""" 3 | 4 | 5 | def main(): 6 | globals().pop('main') 7 | from ucomponent import invoke, get_list as get_components 8 | from ucomputer import crash, get_computer_address 9 | 10 | def component(t): 11 | seq = get_components(t) 12 | return seq[0] if seq else None 13 | 14 | def check_bootable(filesystems, address): 15 | return address in filesystems and invoke(address, 'exists', '/init.py') 16 | 17 | eeprom = __path__ 18 | filesystems = get_components("filesystem") 19 | 20 | address = invoke(eeprom, 'getData').decode() 21 | if not check_bootable(filesystems, address): 22 | invoke(__path__, 'setData', b'') 23 | for address in filesystems: 24 | if check_bootable(filesystems, address): 25 | invoke(eeprom, 'setData', address.encode()) 26 | break 27 | else: 28 | crash("no bootable medium found") 29 | 30 | computer = get_computer_address() 31 | invoke(computer, 'beep', 1000, 0.2) 32 | 33 | gpu = component("gpu") 34 | monitor = component("monitor") 35 | if gpu and monitor: 36 | invoke(gpu, "bind", monitor) 37 | 38 | def load(address): 39 | handle = invoke(address, 'open', '/init.py', 'r') 40 | buffer = [] 41 | 42 | try: 43 | while True: 44 | buf = invoke(address, 'read', handle, 4096) 45 | if not buf: break 46 | buffer.append(buf) 47 | finally: 48 | invoke(address, 'close', handle) 49 | handle.dispose() 50 | 51 | content = b"".join(buffer) 52 | return content.decode() 53 | 54 | content = load(address) 55 | context = {'__name__': '__main__', '__path__': address} 56 | func = compile(content, '/init.py', "exec") 57 | exec(func, context) 58 | 59 | 60 | if __name__ == '__main__': 61 | main() 62 | 63 | # ]==] error "This EEPROM requires a CPU running the OpenPython architecture." 64 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/component.py: -------------------------------------------------------------------------------- 1 | from ucomponent import invoke, get_methods, get_doc, get_list 2 | 3 | __all__ = ['Component', 'get_component', 'find_components', 'components'] 4 | 5 | PRIMARY_COMPONENTS = {} 6 | 7 | 8 | class ComponentMethod: 9 | def __init__(self, component, name): 10 | self.component = component 11 | self.name = name 12 | 13 | def __call__(self, *args): 14 | return invoke(self.component.address, self.name, *args) 15 | 16 | @property 17 | def __doc__(self): 18 | return get_doc(self.component.address, self.name) 19 | 20 | def __repr__(self): 21 | doc = self.__doc__ 22 | if doc: 23 | doc = "\n" + doc.replace(" -- ", "\n") 24 | else: 25 | doc = "" 26 | 27 | return "ComponentMethod<{0!r}, {1!r}>{2}".format(self.component, self.name, doc) 28 | 29 | 30 | class Component: 31 | def __init__(self, address, type): 32 | self.address = address 33 | self.type = type 34 | 35 | def __getattr__(self, name): 36 | return ComponentMethod(self, name) 37 | 38 | def __dir__(self): 39 | return dir(object()) + ["address", "type"] + list(get_methods(self.address)) 40 | 41 | def __repr__(self): 42 | return "Component<{0}:{1}>".format(self.type, self.address) 43 | 44 | 45 | components = get_list # TODO: ? 46 | 47 | 48 | def set_primary(compoent): 49 | PRIMARY_COMPONENTS[compoent.type] = compoent 50 | 51 | 52 | def get_component(component_type): 53 | component = PRIMARY_COMPONENTS.get(component_type) 54 | if component: 55 | return component 56 | 57 | for address in get_list(component_type): 58 | component = Component(address, component_type) 59 | set_primary(component) 60 | return component 61 | 62 | return None 63 | 64 | 65 | # alias 66 | get = get_component 67 | 68 | 69 | def find_components(component_type): 70 | return [Component(address, component_type) for address in get_list(component_type)] 71 | 72 | 73 | # alias 74 | find = find_components 75 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/openpython/console/OpenPieBenchmark.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.openpython.console 2 | 3 | import kr.pe.ecmaxp.openpython.arch.consts.KB 4 | import kr.pe.ecmaxp.openpython.arch.versions.v1.OpenPythonArchitectureV1_1 5 | import kr.pe.ecmaxp.openpython.arch.versions.v1.OpenPythonMemoryRegionV1.* 6 | import kr.pe.ecmaxp.openpython.arch.versions.v1.SYS_DEBUG 7 | import kr.pe.ecmaxp.openpython.arch.versions.v1.SYS_INFO_RAM_SIZE 8 | import kr.pe.ecmaxp.thumbsf.CPU 9 | import kr.pe.ecmaxp.thumbsf.MemoryFlag 10 | import kr.pe.ecmaxp.thumbsf.consts.PC 11 | import kr.pe.ecmaxp.thumbsf.signal.ControlStopSignal 12 | import java.nio.charset.Charset 13 | import java.time.Instant 14 | 15 | 16 | object OpenPythonBenchmark { 17 | @JvmStatic 18 | fun main(args: Array) { 19 | val cpu = CPU() 20 | val firmware = OpenPythonArchitectureV1_1.LATEST_FIRMWARE 21 | cpu.memory.apply { 22 | flash(FLASH.address, FLASH.size, firmware.loadFirmware()) 23 | map(SRAM.address, SRAM.size, MemoryFlag.RW) // ram 24 | map(RAM.address, 256 * KB, MemoryFlag.RW) // ram 25 | map(SYSCALL.address, SYSCALL.size, MemoryFlag.RW) // syscall 26 | } 27 | 28 | for (i in 1..10) { 29 | val start = Instant.now() 30 | cpu.regs[PC] = cpu.memory.readInt(0x08000000 + 4) 31 | 32 | try { 33 | while (true) 34 | cpu.run(1000000) { 35 | when (cpu.regs[7]) { 36 | SYS_INFO_RAM_SIZE -> cpu.regs[0] = 64 * KB 37 | 0xDEADBEEFL.toInt() -> throw ControlStopSignal() 38 | SYS_DEBUG -> print(String(cpu.memory.readBuffer(cpu.regs[0], cpu.regs[1]), Charset.defaultCharset())) 39 | else -> cpu.regs[0] = 0; 40 | } 41 | } 42 | } catch (e: ControlStopSignal) { 43 | val end = Instant.now() 44 | println(end.toEpochMilli() - start.toEpochMilli()) 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.0/lib/micropython/time.py: -------------------------------------------------------------------------------- 1 | from utime import * 2 | from ucollections import namedtuple 3 | import ustruct 4 | import uctypes 5 | import ffi 6 | import ffilib 7 | import array 8 | 9 | libc = ffilib.libc() 10 | 11 | # struct tm *gmtime(const time_t *timep); 12 | # struct tm *localtime(const time_t *timep); 13 | # size_t strftime(char *s, size_t max, const char *format, 14 | # const struct tm *tm); 15 | gmtime_ = libc.func("P", "gmtime", "P") 16 | localtime_ = libc.func("P", "localtime", "P") 17 | strftime_ = libc.func("i", "strftime", "sisP") 18 | mktime_ = libc.func("i", "mktime", "P") 19 | 20 | _struct_time = namedtuple("struct_time", 21 | ["tm_year", "tm_mon", "tm_mday", "tm_hour", "tm_min", "tm_sec", "tm_wday", "tm_yday", "tm_isdst"]) 22 | 23 | def _tuple_to_c_tm(t): 24 | return ustruct.pack("@iiiiiiiii", t[5], t[4], t[3], t[2], t[1] - 1, t[0] - 1900, (t[6] + 1) % 7, t[7] - 1, t[8]) 25 | 26 | 27 | def _c_tm_to_tuple(tm): 28 | t = ustruct.unpack("@iiiiiiiii", tm) 29 | return _struct_time(t[5] + 1900, t[4] + 1, t[3], t[2], t[1], t[0], (t[6] - 1) % 7, t[7] + 1, t[8]) 30 | 31 | def struct_time(tm): 32 | return _struct_time(*tm) 33 | 34 | 35 | def strftime(format, t=None): 36 | if t is None: 37 | t = localtime() 38 | 39 | buf = bytearray(32) 40 | l = strftime_(buf, 32, format, _tuple_to_c_tm(t)) 41 | return str(buf[:l], "utf-8") 42 | 43 | 44 | def localtime(t=None): 45 | if t is None: 46 | t = time() 47 | 48 | t = int(t) 49 | a = ustruct.pack('l', t) 50 | tm_p = localtime_(a) 51 | return _c_tm_to_tuple(uctypes.bytearray_at(tm_p, 36)) 52 | 53 | 54 | def gmtime(t=None): 55 | if t is None: 56 | t = time() 57 | 58 | t = int(t) 59 | a = ustruct.pack('l', t) 60 | tm_p = gmtime_(a) 61 | return _c_tm_to_tuple(uctypes.bytearray_at(tm_p, 36)) 62 | 63 | 64 | def mktime(tt): 65 | return mktime_(_tuple_to_c_tm(tt)) 66 | 67 | 68 | def perf_counter(): 69 | return time() 70 | 71 | def process_time(): 72 | return clock() 73 | 74 | 75 | daylight = 0 76 | timezone = 0 77 | -------------------------------------------------------------------------------- /src/main/resources/assets/openpython/opos/v1.1/lib/micropython/time.py: -------------------------------------------------------------------------------- 1 | from utime import * 2 | from ucollections import namedtuple 3 | import ustruct 4 | import uctypes 5 | import ffi 6 | import ffilib 7 | import array 8 | 9 | libc = ffilib.libc() 10 | 11 | # struct tm *gmtime(const time_t *timep); 12 | # struct tm *localtime(const time_t *timep); 13 | # size_t strftime(char *s, size_t max, const char *format, 14 | # const struct tm *tm); 15 | gmtime_ = libc.func("P", "gmtime", "P") 16 | localtime_ = libc.func("P", "localtime", "P") 17 | strftime_ = libc.func("i", "strftime", "sisP") 18 | mktime_ = libc.func("i", "mktime", "P") 19 | 20 | _struct_time = namedtuple("struct_time", 21 | ["tm_year", "tm_mon", "tm_mday", "tm_hour", "tm_min", "tm_sec", "tm_wday", "tm_yday", "tm_isdst"]) 22 | 23 | def _tuple_to_c_tm(t): 24 | return ustruct.pack("@iiiiiiiii", t[5], t[4], t[3], t[2], t[1] - 1, t[0] - 1900, (t[6] + 1) % 7, t[7] - 1, t[8]) 25 | 26 | 27 | def _c_tm_to_tuple(tm): 28 | t = ustruct.unpack("@iiiiiiiii", tm) 29 | return _struct_time(t[5] + 1900, t[4] + 1, t[3], t[2], t[1], t[0], (t[6] - 1) % 7, t[7] + 1, t[8]) 30 | 31 | def struct_time(tm): 32 | return _struct_time(*tm) 33 | 34 | 35 | def strftime(format, t=None): 36 | if t is None: 37 | t = localtime() 38 | 39 | buf = bytearray(32) 40 | l = strftime_(buf, 32, format, _tuple_to_c_tm(t)) 41 | return str(buf[:l], "utf-8") 42 | 43 | 44 | def localtime(t=None): 45 | if t is None: 46 | t = time() 47 | 48 | t = int(t) 49 | a = ustruct.pack('l', t) 50 | tm_p = localtime_(a) 51 | return _c_tm_to_tuple(uctypes.bytearray_at(tm_p, 36)) 52 | 53 | 54 | def gmtime(t=None): 55 | if t is None: 56 | t = time() 57 | 58 | t = int(t) 59 | a = ustruct.pack('l', t) 60 | tm_p = gmtime_(a) 61 | return _c_tm_to_tuple(uctypes.bytearray_at(tm_p, 36)) 62 | 63 | 64 | def mktime(tt): 65 | return mktime_(_tuple_to_c_tm(tt)) 66 | 67 | 68 | def perf_counter(): 69 | return time() 70 | 71 | def process_time(): 72 | return clock() 73 | 74 | 75 | daylight = 0 76 | timezone = 0 77 | -------------------------------------------------------------------------------- /LICENSE-OpenComputers: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2015 Florian "Sangar" Nücke 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | 21 | ------------------------------------------------------------------------------- 22 | 23 | All images / textures and localization strings (resources) are put in the 24 | public domain, unless explicitly excluded below. More specicially, see CC0 1.0 25 | Universal: 26 | 27 | http://creativecommons.org/publicdomain/zero/1.0/ 28 | 29 | Contributions: 30 | PixelToast - Capacitor textures. 31 | asie - Disk drive inject/eject and floppy disk access sound samples. 32 | 33 | Thanks a lot! 34 | 35 | ------------------------------------------------------------------------------- 36 | 37 | The font used for screens and for monospace text in manual is unscii, made by 38 | viznut, and was further expanded by asie. For more information, please see: 39 | 40 | https://github.com/asiekierka/unscii-asie 41 | 42 | ------------------------------------------------------------------------------- 43 | 44 | Assets from other sources: 45 | HDD access samples based on this sample from freesound.org: 46 | https://www.freesound.org/people/artykris/sounds/117401/ -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/openpython/arch/msgpack/MsgpackUnpacker.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.openpython.arch.msgpack 2 | 3 | import kr.pe.ecmaxp.openpython.OpenPythonVirtualMachine 4 | import kr.pe.ecmaxp.openpython.repack.org.msgpack.core.MessagePack 5 | import kr.pe.ecmaxp.openpython.repack.org.msgpack.value.ValueType 6 | 7 | 8 | class MsgpackUnpacker(buffer: ByteArray, val vm: OpenPythonVirtualMachine? = null) { 9 | val unpacker = MessagePack.newDefaultUnpacker(buffer) 10 | 11 | fun unpack(): Any? { 12 | if (!unpacker.hasNext()) 13 | throw Exception("invalid unpack") 14 | 15 | unpacker.apply { 16 | return when (nextFormat.valueType) { 17 | null -> throw Exception() 18 | ValueType.NIL -> unpackNil() 19 | ValueType.BOOLEAN -> unpackBoolean() 20 | ValueType.INTEGER -> unpackInt() 21 | ValueType.FLOAT -> unpackFloat() 22 | ValueType.STRING -> unpackString() 23 | ValueType.BINARY -> { 24 | val length = unpackBinaryHeader() 25 | readPayload(length) 26 | } 27 | ValueType.ARRAY -> { 28 | val length = unpackArrayHeader() 29 | val list = arrayOfNulls(length) 30 | for (i in 0 until length) 31 | list[i] = unpack() 32 | 33 | list 34 | } 35 | ValueType.MAP -> { 36 | val length = unpackMapHeader() 37 | val map = HashMap() 38 | for (i in 0 until length) 39 | map.put(unpack(), unpack()) 40 | 41 | map 42 | } 43 | ValueType.EXTENSION -> { 44 | vm!!.unpackExtension(this) 45 | } 46 | else -> throw Exception() 47 | } 48 | } 49 | 50 | throw Exception() 51 | } 52 | 53 | fun unpackObj(): Any? { 54 | val value = unpack() 55 | finish() 56 | return value 57 | } 58 | 59 | private fun finish() { 60 | if (unpacker.hasNext()) 61 | throw Exception("too many argument") 62 | } 63 | } 64 | 65 | -------------------------------------------------------------------------------- /src/main/java/kr/pe/ecmaxp/openpython/arch/state/ValueContainerMap.kt: -------------------------------------------------------------------------------- 1 | package kr.pe.ecmaxp.openpython.arch.state 2 | 3 | import li.cil.oc.api.Persistable 4 | import li.cil.oc.api.machine.Value 5 | import net.minecraft.nbt.NBTTagCompound 6 | import net.minecraft.nbt.NBTTagList 7 | import java.util.* 8 | 9 | class ValueContainerMap : Persistable { 10 | var containerSet: HashSet = HashSet() 11 | var pointerMap: HashMap = HashMap() 12 | var valueMap: HashMap = HashMap() 13 | 14 | operator fun get(id: Int): Value { 15 | return pointerMap[id]!!.value!! 16 | } 17 | 18 | fun register(value: Value): ValueContainer = valueMap.get(value) ?: register(findEmptyId(), value) 19 | 20 | fun register(id: Int, value: Value): ValueContainer { 21 | val container = ValueContainer(value, id) 22 | 23 | valueMap[value] = container 24 | pointerMap[id] = container 25 | containerSet.add(container) 26 | return container 27 | } 28 | 29 | fun unregister(value: Value) = unregister(valueMap[value]!!) 30 | 31 | fun unregister(container: ValueContainer) { 32 | valueMap.remove(container.value) 33 | pointerMap.remove(container.id) 34 | containerSet.remove(container) 35 | } 36 | 37 | 38 | private val rand = Random() 39 | private fun findEmptyId(): Int { 40 | for (num in rand.ints()) { 41 | if (!pointerMap.containsKey(num)) { 42 | return num 43 | } 44 | } 45 | 46 | return 0 47 | } 48 | 49 | override fun load(nbt: NBTTagCompound) { 50 | val tagList = nbt.getTagList("list", NBTTagCompound().id.toInt()) 51 | for (containerBaseTag in tagList) { 52 | val containerTag = containerBaseTag as NBTTagCompound 53 | val container = ValueContainer() 54 | container.load(containerTag) 55 | register(container.id, container.value!!) 56 | } 57 | } 58 | 59 | override fun save(nbt: NBTTagCompound) { 60 | val tagList = NBTTagList() 61 | for (container in containerSet) { 62 | val containerTag = NBTTagCompound() 63 | container.save(containerTag) 64 | tagList.appendTag(containerTag) 65 | } 66 | 67 | nbt.setTag("list", tagList) 68 | } 69 | } --------------------------------------------------------------------------------