Skip to main content
gamedev.net
🔒 Locked

How does bytecode work?

Started by olle55 2 replies 1.4k views
Original Post
olle55
olle55
Iv never understood how compiling script to bytecode works. A ascii script file interpeted by a interpreter i understand. But what happens when you compile a script to bytecode? It like.. becomes something other than ascii, is it still interpreted?
Raloth
Raloth
Yep.

However, it''s more efficient and easier/faster for the runtime to interpret. The slowdown of it can be taken away by compiling all the bytecode to native code at runtime (Just In Time compiling).
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
Fruny
Fruny
Each ''ascii statement'' is turned into a sequence of basic operations, each assigned a binary representation (bytecode).
Then you can have

a) a code tile-based compiler matching actual executable code to known ''tiles'' of bytecode.
b) a big switch statement (basically bytecode tiles of size 1) acting on the stream of bytecode.
c) other similar techniques


“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” — Brian W. Kernighan (C programming language co-inventor)
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Wyrframe
Wyrframe
Picture it this way, if you want...

A text file containing instructions and data contains instructions and expressions of variable length. Unpredictable by the interpreter. It has to check multiple bytes against a wide variety of multiple-byte values, and it has to do lots of conversion.

A binary file containing instructions and data contains instructions and data of predictable and fixed length. A single byte or word need only be checked against a variety of same-length values, or it could even be used as a simple index into an array of operation functions. Values are already in binary format, ready to be used by the computer without converting them from text. And complicated math or logic expressions are already broken down and optimized into individual small steps, easily executed without further thought.
RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.