views:

107

answers:

4

I'm looking for a fast and much lightweight as possible open source virtual machine for implementing my custom programming language. The virtual machine should support some minimal set of bytecode (like LLVM IR), but can easily embedable from a C++ application (which filters out LLVM from the list). It should be wrriten in C/C++.

I'm looking for something like Dalvik, but cross platform (Linux, Windows and OS X) and supports x86 at least.

Thanks.

+1  A: 

Lua is famous for being ridiculously easy to embed in C/C++. Its VM is open source and cross-platform, very small (both exe size and bytecode instruction set) and at the same time quite fast. But its bytecode may be not suitable for your language. The bytecode format is documented here.

delnan
Lua's VM is not general purpose VM but it may work for your custom language if your language and Lua are not too far apart semantically. A short description of Lua's VM is at http://www.lua.org/source/5.1/lopcodes.h.html#OP_MOVE . If you go this way, I suggest you first try to compile your language to Lua source code.
lhf
A: 

NekoVM is a programming language and a lightweight virtual machine designed as a generic target for compiler writers. The documentation makes it seem really easy to embed the VM in a C or C++ application, but it seems the VM API is not yet documented.

Jon Purdy
A: 

Why filter out LLVM ? It's a set of C libraries

I guess it's not as easy to embed than Lua, but LLVM is so great that it would probably overcome the hassle of integrating it. See this SO question, does it help ?

Calvin1602
A: 

Other possible answer : why not output assembler instead ? it's fast and lightweight, and you don't need a VM at all. Since you target x86 only, it could make sense, depending on what you're trying to do.

Calvin1602