[ a / b / cf / cy / g / lain / un ] [ fresh / meta ] [ home / rules / faq / affiliates ]

/g/ - Technology

Programming and Electronics
Name
Subject
Comment
File
Embed
Password (For file deletion.)

Hop in to our IRC channel! #wirechan@rizon.net

File: 1520648129111.png (459.91 KB, 1080x1080, Cute_Fish_Fauna.png)

 No.16

Have you heard of Hy?
It's Lisp that works like Python.
You can access Python libraries even.
What do you think of it?

 No.55

File: 1533299643019.jpeg (50.82 KB, 500x333, hissing.jpeg)

Hith~

 No.74

I think it actually great.
I don't know any thing about Hy macro system yet, but I think it will be great.
I skimmed it's getting start page and it seem to be some one build clojure on python.

 No.99

Cute fish

 No.224

Do you know: is it compiled to Python bytecode or Python itself? If the former, is there some kind of description of the Python virtual machine that could be studied?

 No.225

File: 1583152416332.jpeg (310.11 KB, 600x803, 3135025.jpeg)


 No.226

File: 1583173039936.jpg (763.58 KB, 2520x3564, 906a27d87e76d2cd46c55c2a8b….jpg)

>>225
Thank you, but I was hoping for something more detailed. What are the opcodes (not the mnemonics), how to format a bytecode compiled file, how to load it into the VM… Although I am unsure if it actually makes sense. Is the format even the same for CPython, PyPy and other Python interpreters? Sorry for the questions, I have no idea how it works.

By the way, if Wikipedia is to believed, Hy is translated into Python AST, which must be uniform among different Python implementations. Maybe they do it like this because there's no portable bytecode format?

 No.227

File: 1583185535370.png (684.46 KB, 600x890, 4202798.png)

>>226
>Is the format even the same for CPython, PyPy and other Python interpreters? Sorry for the questions, I have no idea how it works.
https://docs.python.org/3/glossary.html#term-bytecode
"""Python source code is compiled into bytecode, the internal representation of a Python program in the CPython interpreter. The bytecode is also cached in .pyc files so that executing the same file is faster the second time (recompilation from source to bytecode can be avoided). This “intermediate language” is said to run on a virtual machine that executes the machine code corresponding to each bytecode. Do note that bytecodes are not expected to work between different Python virtual machines, nor to be stable between Python releases.

A list of bytecode instructions can be found in the documentation for the dis module."""

https://docs.python.org/3/library/dis.html
"""The dis module supports the analysis of CPython bytecode by disassembling it. The CPython bytecode which this module takes as an input is defined in the file Include/opcode.h and used by the compiler and the interpreter.

CPython implementation detail: Bytecode is an implementation detail of the CPython interpreter. No guarantees are made that bytecode will not be added, removed, or changed between versions of Python. Use of this module should not be considered to work across Python VMs or Python releases."""

>I was hoping for something more detailed

https://github.com/python/cpython/blob/3.8/Python/compile.c

 No.228

File: 1583186946524.jpg (312.76 KB, 2048x1739, 9ceab00eb6aa52da64d7584f5c….jpg)

>>227
Looks like I just need to RTFM. Do they somewhere also explain why they decided to keep the bytecode implementation defined?

 No.229

File: 1583201092528.jpg (746.8 KB, 1280x1920, 3241784.jpg)

>>228
I'm not aware of a direct statement of the rationale behind that decision – it's not in e.g. the Design and History FAQ [0]. The spirit of The Python Language Reference suggests that it was specified in terms of an abstract execution model [1] precisely to allow more freedom for Alternate Implementations [2].

[0] https://docs.python.org/3/faq/design.html
[1] https://docs.python.org/3/reference/executionmodel.html
[2] https://docs.python.org/3/reference/introduction.html#alternate-implementations

 No.234

>>224
When running a python program, the following steps are taken:
Python source code -> abstract syntax tree (AST) -> bytecode
Hy replaces the "Python source code -> AST" step.

We should note that bytecode is an implementation detail.
CPython has its own format, Jython compiles to JRE bytecode, and other implementations can use more complicated means such as running and compiling simultaneously (JIT compilation).


>>226
>Maybe they do it like this because there's no portable bytecode format?
It's simpler if you just replace the "source code -> AST" step.
AST is the ideal model to compile your code to
because it is the same level of abstraction as it's input (source code).
You can easily see create and run your own AST with python's ast library.
It's pretty trivial to even implement a simple language yourself using that library.

 No.236

File: 1583868798991.jpeg (117.25 KB, 929x1245, 9922a90984ae75be.jpeg)

>>234
Doesn't it make a lot of optimizations impossible to do? Since you are basically translating your semantics into sugar-free Python.



[Return][Go to top] [Catalog] [Post a Reply]
Delete Post [ ]
[ a / b / cf / cy / g / lain / un ] [ fresh / meta ] [ home / rules / faq / affiliates ]