5 ms·
If you stick to this subset of python https://github.com/adsharma/py2many/blob/main/doc/langspec.md https://github.com/adsharma/py2many/blob/main/doc/langspec.
by adsharma 5y ago
If you stick to this subset of python
https://github.com/adsharma/py2many/blob/main/doc/langspec.md https://github.com/adsharma/py2many/blob/main/doc/langspec.m...
The tool can convert your code to C++/Rust/Go and give you a native binary which like you observe will run faster without the python runtime.
There are many open tasks that could use help.
- gcr 5y agoHow does this compare to Cython?
- sodality2 5y agoCython is a compiler, which converts (compiles) Python source code into more performant yet still compiled executables. Py2many is a transpiler, which converts source code of one language to source code of another language (which then needs to be compiled). So far, Py2many seems to support Rust and C++14, and preliminary support for Julia, Kotlin, Nim, Go and Dart.
- adsharma 5y agoYou can also think of Cython as a .pyx -> .c transpiler, but it tries to build a python C extension primarily. Py2many tries to primarily build a standalone C program without the python runtime, although it supports a --extension flag, where it generates a PyO3 extension for rust.
- takeda 5y agoNo, Cython is transpiler as well, it converts the code into C which you can then compile. If you use additional type markings it can generate more performant C code. BTW: I remember a blog article of someone who was using Cython as the primary language instead of Python.
- gpderetta 5y agoThe typical C compiler is a transpiler as well. It convert C code to assembly that is then converted by the assembler (another transpiler) to machine code. As the sibling comment notes, transpiler is not a very useful term.
- stonemetal12 5y ago>assembler (another transpiler) to machine code. A thought assembler was a "compiler", where a "compiler" is a special type of transpiler that is only capable of producing machine code.
- Stratoscope 5y agoI realize that many people, like yourself, make a distinction between compilers and transpilers. There are also many, like me, who find it to be a distinction without a difference. We call them all compilers. One example is the TypeScript team: > Let’s get acquainted with our new friend tsc, the TypeScript compiler. https://www.typescriptlang.org/docs/handbook/2/basic-types.html#tsc-the-typescript-compiler https://www.typescriptlang.org/docs/handbook/2/basic-types.h... Another is Bjarne Stroustrup. Back in the glory days of BIX, I posted a comment in one of the forums that said, "C++? That's a preprocessor, isn't it?" (At the time, the only C++ implementation was Cfront, which translated C++ to C.) Bjarne replied in no uncertain terms that Cfront was a compiler. Longer version of the story with some discussion of other words and phrases: https://news.ycombinator.com/item?id=15154994 https://news.ycombinator.com/item?id=15154994 Of course, the word "transpiler" had not yet been coined, but I have a feeling Bjarne still prefers to call Cfront a compiler, as the Wikipedia page does: > Cfront was the original compiler for C++ (then known as "C with Classes") from around 1983, which converted C++ to C; developed by Bjarne Stroustrup at AT&T Bell Labs. https://en.wikipedia.org/wiki/Cfront https://en.wikipedia.org/wiki/Cfront So to my mind, a compiler doesn't have to generate a "compiled executable". It also doesn't have to take "source code" as input. Most implementations of JavaScript and Java have at least two compilers: one that translates source code into bytecode, and a Just In Time Compiler that never sees the source code, but analyzes and profiles the bytecode while it runs, and translates sections of the code into machine language as it finds hotspots. Now if you like the word "transpiler", as many do, I won't try to convince you otherwise. I just wanted to explain why some don't find it a useful distinction and prefer "compiler" for all these cases. It's a program that translates computer code from one language to another, whatever the form of those languages may be. I suppose by my own argument I should also call an assembler a compiler! But no one does that... :-)
- jasode 5y ago>Back in the mid-80s, [...] Of course, the word "transpiler" had not yet been coined, Friend fyi... the word "transpiler" to make a distinction of converting the source to another higher-level language rather than a lower-level machine language appeared as early as 1960s. In the 1964 paper, see the last page and the 2nd-to-last paragraph: http://comjnl.oxfordjournals.org/content/7/1/28.full.pdf+html http://comjnl.oxfordjournals.org/content/7/1/28.full.pdf+htm... >There are also many, like me, who find it to be a distinction without a difference. We call them all compilers. [...] Now if you like the word "transpiler", as many do, I won't try to convince you otherwise. I just wanted to explain why some don't find it a useful distinction and prefer "compiler" for all these cases. I understand your point of why "compilers" already encompasses transpilers so the word "transpilers" seems redundant. But I'll try to explain why "transpilers" still endures. If you're not familiar with concept of "lumpers vs splitters", take a look at: https://en.wikipedia.org/wiki/Lumpers_and_splitters https://en.wikipedia.org/wiki/Lumpers_and_splitters Imagine if we did not have the word "transpiler". Language usage would still evolve to make a distinction via extra prefixes or suffixes or extra adjectives. Examples of alternative history might be: - "compiler-to-asm" or CTA acronym, or "compiler-to-executable", or "native compiler" - "compiler-to-another-high-level-language" or CTAHLA acronym, or "programming language translator" But humans don't like to say or write verbose multi-syllable terminology and they'd eventually substitute a simpler word as shorthand for the distinction. That shorthand word might be "transpilers" or another word to serve the same purpose. And that's what happened in 1964 when AF Parker-Rhodes suggested the word "transpiler". Similar concept of labeling Linux ext4, Microsoft NTFS, Apple HFS as "file systems" instead of just "databases" -- even though they are all conceptually "databases" which have same computer science concepts of keys, blocks, btree indexes. If we tried to police the language and insist that "file system" adds no useful distinction because it's a "database"... human language usage would still evolve with extra adjectives such as "operating-system-built-in-database-for-documents-and-arbitrary-files-etc" ... which is a cumbersome mouthful which motivates a shorthand terminology... perhaps call it "file system".
- adsharma 5y agocython requires you to express types in a special way (cdef int in a .pyx file). py2many uses standard python3 types plus a few derived from ctypes, with rust compatible names.