[HN Gopher] Pikascript: An ultra-lightweight Python engine that ...
       ___________________________________________________________________
        
       Pikascript: An ultra-lightweight Python engine that can run in 4Kb
       of RAM
        
       Author : watchdogtimer
       Score  : 118 points
       Date   : 2022-05-19 12:41 UTC (10 hours ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | dublin wrote:
       | But 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.
        
         | zasdffaa wrote:
         | Not sure I could tell a castrated Python from an uncastrated
         | Python except by the look on its face.
        
         | sophacles wrote:
         | How 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.
        
       | DeathArrow wrote:
       | Cool. So you can use Python on ZX Spectrum
        
       | [deleted]
        
       | jlundberg wrote:
       | For those who find this interesting, be sure to check out
       | MicroPython:
       | 
       | http://micropython.org/
       | 
       | It's super fun to use the built in interpreter over serial
       | connection with say a Raspberry Pi Pico.
        
         | nousermane wrote:
         | MicroPython'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/
         | 
         | PikaScript appear to be even more compact at 32KB code (and is
         | even smaller subset of the language)
        
           | jonjacky wrote:
           | There 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
        
       | fizx wrote:
       | I wonder if this works in webassembly?
        
       | facorreia wrote:
       | This 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-
       | embedde...
        
       | mc4ndr3 wrote:
       | Upvote. Stupid and really cool at the same time haha.
       | 
       | A nice migration path for existing Python apps to eventually be
       | rewritten in leaner languages.
        
       | Joyfield wrote:
       | Small "k" for kilo and big "b" for byte.
        
         | numlock86 wrote:
         | I 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]
        
           | qsort wrote:
           | According 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 wrote:
             | Among other things, hard drive labeled capacities are
             | noteworthy for using the decimal definitions.
        
               | Teknoman117 wrote:
               | Hah! 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.
        
       | BiteCode_dev wrote:
       | Interesing 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 wrote:
         | > 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.
        
       ___________________________________________________________________
       (page generated 2022-05-19 23:01 UTC)