Convert Ruby to low level languages?

后端 未结 6 745
Happy的楠姐
Happy的楠姐 2020-12-31 05:09

I have all kind of scripting with Ruby:

rails (symfony)
ruby (php, bash)
rb-appscript (applescript)

Is it possible to replace low level lan

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-31 05:53

    "Low level" is highly subjective. Many people draw the line differently, so for the sake of this argument, I'm just going to assume you mean compiling Ruby down to an intermediate form which can then be turned into machine code for your particular platform. I.e., compiling ruby to C or LLVM IR, or something of that nature.

    The short answer is yes this is possible.

    The longer answer goes something like this:

    Several languages (Objective-C most notably) exist as a thin layer over other languages. ObjC syntax is really just a loose wrapper around the objc_*() libobjc runtime calls, for all practical purposes.

    Knowing this, then what does the compiler do? Well, it basically works as any C compiler would, but also takes the objc-specific stuff, and generates the appropriate C function calls to interact with the objc runtime.

    A ruby compiler could be implemented in similar terms.

    It should also be noted however, that just by converting one language to a lower level form does not mean that language is instantly going to perform better, though it does not mean it will perform worse either. You really have to ask yourself why you're wanting to do it, and if that is a good reason.

提交回复
热议问题