Jump to content
  • Advertisement
Sign in to follow this  
Triad_prague

compile script bytecode into machine code

This topic is 2544 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I've just finished working on my scripting language, debugging, improving things, and I think it's usable now. However, scripts are currently compiled into byte codes that get sent to the virtual machine and get executed. I think I ever heard that some scripting language can compile their scripts into machine language. This is where I get a bit skeptical.

Is it really true? if so, how is the compilation process? how does it get executed by the application? does it get "appended" into the .exe or does the machine code stored somewhere else (another file / somewhere in RAM)?

Another question...I can compile a single .cpp file into an .obj file using standard MSVC compiler, what does that file contain? I guess those .obj files are going to be linked in the final step, is it right? CMIIW :D

Share this post


Link to post
Share on other sites
Advertisement
Yes, this is true. It's usually called just-in-time compilation. Generally the machine code get's loaded into memory and cast to an appropriate function pointer type and that function pointer is invoked like any other function pointer.

An object file contains machine code for functions as well as language support data structures such as virtual function tables, RTTI structures and other static data like global function initialization information.

Share this post


Link to post
Share on other sites
Thx for the reply, anyway I've been googling to get some info about the detail of that (compiling script's bytecode into machine code and how to execute it), but I couldn't find any (this is kinda 'new' to me). Can anyone give a "hint" (keyword or link) so I can get more info about it? thx before btw :lol:

Share this post


Link to post
Share on other sites

Thx for the reply, anyway I've been googling to get some info about the detail of that (compiling script's bytecode into machine code and how to execute it), but I couldn't find any (this is kinda 'new' to me). Can anyone give a "hint" (keyword or link) so I can get more info about it? thx before btw :lol:


What kind of information are you looking for? It's just like compiling anything else--C++, C, etc. except instead of compiling it from the original source, you compile it from an intermediate byte code format. There are certain tricks that can be used, but the general idea is just like compiling anything else. SiCrane's link should give you lots of terms to google for and things on Wikipedia to click. Once it's compiled into the machine's native language, it's pretty easy to execute it. Like SiCrane said, once it's compiled into machine code, that machine code can be "loaded into memory and cast to an appropriate function pointer type and that function pointer is invoked like any other function pointer."

Share this post


Link to post
Share on other sites

SiCrane's link should give you lots of terms to google for and things on Wikipedia to click.

... including the websites for multiple open-source JIT libraries that you can look at the source for.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!