I've been thinking of how machine code is specific to architecture and how Javascript works in (nearly)every browser. I've been working on a project that has to do some serious calculations and it is Javascript based and takes a full minute to finish the calculating. It makes me long for the speed of C. But the whole reason the project is in Javascript is for simplicity and portability.

Which gave me the idea, what if there was a language similar to Javascript that was just as portable and ran as an executable file on every architecture? Most people would point to Java, but I'm thinking something with less overhead and handled by the OS. Not byte code but native machine code.

Did a bit of researching and thinking to come to the impossibility of this task. How would you make an executable file as small as the normal C written application for a specific architecture that works on every architecture with the same speed as if it were natively compiled in C for that architecture?

Which comes to my next idea. Native machine code is specific to architecture, each architecture has certain special features and sometimes handles the same task differently. Also certain optimizations are specific per architecture. What if there was a Universal Machine Code? When the OS loads the instructions into ram, it automagically converts the instructions to adapt to the architecture. Or perhaps (crazier idea) the CPU could contain the ability to receive the universal machine code and automatically adapts the universal machine code into it's native machine code?

The Universal Machine Code specification would have to be generic enough to cover the normal Machine Code functions.

Of course if the Universal Machine Code did work, people would probably want a universal executable format that's handled by all OSes. That way the executable need not change across OSes. Which leads to frameworks that need to be made specifically to be universal across machines. And more nitty gritty would be OS specific features, and the ability for input and output which is going beyond what I know.

Universal Machine Code compiled executable:

Pros:

  • Nearly same size as a native compiled executable
  • Nearly if not the same performance of a native compiled executable

Cons:

  • Slightly(hopefully non-existantly) slower in loading as it converts the universal machine code to native machine code when loading the executable in ram

Is it feasible?

Edit:

I have used Java, made a game in it. It's not as *universal as I'd like, nor as friendly. * It is it's own programming language, maintained by Oracle. Proprietary and a bit too massive. Requires installation on some machines.

And to be more specific I'm not talking about having a new programming language. I'm talking about having a new machine code language that holds enough extra information that when executed, a very thin process of translating it to the architecture's machine code happens. That way C compilers can just compile their executables into the universal machine code and the executables could run everywhere.

有帮助吗?

解决方案

there's already something like that, its called p-code

http://en.wikipedia.org/wiki/P-code_machine

these days, VMs basically act in that role

其他提示

Lambda calculus and/or Turing machines. Everything else is just syntactic sugar.

You wont get chip vendors to agree on a universal machine code. And one vendor cannot take over the world with a single new machine code otherwise they would have (ARM almost has but really in the end it wont).

With todays patent litigation you cant even make a VLIW processor and in a thin software layer mimic various instruction sets, and you couldnt take over the world with that anyway, can you say transmeta?

So you are stuck with an interpreter...in software. So it goes back to the "already tried that" of JAVA and the p-code from decades past (pascal), and whatever python is doing, etc. Even llvms bytecode for that matter.

Your requirement of "same speed on every machine" that wont happen.

You are already using the most portable language in javascript, and it is as fast as it is. C is the universal language you are after and it is fairly fast and runs everywhere (more than any other language), problem is the operating systems and more than that the user interfaces.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top