Robo Home | Changes | Preferences | AllPages

The Crazy Idea

I (Strider) had a crazy idea I just had to try to implement. I got it when working on my nanobots. It's a way to cheat codesize.jar and fit more advanced code into the bot than would otherwise be possible. Because only bytecode counts and strings in the class file are free I though that it must be possible to put the actual code into strings and then execute them using an interpreter.

I have implemented an interpreter for a custom "bytecode". The interpreter is just over 700 bytes of bytecode so it fits in a microbot. I think java put a limit of 64Kb on strings so thats the limit of how advanced the bot can be. Well, the interpreted language puts a lot of constraints on what can be done.


The custom bytecode looks a bit like [funge]. It is hard to write, harder to read and probably impossible to debug, so don't expect any killer bot comming out of this. =)

The Code

You can get the code here: /Code

Size optimizations for the interpreter are very welcome.


Have anybody tried something like this before? -- Strider

Way cool that interpreter of yours. When will you release it? I'd like to try build a bot using it. Since I used to code in PostScript? some years ago I might have a head start with it. -- PEZ

The code is here now! -- Strider

Actually, I'm looking at a similar, smaller system for my next bot. What I was making, though, was a command queue, which would include commands like ahead(x), fire(y), turnRight(z). The idea was to set up an exact future for my bot. --Goofy

I just had the same idea and implemented an interpreter robot which fits into a MicroBot and can do theoretical everything a MegaBot can. I saw how you access the setters and getters - very flexible and small. We should take a look at the java API, perhaps java byte code can be executed from an byte array ( converted from String at runtime ) without SecurityException? If not, perhaps classes can be instantiated from a string ( especially Math and Streams ) --Sin Varg

My first thought would be the reflection API... --Alphax

You need a class loader to load from a byte array, and the security manager won't let you make your own class loader. So you have to interpret your byte or string manually. --David Alves

I have implemented a nano interpreter which runs a bit slowly and "requires" a compiler. The source is available here: Interpreter/NanoInterpreter. Comments? -- Kinsen

Uh oh. -- Simonton

You should get rid of the quotation marks. -- Zian

Has anyone tried writing a compiler to generate the shrunken bytecode String (besides Kinsen and I)? -- Zian

Not in my time here. -- Simonton

Robo Home | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited November 12, 2007 4:37 EST by 24-247-120-95.dhcp.klmz.mi.charter.com (diff)