6 ms·
Pikascript: An ultra-lightweight Python engine that can run in 4Kb of RAM
- DeathArrow 4y agoCool. So you can use Python on ZX Spectrum
- deleted 4y ago[deleted]
- Joyfield 4y agoSmall "k" for kilo and big "b" for byte.
- numlock86 4y agoI was always under the impression that k is 1000 and K is 1024 ... same as with g, G or m and M. Full ack on b and B, though. Maybe the engine is indeed only 512B in RAM utilization? Edit: Turns out the official project's claim is indeed 4KB so the title is just bogus.
- deleted 4y ago[deleted]
- qsort 4y agoAccording to the official definitions: 1kb = 1000 bits 1Kib = 1024 bits 1kB = 1000 bytes 1KiB = 1024 bytes Obviously in practice nobody uses the decimal ones.
- MarioMan 4y agoAmong other things, hard drive labeled capacities are noteworthy for using the decimal definitions.
- Teknoman117 4y agoHah! That's a major pet peeve of mine. So, anyone who uses Windows has probably noticed at some point that "GB" "MB" and "KB" are the power-of-2 variants. Whenever I see one of those tech YouTubers say the formatted capacity of a 1 "TB" drive is 931 "GB" I just cringe. Most storage vendors use the power-of-10 definitions and Windows uses the power-of-2 definitions. 10^12 bytes / 2^30 = 931.32, so no, formatting your drive does not make 7% of the space just disappear.
- pezezin 4y agoTransfer speeds of physical interfaces (PCIe, Ethernet, DDR, HDMI, DisplayPort, USB, SATA, whatever) are usually decimal.
- numlock86 4y agoI am aware of k VS Ki but often see K as a shorthand for Ki.
- klyrs 4y agoSince I can never keep it straight... Pika: cute fluffy bunnymouse Pica: the desire to eat inedible stuff
- fizx 4y agoI wonder if this works in webassembly?
- BiteCode_dev 4y agoInteresing project, but I wish it would show me more about what doesn't work. The bottom of the readme indicates the list of control flow instructions it supports, but it would be convenient to have in the table the ones it doesn't as well: yield, yield from, with, try/excep, match, lambda... Does it support "else" in loops? Does it support unpacking? Hard to know how much Python does this Python does. Good luck to the project though.
- jmrm 4y ago> The bottom of the readme indicates the list of control flow instructions it supports, but it would be convenient to have in the table the ones it doesn't as well Totally true. Some people would like to contribute to the project, and knowing what's lacking is a good way to make people know how to help.
- dublin 4y agoBut is it really Python if it doesn't have dictionaries? I'd argue No - they're the fundamental data structure of the language (like tables in Lua, arrays in FORTRAN, etc.). Pikascript could be useful, but it seems to me it's either a castrated Python, or more positively, a minimalist embedded scripting environment with Python-like syntax. But it's not Python.
- sophacles 4y agoHow does python even work without dictionaries? This is one of those rare times I find the word `fundamental` to be a bit understated. I mean, a class is just fancy syntactic sugar around a dict.
- freedomben 4y agoI don't see how you could support dictionaries with only 4k of memory. They're awesomely convenient but not very space efficient. Normally that doesn't matter because there's plenty of memory, but in this case it makes a lot of sense. But yeah so much of the standard library relies on dictionaries, so it wouldn't feel very pythonic.
- throwaway892238 4y agohooray!
- packetlost 4y agoWhen you're dealing with low-level compiler tool-chains like this, it's more accurate to say they translate a subset of python syntax (or the AST) into a lower level language (either machine code, or an ASM), so the dependence on dictionaries as a implementation detail of classes/objects (or really anything else that relies on dict) isn't really there (some things may break, but that's because they rely on a particular CPython implementation detail). Well, outside of dicts themselves. Having worked with a similar system, it's really better to think of it like embedded C and write code imperatively (and no dict, just arrays/lists).
- 4y ago
- facorreia 4y agoThis got me wondering what other scripting languages folks use in embedded, low memory setups. I found this about Lua: [1] [1] https://nicksypark.medium.com/the-feasibility-of-the-embedded-software-development-with-lua-programming-e37c409c3c19 https://nicksypark.medium.com/the-feasibility-of-the-embedde...
- alexisread 4y agoI think it depends on how hard-core you want to go. Fennel runs in 2K of ram https://news.ycombinator.com/item?id=31029478 https://news.ycombinator.com/item?id=31029478 Picbit ran in 256bytes, it's descendent is slightly larger https://github.com/stamourv/picobit https://github.com/stamourv/picobit Staapl compiles scheme to Forth, to also run on the PIC18 https://www.concatenative.org/wiki/view/Staapl https://www.concatenative.org/wiki/view/Staapl Of course there is also Sectorlisp, the smallest language out there in 436bytes, 64k ram https://justine.lol/sectorlisp2/ https://justine.lol/sectorlisp2/
- CharlesW 4y agoThere's JavaScript/ECMAScript via Moddable's XS engine: https://github.com/Moddable-OpenSource/moddable https://github.com/Moddable-OpenSource/moddable "A typical microcontroller used with the Moddable SDK has about 45 KB of free memory, 1 MB of Flash ROM, and runs at 80 MHz. The Moddable SDK uses many different techniques, both at build time and at run time, to work efficiently on these devices."
- mc4ndr3 4y agoUpvote. Stupid and really cool at the same time haha. A nice migration path for existing Python apps to eventually be rewritten in leaner languages.
- jlundberg 4y agoFor those who find this interesting, be sure to check out MicroPython: http://micropython.org/ http://micropython.org/ It’s super fun to use the built in interpreter over serial connection with say a Raspberry Pi Pico.
- nousermane 4y agoMicroPython's authors call it a "subset of python3", and that is a fairly large subset - all the familiar data structures, co-routines, module import, filesystem I/O, FFI, ...; Interpreter is much smaller than CPython and can run on a microcontroller with 256KB code/flash + 16KB RAM. Another step down is snek, where complete interpreter code can fit in 64KB. Although, this is a much more constrained subset of python (for example - yes dictionaries, no list comprehensions): https://sneklang.org/ https://sneklang.org/ PikaScript appear to be even more compact at 32KB code (and is even smaller subset of the language)
- jonjacky 4y agoThere was also PyMite, for 8 bit microcontrollers with 64 KiB of program memory (flash) and 4 KiB of RAM. It supported a subset of the Python 2.5 syntax and could execute a subset of the Python 2.5 bytecodes. https://wiki.python.org/moin/PyMite https://wiki.python.org/moin/PyMite