Ruby,PHP或Perl可以为Python之类的代码创建预编译文件吗? [英] Can Ruby, PHP, or Perl create a pre-compiled file for the code like Python?

查看:96
本文介绍了Ruby,PHP或Perl可以为Python之类的代码创建预编译文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Python,它可以创建一个预编译的版本file.pyc,以便程序可以运行而无需再次解释. Ruby,PHP和Perl可以在命令行上做同样的事情吗?

For Python, it can create a pre-compiled version file.pyc so that the program can be run without interpreted again. Can Ruby, PHP, and Perl do the same on the command line?

推荐答案

没有针对Ruby的可移植字节码规范,因此也没有标准的方式来加载预编译的字节码档案.但是,几乎所有Ruby实现都使用某种字节码或intcode格式,其中一些可以转储和重新加载字节码档案.

There is no portable bytecode specification for Ruby, and thus also no standard way to load precompiled bytecode archives. However, almost all Ruby implementations use some kind of bytecode or intcode format, and several of them can dump and reload bytecode archives.

YARV 始终在执行代码之前编译为字节码,但是通常仅在内存中完成.有几种方法可以将字节码转储到磁盘上. 目前,尚无办法将其读回 中.将来会有所改变:YARV的字节码验证程序正在进行中,一旦完成,便可以将字节码安全地加载到VM中,而不必担心损坏.此外,JRuby开发人员表示他们愿意实现 JRuby中的YARV VM模拟器,一旦YARV字节码格式和验证程序稳定下来,您就可以将YARV字节码加载到JRuby中. (请注意,此版本为已过时.)

YARV always compiles to bytecode before executing the code, however that is usually only done in memory. There are ways to dump out the bytecode to disk. At the moment, there is no way to read it back in, however. This will change in the future: work is underway on a bytecode verifier for YARV, and once that is done, bytecode can safely be loaded into the VM, without fear of corruption. Also, the JRuby developers have indicated that they are willing to implement a YARV VM emulator inside JRuby, once the YARV bytecode format and verifier are stabilized, so that you could load YARV bytecode into JRuby. (Note that this version is obsolete.)

Rubinius 也会始终编译为字节码,并且具有 JRuby中的Rubinius字节码模拟器,如果Rubinius字节码成为部署Ruby应用程序的流行方式. (请注意,此版本为已过时.)

Rubinius also always compiles to bytecode, and it has a format for compiled files (.rbc files, analogous to JVM .class files) and there is talk about a bytecode archive format (.rba files, analogous to JVM .jar files). There is a chance that Rubinius might implement a YARV emulator, if deploying apps as YARV bytecode ever becomes popular. Also, the JRuby developers have indicated that they are willing to implement a Rubinius bytecode emulator inside JRuby, if Rubinius bytecode becomes a popular way of deploying Ruby apps. (Note that this version is obsolete.)

XRuby 是一个纯编译器,它将Ruby源代码直接编译为JVM字节码(.class文件).您可以像部署其他Java应用程序一样部署这些.class文件.

XRuby is a pure compiler, it compiles Ruby sourcecode straight to JVM bytecode (.class files). You can deploy these .class files just like any other Java application.

JRuby 最初是作为解释器的,但它同时具有JIT编译器和 new 编译器的工作可以将Ruby代码编译(带有类型注释)为JVM字节码,实际上看起来像是Java类,并且可以在Java代码中使用而没有障碍.

JRuby started out as an interpreter, but it has both a JIT compiler and an AOT compiler (jrubyc) that can compile Ruby sourcecode to JVM bytecode (.class files). Also, work is underway to create a new compiler that can compile (type-annotated) Ruby code to JVM bytecode that actually looks like a Java class and can be used from Java code without barriers.

Ruby.NET 是将Ruby源代码编译为CIL字节码(PE .dll.exe文件).您可以像部署其他任何CLI应用程序一样部署它们.

Ruby.NET is a pure compiler that compiles Ruby sourcecode to CIL bytecode (PE .dll or .exe files). You can deploy these just like any other CLI application.

IronRuby 也可以编译为CIL字节码,但是通常在内存中进行.但是,您可以传递

IronRuby also compiles to CIL bytecode, but typically does this in-memory. However, you can pass commandline switches to it, so it dumps the .dll and .exe files out to disk. Once you have those, they can be deployed normally.

BlueRuby 自动预解析Ruby源代码到BRIL(BlueRuby中间语言)中,它基本上是一个序列化的parsetree. (请参见 Blue Ruby-SAP ABAP中的Ruby VM (PDF)了解详情.)

BlueRuby automatically pre-parses Ruby sourcecode into BRIL (BlueRuby Intermediate Language), which is basically a serialized parsetree. (See Blue Ruby - A Ruby VM in SAP ABAP(PDF) for details.)

认为(但我绝对不确定),有一种方法可以获取基数转储鹦鹉字节码档案. (实际上,Cardinal仅编译为PAST,然后由Parrot接管,因此,转储和加载字节码归档文件将是Parrot的工作.)

I think (but I am definitely not sure) that there is a way to get Cardinal to dump out Parrot bytecode archives. (Actually, Cardinal only compiles to PAST, and then Parrot takes over, so it would be Parrot's job to dump and load bytecode archives.)

这篇关于Ruby,PHP或Perl可以为Python之类的代码创建预编译文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆