9

As the title indicates, are there any C/C++ bytecode compilers/interpreters? I'm writing an application in an interpreted language that depends on certain libraries that are fully cross-compilable (there are no special flags to indicate code changes during compilation for a certain platform) but are written in C and C++. Rather than shipping n-platform-specific-libs with each platform, it would be nice to ship one set of libs which are interpreted by one platform specific interpreter.

Possible and/or available?

EDIT1: The interpreted language in question is Python, though I may also use Ruby.

rene
  • 41,474
  • 78
  • 114
  • 152
Matt
  • 515
  • 3
  • 16
  • 2
    What interpreted language? Many of the more popular ones have portable ways to add C (and maybe C++) extensions. – Chris Lutz Apr 04 '10 at 21:47
  • 1
    `llvm-gcc` and `clang` exist within LLVM for this job, i think. – Johannes Schaub - litb Apr 04 '10 at 21:49
  • The language is python, though I may also use Ruby. I may use both or one or the other, all I have a diagram so I haven't really started yet. – Matt Apr 04 '10 at 22:12
  • Both Python and Ruby have standardized ways to write (and probably distribute) C extensions. Maybe also C++ extensions, but if not, you can write C wrappers for the C++ code you need. – Chris Lutz Apr 04 '10 at 22:20
  • 1
    http://stackoverflow.com/questions/1189097/c-interpreter-console-snippet-compiler, http://stackoverflow.com/questions/69539/have-you-used-any-of-the-c-interpreters-not-compilers, http://stackoverflow.com/questions/759279/run-interpret-c and I think a few others answer the questions "Are there c++ interpreters in the affirmative. I'm not sure that they are duplicates *per se*, but I think that they are the best you're going to do. Answer: cint, ch. – dmckee --- ex-moderator kitten Apr 05 '10 at 00:45

2 Answers2

3

Which interpreted language are you using? If it has a .NET based implementation (e.g. IronPython) you could possibly use it with the C++/CLI compiler to produce byte code for the .NET CLR and Mono.

This is only likely to be feasible if you have full control over your C++ libraries.

richj
  • 7,499
  • 3
  • 32
  • 50
  • I honestly hadn't thought of doing that. – Matt Apr 04 '10 at 22:09
  • Using Mono may not be the most stable way to accomplish this. Especially for Python, which already has portable ways to distribute C extensions. – Chris Lutz Apr 04 '10 at 22:22
  • Using the standard approach, the Python code is portable, but the C/C++ libraries have to be recompiled for each platform. The standard approach might have advantages over the CLR/Mono approach, but it doesn't meet the "ship one set of libs which are interpreted by one platform specific interpreter" requirement for the C/C++ libraries. – richj Apr 04 '10 at 22:46
  • My point is that you can just ship the C source, and let the receiver compile it the normal way. – Chris Lutz Apr 04 '10 at 23:45
1

If you are not sure about using the .NET VM/CLR, then you could give the Java VM a try with LLJVM (via llvm-gcc) and either Jython or JRuby.

clstrfsck
  • 14,715
  • 4
  • 44
  • 59