Since Ruby lets you drop down into C for any bits where performance is critical and plain Ruby is not up to the task, and since C lets you drop down into assembly for the same sort of circumstance, I've always wondered if it would be possible to embed assembly language inside your Ruby code by first dropping down to C and then from within the C code dropping down to assembly.
因为Ruby允许您为任何比特性能下降到C纯Ruby并不是至关重要的任务,因为C可以降至装配同样的情况,我一直在想如果有可能嵌入汇编语言在你的Ruby代码,首先下降到C,然后从C代码中下降到组装。
I've always hoped that was possible, but never until now found anything to confirm or deny it. Because of research on Qt (and therefore C++) for a side project, I happened upon a statement on ruby-lang.com's comparison of Ruby with C & C++ that in Ruby
我一直希望这是可能的,但直到现在我才发现有什么可以证实或否认它。由于对Qt(以及c++)的研究,我偶然发现了Ruby -lang.com对Ruby中Ruby与c++的比较
- You cannot drop down to assembly
- 你不能下到大会。
Does this mean simply that you cannot go directly to assembly, or that you cannot do it by way of C at all? What about if you're writing an extension to Ruby in C: can I assume that since that is just C (not embedded in Ruby) you can still use assembly there and Ruby can still use the C extension with assembly in it?
这是否仅仅意味着你不能直接去装配,或者你根本不能用C实现?如果您正在用C编写Ruby的扩展:我是否可以假设,因为那只是C(不是嵌入在Ruby中),您仍然可以在那里使用汇编,而Ruby仍然可以使用带有程序集的C扩展?
1 个解决方案
#1
6
Given the context, it seems pretty clear that it means in Ruby, you can't just drop something crazy like:
考虑到上下文,很明显,在Ruby中,它的意思是,你不能像:
def func1(arr)
arr.map { |v| func2(v) }
end
def func2(val)
asm do
mov ax, 1234h
mov bx, ax
end
end
Ruby can't stop you from using something like that in a linked C object.
Ruby无法阻止您在链接的C对象中使用类似的东西。
But, having seen that as an example, it'd be a pretty cool library if someone made it. :)
但是,作为一个例子,如果有人创建了它,它将是一个非常酷的库。:)
#1
6
Given the context, it seems pretty clear that it means in Ruby, you can't just drop something crazy like:
考虑到上下文,很明显,在Ruby中,它的意思是,你不能像:
def func1(arr)
arr.map { |v| func2(v) }
end
def func2(val)
asm do
mov ax, 1234h
mov bx, ax
end
end
Ruby can't stop you from using something like that in a linked C object.
Ruby无法阻止您在链接的C对象中使用类似的东西。
But, having seen that as an example, it'd be a pretty cool library if someone made it. :)
但是,作为一个例子,如果有人创建了它,它将是一个非常酷的库。:)