首页 \ 问答 \ OCaml字节码的可移植性(Portability of OCaml bytecode)

OCaml字节码的可移植性(Portability of OCaml bytecode)

我在x86机器上用字节码编译OCaml程序,并将字节码传送到ppc64机器。 假设ppc64机器有ocamlrun(编译为ppc64),我能在ppc64架构上执行我的程序吗? 这么简单吗?

换句话说,字节码是否符合字节序?

如果没有,那么字节码的目的是什么?


I compile an OCaml program in bytecode on an x86 machine, and transfer the bytecode to a ppc64 machine. Assuming that the ppc64 machine has ocamlrun (compiled for ppc64), will I be able to execute my program on the ppc64 architecture ? Is it that simple ?

In other terms, is the bytecode resistant to endianness ?

If not, then what is the purpose of the bytecode ?


原文:https://stackoverflow.com/questions/34814010
更新时间:2023-02-20 15:02

最满意答案

根据规范 ,在"12345" >> 0 ,会发生这种情况:

  1. "12345"通过规范的抽象ToInt32函数
    • ToInt32通过ToNumber运行它以将字符串强制转换为标准JavaScript号(IEEE-754双精度二进制浮点值); 它最终成为12345
    • ToInt32然后将其转换为32位整数值; 它最终成为...... 12345
  2. 这个32位整数被移位......完全没有,因为你使用了>> 0 ,所以我们仍然有12345

并将返回一个int

有点。 如果将结果存储在变量中,它最终将再次成为标准JavaScript编号(双精度)。 如果将这个操作与其他操作相结合,那么规范似乎允许将int值原样使用,这是有道理的。

如果您的目标只是使用默认的强制规则强制"12345"为数字,则>> 0是一种相当模糊且有些低效的方法(不是后者可能很重要)。 一元+更直接并适用相同的规则: +"12345"


According to the specification, in "12345" >> 0, this happens:

  1. "12345" is put through the specification's abstract ToInt32 function:
    • ToInt32 runs it through ToNumber to coerce the string to a standard JavaScript number (an IEEE-754 double-precision binary floating-point value); it ends up being 12345
    • ToInt32 then converts it to a 32-bit integer value; it ends up being...12345
  2. That 32-bit integer is shifted...not at all because you used >> 0, so we still have 12345

and will return a int

Sort of. If you stored the result in a variable, it would end up being a standard JavaScript number again (a double). The spec seems to allow for the possibility the int value would be used as-is if you combined this operation with others, though, which makes sense.

If your goal is just to force "12345" to be a number using the default coercion rules, >> 0 is a fairly obscure and somewhat inefficient way to do it (not that the latter is likely to matter). The unary + is rather more direct and applies the same rules: +"12345"

相关问答

更多
  • 你肯定做的工作超出了你的需要。 注意函数ReverseBits()如何努力将反转字的字节按正确的顺序排列,以及下一个发生的事情 - 你将减速的部分归因于 - 重新排序那些相同的字节。 您可以编写并使用ReverseBits()的修改版本, ReverseBits()反转表示的字节直接放入数组中的正确位置,而不是将它们打包成整数,只是为了再次解压缩它们。 这应该至少要快一点,因为你会严格删除操作。 You're certainly doing more work than you need to do. No ...
  • public static string ToHex(byte[] bytes) { char[] c = new char[bytes.Length * 2]; byte b; for (int bx = 0, cx = c.Length - 1; bx < bytes.Length; ++bx) { b = ((byte)(bytes[bx] & 0x0F)); c[cx--] = (char)(b > 9 ? b + 0x37 + 0x2 ...
  • 你所看到的可能是算术位移 。 当向右移动时,最左边的位(通常是有符号整数表示中的符号位)被复制以填充所有空置位置(这是一种符号扩展)。 C99标准 6.5.7§5说: E1 >> E2的结果是E1右移E2位的位置。 [...]如果E1有签名类型和负值,则结果值是实现定义的。 所以结果可能是编译器作者决定的任何东西。 他们可能决定扩展符号位,编译器文档应该提及它。 What you are seeing is probably arithmetic bit shift. when shifting to th ...
  • 根据规范 ,在"12345" >> 0 ,会发生这种情况: "12345"通过规范的抽象ToInt32函数 : ToInt32通过ToNumber运行它以将字符串强制转换为标准JavaScript号(IEEE-754双精度二进制浮点值); 它最终成为12345 ToInt32然后将其转换为32位整数值; 它最终成为...... 12345 这个32位整数被移位......完全没有,因为你使用了>> 0 ,所以我们仍然有12345 并将返回一个int 有点。 如果将结果存储在变量中,它最终将再次成为标准Jav ...
  • 16^(n - i -1) = 2^(4 * (n - i -1)) 2^x = 1 << x. 因此: 16^(ni-1) = 1 << (4 * (n -i -1)) (使用^符号表示“对于权力”,而不是XOR) 16^(n - i -1) = 2^(4 * (n - i -1)) 2^x = 1 << x. Therefore: 16^(n-i-1) = 1 << (4 * (n -i -1)) (Using the ^ symbol to mean "to the power of", not XO ...
  • 对于您显示的枚举,以下内容将起作用: int dbValue = ...; var status = (Status)dbValue; 如果数据库值只能取三个值中的一个 - 0(活动),1(空白),2(退款) - 则可能更清楚地使您的枚举具有以下等效值。 public enum Status { Active = 0, Voided = 1, Refunded = 2 } 你使用的位移建议一个位字段,但这不是你实际处理的。 拥有Status.Voided | Status.Ref ...
  • 我知道它有时被用作将浮点值截断为整数的丑陋方式 不完全是。 value >>> 0是使用ToUint32(value)抽象操作的唯一公开方式。 数组具有不变量,即它们的长度必须是Uint32值: 每个Array对象都有一个length属性,其值始终是小于2 32的非负整数。 这就是为什么规范在数组方法定义中使用ToUint32的原因。 Polyfill使用>>> 0而不是ToUint32,因为ToUint32没有暴露给JS代码。 您需要使用ToUint32,因为您无法知道它在数组方法中的含义,它可以是非数组 ...
  • 如果你的意思是一个实际的char数组,你可以使用memmove()和memset() : char str[] = "0000000101"; int shift = 3; int length = strlen(str); memmove(str, str + shift,length - shift); memset(str + length - shift,'0',shift); // Result: // "0000101000" If you meant an actual char ...
  • charCodeAt函数接受一个索引,而不是一个字符串。 当你传递一个字符串时,它会尝试将字符串转换为数字,如果不能,则使用0 。 你的第一次迭代调用'1'.charCodeAt('1') 。 它会将'1'解析为一个数字并尝试获取字符串中的第二个字符代码。 由于字符串只有一个字符,这就是NaN 。 你的第二次迭代调用'f'.charCodeAt('f') 。 由于'f'不能被解析为一个数字,它会被解释为0 ,这会给你第一个字符代码。 您应该编写var hexval = result.charCodeAt(i ...
  • 这是使用系数0.59和0.11将24位RGB值转换为灰度值的技巧(请注意,这些值加起来为1 )。 此操作(rgbValue & 0xFF0000) >>> 16将位17..24切除,并将它们右移到位置0..7,产生0到255之间的值,包括0和255。 类似地, (rgbValue & 0xFF00) >>> 8切出位8..16,并将它们移位到位置0..7。 本问答讨论了系数,并讨论了其他替代方案。 This is the trick that converts a 24-bit RGB value to a ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。