Skip to main content
GameDev.net gamedev.net
🔒 Locked

2 compile or 2 interpret?

Started by vesoljc Nov 19, 2003 at 4:09 PM 8 replies 650+ views
Original Post
vesoljc
vesoljc
is it possible to have a piece of compiled code that would run on any platform? or can something like that only be achived with jit compilation or interpretation?
Abnormal behaviour of abnormal brain makes me normal...www.zootfly.com
Krysole
Krysole
short answer: no

not so short answer: it depends [read below]

the binary format is different not only for different cpu archetectures but also for different operating systems

this means that to use a single type of binary some sort of intermediate language or byte code is required (or you will have to translate the chosen binary format to the platform your program is executing on)

that said you could use a host program that reads a binary stream and processes it for execution only replacing small pieces of code that wont work on the current os (defined by the host executable designed for that platform)

unfortunately such a method requires some effort much of which is already done if you were to use a IM/bytecode format and if you were to use a bytecode/IM format the code would also run on multiple platforms!

you might also like to know that you can find specs and indeed use with your own compiler java, tcl, and most other bytecode formats available (even .NET afaik)

< krysole || krysollix >
cmdkeen
cmdkeen
What about Windows NT/2000 with it''s POSIX and OS/2 sub systems? I remember it could run unix and os/2 programs "natively" - or does it require a recompile?
vesoljc
vesoljc
my idea was to have an os specific shell app (host program) with os specific modules (via dynamic libs). so, the whole real code would be implemented this way. tthe second part of the plan, was to have a one portable piece of code (would act just like a "ROM"), which would run on any shell.

quote:
Original post by Krysole
that said you could use a host program that reads a binary stream and processes it for execution only replacing small pieces of code that wont work on the current os (defined by the host executable designed for that platform)



soo, if the whole real code is in the modules, how much of this code is required to be replaced ??? ie: if the "user" (app) only calls the functions from the dyn libs?

quote:
Original post by Krysole
...if you were to use a IM/bytecode format and if you were to use a bytecode/IM format the code would also run on multiple platforms!



bytecode is java, right?
but IM is what?
Abnormal behaviour of abnormal brain makes me normal...www.zootfly.com
Shannon Barber
Shannon Barber
quote:
Original post by cmdkeen
What about Windows NT/2000 with it's POSIX and OS/2 sub systems? I remember it could run unix and os/2 programs "natively" - or does it require a recompile?


Natively means you can recompile on that platform - meaning no translation, interpretor, virtual-machine, nor thrid-party-libraries arerequired.

[edited by - Magmai Kai Holmlor on November 20, 2003 9:39:12 PM]
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Shannon Barber
Shannon Barber
quote:
Original post by vesoljc
bytecode is java, right?
but IM is what?


Intermediate Language, it''s for .Net and is a bit like a virtual assembly language.
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Krysole
Krysole
thanks magmai, it should have indeed said IL or intermediate language.

bytecode is a term that describes a 'fake' archetecture or instruction set, java's bytecode is one such instruction set and so is tcl's bytecode is another. Java bytecode is often mistaken as the only type of bytecode since there are now real archetectures that can execute bytecode natively (think mobile phones:D)

as for the amount of code that must be replaced as it is running, well you'll need a support library that is cross platform otherwise your binary will be unable to call into the system, this means you must build your own jump tables although hacking microsofts pe format might be better and just use their jump tables. Then a search algo that looks for code that would crash the current platform must be replaced with code that wont (not because the platform is bad but simply because it is different).

in the end the two above points are only just the beginning, i suggest you just recompile your program and use portable code, the people of each platform will love you for it too! or consider reading a book on system ordering, operating systems, and assembler so that you better understand the intricites of instruction sets and how they apply to platform specific binary files.

< krysole || krysollix >

edit: forgot to mention a good text; Art of Assembler i've only read the first third of the text and even then only the dos/real mode version (there's a win32 version too! based on HLA) but it's really an eye opener if you've never done anything so 'low-level' before! great fun and you'll learn asm too:D

[edited by - krysole on November 21, 2003 3:51:46 AM]
vesoljc
vesoljc
soo, if going the interpret way, how fast can we go?
75%?
Abnormal behaviour of abnormal brain makes me normal...www.zootfly.com
Shannon Barber
Shannon Barber
Interpreted? I''d be impressed with anything over about 5%.
That''s the reason for byte-code, you can get ~20%.

To make up for these gross differences in performance, interpreters come with a pile of natively compiled functions that you call to do work (so you don''t have to write strlen in the interpreted language). Virtual-machines also have just-in-time compilers (to turn the byte-code into op codes) in addition to compiled-in functions (and classes).

The latter mechanism approaches natively-compiled speeds once the JIT process has completed (and given sufficient memory and memory bandwidth - the memory demands are greater than a natively app).
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
vesoljc
vesoljc
damn...

so, what am i to do? or better yet, how???
Abnormal behaviour of abnormal brain makes me normal...www.zootfly.com

Topic Locked

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

Sign in to reply to this topic.